aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/bytecode/LineNumberAttribute.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-31 05:56:29 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2003-12-31 05:56:29 +0000
commit33894b1cae728946d3363b5ad27fcbfcf33c86d1 (patch)
tree3f430ab69c49cca58ea0114f60bf211d57948303 /src/main/javassist/bytecode/LineNumberAttribute.java
parentba0a3e173968737f8683069775e491d3b8764a9d (diff)
downloadjavassist-33894b1cae728946d3363b5ad27fcbfcf33c86d1.tar.gz
javassist-33894b1cae728946d3363b5ad27fcbfcf33c86d1.zip
CtBehavior#insertAt() and support methods have been implemented.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@63 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode/LineNumberAttribute.java')
-rw-r--r--src/main/javassist/bytecode/LineNumberAttribute.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/javassist/bytecode/LineNumberAttribute.java b/src/main/javassist/bytecode/LineNumberAttribute.java
index 0a6df55a..6d892aab 100644
--- a/src/main/javassist/bytecode/LineNumberAttribute.java
+++ b/src/main/javassist/bytecode/LineNumberAttribute.java
@@ -103,6 +103,53 @@ public class LineNumberAttribute extends AttributeInfo {
}
/**
+ * Used as a return type of <code>toNearPc()</code>.
+ */
+ static public class Pc {
+ /**
+ * The index into the code array.
+ */
+ public int index;
+ /**
+ * The line number.
+ */
+ public int line;
+ }
+
+ /**
+ * Returns the index into the code array at which the code for
+ * the specified line (or the nearest line after the specified one)
+ * begins.
+ *
+ * @param line the line number.
+ * @return a pair of the index and the line number of the
+ * bytecode at that index.
+ */
+ public Pc toNearPc(int line) {
+ int n = tableLength();
+ int nearPc = 0;
+ int distance = 0;
+ if (n > 0) {
+ distance = lineNumber(0) - line;
+ nearPc = startPc(0);
+ }
+
+ for (int i = 1; i < n; ++i) {
+ int d = lineNumber(i) - line;
+ if ((d < 0 && d > distance)
+ || (d >= 0 && (d < distance || distance < 0))) {
+ distance = d;
+ nearPc = startPc(i);
+ }
+ }
+
+ Pc res = new Pc();
+ res.index = nearPc;
+ res.line = line + distance;
+ return res;
+ }
+
+ /**
* Makes a copy.
*
* @param newCp the constant pool table used by the new copy.
@@ -118,4 +165,17 @@ public class LineNumberAttribute extends AttributeInfo {
LineNumberAttribute attr = new LineNumberAttribute(newCp, dest);
return attr;
}
+
+ /**
+ * Adjusts start_pc if bytecode is inserted in a method body.
+ */
+ void shiftPc(int where, int gapLength, boolean exclusive) {
+ int n = tableLength();
+ for (int i = 0; i < n; ++i) {
+ int pos = i * 4 + 2;
+ int pc = ByteArray.readU16bit(info, pos);
+ if (pc > where || (exclusive && pc == where))
+ ByteArray.write16bit(pc + gapLength, info, pos);
+ }
+ }
}