-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #484 from kuznet1/master
Line numbers support
- Loading branch information
Showing
49 changed files
with
958 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/javassist/bytecode/LineNumberAttributeBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package javassist.bytecode; | ||
|
||
import javassist.compiler.ast.ASTree; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class LineNumberAttributeBuilder { | ||
private final HashMap<Integer, Integer> map = new HashMap<>(); | ||
|
||
public void put(int newPc, ASTree tree) { | ||
if (tree != null) | ||
put(newPc, tree.getLineNumber()); | ||
} | ||
|
||
private void put(int newPc, int lineNum) { | ||
Integer pc = map.get(lineNum); | ||
if (pc == null || newPc < pc) { | ||
map.put(lineNum, newPc); | ||
} | ||
} | ||
|
||
public LineNumberAttribute build(ConstPool cp) { | ||
int size = map.size(); | ||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(size * 4 + 2); | ||
DataOutputStream dos = new DataOutputStream(bos)) { | ||
dos.writeShort(size); | ||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) { | ||
dos.writeShort(entry.getValue()); | ||
dos.writeShort(entry.getKey()); | ||
} | ||
return new LineNumberAttribute(cp, bos.toByteArray()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.