@@ -1,9 +1,10 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<classpath> | |||
<classpathentry kind="src" path="src"/> | |||
<classpathentry kind="src" path="verifier-src"/> | |||
<classpathentry kind="src" path="testsrc"/> | |||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | |||
<classpathentry kind="lib" path="/lib/regexp/jakarta-regexp-1.2.jar"/> | |||
<classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar"/> | |||
<classpathentry kind="lib" path="/lib/junit/junit.jar" sourcepath="/lib/junit/junit-src.jar"/> | |||
<classpathentry kind="output" path="bin"/> | |||
</classpath> |
@@ -1,10 +1,5 @@ | |||
<project name="bcel-builder" default="packageAndPush" basedir="."> | |||
<!-- *********************************************************************** --> | |||
<!-- compliance for Alex build --> | |||
<!-- *********************************************************************** --> | |||
<!--<import file="../build/build-common.xml"/>--> | |||
<path id="bcel-builder.test.src.path"> | |||
<fileset dir="${basedir}/../lib"> | |||
<include name="junit/*.jar"/> | |||
@@ -21,7 +16,6 @@ | |||
<target name="cleanall" depends="clean"> | |||
<delete dir="bin"/> | |||
<delete dir="bintest"/> | |||
<!-- FIXME: not consistent with Alex policy --> | |||
<mkdir dir="bin"/> | |||
</target> | |||
@@ -63,14 +57,20 @@ | |||
<target name="push"> | |||
<copy file="bcel.jar" todir="../lib/bcel" /> | |||
<copy file="bcel-verifier.jar" todir="../lib/bcel" /> | |||
<copy file="bcel-src.zip" todir="../lib/bcel" /> | |||
<copy file="bcel-verifier-src.zip" todir="../lib/bcel" /> | |||
<delete file="bcel.jar"/> | |||
<delete file="bcel-verifier.jar"/> | |||
<delete file="bcel-src.zip"/> | |||
<delete file="bcel-verifier-src.zip"/> | |||
</target> | |||
<target name="buildTheJars"> | |||
<zip file="bcel.jar" basedir="bin" includes="**/*" excludes="**/tests/*.class"/> | |||
<zip file="bcel-src.zip" basedir="src" includes="**/*"/> | |||
<zip file="bcel.jar" basedir="bin" includes="**/*" excludes="**/tests/*,**/verifier/**/*,**/tests"/> | |||
<zip file="bcel-verifier.jar" basedir="bin" includes="**/verifier/**/*" excludes="**/tests,**/tests/*"/> | |||
<zip file="bcel-src.zip" basedir="src" includes="**/*" excludes="**/tests/*.java,**/verifier/**/*"/> | |||
<zip file="bcel-verifier-src.zip" basedir="verifier-src" includes="**/verifier/**/*" excludes="**/tests,**/tests/*"/> | |||
</target> | |||
<target name="diff" depends="transformFromAJ,pack"> |
@@ -1,310 +0,0 @@ | |||
diff -N -a -u -r -b bcel-5.1/build.xml bcel/build.xml | |||
--- bcel-5.1/build.xml 2003-04-25 09:06:14.000000000 +0100 | |||
+++ bcel/build.xml 2004-08-11 21:25:17.449281600 +0100 | |||
@@ -65,7 +65,7 @@ | |||
<target name="build" depends="compile"/> | |||
<!-- Jar the library --> | |||
- <target name="jar" depends="examples"> | |||
+ <target name="jar" depends="init,compile"> | |||
<jar jarfile="${build.dir}/${name}.jar" | |||
basedir="${build.dest}" | |||
manifest="${basedir}/manifest.txt" | |||
diff -N -a -u -r -b bcel-5.1/manifest.txt bcel/manifest.txt | |||
--- bcel-5.1/manifest.txt 1970-01-01 00:00:00.000000000 +0000 | |||
+++ bcel/manifest.txt 2004-08-11 21:25:17.509368000 +0100 | |||
@@ -0,0 +1,3 @@ | |||
+Created-By: Jakarta BCEL 5.1 | |||
+Manifest-Version: 1.0 | |||
+Main-Class: listclass | |||
diff -N -a -u -r -b bcel-5.1/src/java/org/apache/bcel/generic/Instruction.java bcel/src/java/org/apache/bcel/generic/Instruction.java | |||
--- bcel-5.1/src/java/org/apache/bcel/generic/Instruction.java 2003-04-25 09:06:16.000000000 +0100 | |||
+++ bcel/src/java/org/apache/bcel/generic/Instruction.java 2004-08-11 21:28:49.424086400 +0100 | |||
@@ -190,26 +190,223 @@ | |||
Class clazz; | |||
try { | |||
- clazz = Class.forName(className(opcode)); | |||
- } catch (ClassNotFoundException cnfe){ | |||
- // If a class by that name does not exist, the opcode is illegal. | |||
- // Note that IMPDEP1, IMPDEP2, BREAKPOINT are also illegal in a sense. | |||
- throw new ClassGenException("Illegal opcode detected."); | |||
+ switch(opcode) { | |||
+ case Constants.NOP: obj = new NOP(); break; | |||
+ case Constants.ACONST_NULL: obj = new ACONST_NULL(); break; | |||
+ case Constants.ICONST_M1: | |||
+ case Constants.ICONST_0: | |||
+ case Constants.ICONST_1: | |||
+ case Constants.ICONST_2: | |||
+ case Constants.ICONST_3: | |||
+ case Constants.ICONST_4: | |||
+ case Constants.ICONST_5: obj = new ICONST(); break; | |||
+ case Constants.LCONST_0: | |||
+ case Constants.LCONST_1: obj = new LCONST(); break; | |||
+ case Constants.FCONST_0: | |||
+ case Constants.FCONST_1: | |||
+ case Constants.FCONST_2: obj = new FCONST(); break; | |||
+ case Constants.DCONST_0: | |||
+ case Constants.DCONST_1: obj = new DCONST(); break; | |||
+ case Constants.BIPUSH : obj = new BIPUSH(); break; | |||
+ case Constants.SIPUSH : obj = new SIPUSH(); break; | |||
+ case Constants.LDC : obj = new LDC(); break; | |||
+ case Constants.LDC_W: obj = new LDC_W(); break; | |||
+ case Constants.LDC2_W: obj = new LDC2_W(); break; | |||
+ case Constants.ILOAD : obj = new ILOAD(); break; | |||
+ case Constants.LLOAD : obj = new LLOAD(); break; | |||
+ case Constants.FLOAD : obj = new FLOAD(); break; | |||
+ case Constants.DLOAD : obj = new DLOAD(); break; | |||
+ case Constants.ALOAD : obj = new ALOAD(); break; | |||
+ case Constants.ILOAD_0: | |||
+ case Constants.ILOAD_1: | |||
+ case Constants.ILOAD_2: | |||
+ case Constants.ILOAD_3: obj = new ILOAD(); break; | |||
+ case Constants.LLOAD_0: | |||
+ case Constants.LLOAD_1: | |||
+ case Constants.LLOAD_2: | |||
+ case Constants.LLOAD_3: obj = new LLOAD(); break; | |||
+ case Constants.FLOAD_0: | |||
+ case Constants.FLOAD_1: | |||
+ case Constants.FLOAD_2: | |||
+ case Constants.FLOAD_3: obj = new FLOAD(); break; | |||
+ case Constants.DLOAD_0: | |||
+ case Constants.DLOAD_1: | |||
+ case Constants.DLOAD_2: | |||
+ case Constants.DLOAD_3: obj = new DLOAD(); break; | |||
+ case Constants.ALOAD_0: | |||
+ case Constants.ALOAD_1: | |||
+ case Constants.ALOAD_2: | |||
+ case Constants.ALOAD_3: obj = new ALOAD(); break; | |||
+ case Constants.IALOAD : obj = new IALOAD(); break; | |||
+ case Constants.LALOAD : obj = new LALOAD(); break; | |||
+ case Constants.FALOAD : obj = new FALOAD(); break; | |||
+ case Constants.DALOAD : obj = new DALOAD(); break; | |||
+ case Constants.AALOAD : obj = new AALOAD(); break; | |||
+ case Constants.BALOAD : obj = new BALOAD(); break; | |||
+ case Constants.CALOAD : obj = new CALOAD(); break; | |||
+ case Constants.SALOAD : obj = new SALOAD(); break; | |||
+ case Constants.ISTORE : obj = new ISTORE(); break; | |||
+ case Constants.LSTORE : obj = new LSTORE(); break; | |||
+ case Constants.FSTORE : obj = new FSTORE(); break; | |||
+ case Constants.DSTORE : obj = new DSTORE(); break; | |||
+ case Constants.ASTORE : obj = new ASTORE(); break; | |||
+ case Constants.ISTORE_0: | |||
+ case Constants.ISTORE_1: | |||
+ case Constants.ISTORE_2: | |||
+ case Constants.ISTORE_3: obj = new ISTORE(); break; | |||
+ case Constants.LSTORE_0: | |||
+ case Constants.LSTORE_1: | |||
+ case Constants.LSTORE_2: | |||
+ case Constants.LSTORE_3: obj = new LSTORE(); break; | |||
+ case Constants.FSTORE_0: | |||
+ case Constants.FSTORE_1: | |||
+ case Constants.FSTORE_2: | |||
+ case Constants.FSTORE_3: obj = new FSTORE(); break; | |||
+ case Constants.DSTORE_0: | |||
+ case Constants.DSTORE_1: | |||
+ case Constants.DSTORE_2: | |||
+ case Constants.DSTORE_3: obj = new DSTORE(); break; | |||
+ case Constants.ASTORE_0: | |||
+ case Constants.ASTORE_1: | |||
+ case Constants.ASTORE_2: | |||
+ case Constants.ASTORE_3: obj = new ASTORE(); break; | |||
+ case Constants.IASTORE : obj = new IASTORE(); break; | |||
+ case Constants.LASTORE : obj = new LASTORE(); break; | |||
+ case Constants.FASTORE : obj = new FASTORE(); break; | |||
+ case Constants.DASTORE : obj = new DASTORE(); break; | |||
+ case Constants.AASTORE : obj = new AASTORE(); break; | |||
+ case Constants.BASTORE : obj = new BASTORE(); break; | |||
+ case Constants.CASTORE : obj = new CASTORE(); break; | |||
+ case Constants.SASTORE : obj = new SASTORE(); break; | |||
+ case Constants.POP : obj = new POP(); break; | |||
+ case Constants.POP2 : obj = new POP2(); break; | |||
+ case Constants.DUP : obj = new DUP(); break; | |||
+ case Constants.DUP_X1: obj = new DUP_X1(); break; | |||
+ case Constants.DUP_X2: obj = new DUP_X2(); break; | |||
+ case Constants.DUP2 : obj = new DUP2(); break; | |||
+ case Constants.DUP2_X1: obj = new DUP2_X1(); break; | |||
+ case Constants.DUP2_X2: obj = new DUP2_X2(); break; | |||
+ case Constants.SWAP : obj = new SWAP(); break; | |||
+ case Constants.IADD : obj = new IADD(); break; | |||
+ case Constants.LADD : obj = new LADD(); break; | |||
+ case Constants.FADD : obj = new FADD(); break; | |||
+ case Constants.DADD : obj = new DADD(); break; | |||
+ case Constants.ISUB : obj = new ISUB(); break; | |||
+ case Constants.LSUB : obj = new LSUB(); break; | |||
+ case Constants.FSUB : obj = new FSUB(); break; | |||
+ case Constants.DSUB : obj = new DSUB(); break; | |||
+ case Constants.IMUL : obj = new IMUL(); break; | |||
+ case Constants.LMUL : obj = new LMUL(); break; | |||
+ case Constants.FMUL : obj = new FMUL(); break; | |||
+ case Constants.DMUL : obj = new DMUL(); break; | |||
+ case Constants.IDIV : obj = new IDIV(); break; | |||
+ case Constants.LDIV : obj = new LDIV(); break; | |||
+ case Constants.FDIV : obj = new FDIV(); break; | |||
+ case Constants.DDIV : obj = new DDIV(); break; | |||
+ case Constants.IREM : obj = new IREM(); break; | |||
+ case Constants.LREM : obj = new LREM(); break; | |||
+ case Constants.FREM : obj = new FREM(); break; | |||
+ case Constants.DREM : obj = new DREM(); break; | |||
+ case Constants.INEG : obj = new INEG(); break; | |||
+ case Constants.LNEG : obj = new LNEG(); break; | |||
+ case Constants.FNEG : obj = new FNEG(); break; | |||
+ case Constants.DNEG : obj = new DNEG(); break; | |||
+ case Constants.ISHL : obj = new ISHL(); break; | |||
+ case Constants.LSHL : obj = new LSHL(); break; | |||
+ case Constants.ISHR : obj = new ISHR(); break; | |||
+ case Constants.LSHR : obj = new LSHR(); break; | |||
+ case Constants.IUSHR : obj = new IUSHR(); break; | |||
+ case Constants.LUSHR : obj = new LUSHR(); break; | |||
+ case Constants.IAND : obj = new IAND(); break; | |||
+ case Constants.LAND : obj = new LAND(); break; | |||
+ case Constants.IOR : obj = new IOR(); break; | |||
+ case Constants.LOR : obj = new LOR(); break; | |||
+ case Constants.IXOR : obj = new IXOR(); break; | |||
+ case Constants.LXOR : obj = new LXOR(); break; | |||
+ case Constants.IINC : obj = new IINC(); break; | |||
+ case Constants.I2L : obj = new I2L(); break; | |||
+ case Constants.I2F : obj = new I2F(); break; | |||
+ case Constants.I2D : obj = new I2D(); break; | |||
+ case Constants.L2I : obj = new L2I(); break; | |||
+ case Constants.L2F : obj = new L2F(); break; | |||
+ case Constants.L2D : obj = new L2D(); break; | |||
+ case Constants.F2I : obj = new F2I(); break; | |||
+ case Constants.F2L : obj = new F2L(); break; | |||
+ case Constants.F2D : obj = new F2D(); break; | |||
+ case Constants.D2I : obj = new D2I(); break; | |||
+ case Constants.D2L : obj = new D2L(); break; | |||
+ case Constants.D2F : obj = new D2F(); break; | |||
+ case Constants.I2B : obj = new I2B(); break; | |||
+ case Constants.I2C : obj = new I2C(); break; | |||
+ case Constants.I2S : obj = new I2S(); break; | |||
+ case Constants.LCMP : obj = new LCMP(); break; | |||
+ case Constants.FCMPL : obj = new FCMPL(); break; | |||
+ case Constants.FCMPG : obj = new FCMPG(); break; | |||
+ case Constants.DCMPL : obj = new DCMPL(); break; | |||
+ case Constants.DCMPG : obj = new DCMPG(); break; | |||
+ case Constants.IFEQ : obj = new IFEQ(); break; | |||
+ case Constants.IFNE : obj = new IFNE(); break; | |||
+ case Constants.IFLT : obj = new IFLT(); break; | |||
+ case Constants.IFGE : obj = new IFGE(); break; | |||
+ case Constants.IFGT : obj = new IFGT(); break; | |||
+ case Constants.IFLE : obj = new IFLE(); break; | |||
+ case Constants.IF_ICMPEQ: obj = new IF_ICMPEQ(); break; | |||
+ case Constants.IF_ICMPNE: obj = new IF_ICMPNE(); break; | |||
+ case Constants.IF_ICMPLT: obj = new IF_ICMPLT(); break; | |||
+ case Constants.IF_ICMPGE: obj = new IF_ICMPGE(); break; | |||
+ case Constants.IF_ICMPGT: obj = new IF_ICMPGT(); break; | |||
+ case Constants.IF_ICMPLE: obj = new IF_ICMPLE(); break; | |||
+ case Constants.IF_ACMPEQ: obj = new IF_ACMPEQ(); break; | |||
+ case Constants.IF_ACMPNE : obj = new IF_ACMPNE(); break; | |||
+ case Constants.GOTO : obj = new GOTO(); break; | |||
+ case Constants.JSR : obj = new JSR(); break; | |||
+ case Constants.RET : obj = new RET(); break; | |||
+ case Constants.TABLESWITCH : obj = new TABLESWITCH(); break; | |||
+ case Constants.LOOKUPSWITCH : obj = new LOOKUPSWITCH(); break; | |||
+ case Constants.IRETURN : obj = new IRETURN(); break; | |||
+ case Constants.LRETURN : obj = new LRETURN(); break; | |||
+ case Constants.FRETURN : obj = new FRETURN(); break; | |||
+ case Constants.DRETURN : obj = new DRETURN(); break; | |||
+ case Constants.ARETURN : obj = new ARETURN(); break; | |||
+ case Constants.RETURN : obj = new RETURN(); break; | |||
+ case Constants.GETSTATIC : obj = new GETSTATIC(); break; | |||
+ case Constants.PUTSTATIC : obj = new PUTSTATIC(); break; | |||
+ case Constants.GETFIELD : obj = new GETFIELD(); break; | |||
+ case Constants.PUTFIELD : obj = new PUTFIELD(); break; | |||
+ case Constants.INVOKEVIRTUAL : obj = new INVOKEVIRTUAL(); break; | |||
+ case Constants.INVOKESPECIAL : obj = new INVOKESPECIAL(); break; | |||
+ case Constants.INVOKESTATIC : obj = new INVOKESTATIC(); break; | |||
+ case Constants.INVOKEINTERFACE : obj = new INVOKEINTERFACE(); break; | |||
+ case Constants.NEW : obj = new NEW(); break; | |||
+ case Constants.NEWARRAY : obj = new NEWARRAY(); break; | |||
+ case Constants.ANEWARRAY : obj = new ANEWARRAY(); break; | |||
+ case Constants.ARRAYLENGTH : obj = new ARRAYLENGTH(); break; | |||
+ case Constants.ATHROW : obj = new ATHROW(); break; | |||
+ case Constants.CHECKCAST : obj = new CHECKCAST(); break; | |||
+ case Constants.INSTANCEOF : obj = new INSTANCEOF(); break; | |||
+ case Constants.MONITORENTER : obj = new MONITORENTER(); break; | |||
+ case Constants.MONITOREXIT : obj = new MONITOREXIT(); break; | |||
+ case Constants.MULTIANEWARRAY : obj = new MULTIANEWARRAY(); break; | |||
+ case Constants.IFNULL : obj = new IFNULL(); break; | |||
+ case Constants.IFNONNULL : obj = new IFNONNULL(); break; | |||
+ case Constants.GOTO_W : obj = new GOTO_W(); break; | |||
+ case Constants.JSR_W : obj = new JSR_W(); break; | |||
+ default: | |||
+ throw new ClassGenException("Illegal opcode detected"); | |||
+ } | |||
+ } catch (ClassGenException e) { | |||
+ throw e; | |||
+ } catch (Exception e) { | |||
+ throw new ClassGenException(e.toString()); | |||
} | |||
- | |||
- try { | |||
- obj = (Instruction)clazz.newInstance(); | |||
- | |||
if(wide && !((obj instanceof LocalVariableInstruction) || | |||
(obj instanceof IINC) || | |||
(obj instanceof RET))) | |||
- throw new Exception("Illegal opcode after wide: " + opcode); | |||
+ throw new ClassGenException("Illegal opcode after wide: " + opcode); | |||
obj.setOpcode(opcode); | |||
obj.initFromFile(bytes, wide); // Do further initializations, if any | |||
// Byte code offset set in InstructionList | |||
- } catch(Exception e) { throw new ClassGenException(e.toString()); } | |||
- | |||
return obj; | |||
} | |||
diff -N -a -u -r -b bcel-5.1/src/java/org/apache/bcel/generic/LDC_W.java bcel/src/java/org/apache/bcel/generic/LDC_W.java | |||
--- bcel-5.1/src/java/org/apache/bcel/generic/LDC_W.java 2003-04-25 09:06:16.000000000 +0100 | |||
+++ bcel/src/java/org/apache/bcel/generic/LDC_W.java 2004-08-11 21:28:47.160832000 +0100 | |||
@@ -83,6 +83,6 @@ | |||
{ | |||
setIndex(bytes.readUnsignedShort()); | |||
// Override just in case it has been changed | |||
- opcode = org.apache.bcel.Constants.LDC_W; | |||
+ // opcode = org.apache.bcel.Constants.LDC_W; | |||
} | |||
} | |||
diff -N -a -u -r -b bcel-5.1/src/java/org/apache/bcel/generic/MethodGen.java bcel/src/java/org/apache/bcel/generic/MethodGen.java | |||
--- bcel-5.1/src/java/org/apache/bcel/generic/MethodGen.java 2003-04-25 09:06:16.000000000 +0100 | |||
+++ bcel/src/java/org/apache/bcel/generic/MethodGen.java 2004-08-11 21:28:47.641523200 +0100 | |||
@@ -133,9 +133,9 @@ | |||
/* Add local variables, namely the implicit `this' and the arguments | |||
*/ | |||
- if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0 | |||
- addLocalVariable("this", new ObjectType(class_name), start, end); | |||
- } | |||
+// if(!isStatic() && (class_name != null)) { // Instance method -> `this' is local var 0 | |||
+// addLocalVariable("this", new ObjectType(class_name), start, end); | |||
+// } | |||
} | |||
if(arg_types != null) { | |||
@@ -152,17 +152,17 @@ | |||
throw new ClassGenException("Mismatch in argument array lengths: " + | |||
size + " vs. " + arg_names.length); | |||
} else { // Give them dummy names | |||
- arg_names = new String[size]; | |||
- | |||
- for(int i=0; i < size; i++) | |||
- arg_names[i] = "arg" + i; | |||
- | |||
- setArgumentNames(arg_names); | |||
+// arg_names = new String[size]; | |||
+// | |||
+// for(int i=0; i < size; i++) | |||
+// arg_names[i] = "arg" + i; | |||
+// | |||
+// setArgumentNames(arg_names); | |||
} | |||
if(!abstract_) { | |||
for(int i=0; i < size; i++) { | |||
- addLocalVariable(arg_names[i], arg_types[i], start, end); | |||
+// addLocalVariable(arg_names[i], arg_types[i], start, end); | |||
} | |||
} | |||
} |
@@ -27,12 +27,6 @@ This module includes a modified form of BCEL - with some fixes in *and* support | |||
<li>The LocalVariableTypeTable attribute is supported (used for generics to tell you the original variable signature)</li> | |||
</ul> | |||
<p>All this is implemented without using any Java 5 APIs.</p> | |||
<p>There are a number of new TODO type tags in the code that may prove useful:</p> | |||
<ul> | |||
<li>J5SUPPORT: Marks places where BCEL has been changed for 1.5 (might have missed a couple...)</li> | |||
<li>BCELBUG: Marks things that might be BCEL problems that I came across</li> | |||
<li>J5TODO: Marks either a missing bit of implementation (hopefully corner case) or an optimization we could make</li> | |||
</ul> | |||
<hr> | |||
<p> The contents of this directory are: | |||
</p> | |||
@@ -40,6 +34,8 @@ This module includes a modified form of BCEL - with some fixes in *and* support | |||
<ul> | |||
<li>This file</li> | |||
<li>src -- contains the source for BCEL, a modified variant of BCEL 5.1 that includes bug fixes and Java 5 support</li> | |||
<li>verifier-src -- contains the source for the bcel verifier package, something used by tests but not packaged | |||
and distributed (at the moment). | |||
<li>testsrc -- JUnit test cases for the Java 5 support</li> | |||
<li>testdata -- Java5 testcode that can be built using the build.xml script in the testdata directory (see note on this below)</li> | |||
<li>build.xml -- an ant script for manipulating the src folder, possibly useful if ever merging a base BCEL version</li> | |||
@@ -66,83 +62,5 @@ then used by the testcases - so if you do change the testdata code then you shou | |||
to rebuild testcode.jar. | |||
<hr> | |||
<h3>The old stuff...</h3> | |||
Before the Java 5 support was added we maintained this module as basically a patch to apply against | |||
a particular download of BCEL. Changes to BCEL are occurring more frequently than we integrate | |||
a new version of BCEL so it made sense to make the patching process easier, so we have checked in | |||
the modified source for BCEL. | |||
The original instructions for patching BCEL in the old way are below... | |||
<p> And pretty much nothing else. Well, then, what do you do with | |||
this directory? Well, the whole point is to generate bcel/bcel.jar in | |||
the lib package. To do so, first stick | |||
<strong>bcel-5.1-src.zip</strong> in this directory, then run ant. | |||
(at one point, this was available at | |||
<a href="http://archive.apache.org/dist/jakarta/bcel/source/bcel-5.1-src.zip"> | |||
http://archive.apache.org/dist/jakarta/bcel/source/bcel-5.1-src.zip</a>) | |||
After much unzipping, patching, and compiling, you should get an | |||
appropriate bcel.jar file. Now put it in the appropriate place. </p> | |||
<p> If there's something <em>wrong</em> with the bcel.jar in the lib | |||
project, well, then you've got some development to do. You'll need | |||
to know some more ant targets. But before anything, get that | |||
<strong>bcel-5.1-src.zip</strong> and stick it in this directory. | |||
<b>NOTE: You should be working on BCEL when the package names are org.aspectj.apache.bcel, | |||
and *not* when the package names are org.apache.bcel. If you run the extractAndPatch task | |||
below, you will be left with a src folder in the correct state for further development.</b> | |||
</p> | |||
<p> There are five top-level ant targets apart from the usual "clean":</p> | |||
<ul> | |||
<li>ant extractAndPatchAndJar -- this is just the composition of the extract, | |||
jar and srcjar targets, and is the default. It extracts the source from bcel-5.1-src.zip, | |||
patches it, renames the files to start org.aspectj.apache rather than org.apache then | |||
compiles the patched version into a jar and drops the new archives: | |||
bcel.jar and bcel-src.zip, into the project root. This is the default task, mainly used | |||
to sanity check the building and make sure we're generating something. | |||
The bcel.jar and bcel-src.zip generated should be the same as that in ..\lib\bcel\. | |||
</li> | |||
<li>ant extractAndPatch -- this extracts the source from bcel-5.1-src.zip, | |||
patches it, renames the files to start org.aspectj.apache rather than org.apache then | |||
copies the patched source into the project src directory, | |||
there to be visible by eclipse for people to do development on it. | |||
For the patch file to be applied you need to have a patch.exe on your path, | |||
this bcel building process was tested with the version from cygwin. | |||
</li> | |||
<li>ant jar -- this copies the edited source from the project source | |||
directory and jars it up into bcel.jar, there to be tested. | |||
</li> | |||
<li>ant srcjar -- this copies the edited source from the project source | |||
directory and jars up the source code into bcel-src.zip. | |||
</li> | |||
<li>ant push -- this pushes the new bcel.jar and bcel-src.zip into ..\lib\bcel\. | |||
- ready to be used by the greater compiler.</li> | |||
<li>ant diff -- this creates the patch.txt file, composed of the differences | |||
between the project src directory and the original bcel-5.1 source. | |||
In order to create the patch, we transform the packages back to org.apache from | |||
org.aspectj.apache. To continue working on BCEL once you have done this, you might | |||
need to run the transformToAJ task to switch the packages back to the AJ prefix. | |||
For the patch file to be built successfully you need to have a diff.exe on your path, | |||
this bcel building process was tested with the version from cygwin. | |||
</li> | |||
<li>ant transformToAJ - this changes the packages for the BCEL classes to | |||
org.aspectj.apache from org.apache. This is used by the extractAndPatch task above. | |||
</li> | |||
<li>ant transformFromAJ - this changes the packages for the BCEL classes to | |||
org.apache from org.aspectj.apache. This is used by the diff task. | |||
</li> | |||
</ul> | |||
<p> All of the tasks are destructive, so don't do "ant extract", for example, | |||
if you have anything in the project source directory you care about. | |||
</p> | |||
</body> </html> |
@@ -1,7 +0,0 @@ | |||
15/2/07 | |||
There are problems with the 'refactoring' branch of the bcel-builder project. | |||
For some reason if I commit things into the branch, they go into HEAD - whether | |||
there was a problem creating the branch, I'm not sure. So as a temporary measure | |||
I am committing the refactored form of the bcel-builder module in as a jar called | |||
bcel-builder.refactored.jar. |
@@ -1,5 +1,7 @@ | |||
package org.aspectj.apache.bcel; | |||
import org.aspectj.apache.bcel.generic.Type; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
@@ -57,12 +59,11 @@ package org.aspectj.apache.bcel; | |||
/** | |||
* Constants for the project, mostly defined in the JVM specification. | |||
* | |||
* @version $Id: Constants.java,v 1.3 2006/05/04 11:28:26 aclement Exp $ | |||
* @version $Id: Constants.java,v 1.4 2008/05/28 23:53:04 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public interface Constants { | |||
/** Major and minor version of the code. | |||
*/ | |||
// Major and minor version of the code | |||
public final static short MAJOR_1_1 = 45; | |||
public final static short MINOR_1_1 = 3; | |||
public final static short MAJOR_1_2 = 46; | |||
@@ -75,19 +76,17 @@ public interface Constants { | |||
public final static short MINOR_1_5 = 0; | |||
public final static short MAJOR_1_6 = 50; | |||
public final static short MINOR_1_6 = 0; | |||
public final static short MAJOR = MAJOR_1_1; // Defaults | |||
// Defaults | |||
public final static short MAJOR = MAJOR_1_1; | |||
public final static short MINOR = MINOR_1_1; | |||
/** Maximum value for an unsigned short. | |||
*/ | |||
/** Maximum value for an unsigned short */ | |||
public final static int MAX_SHORT = 65535; // 2^16 - 1 | |||
/** Maximum value for an unsigned byte. | |||
*/ | |||
/** Maximum value for an unsigned byte */ | |||
public final static int MAX_BYTE = 255; // 2^8 - 1 | |||
/** Access flags for classes, fields and methods. | |||
*/ | |||
/** Access flags for classes, fields and methods */ | |||
public final static short ACC_PUBLIC = 0x0001; | |||
public final static short ACC_PRIVATE = 0x0002; | |||
public final static short ACC_PROTECTED = 0x0004; | |||
@@ -103,7 +102,6 @@ public interface Constants { | |||
public final static short ACC_ABSTRACT = 0x0400; | |||
public final static short ACC_STRICT = 0x0800; | |||
// J5SUPPORT: | |||
public final static short ACC_ANNOTATION = 0x2000; | |||
public final static short ACC_ENUM = 0x4000; | |||
public final static short ACC_BRIDGE = 0x0040; | |||
@@ -119,8 +117,7 @@ public interface Constants { | |||
"volatile", "transient", "native", "interface", "abstract", "strictfp" | |||
}; | |||
/** Tags in constant pool to denote type of constant. | |||
*/ | |||
/** Tags in constant pool to denote type of constant */ | |||
public final static byte CONSTANT_Utf8 = 1; | |||
public final static byte CONSTANT_Integer = 3; | |||
public final static byte CONSTANT_Float = 4; | |||
@@ -410,8 +407,8 @@ public interface Constants { | |||
/** | |||
* Illegal codes | |||
*/ | |||
public static final short UNDEFINED = -1; | |||
public static final short UNPREDICTABLE = -2; | |||
public static final short UNDEFINED = '/'-'0'; //-1; | |||
public static final short UNPREDICTABLE = '.'-'0';//-2; | |||
public static final short RESERVED = -3; | |||
public static final String ILLEGAL_OPCODE = "<illegal opcode>"; | |||
public static final String ILLEGAL_TYPE = "<illegal type>"; | |||
@@ -460,72 +457,246 @@ public interface Constants { | |||
"Z", "C", "F", "D", "B", "S", "I", "J", | |||
"V", ILLEGAL_TYPE, ILLEGAL_TYPE, ILLEGAL_TYPE | |||
}; | |||
/** | |||
* Number of byte code operands, i.e., number of bytes after the tag byte | |||
* itself. | |||
*/ | |||
public static final short[] NO_OF_OPERANDS = { | |||
0/*nop*/, 0/*aconst_null*/, 0/*iconst_m1*/, 0/*iconst_0*/, | |||
0/*iconst_1*/, 0/*iconst_2*/, 0/*iconst_3*/, 0/*iconst_4*/, | |||
0/*iconst_5*/, 0/*lconst_0*/, 0/*lconst_1*/, 0/*fconst_0*/, | |||
0/*fconst_1*/, 0/*fconst_2*/, 0/*dconst_0*/, 0/*dconst_1*/, | |||
1/*bipush*/, 2/*sipush*/, 1/*ldc*/, 2/*ldc_w*/, 2/*ldc2_w*/, | |||
1/*iload*/, 1/*lload*/, 1/*fload*/, 1/*dload*/, 1/*aload*/, | |||
0/*iload_0*/, 0/*iload_1*/, 0/*iload_2*/, 0/*iload_3*/, | |||
0/*lload_0*/, 0/*lload_1*/, 0/*lload_2*/, 0/*lload_3*/, | |||
0/*fload_0*/, 0/*fload_1*/, 0/*fload_2*/, 0/*fload_3*/, | |||
0/*dload_0*/, 0/*dload_1*/, 0/*dload_2*/, 0/*dload_3*/, | |||
0/*aload_0*/, 0/*aload_1*/, 0/*aload_2*/, 0/*aload_3*/, | |||
0/*iaload*/, 0/*laload*/, 0/*faload*/, 0/*daload*/, | |||
0/*aaload*/, 0/*baload*/, 0/*caload*/, 0/*saload*/, | |||
1/*istore*/, 1/*lstore*/, 1/*fstore*/, 1/*dstore*/, | |||
1/*astore*/, 0/*istore_0*/, 0/*istore_1*/, 0/*istore_2*/, | |||
0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/, 0/*lstore_2*/, | |||
0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/, | |||
0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/, | |||
0/*dstore_3*/, 0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/, | |||
0/*astore_3*/, 0/*iastore*/, 0/*lastore*/, 0/*fastore*/, | |||
0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/, | |||
0/*sastore*/, 0/*pop*/, 0/*pop2*/, 0/*dup*/, 0/*dup_x1*/, | |||
0/*dup_x2*/, 0/*dup2*/, 0/*dup2_x1*/, 0/*dup2_x2*/, 0/*swap*/, | |||
0/*iadd*/, 0/*ladd*/, 0/*fadd*/, 0/*dadd*/, 0/*isub*/, | |||
0/*lsub*/, 0/*fsub*/, 0/*dsub*/, 0/*imul*/, 0/*lmul*/, | |||
0/*fmul*/, 0/*dmul*/, 0/*idiv*/, 0/*ldiv*/, 0/*fdiv*/, | |||
0/*ddiv*/, 0/*irem*/, 0/*lrem*/, 0/*frem*/, 0/*drem*/, | |||
0/*ineg*/, 0/*lneg*/, 0/*fneg*/, 0/*dneg*/, 0/*ishl*/, | |||
0/*lshl*/, 0/*ishr*/, 0/*lshr*/, 0/*iushr*/, 0/*lushr*/, | |||
0/*iand*/, 0/*land*/, 0/*ior*/, 0/*lor*/, 0/*ixor*/, 0/*lxor*/, | |||
2/*iinc*/, 0/*i2l*/, 0/*i2f*/, 0/*i2d*/, 0/*l2i*/, 0/*l2f*/, | |||
0/*l2d*/, 0/*f2i*/, 0/*f2l*/, 0/*f2d*/, 0/*d2i*/, 0/*d2l*/, | |||
0/*d2f*/, 0/*i2b*/, 0/*i2c*/, 0/*i2s*/, 0/*lcmp*/, 0/*fcmpl*/, | |||
0/*fcmpg*/, 0/*dcmpl*/, 0/*dcmpg*/, 2/*ifeq*/, 2/*ifne*/, | |||
2/*iflt*/, 2/*ifge*/, 2/*ifgt*/, 2/*ifle*/, 2/*if_icmpeq*/, | |||
2/*if_icmpne*/, 2/*if_icmplt*/, 2/*if_icmpge*/, 2/*if_icmpgt*/, | |||
2/*if_icmple*/, 2/*if_acmpeq*/, 2/*if_acmpne*/, 2/*goto*/, | |||
2/*jsr*/, 1/*ret*/, UNPREDICTABLE/*tableswitch*/, UNPREDICTABLE/*lookupswitch*/, | |||
0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/, | |||
0/*dreturn*/, 0/*areturn*/, 0/*return*/, | |||
2/*getstatic*/, 2/*putstatic*/, 2/*getfield*/, | |||
2/*putfield*/, 2/*invokevirtual*/, 2/*invokespecial*/, 2/*invokestatic*/, | |||
4/*invokeinterface*/, UNDEFINED, 2/*new*/, | |||
1/*newarray*/, 2/*anewarray*/, | |||
0/*arraylength*/, 0/*athrow*/, 2/*checkcast*/, | |||
2/*instanceof*/, 0/*monitorenter*/, | |||
0/*monitorexit*/, UNPREDICTABLE/*wide*/, 3/*multianewarray*/, | |||
2/*ifnull*/, 2/*ifnonnull*/, 4/*goto_w*/, | |||
4/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, RESERVED/*impdep1*/, RESERVED/*impdep2*/ | |||
}; | |||
public static int PUSH_INST = 0x0001; | |||
public static int CONSTANT_INST = 0x0002; | |||
public static long LOADCLASS_INST = 0x0004; | |||
public static int CP_INST = 0x0008; | |||
public static int INDEXED = 0x0010; | |||
public static int LOAD_INST = 0x0020; // load instruction | |||
public static int LV_INST = 0x0040; // local variable instruction | |||
public static int POP_INST = 0x0080; | |||
public static int STORE_INST = 0x0100; | |||
public static long STACK_INST =0x0200; | |||
public static long BRANCH_INSTRUCTION =0x0400; | |||
public static long TARGETER_INSTRUCTION =0x0800; | |||
public static long NEGATABLE =0x1000; | |||
public static long IF_INST =0x2000; | |||
public static long JSR_INSTRUCTION =0x4000; | |||
public static long RET_INST =0x8000; | |||
public static long EXCEPTION_THROWER =0x10000; | |||
public static final byte[] iLen = new byte[256]; | |||
public static final byte UNDEFINED_LENGTH = 'X'-'0'; | |||
public static final byte VARIABLE_LENGTH = 'V'-'0'; | |||
public static final byte[] stackEntriesProduced = new byte[256]; | |||
public static final Type[] types = new Type[256]; | |||
public static final long[] instFlags = new long[256]; | |||
public static final Class[][] instExcs = new Class[256][]; | |||
static final Clinit _unused = new Clinit(); | |||
static class Clinit { | |||
static { | |||
types[ILOAD] =Type.INT;types[ISTORE]=Type.INT;types[ILOAD_0]=Type.INT;types[ISTORE_0]=Type.INT; | |||
types[ILOAD_1]=Type.INT;types[ISTORE_1]=Type.INT;types[ILOAD_2]=Type.INT;types[ISTORE_2]=Type.INT; | |||
types[ILOAD_3]=Type.INT;types[ISTORE_3]=Type.INT; | |||
types[LLOAD] =Type.LONG;types[LSTORE]=Type.LONG;types[LLOAD_0]=Type.LONG;types[LSTORE_0]=Type.LONG; | |||
types[LLOAD_1]=Type.LONG;types[LSTORE_1]=Type.LONG;types[LLOAD_2]=Type.LONG;types[LSTORE_2]=Type.LONG; | |||
types[LLOAD_3]=Type.LONG;types[LSTORE_3]=Type.LONG; | |||
types[DLOAD] =Type.DOUBLE;types[DSTORE]=Type.DOUBLE;types[DLOAD_0]=Type.DOUBLE;types[DSTORE_0]=Type.DOUBLE; | |||
types[DLOAD_1]=Type.DOUBLE;types[DSTORE_1]=Type.DOUBLE;types[DLOAD_2]=Type.DOUBLE;types[DSTORE_2]=Type.DOUBLE; | |||
types[DLOAD_3]=Type.DOUBLE;types[DSTORE_3]=Type.DOUBLE; | |||
types[FLOAD] =Type.FLOAT;types[FSTORE]=Type.FLOAT;types[FLOAD_0]=Type.FLOAT;types[FSTORE_0]=Type.FLOAT; | |||
types[FLOAD_1]=Type.FLOAT;types[FSTORE_1]=Type.FLOAT;types[FLOAD_2]=Type.FLOAT;types[FSTORE_2]=Type.FLOAT; | |||
types[FLOAD_3]=Type.FLOAT;types[FSTORE_3]=Type.FLOAT; | |||
types[ALOAD] =Type.OBJECT;types[ASTORE]=Type.OBJECT;types[ALOAD_0]=Type.OBJECT;types[ASTORE_0]=Type.OBJECT; | |||
types[ALOAD_1]=Type.OBJECT;types[ASTORE_1]=Type.OBJECT;types[ALOAD_2]=Type.OBJECT;types[ASTORE_2]=Type.OBJECT; | |||
types[ALOAD_3]=Type.OBJECT;types[ASTORE_3]=Type.OBJECT; | |||
// INSTRUCTION_FLAGS - set for all | |||
instFlags[NOP] = 0; | |||
instFlags[ACONST_NULL]=PUSH_INST; | |||
instFlags[ICONST_M1]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_0]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_1]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_2]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_3]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_4]=PUSH_INST|CONSTANT_INST; | |||
instFlags[ICONST_5]=PUSH_INST|CONSTANT_INST; | |||
instFlags[LCONST_0]=PUSH_INST|CONSTANT_INST; | |||
instFlags[LCONST_1]=PUSH_INST|CONSTANT_INST; | |||
instFlags[FCONST_0]=PUSH_INST|CONSTANT_INST; | |||
instFlags[FCONST_1]=PUSH_INST|CONSTANT_INST; | |||
instFlags[FCONST_2]=PUSH_INST|CONSTANT_INST; | |||
instFlags[DCONST_0]=PUSH_INST|CONSTANT_INST; | |||
instFlags[DCONST_1]=PUSH_INST|CONSTANT_INST; | |||
instFlags[BIPUSH]=PUSH_INST|CONSTANT_INST; | |||
instFlags[SIPUSH]=PUSH_INST|CONSTANT_INST; | |||
instFlags[LDC]=EXCEPTION_THROWER|PUSH_INST|CP_INST|INDEXED; | |||
instFlags[LDC_W]=EXCEPTION_THROWER|PUSH_INST|CP_INST|INDEXED; | |||
instFlags[LDC2_W]=EXCEPTION_THROWER|PUSH_INST|CP_INST|INDEXED; | |||
// the next five could be 'wide' prefixed and so have longer lengths | |||
instFlags[ILOAD]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
instFlags[LLOAD]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
instFlags[FLOAD]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
instFlags[DLOAD]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
instFlags[ALOAD]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
for (int ii=ILOAD_0;ii<=ALOAD_3;ii++) { | |||
instFlags[ii]=INDEXED|LOAD_INST|PUSH_INST|LV_INST; | |||
} | |||
// the next five could be 'wide' prefixed and so have longer lengths | |||
instFlags[ISTORE]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
instFlags[LSTORE]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
instFlags[FSTORE]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
instFlags[DSTORE]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
instFlags[ASTORE]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
for (int ii=ISTORE_0;ii<=ASTORE_3;ii++) { | |||
instFlags[ii]=INDEXED|STORE_INST|POP_INST|LV_INST; | |||
} | |||
instFlags[IDIV]=EXCEPTION_THROWER; | |||
instExcs[IDIV] = new Class[]{org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION}; | |||
instFlags[IREM]=EXCEPTION_THROWER; | |||
instExcs[IREM] = new Class[]{org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION}; | |||
instFlags[LDIV]=EXCEPTION_THROWER;instExcs[LDIV] = new Class[]{ org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION}; | |||
instFlags[LREM]=EXCEPTION_THROWER;instExcs[LREM] = new Class[]{org.aspectj.apache.bcel.ExceptionConstants.ARITHMETIC_EXCEPTION}; | |||
instFlags[ARRAYLENGTH]=EXCEPTION_THROWER; instExcs[ARRAYLENGTH]=new Class[]{org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION}; | |||
instFlags[ATHROW]=EXCEPTION_THROWER;instExcs[ATHROW]=new Class[]{org.aspectj.apache.bcel.ExceptionConstants.THROWABLE}; | |||
instFlags[AALOAD]=EXCEPTION_THROWER;instExcs[AALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[IALOAD]=EXCEPTION_THROWER;instExcs[IALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[BALOAD]=EXCEPTION_THROWER;instExcs[BALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[FALOAD]=EXCEPTION_THROWER;instExcs[FALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[DALOAD]=EXCEPTION_THROWER;instExcs[DALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[CALOAD]=EXCEPTION_THROWER;instExcs[CALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[LALOAD]=EXCEPTION_THROWER;instExcs[LALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[SALOAD]=EXCEPTION_THROWER;instExcs[SALOAD]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[AASTORE]=EXCEPTION_THROWER;instExcs[AASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[IASTORE]=EXCEPTION_THROWER;instExcs[IASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[BASTORE]=EXCEPTION_THROWER;instExcs[BASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[FASTORE]=EXCEPTION_THROWER;instExcs[FASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[DASTORE]=EXCEPTION_THROWER;instExcs[DASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[CASTORE]=EXCEPTION_THROWER;instExcs[CASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[LASTORE]=EXCEPTION_THROWER;instExcs[LASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
instFlags[SASTORE]=EXCEPTION_THROWER;instExcs[SASTORE]=org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
// stack instructions | |||
instFlags[DUP]=PUSH_INST|STACK_INST; | |||
instFlags[DUP_X1]=STACK_INST; // TODO fixme - aren't these two push/stack producers? (although peculiar ones...) | |||
instFlags[DUP_X2]=STACK_INST; | |||
instFlags[DUP2]=PUSH_INST|STACK_INST; | |||
instFlags[DUP2_X1]=STACK_INST; // TODO fixme - aren't these two push/stack producers? (although peculiar ones...) | |||
instFlags[DUP2_X2]=STACK_INST; | |||
instFlags[POP]=STACK_INST|POP_INST; | |||
instFlags[POP2]=STACK_INST|POP_INST; | |||
instFlags[SWAP]=STACK_INST; | |||
instFlags[MONITORENTER]=EXCEPTION_THROWER;instExcs[MONITORENTER]=new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; | |||
instFlags[MONITOREXIT]=EXCEPTION_THROWER;instExcs[MONITOREXIT]=new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; | |||
// branching instructions | |||
instFlags[GOTO]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION; | |||
instFlags[GOTO_W]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION; | |||
instFlags[JSR]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|JSR_INSTRUCTION; | |||
instFlags[JSR_W]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|JSR_INSTRUCTION; | |||
instFlags[IFGT]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFLE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFNE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFEQ]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFGE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFLT]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFNULL]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IFNONNULL]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ACMPEQ]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ACMPNE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPEQ]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPGE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPGT]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPLE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPLT]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[IF_ICMPNE]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION|NEGATABLE|IF_INST; | |||
instFlags[LOOKUPSWITCH]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION; | |||
instFlags[TABLESWITCH]=BRANCH_INSTRUCTION|TARGETER_INSTRUCTION; | |||
// fixme these class arrays should be constants | |||
instFlags[ARETURN]=RET_INST|EXCEPTION_THROWER;instExcs[ARETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[DRETURN]=RET_INST|EXCEPTION_THROWER;instExcs[DRETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[FRETURN]=RET_INST|EXCEPTION_THROWER;instExcs[FRETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[IRETURN]=RET_INST|EXCEPTION_THROWER;instExcs[IRETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[LRETURN]=RET_INST|EXCEPTION_THROWER;instExcs[LRETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[RETURN]=RET_INST|EXCEPTION_THROWER;instExcs[RETURN]=new Class[] { ExceptionConstants.ILLEGAL_MONITOR_STATE }; | |||
instFlags[NEW]=LOADCLASS_INST|EXCEPTION_THROWER|CP_INST|INDEXED;instExcs[NEW]=ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS; | |||
instFlags[NEWARRAY]=EXCEPTION_THROWER;instExcs[NEWARRAY]=new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION }; | |||
types[IINC]=Type.INT;instFlags[IINC]=LV_INST|INDEXED; | |||
instFlags[RET]=INDEXED; | |||
instFlags[ANEWARRAY]=CP_INST|LOADCLASS_INST|EXCEPTION_THROWER|INDEXED;instExcs[ANEWARRAY]=ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY; | |||
instFlags[CHECKCAST]=CP_INST|LOADCLASS_INST|EXCEPTION_THROWER|INDEXED;instExcs[CHECKCAST]=ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST; | |||
instFlags[INSTANCEOF]=CP_INST|LOADCLASS_INST|EXCEPTION_THROWER|INDEXED;instExcs[INSTANCEOF]=ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION; | |||
instFlags[MULTIANEWARRAY]=CP_INST|LOADCLASS_INST|EXCEPTION_THROWER|INDEXED;instExcs[MULTIANEWARRAY]=ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY; // fixme i think this is a stackproducer, old bcel says no... | |||
instFlags[GETFIELD]=EXCEPTION_THROWER|CP_INST|LOADCLASS_INST|INDEXED;instExcs[GETFIELD]=ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD; | |||
instFlags[GETSTATIC]=PUSH_INST|EXCEPTION_THROWER|LOADCLASS_INST|CP_INST|INDEXED;instExcs[GETSTATIC]=ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC; | |||
instFlags[PUTFIELD]=POP_INST|EXCEPTION_THROWER|LOADCLASS_INST|CP_INST|INDEXED;instExcs[PUTFIELD]=ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD; | |||
instFlags[PUTSTATIC]=EXCEPTION_THROWER|POP_INST|CP_INST|LOADCLASS_INST|INDEXED;instExcs[PUTSTATIC]=ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC; | |||
instFlags[INVOKEINTERFACE]=EXCEPTION_THROWER|CP_INST|LOADCLASS_INST|INDEXED;instExcs[INVOKEINTERFACE]=ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE; | |||
instFlags[INVOKESPECIAL]=EXCEPTION_THROWER|CP_INST|LOADCLASS_INST|INDEXED;instExcs[INVOKESPECIAL]=ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL; | |||
instFlags[INVOKESTATIC]=EXCEPTION_THROWER|CP_INST|LOADCLASS_INST|INDEXED;instExcs[INVOKESTATIC]=ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC; | |||
instFlags[INVOKEVIRTUAL]=EXCEPTION_THROWER|CP_INST|LOADCLASS_INST|INDEXED;instExcs[INVOKEVIRTUAL]=ExceptionConstants.EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL; | |||
char[] lengths = // . = varies in length, / = undefined | |||
("1111111111111111"+ // nop > dconst_1 | |||
"2323322222111111"+ // bipush > lload_1 | |||
"1111111111111111"+ // lload_2 > laload | |||
"1111112222211111"+ // faload > lstore_0 | |||
"1111111111111111"+ // lstore_1 > iastore | |||
"1111111111111111"+ // lastore > swap | |||
"1111111111111111"+ // iadd > ddiv | |||
"1111111111111111"+ // irem > land | |||
"1111311111111111"+ // ior > d2l | |||
"1111111113333333"+ // d2f > if_icmpeq | |||
"3333333332..1111"+ // if_icmpne > dreturn | |||
"1133333335/32311"+ // areturn > athrow | |||
"3311.433551/////").toCharArray(); // checkcast > | |||
int count=0; | |||
for (;count<lengths.length;count++) iLen[count] = (byte)(lengths[count]-48); | |||
while (count<256) { iLen[count]=UNDEFINED;count++;} | |||
iLen[BREAKPOINT]=1; | |||
iLen[IMPDEP1]=1; | |||
iLen[IMPDEP2]=1; | |||
char[] producesOnStack = | |||
("0111111112211122"+ // nop > dconst_1 | |||
"1111212121111122"+ // bipush > lload_1 | |||
"2211112222111112"+ // lload_2 > laload | |||
"1211110000000000"+ // faload > lstore_0 | |||
"0000000000000000"+ // lstore_1 > iastore | |||
"0000000002344562"+ // lastore > swap | |||
"1212121212121212"+ // iadd > ddiv | |||
"1212121212121212"+ // irem > land | |||
"1212021211212212"+ // ior > d2l | |||
"1111111110000000"+ // d2f > if_icmpeq | |||
"0000000010000000"+ // if_icmpne > dreturn | |||
"00.0.0..../11111"+ // areturn > athrow | |||
"11000100010/").toCharArray(); // checkcast > | |||
count=0; | |||
for (;count<producesOnStack.length;count++) stackEntriesProduced[count] = (byte)(producesOnStack[count]-48); | |||
while (count<256) { iLen[count]=UNDEFINED;count++;} | |||
} | |||
} | |||
/** | |||
* How the byte code operands are to be interpreted. | |||
*/ | |||
@@ -699,62 +870,8 @@ public interface Constants { | |||
UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/ | |||
}; | |||
/** | |||
* Number of words produced onto operand stack by instructions. | |||
*/ | |||
public static final int[] PRODUCE_STACK = { | |||
0/*nop*/, 1/*aconst_null*/, 1/*iconst_m1*/, 1/*iconst_0*/, 1/*iconst_1*/, | |||
1/*iconst_2*/, 1/*iconst_3*/, 1/*iconst_4*/, 1/*iconst_5*/, 2/*lconst_0*/, | |||
2/*lconst_1*/, 1/*fconst_0*/, 1/*fconst_1*/, 1/*fconst_2*/, 2/*dconst_0*/, | |||
2/*dconst_1*/, 1/*bipush*/, 1/*sipush*/, 1/*ldc*/, 1/*ldc_w*/, 2/*ldc2_w*/, 1/*iload*/, | |||
2/*lload*/, 1/*fload*/, 2/*dload*/, 1/*aload*/, 1/*iload_0*/, 1/*iload_1*/, 1/*iload_2*/, | |||
1/*iload_3*/, 2/*lload_0*/, 2/*lload_1*/, 2/*lload_2*/, 2/*lload_3*/, 1/*fload_0*/, | |||
1/*fload_1*/, 1/*fload_2*/, 1/*fload_3*/, 2/*dload_0*/, 2/*dload_1*/, 2/*dload_2*/, | |||
2/*dload_3*/, 1/*aload_0*/, 1/*aload_1*/, 1/*aload_2*/, 1/*aload_3*/, 1/*iaload*/, | |||
2/*laload*/, 1/*faload*/, 2/*daload*/, 1/*aaload*/, 1/*baload*/, 1/*caload*/, 1/*saload*/, | |||
0/*istore*/, 0/*lstore*/, 0/*fstore*/, 0/*dstore*/, 0/*astore*/, 0/*istore_0*/, | |||
0/*istore_1*/, 0/*istore_2*/, 0/*istore_3*/, 0/*lstore_0*/, 0/*lstore_1*/, | |||
0/*lstore_2*/, 0/*lstore_3*/, 0/*fstore_0*/, 0/*fstore_1*/, 0/*fstore_2*/, | |||
0/*fstore_3*/, 0/*dstore_0*/, 0/*dstore_1*/, 0/*dstore_2*/, 0/*dstore_3*/, | |||
0/*astore_0*/, 0/*astore_1*/, 0/*astore_2*/, 0/*astore_3*/, 0/*iastore*/, 0/*lastore*/, | |||
0/*fastore*/, 0/*dastore*/, 0/*aastore*/, 0/*bastore*/, 0/*castore*/, 0/*sastore*/, | |||
0/*pop*/, 0/*pop2*/, 2/*dup*/, 3/*dup_x1*/, 4/*dup_x2*/, 4/*dup2*/, 5/*dup2_x1*/, | |||
6/*dup2_x2*/, 2/*swap*/, 1/*iadd*/, 2/*ladd*/, 1/*fadd*/, 2/*dadd*/, 1/*isub*/, 2/*lsub*/, | |||
1/*fsub*/, 2/*dsub*/, 1/*imul*/, 2/*lmul*/, 1/*fmul*/, 2/*dmul*/, 1/*idiv*/, 2/*ldiv*/, | |||
1/*fdiv*/, 2/*ddiv*/, 1/*irem*/, 2/*lrem*/, 1/*frem*/, 2/*drem*/, 1/*ineg*/, 2/*lneg*/, | |||
1/*fneg*/, 2/*dneg*/, 1/*ishl*/, 2/*lshl*/, 1/*ishr*/, 2/*lshr*/, 1/*iushr*/, 2/*lushr*/, | |||
1/*iand*/, 2/*land*/, 1/*ior*/, 2/*lor*/, 1/*ixor*/, 2/*lxor*/, | |||
0/*iinc*/, 2/*i2l*/, 1/*i2f*/, 2/*i2d*/, 1/*l2i*/, 1/*l2f*/, 2/*l2d*/, 1/*f2i*/, | |||
2/*f2l*/, 2/*f2d*/, 1/*d2i*/, 2/*d2l*/, 1/*d2f*/, | |||
1/*i2b*/, 1/*i2c*/, 1/*i2s*/, 1/*lcmp*/, 1/*fcmpl*/, 1/*fcmpg*/, | |||
1/*dcmpl*/, 1/*dcmpg*/, 0/*ifeq*/, 0/*ifne*/, 0/*iflt*/, 0/*ifge*/, 0/*ifgt*/, 0/*ifle*/, | |||
0/*if_icmpeq*/, 0/*if_icmpne*/, 0/*if_icmplt*/, 0/*if_icmpge*/, 0/*if_icmpgt*/, | |||
0/*if_icmple*/, 0/*if_acmpeq*/, 0/*if_acmpne*/, 0/*goto*/, 1/*jsr*/, 0/*ret*/, | |||
0/*tableswitch*/, 0/*lookupswitch*/, 0/*ireturn*/, 0/*lreturn*/, 0/*freturn*/, | |||
0/*dreturn*/, 0/*areturn*/, 0/*return*/, UNPREDICTABLE/*getstatic*/, 0/*putstatic*/, | |||
UNPREDICTABLE/*getfield*/, 0/*putfield*/, UNPREDICTABLE/*invokevirtual*/, | |||
UNPREDICTABLE/*invokespecial*/, UNPREDICTABLE/*invokestatic*/, | |||
UNPREDICTABLE/*invokeinterface*/, UNDEFINED, 1/*new*/, 1/*newarray*/, 1/*anewarray*/, | |||
1/*arraylength*/, 1/*athrow*/, 1/*checkcast*/, 1/*instanceof*/, 0/*monitorenter*/, | |||
0/*monitorexit*/, 0/*wide*/, 1/*multianewarray*/, 0/*ifnull*/, 0/*ifnonnull*/, | |||
0/*goto_w*/, 1/*jsr_w*/, 0/*breakpoint*/, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNDEFINED, UNDEFINED, UNDEFINED, | |||
UNDEFINED, UNPREDICTABLE/*impdep1*/, UNPREDICTABLE/*impdep2*/ | |||
}; | |||
/** Attributes and their corresponding names. | |||
*/ | |||
// Attributes and their corresponding names. | |||
public static final byte ATTR_UNKNOWN = -1; | |||
public static final byte ATTR_SOURCE_FILE = 0; | |||
public static final byte ATTR_CONSTANT_VALUE = 1; | |||
@@ -766,10 +883,8 @@ public interface Constants { | |||
public static final byte ATTR_SYNTHETIC = 7; | |||
public static final byte ATTR_DEPRECATED = 8; | |||
public static final byte ATTR_PMG = 9; | |||
public static final byte ATTR_SIGNATURE = 10; //J5TODO: Is this the same as a Java5 signature attribute? | |||
public static final byte ATTR_SIGNATURE = 10; | |||
public static final byte ATTR_STACK_MAP = 11; | |||
// J5SUPPORT: | |||
public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS = 12; | |||
public static final byte ATTR_RUNTIME_INVISIBLE_ANNOTATIONS = 13; | |||
public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = 14; | |||
@@ -785,7 +900,6 @@ public interface Constants { | |||
"LineNumberTable", "LocalVariableTable", | |||
"InnerClasses", "Synthetic", "Deprecated", | |||
"PMGClass", "Signature", "StackMap", | |||
// J5SUPPORT: | |||
"RuntimeVisibleAnnotations","RuntimeInvisibleAnnotations", | |||
"RuntimeVisibleParameterAnnotations","RuntimeInvisibleParameterAnnotations", | |||
"LocalVariableTypeTable","EnclosingMethod","AnnotationDefault" |
@@ -57,7 +57,7 @@ package org.aspectj.apache.bcel; | |||
/** | |||
* Exception constants. | |||
* | |||
* @version $Id: ExceptionConstants.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ | |||
* @version $Id: ExceptionConstants.java,v 1.3 2008/05/28 23:53:04 aclement Exp $ | |||
* @author <A HREF="http://www.inf.fu-berlin.de/~ehaase">E. Haase</A> | |||
*/ | |||
public interface ExceptionConstants { | |||
@@ -107,11 +107,47 @@ public interface ExceptionConstants { | |||
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, | |||
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR | |||
}; // Chapter 5.1 | |||
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_MULTIANEWARRAY = { | |||
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, | |||
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION,ILLEGAL_ACCESS_ERROR | |||
}; | |||
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY = { | |||
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, | |||
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION | |||
}; // Chapter 5.1 | |||
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST = { | |||
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, | |||
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,CLASS_CAST_EXCEPTION | |||
}; // Chapter 5.1 | |||
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS= { | |||
NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, | |||
EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, INSTANTIATION_ERROR,ILLEGAL_ACCESS_ERROR | |||
}; | |||
public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = { | |||
NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR | |||
}; // Chapter 5.2 | |||
public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD = { | |||
NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION | |||
}; | |||
public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC = { | |||
NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR | |||
}; | |||
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE = { | |||
INCOMPATIBLE_CLASS_CHANGE_ERROR,ILLEGAL_ACCESS_ERROR,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR | |||
}; | |||
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { | |||
INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR | |||
}; | |||
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { | |||
INCOMPATIBLE_CLASS_CHANGE_ERROR,UNSATISFIED_LINK_ERROR | |||
}; | |||
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below) | |||
public static final Class[] EXCS_STRING_RESOLUTION = new Class[0]; | |||
// Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.) |
@@ -66,7 +66,7 @@ import java.io.*; | |||
* @see org.aspectj.apache.bcel.util.Repository | |||
* @see org.aspectj.apache.bcel.util.SyntheticRepository | |||
* | |||
* @version $Id: Repository.java,v 1.3 2004/11/19 16:45:19 aclement Exp $ | |||
* @version $Id: Repository.java,v 1.4 2008/05/28 23:53:04 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class Repository { | |||
@@ -95,11 +95,9 @@ public abstract class Repository { | |||
try { | |||
JavaClass clazz = getRepository().findClass(class_name); | |||
if(clazz == null) { | |||
return getRepository().loadClass(class_name); | |||
} else { | |||
return clazz; | |||
} | |||
if(clazz != null) return clazz; | |||
return getRepository().loadClass(class_name); | |||
} catch(ClassNotFoundException ex) { return null; } | |||
} | |||
@@ -1,183 +0,0 @@ | |||
package org.aspectj.apache.bcel.classfile; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Super class for all objects that have modifiers like private, final, ... | |||
* I.e. classes, fields, and methods. | |||
* | |||
* @version $Id: AccessFlags.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class AccessFlags implements java.io.Serializable { | |||
protected int access_flags; | |||
public AccessFlags() {} | |||
/** | |||
* @param a inital access flags | |||
*/ | |||
public AccessFlags(int a) { | |||
access_flags = a; | |||
} | |||
/** | |||
* @return Access flags of the object aka. "modifiers". | |||
*/ | |||
public final int getAccessFlags() { return access_flags; } | |||
/** | |||
* @return Access flags of the object aka. "modifiers". | |||
*/ | |||
public final int getModifiers() { return access_flags; } | |||
/** Set access flags aka "modifiers". | |||
* @param access_flags Access flags of the object. | |||
*/ | |||
public final void setAccessFlags(int access_flags) { | |||
this.access_flags = access_flags; | |||
} | |||
/** Set access flags aka "modifiers". | |||
* @param access_flags Access flags of the object. | |||
*/ | |||
public final void setModifiers(int access_flags) { | |||
setAccessFlags(access_flags); | |||
} | |||
private final void setFlag(int flag, boolean set) { | |||
if((access_flags & flag) != 0) { // Flag is set already | |||
if(!set) // Delete flag ? | |||
access_flags ^= flag; | |||
} else { // Flag not set | |||
if(set) // Set flag ? | |||
access_flags |= flag; | |||
} | |||
} | |||
public final void isPublic(boolean flag) { setFlag(Constants.ACC_PUBLIC, flag); } | |||
public final boolean isPublic() { | |||
return (access_flags & Constants.ACC_PUBLIC) != 0; | |||
} | |||
public final void isPrivate(boolean flag) { setFlag(Constants.ACC_PRIVATE, flag); } | |||
public final boolean isPrivate() { | |||
return (access_flags & Constants.ACC_PRIVATE) != 0; | |||
} | |||
public final void isProtected(boolean flag) { setFlag(Constants.ACC_PROTECTED, flag); } | |||
public final boolean isProtected() { | |||
return (access_flags & Constants.ACC_PROTECTED) != 0; | |||
} | |||
public final void isStatic(boolean flag) { setFlag(Constants.ACC_STATIC, flag); } | |||
public final boolean isStatic() { | |||
return (access_flags & Constants.ACC_STATIC) != 0; | |||
} | |||
public final void isFinal(boolean flag) { setFlag(Constants.ACC_FINAL, flag); } | |||
public final boolean isFinal() { | |||
return (access_flags & Constants.ACC_FINAL) != 0; | |||
} | |||
public final void isSynchronized(boolean flag) { setFlag(Constants.ACC_SYNCHRONIZED, flag); } | |||
public final boolean isSynchronized() { | |||
return (access_flags & Constants.ACC_SYNCHRONIZED) != 0; | |||
} | |||
public final void isVolatile(boolean flag) { setFlag(Constants.ACC_VOLATILE, flag); } | |||
public final boolean isVolatile() { | |||
return (access_flags & Constants.ACC_VOLATILE) != 0; | |||
} | |||
public final void isTransient(boolean flag) { setFlag(Constants.ACC_TRANSIENT, flag); } | |||
public final boolean isTransient() { | |||
return (access_flags & Constants.ACC_TRANSIENT) != 0; | |||
} | |||
public final void isNative(boolean flag) { setFlag(Constants.ACC_NATIVE, flag); } | |||
public final boolean isNative() { | |||
return (access_flags & Constants.ACC_NATIVE) != 0; | |||
} | |||
public final void isInterface(boolean flag) { setFlag(Constants.ACC_INTERFACE, flag); } | |||
public final boolean isInterface() { | |||
return (access_flags & Constants.ACC_INTERFACE) != 0; | |||
} | |||
public final void isAbstract(boolean flag) { setFlag(Constants.ACC_ABSTRACT, flag); } | |||
public final boolean isAbstract() { | |||
return (access_flags & Constants.ACC_ABSTRACT) != 0; | |||
} | |||
public final void isStrictfp(boolean flag) { setFlag(Constants.ACC_STRICT, flag); } | |||
public final boolean isStrictfp() { | |||
return (access_flags & Constants.ACC_STRICT) != 0; | |||
} | |||
public final void isVarargs(boolean flag) { setFlag(Constants.ACC_VARARGS, flag); } | |||
/** J5SUPPORT: Called on methods to determine if they were written with varargs. */ | |||
public final boolean isVarargs() { | |||
return (access_flags & Constants.ACC_VARARGS) != 0; | |||
} | |||
public final void isBridge(boolean flag) { setFlag(Constants.ACC_BRIDGE, flag); } | |||
/** J5SUPPORT: Called on methods to determine if they are bridge methods */ | |||
public final boolean isBridge() { | |||
return (access_flags & Constants.ACC_BRIDGE) != 0; | |||
} | |||
} |
@@ -17,7 +17,7 @@ import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen; | |||
/** | |||
* This attribute is attached to a method and indicates the default | |||
@@ -25,31 +25,31 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
*/ | |||
public class AnnotationDefault extends Attribute { | |||
private ElementValue value; | |||
private ElementValueGen value; | |||
public AnnotationDefault(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { | |||
this(nameIndex, len, ElementValue.readElementValue(dis,cpool), cpool); | |||
this(nameIndex, len, ElementValueGen.readElementValue(dis,cpool), cpool); | |||
} | |||
private AnnotationDefault(int nameIndex, int len, ElementValue value, ConstantPool cpool) { | |||
private AnnotationDefault(int nameIndex, int len, ElementValueGen value, ConstantPool cpool) { | |||
super(Constants.ATTR_ANNOTATION_DEFAULT, nameIndex, len, cpool); | |||
this.value = value; | |||
} | |||
public void accept(Visitor v) { | |||
v.visitAnnotationDefault(this); | |||
} | |||
public Attribute copy(ConstantPool constant_pool) { | |||
throw new RuntimeException("Not implemented yet!"); | |||
// is this next line sufficient? | |||
// return (EnclosingMethod)clone(); | |||
} | |||
public final ElementValue getElementValue() { return value; } | |||
public final ElementValueGen getElementValue() { return value; } | |||
public final void dump(DataOutputStream dos) throws IOException { | |||
super.dump(dos); | |||
value.dump(dos); | |||
} | |||
public void accept(ClassVisitor v) { | |||
v.visitAnnotationDefault(this); | |||
} | |||
} |
@@ -61,7 +61,6 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; | |||
import java.io.*; | |||
import java.util.HashMap; | |||
/** | |||
* Abstract super class for <em>Attribute</em> objects. Currently the | |||
@@ -71,7 +70,7 @@ import java.util.HashMap; | |||
* <em>Synthetic</em> attributes are supported. The | |||
* <em>Unknown</em> attribute stands for non-standard-attributes. | |||
* | |||
* @version $Id: Attribute.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Attribute.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see ConstantValue | |||
* @see SourceFile | |||
@@ -86,218 +85,86 @@ import java.util.HashMap; | |||
* @see Signature | |||
*/ | |||
public abstract class Attribute implements Cloneable, Node, Serializable { | |||
protected int name_index; // Points to attribute name in constant pool | |||
protected int length; // Content length of attribute field | |||
protected byte tag; // Tag to distiguish subclasses | |||
protected ConstantPool constant_pool; | |||
public static Attribute[] NoAttributes = new Attribute[0]; | |||
protected Attribute(byte tag, int name_index, int length, | |||
ConstantPool constant_pool) { | |||
this.tag = tag; | |||
this.name_index = name_index; | |||
this.length = length; | |||
this.constant_pool = constant_pool; | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
* defined by the contents of a Java class. I.e., the hierarchy of methods, | |||
* fields, attributes, etc. spawns a tree of objects. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public abstract void accept(Visitor v); | |||
/** | |||
* Dump attribute to file stream in binary format. | |||
* | |||
* @param file Output file stream | |||
* @throws IOException | |||
*/ | |||
public void dump(DataOutputStream file) throws IOException | |||
{ | |||
file.writeShort(name_index); | |||
file.writeInt(length); | |||
} | |||
private static HashMap readers = new HashMap(); | |||
/** Add an Attribute reader capable of parsing (user-defined) attributes | |||
* named "name". You should not add readers for the standard attributes | |||
* such as "LineNumberTable", because those are handled internally. | |||
* | |||
* @param name the name of the attribute as stored in the class file | |||
* @param r the reader object | |||
*/ | |||
public static void addAttributeReader(String name, AttributeReader r) { | |||
readers.put(name, r); | |||
} | |||
/** Remove attribute reader | |||
* | |||
* @param name the name of the attribute as stored in the class file | |||
*/ | |||
public static void removeAttributeReader(String name) { | |||
readers.remove(name); | |||
} | |||
protected byte tag; // Tag to distinguish subclasses | |||
protected int nameIndex; // Points to attribute name in constant pool | |||
protected int length; // Content length of attribute field | |||
protected ConstantPool constantPool; | |||
protected Attribute(byte tag, int nameIndex, int length, ConstantPool constantPool) { | |||
this.tag = tag; | |||
this.nameIndex = nameIndex; | |||
this.length = length; | |||
this.constantPool = constantPool; | |||
} | |||
/* Class method reads one attribute from the input data stream. | |||
* This method must not be accessible from the outside. It is | |||
* called by the Field and Method constructor methods. | |||
* | |||
* @see Field | |||
* @see Method | |||
* @param file Input stream | |||
* @param constant_pool Array of constants | |||
* @return Attribute | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
public static final Attribute readAttribute(DataInputStream file, | |||
ConstantPool constant_pool) | |||
throws IOException, ClassFormatException | |||
{ | |||
ConstantUtf8 c; | |||
String name; | |||
int name_index; | |||
int length; | |||
byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute | |||
/** Dump attribute to file stream in binary format */ | |||
public void dump(DataOutputStream file) throws IOException { | |||
file.writeShort(nameIndex); | |||
file.writeInt(length); | |||
} | |||
// Get class name from constant pool via 'name_index' indirection | |||
name_index = (int)file.readUnsignedShort(); | |||
c = (ConstantUtf8)constant_pool.getConstant(name_index, | |||
Constants.CONSTANT_Utf8); | |||
name = c.getBytes(); | |||
// Length of data in bytes | |||
length = file.readInt(); | |||
public static final Attribute readAttribute(DataInputStream file, ConstantPool cpool) throws IOException { | |||
byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute | |||
int idx = file.readUnsignedShort(); | |||
String name = cpool.getConstantUtf8(idx).getBytes(); | |||
int len = file.readInt(); | |||
// Compare strings to find known attribute | |||
for(byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) { | |||
if(name.equals(Constants.ATTRIBUTE_NAMES[i])) { | |||
tag = i; // found! | |||
break; | |||
} | |||
for (byte i=0; i < Constants.KNOWN_ATTRIBUTES; i++) { | |||
if (name.equals(Constants.ATTRIBUTE_NAMES[i])) { tag = i; break; } | |||
} | |||
// Call proper constructor, depending on `tag' | |||
switch(tag) { | |||
case Constants.ATTR_UNKNOWN: | |||
AttributeReader r = (AttributeReader)readers.get(name); | |||
if(r != null) | |||
return r.createAttribute(name_index, length, file, constant_pool); | |||
else | |||
return new Unknown(name_index, length, file, constant_pool); | |||
case Constants.ATTR_CONSTANT_VALUE: | |||
return new ConstantValue(name_index, length, file, constant_pool); | |||
case Constants.ATTR_SOURCE_FILE: | |||
return new SourceFile(name_index, length, file, constant_pool); | |||
case Constants.ATTR_CODE: | |||
return new Code(name_index, length, file, constant_pool); | |||
case Constants.ATTR_EXCEPTIONS: | |||
return new ExceptionTable(name_index, length, file, constant_pool); | |||
case Constants.ATTR_LINE_NUMBER_TABLE: | |||
return new LineNumberTable(name_index, length, file, constant_pool); | |||
case Constants.ATTR_LOCAL_VARIABLE_TABLE: | |||
return new LocalVariableTable(name_index, length, file, constant_pool); | |||
case Constants.ATTR_INNER_CLASSES: | |||
return new InnerClasses(name_index, length, file, constant_pool); | |||
case Constants.ATTR_SYNTHETIC: | |||
return new Synthetic(name_index, length, file, constant_pool); | |||
case Constants.ATTR_DEPRECATED: | |||
return new Deprecated(name_index, length, file, constant_pool); | |||
case Constants.ATTR_PMG: | |||
return new PMGClass(name_index, length, file, constant_pool); | |||
case Constants.ATTR_SIGNATURE: | |||
return new Signature(name_index, length, file, constant_pool); | |||
case Constants.ATTR_STACK_MAP: | |||
return new StackMap(name_index, length, file, constant_pool); | |||
// J5SUPPORT: | |||
case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS: | |||
return new RuntimeVisibleAnnotations(name_index,length,file,constant_pool); | |||
case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS: | |||
return new RuntimeInvisibleAnnotations(name_index,length,file,constant_pool); | |||
case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS: | |||
return new RuntimeVisibleParameterAnnotations(name_index,length,file,constant_pool); | |||
case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS: | |||
return new RuntimeInvisibleParameterAnnotations(name_index,length,file,constant_pool); | |||
case Constants.ATTR_ANNOTATION_DEFAULT: | |||
return new AnnotationDefault(name_index,length,file,constant_pool); | |||
case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE: | |||
return new LocalVariableTypeTable(name_index,length,file,constant_pool); | |||
case Constants.ATTR_ENCLOSING_METHOD: | |||
return new EnclosingMethod(name_index,length,file,constant_pool); | |||
default: // Never reached | |||
throw new IllegalStateException("Ooops! default case reached."); | |||
} | |||
case Constants.ATTR_UNKNOWN: return new Unknown(idx, len, file, cpool); | |||
case Constants.ATTR_CONSTANT_VALUE: return new ConstantValue(idx, len, file, cpool); | |||
case Constants.ATTR_SOURCE_FILE: return new SourceFile(idx, len, file, cpool); | |||
case Constants.ATTR_CODE: return new Code(idx, len, file, cpool); | |||
case Constants.ATTR_EXCEPTIONS: return new ExceptionTable(idx, len, file, cpool); | |||
case Constants.ATTR_LINE_NUMBER_TABLE: return new LineNumberTable(idx, len, file, cpool); | |||
case Constants.ATTR_LOCAL_VARIABLE_TABLE: return new LocalVariableTable(idx, len, file, cpool); | |||
case Constants.ATTR_INNER_CLASSES: return new InnerClasses(idx, len, file, cpool); | |||
case Constants.ATTR_SYNTHETIC: return new Synthetic(idx, len, file, cpool); | |||
case Constants.ATTR_DEPRECATED: return new Deprecated(idx, len, file, cpool); | |||
case Constants.ATTR_PMG: return new PMGClass(idx, len, file, cpool); | |||
case Constants.ATTR_SIGNATURE: return new Signature(idx, len, file, cpool); | |||
case Constants.ATTR_STACK_MAP: return new StackMap(idx, len, file, cpool); | |||
case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS: | |||
return new RuntimeVisibleAnnotations(idx,len,file,cpool); | |||
case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS: | |||
return new RuntimeInvisibleAnnotations(idx,len,file,cpool); | |||
case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS: | |||
return new RuntimeVisibleParameterAnnotations(idx,len,file,cpool); | |||
case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS: | |||
return new RuntimeInvisibleParameterAnnotations(idx,len,file,cpool); | |||
case Constants.ATTR_ANNOTATION_DEFAULT: | |||
return new AnnotationDefault(idx,len,file,cpool); | |||
case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE: | |||
return new LocalVariableTypeTable(idx,len,file,cpool); | |||
case Constants.ATTR_ENCLOSING_METHOD: | |||
return new EnclosingMethod(idx,len,file,cpool); | |||
default: throw new IllegalStateException(); | |||
} | |||
} | |||
public String getName() { | |||
ConstantUtf8 c = | |||
(ConstantUtf8)constant_pool.getConstant(name_index,Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
return constantPool.getConstantUtf8(nameIndex).getBytes(); | |||
} | |||
/** | |||
* @return Length of attribute field in bytes. | |||
*/ | |||
public final int getLength() { return length; } | |||
/** | |||
* @param Attribute length in bytes. | |||
*/ | |||
public final void setLength(int length) { | |||
this.length = length; | |||
} | |||
/** | |||
* @param name_index of attribute. | |||
*/ | |||
public final void setNameIndex(int name_index) { | |||
this.name_index = name_index; | |||
} | |||
/** | |||
* @return Name index in constant pool of attribute name. | |||
*/ | |||
public final int getNameIndex() { return name_index; } | |||
/** | |||
* @return Tag of attribute, i.e., its type. Value may not be altered, thus | |||
* there is no setTag() method. | |||
*/ | |||
public final byte getTag() { return tag; } | |||
public final int getLength() { return length; } | |||
/** | |||
* @return Constant pool used by this object. | |||
* @see ConstantPool | |||
*/ | |||
public final ConstantPool getConstantPool() { return constant_pool; } | |||
public final int getNameIndex() { return nameIndex; } | |||
public final byte getTag() { return tag; } | |||
/** | |||
* @param constant_pool Constant pool to be used for this object. | |||
* @see ConstantPool | |||
*/ | |||
public final void setConstantPool(ConstantPool constant_pool) { | |||
this.constant_pool = constant_pool; | |||
} | |||
public final ConstantPool getConstantPool() { return constantPool; } | |||
/** | |||
* Use copy() if you want to have a deep copy(), i.e., with all references | |||
* Use copy() if you want to have a deep copy(), ie. with all references | |||
* copied correctly. | |||
* | |||
* @return shallow copy of this attribute | |||
@@ -319,10 +186,10 @@ public abstract class Attribute implements Cloneable, Node, Serializable { | |||
*/ | |||
public abstract Attribute copy(ConstantPool constant_pool); | |||
/** | |||
* @return attribute name. | |||
*/ | |||
public String toString() { | |||
return Constants.ATTRIBUTE_NAMES[tag]; | |||
} | |||
public abstract void accept(ClassVisitor v); | |||
} |
@@ -1,97 +0,0 @@ | |||
package org.aspectj.apache.bcel.classfile; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* Unknown (non-standard) attributes may be read via user-defined factory | |||
* objects that can be registered with the Attribute.addAttributeReader | |||
* method. These factory objects should implement this interface. | |||
* @see Attribute | |||
* @version $Id: AttributeReader.java,v 1.6 2008/04/25 17:58:22 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public interface AttributeReader { | |||
/** | |||
When this attribute reader is added via the static method | |||
Attribute.addAttributeReader, an attribute name is associated with it. | |||
As the class file parser parses attributes, it will call various | |||
AttributeReaders based on the name of the attributes it is | |||
constructing. | |||
@param name_index An index into the constant pool, indexing a | |||
ConstantUtf8 that represents the name of the attribute. | |||
@param length The length of the data contained in the attribute. This | |||
is written into the constant pool and should agree with what the | |||
factory expects the length to be. | |||
@param file This is the data input stream that the factory needs to read | |||
its data from. | |||
@param constant_pool This is the constant pool associated with the | |||
Attribute that we are constructing. | |||
@return The user-defined AttributeReader should take this data and use | |||
it to construct an attribute. In the case of errors, a null can be | |||
returned which will cause the parsing of the class file to fail. | |||
@see Attribute#addAttributeReader( String, AttributeReader ) | |||
*/ | |||
public Attribute createAttribute(int name_index, | |||
int length, | |||
java.io.DataInputStream file, | |||
ConstantPool constant_pool); | |||
} |
@@ -0,0 +1,93 @@ | |||
package org.aspectj.apache.bcel.classfile; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
public class AttributeUtils { | |||
public static Attribute[] readAttributes(DataInputStream dataInputstream, ConstantPool cpool) { | |||
try { | |||
int length = dataInputstream.readUnsignedShort(); | |||
if (length==0) return Attribute.NoAttributes; | |||
Attribute[] attrs = new Attribute[length]; | |||
for (int i=0; i < length; i++) | |||
attrs[i] = Attribute.readAttribute(dataInputstream, cpool); | |||
return attrs; | |||
} catch (IOException e) { | |||
throw new ClassFormatException("IOException whilst reading set of attributes: "+e.toString()); | |||
} | |||
} | |||
/** Write (serialize) a set of attributes into a specified output stream */ | |||
public static void writeAttributes(Attribute[] attributes,DataOutputStream file) throws IOException { | |||
if (attributes==null) { | |||
file.writeShort(0); | |||
} else { | |||
file.writeShort(attributes.length); | |||
for(int i=0; i < attributes.length; i++) | |||
attributes[i].dump(file); | |||
} | |||
} | |||
public static Attribute[] copy(Attribute[] attributes, ConstantPool constant_pool) { | |||
if (attributes==null || attributes.length==0) return Attribute.NoAttributes; | |||
Attribute[] attrs = new Attribute[attributes.length]; | |||
for (int i = 0; i < attributes.length; i++) { | |||
attrs[i] = attributes[i].copy(constant_pool); | |||
} | |||
return attrs; | |||
} | |||
public static Signature getSignatureAttribute(Attribute[] attributes) { | |||
for(int i=0; i < attributes.length; i++) { | |||
if (attributes[i].tag==Constants.ATTR_SIGNATURE) return ((Signature)attributes[i]); | |||
} | |||
return null; | |||
} | |||
public static Code getCodeAttribute(Attribute[] attributes) { | |||
for(int i=0; i < attributes.length; i++) { | |||
if (attributes[i].tag==Constants.ATTR_CODE) { return ((Code)attributes[i]);} | |||
} | |||
return null; | |||
} | |||
public static ExceptionTable getExceptionTableAttribute(Attribute[] attributes) { | |||
for(int i=0; i < attributes.length; i++) { | |||
if (attributes[i].tag==Constants.ATTR_EXCEPTIONS) { return ((ExceptionTable)attributes[i]);} | |||
} | |||
return null; | |||
} | |||
public static ConstantValue getConstantValueAttribute(Attribute[] attributes) { | |||
for(int i=0; i < attributes.length; i++) { | |||
if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) return (ConstantValue)attributes[i]; | |||
} | |||
return null; | |||
} | |||
public static void accept(Attribute[] attributes,ClassVisitor visitor) { | |||
for(int i=0; i < attributes.length; i++) | |||
attributes[i].accept(visitor); | |||
} | |||
public static boolean hasSyntheticAttribute(Attribute[] attributes) { | |||
for (int i = 0; i < attributes.length; i++) { | |||
if (attributes[i].tag==Constants.ATTR_SYNTHETIC) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
public static SourceFile getSourceFileAttribute(Attribute[] attributes) { | |||
for(int i=0; i < attributes.length; i++) { | |||
if (attributes[i].tag==Constants.ATTR_SOURCE_FILE) { return ((SourceFile)attributes[i]);} | |||
} | |||
return null; | |||
} | |||
} |
@@ -59,7 +59,7 @@ package org.aspectj.apache.bcel.classfile; | |||
* that the file is malformed or otherwise cannot be interpreted as a | |||
* class file. | |||
* | |||
* @version $Id: ClassFormatException.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ClassFormatException.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ClassFormatException extends RuntimeException { |
@@ -70,71 +70,40 @@ import java.util.zip.*; | |||
* JVM specification 1.0</a>. See this paper for | |||
* further details about the structure of a bytecode file. | |||
* | |||
* @version $Id: ClassParser.java,v 1.4 2005/10/14 08:39:32 aclement Exp $ | |||
* @version $Id: ClassParser.java,v 1.5 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class ClassParser { | |||
private DataInputStream file; | |||
private ZipFile zip; | |||
private String file_name; | |||
private int class_name_index, superclass_name_index; | |||
private int major, minor; // Compiler version | |||
private int access_flags; // Access rights of parsed class | |||
private int[] interfaces; // Names of implemented interfaces | |||
private ConstantPool constant_pool; // collection of constants | |||
private Field[] fields; // class fields, i.e., its variables | |||
private Method[] methods; // methods defined in the class | |||
private Attribute[] attributes; // attributes defined in the class | |||
private boolean is_zip; // Loaded from zip file | |||
private String filename; | |||
private int classnameIndex; | |||
private int superclassnameIndex; | |||
private int major, minor; | |||
private int accessflags; | |||
private int[] interfaceIndices; | |||
private ConstantPool cpool; | |||
private Field[] fields; | |||
private Method[] methods; | |||
private Attribute[] attributes; | |||
private static final int BUFSIZE = 8192; | |||
/** | |||
* Parse class from the given stream. | |||
* | |||
* @param file Input stream | |||
* @param file_name File name | |||
*/ | |||
public ClassParser(InputStream file, String file_name) { | |||
this.file_name = file_name; | |||
String clazz = file.getClass().getName(); // Not a very clean solution ... | |||
is_zip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar."); | |||
if(file instanceof DataInputStream) // Is already a data stream | |||
this.file = (DataInputStream)file; | |||
else | |||
this.file = new DataInputStream(new BufferedInputStream(file, BUFSIZE)); | |||
/** Parse class from the given stream */ | |||
public ClassParser(InputStream file, String filename) { | |||
this.filename = filename; | |||
if (file instanceof DataInputStream) this.file = (DataInputStream)file; | |||
else this.file = new DataInputStream(new BufferedInputStream(file,BUFSIZE)); | |||
} | |||
/** Parse class from given .class file. | |||
* | |||
* @param file_name file name | |||
* @throws IOException | |||
*/ | |||
public ClassParser(String file_name) throws IOException | |||
{ | |||
is_zip = false; | |||
this.file_name = file_name; | |||
file = new DataInputStream(new BufferedInputStream | |||
(new FileInputStream(file_name), BUFSIZE)); | |||
public ClassParser(ByteArrayInputStream baos, String filename) { | |||
this.filename = filename; | |||
this.file = new DataInputStream(baos); | |||
} | |||
/** Parse class from given .class file in a ZIP-archive | |||
* | |||
* @param file_name file name | |||
* @throws IOException | |||
*/ | |||
public ClassParser(String zip_file, String file_name) throws IOException | |||
{ | |||
is_zip = true; | |||
zip = new ZipFile(zip_file); | |||
ZipEntry entry = zip.getEntry(file_name); | |||
this.file_name = file_name; | |||
file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry), | |||
BUFSIZE)); | |||
/** Parse class from given .class file */ | |||
public ClassParser(String file_name) throws IOException { | |||
this.filename = file_name; | |||
file = new DataInputStream(new BufferedInputStream(new FileInputStream(file_name),BUFSIZE)); | |||
} | |||
/** | |||
@@ -143,13 +112,8 @@ public final class ClassParser { | |||
* A <em>ClassFormatException</em> is raised, if the file is not a valid | |||
* .class file. (This does not include verification of the byte code as it | |||
* is performed by the java interpreter). | |||
* | |||
* @return Class object representing the parsed class file | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
public JavaClass parse() throws IOException, ClassFormatException | |||
{ | |||
*/ | |||
public JavaClass parse() throws IOException, ClassFormatException { | |||
/****************** Read headers ********************************/ | |||
// Check magic tag of class file | |||
readID(); | |||
@@ -160,7 +124,7 @@ public final class ClassParser { | |||
/****************** Read constant pool and related **************/ | |||
// Read constant pool entries | |||
readConstantPool(); | |||
// Get class information | |||
readClassInfo(); | |||
@@ -177,162 +141,105 @@ public final class ClassParser { | |||
// Read class attributes | |||
readAttributes(); | |||
// Check for unknown variables | |||
//Unknown[] u = Unknown.getUnknownAttributes(); | |||
//for(int i=0; i < u.length; i++) | |||
// System.err.println("WARNING: " + u[i]); | |||
// Everything should have been read now | |||
// if(file.available() > 0) { | |||
// int bytes = file.available(); | |||
// byte[] buf = new byte[bytes]; | |||
// file.read(buf); | |||
// if(!(is_zip && (buf.length == 1))) { | |||
// System.err.println("WARNING: Trailing garbage at end of " + file_name); | |||
// System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf)); | |||
// } | |||
// } | |||
// Read everything of interest, so close the file | |||
file.close(); | |||
if(zip != null) | |||
zip.close(); | |||
// Return the information we have gathered in a new object | |||
return new JavaClass(class_name_index, superclass_name_index, | |||
file_name, major, minor, access_flags, | |||
constant_pool, interfaces, fields, | |||
methods, attributes, is_zip? JavaClass.ZIP : JavaClass.FILE); | |||
JavaClass jc= new JavaClass(classnameIndex, superclassnameIndex, | |||
filename, major, minor, accessflags, | |||
cpool, interfaceIndices, fields, | |||
methods, attributes); | |||
return jc; | |||
} | |||
/** | |||
* Read information about the attributes of the class. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readAttributes() throws IOException, ClassFormatException | |||
{ | |||
int attributes_count; | |||
attributes_count = file.readUnsignedShort(); | |||
attributes = new Attribute[attributes_count]; | |||
for(int i=0; i < attributes_count; i++) | |||
attributes[i] = Attribute.readAttribute(file, constant_pool); | |||
/** Read information about the attributes of the class */ | |||
private final void readAttributes() { | |||
attributes = AttributeUtils.readAttributes(file,cpool); | |||
} | |||
/** | |||
* Read information about the class and its super class. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readClassInfo() throws IOException, ClassFormatException | |||
{ | |||
access_flags = file.readUnsignedShort(); | |||
/** Read information about the class and its super class */ | |||
private final void readClassInfo() throws IOException { | |||
accessflags = file.readUnsignedShort(); | |||
/* Interfaces are implicitely abstract, the flag should be set | |||
* according to the JVM specification. | |||
*/ | |||
if((access_flags & Constants.ACC_INTERFACE) != 0) | |||
access_flags |= Constants.ACC_ABSTRACT; | |||
* according to the JVM specification */ | |||
if((accessflags & Constants.ACC_INTERFACE) != 0) | |||
accessflags |= Constants.ACC_ABSTRACT; | |||
// don't police it like this... leave higher level verification code to check it. | |||
// if(((access_flags & Constants.ACC_ABSTRACT) != 0) && | |||
// ((access_flags & Constants.ACC_FINAL) != 0 )) | |||
// throw new ClassFormatException("Class can't be both final and abstract"); | |||
class_name_index = file.readUnsignedShort(); | |||
superclass_name_index = file.readUnsignedShort(); | |||
} | |||
/** | |||
* Read constant pool entries. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readConstantPool() throws IOException, ClassFormatException | |||
{ | |||
classnameIndex = file.readUnsignedShort(); | |||
superclassnameIndex = file.readUnsignedShort(); | |||
} | |||
/** Read constant pool entries */ | |||
private final void readConstantPool() throws IOException { | |||
try { | |||
constant_pool = new ConstantPool(file); | |||
cpool = new ConstantPool(file); | |||
} catch (ClassFormatException cfe) { | |||
// add some context if we can | |||
if (file_name!=null) { | |||
String newmessage = "File: '"+file_name+"': "+cfe.getMessage(); | |||
cfe.printStackTrace(); | |||
if (filename!=null) { | |||
String newmessage = "File: '"+filename+"': "+cfe.getMessage(); | |||
throw new ClassFormatException(newmessage); // this loses the old stack trace but I dont think that matters! | |||
} | |||
throw cfe; | |||
} | |||
} | |||
/** | |||
* Read information about the fields of the class, i.e., its variables. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readFields() throws IOException, ClassFormatException | |||
{ | |||
int fields_count; | |||
fields_count = file.readUnsignedShort(); | |||
fields = new Field[fields_count]; | |||
for(int i=0; i < fields_count; i++) | |||
fields[i] = new Field(file, constant_pool); | |||
/** Read information about the fields of the class */ | |||
private final void readFields() throws IOException, ClassFormatException { | |||
int fieldCount = file.readUnsignedShort(); | |||
if (fieldCount == 0) { | |||
fields = Field.NoFields; | |||
} else { | |||
fields = new Field[fieldCount]; | |||
for(int i=0; i < fieldCount; i++) | |||
fields[i] = new Field(file, cpool); | |||
} | |||
} | |||
/******************** Private utility methods **********************/ | |||
/** | |||
* Check whether the header of the file is ok. | |||
* Of course, this has to be the first action on successive file reads. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readID() throws IOException, ClassFormatException | |||
{ | |||
/** Check whether the header of the file is ok. Of course, this has | |||
* to be the first action on successive file reads */ | |||
private final void readID() throws IOException { | |||
int magic = 0xCAFEBABE; | |||
if(file.readInt() != magic) | |||
throw new ClassFormatException(file_name + " is not a Java .class file"); | |||
} | |||
/** | |||
* Read information about the interfaces implemented by this class. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readInterfaces() throws IOException, ClassFormatException | |||
{ | |||
int interfaces_count; | |||
interfaces_count = file.readUnsignedShort(); | |||
interfaces = new int[interfaces_count]; | |||
for(int i=0; i < interfaces_count; i++) | |||
interfaces[i] = file.readUnsignedShort(); | |||
if (file.readInt() != magic) | |||
throw new ClassFormatException(filename + " is not a Java .class file"); | |||
} | |||
private static final int[] NO_INTERFACES = new int[0]; | |||
/** Read information about the interfaces implemented by this class */ | |||
private final void readInterfaces() throws IOException { | |||
int interfacesCount = file.readUnsignedShort(); | |||
if (interfacesCount==0) { | |||
interfaceIndices = NO_INTERFACES; | |||
} else { | |||
interfaceIndices = new int[interfacesCount]; | |||
for(int i=0; i < interfacesCount; i++) | |||
interfaceIndices[i] = file.readUnsignedShort(); | |||
} | |||
} | |||
/** | |||
* Read information about the methods of the class. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readMethods() throws IOException, ClassFormatException | |||
{ | |||
int methods_count; | |||
methods_count = file.readUnsignedShort(); | |||
methods = new Method[methods_count]; | |||
for(int i=0; i < methods_count; i++) | |||
methods[i] = new Method(file, constant_pool); | |||
/** Read information about the methods of the class */ | |||
private final void readMethods() throws IOException { | |||
int methodsCount = file.readUnsignedShort(); | |||
if (methodsCount==0) { | |||
methods = Method.NoMethods; | |||
} else { | |||
methods = new Method[methodsCount]; | |||
for(int i=0; i < methodsCount; i++) | |||
methods[i] = new Method(file, cpool); | |||
} | |||
} | |||
/** | |||
* Read major and minor version of compiler which created the file. | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
private final void readVersion() throws IOException, ClassFormatException | |||
{ | |||
/** Read major and minor version of compiler which created the file */ | |||
private final void readVersion() throws IOException { | |||
minor = file.readUnsignedShort(); | |||
major = file.readUnsignedShort(); | |||
} | |||
} |
@@ -67,10 +67,10 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnot | |||
* Implemented by wish of | |||
* <A HREF="http://www.inf.fu-berlin.de/~bokowski">Boris Bokowski</A>. | |||
* | |||
* @version $Id: Visitor.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ClassVisitor.java,v 1.2 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public interface Visitor { | |||
public interface ClassVisitor { | |||
public void visitCode(Code obj); | |||
public void visitCodeException(CodeException obj); | |||
public void visitConstantClass(ConstantClass obj); |
@@ -69,23 +69,19 @@ import java.io.*; | |||
* is used for debugging purposes and <em>LocalVariableTable</em> which | |||
* contains information about the local variables. | |||
* | |||
* @version $Id: Code.java,v 1.3 2006/09/22 10:50:17 aclement Exp $ | |||
* @version $Id: Code.java,v 1.4 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
* @see CodeException | |||
* @see LineNumberTable | |||
* @see LocalVariableTable | |||
* @see LocalVariableTable | |||
*/ | |||
public final class Code extends Attribute { | |||
private int max_stack; // Maximum size of stack used by this method | |||
private int max_locals; // Number of local variables | |||
private int code_length; // Length of code in bytes | |||
private byte[] code; // Actual byte code | |||
private int exception_table_length; | |||
private CodeException[] exception_table; // Table of handled exceptions | |||
private int attributes_count; // Attributes of code: LineNumber | |||
private Attribute[] attributes; // or LocalVariable | |||
private int maxStack; // Maximum size of stack used by this method | |||
private int maxLocals; // Number of local variables | |||
private byte[] code; // Actual byte code | |||
private CodeException[] exceptionTable; | |||
private Attribute[] attributes; | |||
/** | |||
* Initialize from another object. Note that both objects use the same | |||
@@ -97,41 +93,28 @@ public final class Code extends Attribute { | |||
c.getConstantPool()); | |||
} | |||
/** | |||
* @param name_index Index pointing to the name <em>Code</em> | |||
* @param length Content length in bytes | |||
* @param file Input stream | |||
* @param constant_pool Array of constants | |||
*/ | |||
Code(int name_index, int length, DataInputStream file, | |||
ConstantPool constant_pool) throws IOException | |||
{ | |||
Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException { | |||
// Initialize with some default values which will be overwritten later | |||
this(name_index, length, | |||
file.readUnsignedShort(), file.readUnsignedShort(), | |||
(byte[])null, (CodeException[])null, (Attribute[])null, | |||
constant_pool); | |||
code_length = file.readInt(); | |||
code = new byte[code_length]; // Read byte code | |||
int len = file.readInt(); | |||
code = new byte[len]; // Read byte code | |||
file.readFully(code); | |||
/* Read exception table that contains all regions where an exception | |||
* handler is active, i.e., a try { ... } catch() block. | |||
*/ | |||
exception_table_length = file.readUnsignedShort(); | |||
exception_table = new CodeException[exception_table_length]; | |||
len = file.readUnsignedShort(); | |||
exceptionTable = new CodeException[len]; | |||
for(int i=0; i < len; i++) | |||
exceptionTable[i] = new CodeException(file); | |||
for(int i=0; i < exception_table_length; i++) | |||
exception_table[i] = new CodeException(file); | |||
/* Read all attributes, currently `LineNumberTable' and | |||
* `LocalVariableTable' | |||
*/ | |||
attributes_count = file.readUnsignedShort(); | |||
attributes = new Attribute[attributes_count]; | |||
for(int i=0; i < attributes_count; i++) | |||
attributes[i] = Attribute.readAttribute(file, constant_pool); | |||
// Read all attributes, eg: LineNumberTable, LocalVariableTable | |||
attributes = AttributeUtils.readAttributes(file,constant_pool); | |||
/* Adjust length, because of setAttributes in this(), s.b. length | |||
* is incorrect, because it didn't take the internal attributes | |||
@@ -159,8 +142,8 @@ public final class Code extends Attribute { | |||
{ | |||
super(Constants.ATTR_CODE, name_index, length, constant_pool); | |||
this.max_stack = max_stack; | |||
this.max_locals = max_locals; | |||
this.maxStack = max_stack; | |||
this.maxLocals = max_locals; | |||
setCode(code); | |||
setExceptionTable(exception_table); | |||
@@ -174,7 +157,7 @@ public final class Code extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitCode(this); | |||
} | |||
@@ -188,17 +171,20 @@ public final class Code extends Attribute { | |||
{ | |||
super.dump(file); | |||
file.writeShort(max_stack); | |||
file.writeShort(max_locals); | |||
file.writeInt(code_length); | |||
file.write(code, 0, code_length); | |||
file.writeShort(maxStack); | |||
if (maxStack==3) { | |||
int stop = 1; // fixme | |||
} | |||
file.writeShort(maxLocals); | |||
file.writeInt(code.length); | |||
file.write(code, 0, code.length); | |||
file.writeShort(exception_table_length); | |||
for(int i=0; i < exception_table_length; i++) | |||
exception_table[i].dump(file); | |||
file.writeShort(exceptionTable.length); | |||
for(int i=0; i < exceptionTable.length; i++) | |||
exceptionTable[i].dump(file); | |||
file.writeShort(attributes_count); | |||
for(int i=0; i < attributes_count; i++) | |||
file.writeShort(attributes.length); | |||
for(int i=0; i < attributes.length; i++) | |||
attributes[i].dump(file); | |||
} | |||
@@ -212,10 +198,8 @@ public final class Code extends Attribute { | |||
* @return LineNumberTable of Code, if it has one | |||
*/ | |||
public LineNumberTable getLineNumberTable() { | |||
for(int i=0; i < attributes_count; i++) | |||
if(attributes[i] instanceof LineNumberTable) | |||
return (LineNumberTable)attributes[i]; | |||
for (int i=0; i < attributes.length; i++) | |||
if (attributes[i].tag==Constants.ATTR_LINE_NUMBER_TABLE) return (LineNumberTable)attributes[i]; | |||
return null; | |||
} | |||
@@ -223,10 +207,8 @@ public final class Code extends Attribute { | |||
* @return LocalVariableTable of Code, if it has one | |||
*/ | |||
public LocalVariableTable getLocalVariableTable() { | |||
for(int i=0; i < attributes_count; i++) | |||
if(attributes[i] instanceof LocalVariableTable) | |||
return (LocalVariableTable)attributes[i]; | |||
for(int i=0; i < attributes.length; i++) | |||
if (attributes[i].tag==Constants.ATTR_LOCAL_VARIABLE_TABLE) return (LocalVariableTable)attributes[i]; | |||
return null; | |||
} | |||
@@ -239,18 +221,18 @@ public final class Code extends Attribute { | |||
* @return Table of handled exceptions. | |||
* @see CodeException | |||
*/ | |||
public final CodeException[] getExceptionTable() { return exception_table; } | |||
public final CodeException[] getExceptionTable() { return exceptionTable; } | |||
/** | |||
* @return Number of local variables. | |||
*/ | |||
public final int getMaxLocals() { return max_locals; } | |||
public final int getMaxLocals() { return maxLocals; } | |||
/** | |||
* @return Maximum size of stack used by this method. | |||
*/ | |||
public final int getMaxStack() { return max_stack; } | |||
public final int getMaxStack() { return maxStack; } | |||
/** | |||
* @return the internal length of this code attribute (minus the first 6 bytes) | |||
@@ -258,9 +240,9 @@ public final class Code extends Attribute { | |||
*/ | |||
private final int getInternalLength() { | |||
return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/ | |||
+ code_length /*byte-code*/ | |||
+ (code==null?0:code.length) /*byte-code*/ | |||
+ 2 /*exception-table length*/ | |||
+ 8 * exception_table_length /* exception table */ | |||
+ 8 * (exceptionTable==null?0:exceptionTable.length) /* exception table */ | |||
+ 2 /* attributes count */; | |||
} | |||
@@ -270,10 +252,10 @@ public final class Code extends Attribute { | |||
*/ | |||
private final int calculateLength() { | |||
int len = 0; | |||
for(int i=0; i < attributes_count; i++) | |||
len += attributes[i].length + 6 /*attribute header size*/; | |||
if (attributes!=null) { | |||
for(int i=0; i < attributes.length; i++) | |||
len += attributes[i].length + 6 /*attribute header size*/; | |||
} | |||
return len + getInternalLength(); | |||
} | |||
@@ -282,7 +264,6 @@ public final class Code extends Attribute { | |||
*/ | |||
public final void setAttributes(Attribute[] attributes) { | |||
this.attributes = attributes; | |||
attributes_count = (attributes == null)? 0 : attributes.length; | |||
length = calculateLength(); // Adjust length | |||
} | |||
@@ -291,30 +272,27 @@ public final class Code extends Attribute { | |||
*/ | |||
public final void setCode(byte[] code) { | |||
this.code = code; | |||
code_length = (code == null)? 0 : code.length; | |||
} | |||
/** | |||
* @param exception_table exception table | |||
*/ | |||
public final void setExceptionTable(CodeException[] exception_table) { | |||
this.exception_table = exception_table; | |||
exception_table_length = (exception_table == null)? 0 : | |||
exception_table.length; | |||
this.exceptionTable = exception_table; | |||
} | |||
/** | |||
* @param max_locals maximum number of local variables | |||
*/ | |||
public final void setMaxLocals(int max_locals) { | |||
this.max_locals = max_locals; | |||
this.maxLocals = max_locals; | |||
} | |||
/** | |||
* @param max_stack maximum stack size | |||
*/ | |||
public final void setMaxStack(int max_stack) { | |||
this.max_stack = max_stack; | |||
this.maxStack = max_stack; | |||
} | |||
/** | |||
@@ -323,22 +301,22 @@ public final class Code extends Attribute { | |||
public final String toString(boolean verbose) { | |||
StringBuffer buf; | |||
buf = new StringBuffer("Code(max_stack = " + max_stack + | |||
", max_locals = " + max_locals + | |||
", code_length = " + code_length + ")\n" + | |||
Utility.codeToString(code, constant_pool, 0, -1, verbose)); | |||
buf = new StringBuffer("Code(max_stack = " + maxStack + | |||
", max_locals = " + maxLocals + | |||
", code_length = " + code.length + ")\n" + | |||
Utility.codeToString(code, constantPool, 0, -1, verbose)); | |||
if(exception_table_length > 0) { | |||
if(exceptionTable.length > 0) { | |||
buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n"); | |||
for(int i=0; i < exception_table_length; i++) | |||
buf.append(exception_table[i].toString(constant_pool, verbose) + "\n"); | |||
for(int i=0; i < exceptionTable.length; i++) | |||
buf.append(exceptionTable[i].toString(constantPool, verbose) + "\n"); | |||
} | |||
if(attributes_count > 0) { | |||
if(attributes.length > 0) { | |||
buf.append("\nAttribute(s) = \n"); | |||
for(int i=0; i < attributes_count; i++) | |||
for(int i=0; i < attributes.length; i++) | |||
buf.append(attributes[i].toString() + "\n"); | |||
} | |||
@@ -358,14 +336,14 @@ public final class Code extends Attribute { | |||
public Attribute copy(ConstantPool constant_pool) { | |||
Code c = (Code)clone(); | |||
c.code = (byte[])code.clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
c.exception_table = new CodeException[exception_table_length]; | |||
for(int i=0; i < exception_table_length; i++) | |||
c.exception_table[i] = exception_table[i].copy(); | |||
c.exceptionTable = new CodeException[exceptionTable.length]; | |||
for(int i=0; i < exceptionTable.length; i++) | |||
c.exceptionTable[i] = exceptionTable[i].copy(); | |||
c.attributes = new Attribute[attributes_count]; | |||
for(int i=0; i < attributes_count; i++) | |||
c.attributes = new Attribute[attributes.length]; | |||
for(int i=0; i < attributes.length; i++) | |||
c.attributes[i] = attributes[i].copy(constant_pool); | |||
return c; | |||
@@ -378,17 +356,17 @@ public final class Code extends Attribute { | |||
*/ | |||
public String getCodeString() { | |||
StringBuffer codeString = new StringBuffer(); | |||
codeString.append("Code(max_stack = ").append(max_stack); | |||
codeString.append(", max_locals = ").append(max_locals); | |||
codeString.append(", code_length = ").append(code_length).append(")\n"); | |||
codeString.append(Utility.codeToString(code, constant_pool, 0, -1,true)); | |||
if (exception_table_length>0) { | |||
codeString.append("\n").append("Exception entries = ").append(exception_table_length).append("\n"); | |||
for (int i = 0; i < exception_table_length; i++) { | |||
CodeException exc = exception_table[i]; | |||
codeString.append("Code(max_stack = ").append(maxStack); | |||
codeString.append(", max_locals = ").append(maxLocals); | |||
codeString.append(", code_length = ").append(code.length).append(")\n"); | |||
codeString.append(Utility.codeToString(code, constantPool, 0, -1,true)); | |||
if (exceptionTable.length>0) { | |||
codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n"); | |||
for (int i = 0; i < exceptionTable.length; i++) { | |||
CodeException exc = exceptionTable[i]; | |||
int type = exc.getCatchType(); | |||
String name = "finally"; | |||
if (type!=0) name = this.constant_pool.getConstantString(type,Constants.CONSTANT_Class); | |||
if (type!=0) name = this.constantPool.getConstantString(type,Constants.CONSTANT_Class); | |||
codeString.append(name).append("["); | |||
codeString.append(exc.getStartPC()).append(">").append(exc.getEndPC()).append("]\n"); | |||
} |
@@ -62,77 +62,44 @@ import java.io.*; | |||
* attribute and is used only there. It contains a range in which a | |||
* particular exception handler is active. | |||
* | |||
* @version $Id: CodeException.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: CodeException.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Code | |||
*/ | |||
public final class CodeException | |||
implements Cloneable, Constants, Node, Serializable | |||
{ | |||
public final class CodeException implements Cloneable, Constants, Node, Serializable { | |||
private int start_pc; // Range in the code the exception handler is | |||
private int end_pc; // active. start_pc is inclusive, end_pc exclusive | |||
private int handler_pc; /* Starting address of exception handler, i.e., | |||
* an offset from start of code. | |||
*/ | |||
* an offset from start of code. | |||
*/ | |||
private int catch_type; /* If this is zero the handler catches any | |||
* exception, otherwise it points to the | |||
* exception class which is to be caught. | |||
*/ | |||
/** | |||
* Initialize from another object. | |||
*/ | |||
public CodeException(CodeException c) { | |||
this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType()); | |||
} | |||
/** | |||
* Construct object from file stream. | |||
* @param file Input stream | |||
* @throws IOException | |||
*/ | |||
CodeException(DataInputStream file) throws IOException | |||
{ | |||
this(file.readUnsignedShort(), file.readUnsignedShort(), | |||
file.readUnsignedShort(), file.readUnsignedShort()); | |||
CodeException(DataInputStream file) throws IOException { | |||
start_pc = file.readUnsignedShort(); | |||
end_pc = file.readUnsignedShort(); | |||
handler_pc = file.readUnsignedShort(); | |||
catch_type = file.readUnsignedShort(); | |||
} | |||
/** | |||
* @param start_pc Range in the code the exception handler is active, | |||
* start_pc is inclusive while | |||
* @param end_pc is exclusive | |||
* @param handler_pc Starting address of exception handler, i.e., | |||
* an offset from start of code. | |||
* @param catch_type If zero the handler catches any | |||
* exception, otherwise it points to the exception class which is | |||
* to be caught. | |||
*/ | |||
public CodeException(int start_pc, int end_pc, int handler_pc, | |||
int catch_type) | |||
{ | |||
public CodeException(int start_pc, int end_pc, int handler_pc, int catch_type) { | |||
this.start_pc = start_pc; | |||
this.end_pc = end_pc; | |||
this.handler_pc = handler_pc; | |||
this.catch_type = catch_type; | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
* defined by the contents of a Java class. I.e., the hierarchy of methods, | |||
* fields, attributes, etc. spawns a tree of objects. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitCodeException(this); | |||
} | |||
/** | |||
* Dump code exception to file stream in binary format. | |||
* | |||
* @param file Output file stream | |||
* @throws IOException | |||
*/ | |||
public final void dump(DataOutputStream file) throws IOException | |||
{ | |||
public final void dump(DataOutputStream file) throws IOException { | |||
file.writeShort(start_pc); | |||
file.writeShort(end_pc); | |||
file.writeShort(handler_pc); |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* in the constant pool of a class file. The classes keep closely to | |||
* the JVM specification. | |||
* | |||
* @version $Id: Constant.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Constant.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class Constant implements Cloneable, Node, Serializable { | |||
@@ -85,7 +85,7 @@ public abstract class Constant implements Cloneable, Node, Serializable { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public abstract void accept(Visitor v); | |||
public abstract void accept(ClassVisitor v); | |||
public abstract void dump(DataOutputStream file) throws IOException; | |||
@@ -117,32 +117,22 @@ public abstract class Constant implements Cloneable, Node, Serializable { | |||
return super.clone(); | |||
} | |||
/** | |||
* Read one constant from the given file, the type depends on a tag byte. | |||
* | |||
* @param file Input stream | |||
* @return Constant object | |||
*/ | |||
static final Constant readConstant(DataInputStream file) | |||
throws IOException, ClassFormatException | |||
{ | |||
byte b = file.readByte(); // Read tag byte | |||
static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { | |||
byte b = file.readByte(); | |||
switch(b) { | |||
case Constants.CONSTANT_Class: return new ConstantClass(file); | |||
case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); | |||
case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); | |||
case Constants.CONSTANT_InterfaceMethodref: return new | |||
ConstantInterfaceMethodref(file); | |||
case Constants.CONSTANT_String: return new ConstantString(file); | |||
case Constants.CONSTANT_Integer: return new ConstantInteger(file); | |||
case Constants.CONSTANT_Float: return new ConstantFloat(file); | |||
case Constants.CONSTANT_Long: return new ConstantLong(file); | |||
case Constants.CONSTANT_Double: return new ConstantDouble(file); | |||
case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); | |||
case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); | |||
default: | |||
throw new ClassFormatException("Invalid byte tag in constant pool: " + b); | |||
case Constants.CONSTANT_Class: return new ConstantClass(file); | |||
case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); | |||
case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); | |||
case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); | |||
case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); | |||
case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); | |||
case Constants.CONSTANT_String: return new ConstantString(file); | |||
case Constants.CONSTANT_Integer: return new ConstantInteger(file); | |||
case Constants.CONSTANT_Float: return new ConstantFloat(file); | |||
case Constants.CONSTANT_Long: return new ConstantLong(file); | |||
case Constants.CONSTANT_Double: return new ConstantDouble(file); | |||
default: | |||
throw new ClassFormatException("Invalid byte tag in constant pool: " + b); | |||
} | |||
} | |||
} |
@@ -59,7 +59,7 @@ import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Abstract super class for Fieldref and Methodref constants. | |||
* | |||
* @version $Id: ConstantCP.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantCP.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see ConstantFieldref | |||
* @see ConstantMethodref |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a (external) class. | |||
* | |||
* @version $Id: ConstantClass.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantClass.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -84,7 +84,9 @@ public final class ConstantClass extends Constant implements ConstantObject { | |||
*/ | |||
ConstantClass(DataInputStream file) throws IOException | |||
{ | |||
this(file.readUnsignedShort()); | |||
super(Constants.CONSTANT_Class); | |||
this.name_index = file.readUnsignedShort(); | |||
// this(file.readUnsignedShort()); | |||
} | |||
/** | |||
@@ -103,7 +105,7 @@ public final class ConstantClass extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantClass(this); | |||
} | |||
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a Double object. | |||
* | |||
* @version $Id: ConstantDouble.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantDouble.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -102,7 +102,7 @@ public final class ConstantDouble extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantDouble(this); | |||
} | |||
/** |
@@ -60,7 +60,7 @@ import java.io.*; | |||
/** | |||
* This class represents a constant pool reference to a field. | |||
* | |||
* @version $Id: ConstantFieldref.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantFieldref.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class ConstantFieldref extends ConstantCP { | |||
@@ -98,7 +98,7 @@ public final class ConstantFieldref extends ConstantCP { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantFieldref(this); | |||
} | |||
} |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a float object. | |||
* | |||
* @version $Id: ConstantFloat.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantFloat.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -101,7 +101,7 @@ public final class ConstantFloat extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantFloat(this); | |||
} | |||
/** |
@@ -64,7 +64,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to an int object. | |||
* | |||
* @version $Id: ConstantInteger.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantInteger.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -105,7 +105,7 @@ public final class ConstantInteger extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantInteger(this); | |||
} | |||
@@ -60,7 +60,7 @@ import java.io.*; | |||
/** | |||
* This class represents a constant pool reference to an interface method. | |||
* | |||
* @version $Id: ConstantInterfaceMethodref.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantInterfaceMethodref.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class ConstantInterfaceMethodref extends ConstantCP { | |||
@@ -98,7 +98,7 @@ public final class ConstantInterfaceMethodref extends ConstantCP { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantInterfaceMethodref(this); | |||
} | |||
} |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a long object. | |||
* | |||
* @version $Id: ConstantLong.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantLong.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -100,7 +100,7 @@ public final class ConstantLong extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantLong(this); | |||
} | |||
/** |
@@ -60,7 +60,7 @@ import java.io.*; | |||
/** | |||
* This class represents a constant pool reference to a method. | |||
* | |||
* @version $Id: ConstantMethodref.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantMethodref.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class ConstantMethodref extends ConstantCP { | |||
@@ -98,7 +98,7 @@ public final class ConstantMethodref extends ConstantCP { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantMethodref(this); | |||
} | |||
} |
@@ -63,7 +63,7 @@ import java.io.*; | |||
* and represents a reference to the name and signature | |||
* of a field or method. | |||
* | |||
* @version $Id: ConstantNameAndType.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantNameAndType.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -86,7 +86,7 @@ public final class ConstantNameAndType extends Constant { | |||
*/ | |||
ConstantNameAndType(DataInputStream file) throws IOException | |||
{ | |||
this((int)file.readUnsignedShort(), (int)file.readUnsignedShort()); | |||
this(file.readUnsignedShort(), file.readUnsignedShort()); | |||
} | |||
/** | |||
@@ -108,7 +108,7 @@ public final class ConstantNameAndType extends Constant { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantNameAndType(this); | |||
} | |||
@@ -58,7 +58,7 @@ package org.aspectj.apache.bcel.classfile; | |||
* This interface denotes those constants that have a "natural" value, | |||
* such as ConstantLong, ConstantString, etc.. | |||
* | |||
* @version $Id: ConstantObject.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantObject.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ |
@@ -1,372 +1,612 @@ | |||
package org.aspectj.apache.bcel.classfile; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.generic.*; | |||
import java.io.*; | |||
/** | |||
* This class represents the constant pool, i.e., a table of constants, of | |||
* a parsed classfile. It may contain null references, due to the JVM | |||
* specification that skips an entry after an 8-byte constant (double, | |||
* long) entry. Those interested in generating constant pools | |||
* programatically should see <a href="../generic/ConstantPoolGen.html"> | |||
* ConstantPoolGen</a>. | |||
* @version $Id: ConstantPool.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @see Constant | |||
* @see org.aspectj.apache.bcel.generic.ConstantPoolGen | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* long) entry. | |||
*/ | |||
public class ConstantPool implements Cloneable, Node, Serializable { | |||
private int constant_pool_count; | |||
private Constant[] constant_pool; | |||
/** | |||
* @param constant_pool Array of constants | |||
*/ | |||
public ConstantPool(Constant[] constant_pool) | |||
{ | |||
setConstantPool(constant_pool); | |||
} | |||
/** | |||
* Read constants from given file stream. | |||
* | |||
* @param file Input stream | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
ConstantPool(DataInputStream file) throws IOException, ClassFormatException | |||
{ | |||
byte tag; | |||
constant_pool_count = file.readUnsignedShort(); | |||
constant_pool = new Constant[constant_pool_count]; | |||
/* constant_pool[0] is unused by the compiler and may be used freely | |||
* by the implementation. | |||
public class ConstantPool implements Node { | |||
private Constant[] pool; | |||
private int poolSize; // number of entries in the pool (could be < pool.length as the array is resized in 'chunks') | |||
public int getSize() { return poolSize; } | |||
public ConstantPool() { | |||
pool = new Constant[10]; | |||
poolSize=0; | |||
} | |||
public ConstantPool(Constant[] constants) { | |||
pool = constants; | |||
poolSize = (constants==null?0:constants.length); | |||
} | |||
ConstantPool(DataInputStream file) throws IOException { | |||
byte tag; | |||
poolSize = file.readUnsignedShort(); | |||
pool = new Constant[poolSize]; | |||
// pool[0] is unused by the compiler and may be used freely by the implementation | |||
for (int i=1; i<poolSize; i++) { | |||
pool[i] = Constant.readConstant(file); | |||
tag = pool[i].getTag(); | |||
if ((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long)) i++; | |||
} | |||
} | |||
public Constant getConstant(int index, byte tag) { | |||
Constant c = getConstant(index); | |||
//if (c == null) throw new ClassFormatException("Constant pool at index " + index + " is null."); | |||
if(c.tag == tag) return c; | |||
throw new ClassFormatException("Expected class '"+Constants.CONSTANT_NAMES[tag]+"' at index "+index+" and found "+c); | |||
} | |||
public Constant getConstant(int index) { | |||
if (index >= pool.length || index < 0) | |||
throw new ClassFormatException("Invalid constant pool reference: " + | |||
index + ". Constant pool size is: " + pool.length); | |||
return pool[index]; | |||
} | |||
/** | |||
* @return deep copy of this constant pool | |||
*/ | |||
public ConstantPool copy() { | |||
ConstantPool c = null; | |||
Constant[] newConstants = new Constant[poolSize]; // use the correct size | |||
for (int i=1;i<poolSize;i++) { | |||
if (pool[i]!=null) { | |||
newConstants[i] = pool[i].copy(); | |||
} | |||
} | |||
return new ConstantPool(newConstants); | |||
} | |||
/** | |||
* Get string from constant pool and bypass the indirection of | |||
* `ConstantClass' and `ConstantString' objects. I.e. these classes have | |||
* an index field that points to another entry of the constant pool of | |||
* type `ConstantUtf8' which contains the real data. | |||
* | |||
* @param index Index in constant pool | |||
* @param tag Tag of expected constant, either ConstantClass or ConstantString | |||
* @return Contents of string reference | |||
* @see ConstantClass | |||
* @see ConstantString | |||
* @throws ClassFormatException | |||
*/ | |||
public String getConstantString(int index, byte tag) throws ClassFormatException { | |||
Constant c = getConstant(index, tag); | |||
int i; | |||
/* This switch() is not that elegant, since the two classes have the | |||
* same contents, they just differ in the name of the index | |||
* field variable. | |||
* But we want to stick to the JVM naming conventions closely though | |||
* we could have solved these more elegantly by using the same | |||
* variable name or by subclassing. | |||
*/ | |||
// OPTIMIZE remove the difference - use the an interface and same index methods for string ref id | |||
switch(tag) { | |||
case Constants.CONSTANT_Class: i = ((ConstantClass)c).getNameIndex(); break; | |||
case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break; | |||
default: | |||
throw new RuntimeException("getConstantString called with illegal tag " + tag); | |||
} | |||
// Finally get the string from the constant pool | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
return ((ConstantUtf8)c).getBytes(); | |||
} | |||
/** | |||
* Resolve constant to a string representation. | |||
*/ | |||
for(int i=1; i < constant_pool_count; i++) { | |||
constant_pool[i] = Constant.readConstant(file); | |||
/* Quote from the JVM specification: | |||
* "All eight byte constants take up two spots in the constant pool. | |||
* If this is the n'th byte in the constant pool, then the next item | |||
* will be numbered n+2" | |||
* | |||
* Thus we have to increment the index counter. | |||
*/ | |||
tag = constant_pool[i].getTag(); | |||
if((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long)) | |||
i++; | |||
} | |||
public String constantToString(Constant c) { | |||
String str; | |||
int i; | |||
switch (c.tag) { | |||
case Constants.CONSTANT_Class: | |||
i = ((ConstantClass)c).getNameIndex(); | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false); | |||
break; | |||
case Constants.CONSTANT_String: | |||
i = ((ConstantString)c).getStringIndex(); | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\""; | |||
break; | |||
case Constants.CONSTANT_Utf8: str = ((ConstantUtf8)c).getBytes(); break; | |||
case Constants.CONSTANT_Double: str = Double.toString(((ConstantDouble)c).getBytes()); break; | |||
case Constants.CONSTANT_Float: str = Float.toString(((ConstantFloat)c).getBytes()); break; | |||
case Constants.CONSTANT_Long: str = Long.toString(((ConstantLong)c).getBytes()); break; | |||
case Constants.CONSTANT_Integer: str = Integer.toString(((ConstantInteger)c).getBytes()); break; | |||
case Constants.CONSTANT_NameAndType: | |||
str = (constantToString(((ConstantNameAndType)c).getNameIndex(), | |||
Constants.CONSTANT_Utf8) + " " + | |||
constantToString(((ConstantNameAndType)c).getSignatureIndex(), | |||
Constants.CONSTANT_Utf8)); | |||
break; | |||
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref: | |||
case Constants.CONSTANT_Fieldref: | |||
str = (constantToString(((ConstantCP)c).getClassIndex(), | |||
Constants.CONSTANT_Class) + "." + | |||
constantToString(((ConstantCP)c).getNameAndTypeIndex(), | |||
Constants.CONSTANT_NameAndType)); | |||
break; | |||
default: // Never reached | |||
throw new RuntimeException("Unknown constant type " + c.tag); | |||
} | |||
return str; | |||
} | |||
private static final String escape(String str) { | |||
int len = str.length(); | |||
StringBuffer buf = new StringBuffer(len + 5); | |||
char[] ch = str.toCharArray(); | |||
for(int i=0; i < len; i++) { | |||
switch(ch[i]) { | |||
case '\n' : buf.append("\\n"); break; | |||
case '\r' : buf.append("\\r"); break; | |||
case '\t' : buf.append("\\t"); break; | |||
case '\b' : buf.append("\\b"); break; | |||
case '"' : buf.append("\\\""); break; | |||
default: buf.append(ch[i]); | |||
} | |||
} | |||
return buf.toString(); | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
* defined by the contents of a Java class. I.e., the hierarchy of methods, | |||
* fields, attributes, etc. spawns a tree of objects. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitConstantPool(this); | |||
} | |||
/** | |||
* Resolve constant to a string representation. | |||
* | |||
* @param constant Constant to be printed | |||
* @return String representation | |||
*/ | |||
public String constantToString(Constant c) | |||
throws ClassFormatException | |||
{ | |||
String str; | |||
int i; | |||
byte tag = c.getTag(); | |||
switch(tag) { | |||
case Constants.CONSTANT_Class: | |||
i = ((ConstantClass)c).getNameIndex(); | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false); | |||
break; | |||
case Constants.CONSTANT_String: | |||
i = ((ConstantString)c).getStringIndex(); | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\""; | |||
break; | |||
case Constants.CONSTANT_Utf8: str = ((ConstantUtf8)c).getBytes(); break; | |||
case Constants.CONSTANT_Double: str = "" + ((ConstantDouble)c).getBytes(); break; | |||
case Constants.CONSTANT_Float: str = "" + ((ConstantFloat)c).getBytes(); break; | |||
case Constants.CONSTANT_Long: str = "" + ((ConstantLong)c).getBytes(); break; | |||
case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break; | |||
case Constants.CONSTANT_NameAndType: | |||
str = (constantToString(((ConstantNameAndType)c).getNameIndex(), | |||
Constants.CONSTANT_Utf8) + " " + | |||
constantToString(((ConstantNameAndType)c).getSignatureIndex(), | |||
Constants.CONSTANT_Utf8)); | |||
break; | |||
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref: | |||
case Constants.CONSTANT_Fieldref: | |||
str = (constantToString(((ConstantCP)c).getClassIndex(), | |||
Constants.CONSTANT_Class) + "." + | |||
constantToString(((ConstantCP)c).getNameAndTypeIndex(), | |||
Constants.CONSTANT_NameAndType)); | |||
break; | |||
default: // Never reached | |||
throw new RuntimeException("Unknown constant type " + tag); | |||
public String constantToString(int index, byte tag) { | |||
Constant c = getConstant(index, tag); | |||
return constantToString(c); | |||
} | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantPool(this); | |||
} | |||
public Constant[] getConstantPool() { return pool; } // TEMPORARY, DONT LIKE PASSING THIS DATA OUT! | |||
public void dump(DataOutputStream file) throws IOException { | |||
file.writeShort(poolSize); | |||
for(int i=1; i < poolSize; i++) if (pool[i]!=null) pool[i].dump(file); | |||
} | |||
public ConstantUtf8 getConstantUtf8(int idx) { | |||
try { | |||
Constant c = pool[idx]; | |||
if (c==null) | |||
throw new ClassFormatException("Constant pool at index " + idx + " is null."); | |||
if (c.tag!=Constants.CONSTANT_Utf8) | |||
throw new ClassFormatException("Expected UTF8Constant "+ | |||
" at index " + idx + " and got " + c); | |||
return (ConstantUtf8)c; | |||
} catch (ArrayIndexOutOfBoundsException aioobe) { | |||
throw new ClassFormatException("Index "+idx+" into constant pool (size:"+poolSize+") is invalid"); | |||
} | |||
} | |||
return str; | |||
} | |||
public String getConstantString_CONSTANTClass(int index) { | |||
ConstantClass c = (ConstantClass)getConstant(index,Constants.CONSTANT_Class); | |||
index = c.getNameIndex(); | |||
return ((ConstantUtf8)getConstant(index,Constants.CONSTANT_Utf8)).getBytes(); | |||
} | |||
public int getLength() { return poolSize; } | |||
private static final String escape(String str) { | |||
int len = str.length(); | |||
StringBuffer buf = new StringBuffer(len + 5); | |||
char[] ch = str.toCharArray(); | |||
for(int i=0; i < len; i++) { | |||
switch(ch[i]) { | |||
case '\n' : buf.append("\\n"); break; | |||
case '\r' : buf.append("\\r"); break; | |||
case '\t' : buf.append("\\t"); break; | |||
case '\b' : buf.append("\\b"); break; | |||
case '"' : buf.append("\\\""); break; | |||
default: buf.append(ch[i]); | |||
public String toString() { | |||
StringBuffer buf = new StringBuffer(); | |||
for(int i=1; i < poolSize; i++) | |||
buf.append(i + ")" + pool[i] + "\n"); | |||
return buf.toString(); | |||
} | |||
public int lookupInteger(int n) { | |||
for (int i=1; i < poolSize; i++) { | |||
if (pool[i] instanceof ConstantInteger) { | |||
ConstantInteger c = (ConstantInteger)pool[i]; | |||
if (c.getBytes() == n) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public int lookupUtf8(String string) { | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Utf8) { | |||
if (((ConstantUtf8)c).getBytes().equals(string)) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public int lookupClass(String classname) { | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Class) { | |||
int cIndex = ((ConstantClass)c).getNameIndex(); | |||
String cName = ((ConstantUtf8)pool[cIndex]).getBytes(); | |||
if (cName.equals(classname)) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public int addUtf8(String n) { | |||
int ret = lookupUtf8(n); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantUtf8(n); | |||
return ret; | |||
} | |||
public int addInteger(int n) { | |||
int ret = lookupInteger(n); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantInteger(n); | |||
return ret; | |||
} | |||
return buf.toString(); | |||
public int addArrayClass(ArrayType type) { | |||
return addClass(type.getSignature()); | |||
} | |||
public int addClass(ObjectType type) { | |||
return addClass(type.getClassName()); | |||
} | |||
public int addClass(String classname) { | |||
String toAdd = classname.replace('.','/'); | |||
int ret = lookupClass(toAdd); | |||
if(ret != -1) return ret; | |||
adjustSize(); | |||
ConstantClass c = new ConstantClass(addUtf8(toAdd)); | |||
ret = poolSize; | |||
pool[poolSize++] = c; | |||
return ret; | |||
} | |||
private void adjustSize() { | |||
if(poolSize + 3 >= pool.length) { | |||
Constant[] cs = pool; | |||
pool = new Constant[cs.length+8]; | |||
System.arraycopy(cs, 0, pool, 0, cs.length); | |||
} | |||
if (poolSize==0) poolSize = 1; // someone about to do something in here! | |||
} | |||
public int addFieldref(String class_name, String field_name, String signature) { | |||
int ret = lookupFieldref(class_name, field_name, signature); | |||
int class_index, name_and_type_index; | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
class_index = addClass(class_name); | |||
name_and_type_index = addNameAndType(field_name, signature); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantFieldref(class_index, name_and_type_index); | |||
return ret; | |||
} | |||
public int lookupFieldref(String searchClassname, String searchFieldname, String searchSignature) { | |||
searchClassname = searchClassname.replace('.','/'); | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Fieldref) { | |||
ConstantFieldref cfr = (ConstantFieldref)c; | |||
ConstantNameAndType cnat = (ConstantNameAndType)pool[cfr.getNameAndTypeIndex()]; | |||
// check the class | |||
int cIndex = cfr.getClassIndex(); | |||
ConstantClass cc = (ConstantClass)pool[cIndex]; | |||
String cName = ((ConstantUtf8)pool[cc.getNameIndex()]).getBytes(); | |||
if (!cName.equals(searchClassname)) continue; | |||
// check the name and type | |||
String name = ((ConstantUtf8)pool[cnat.getNameIndex()]).getBytes(); | |||
if (!name.equals(searchFieldname)) continue; // not this one | |||
String typeSignature = ((ConstantUtf8)pool[cnat.getSignatureIndex()]).getBytes(); | |||
if (!typeSignature.equals(searchSignature)) continue; | |||
return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* Retrieve constant at `index' from constant pool and resolve it to | |||
* a string representation. | |||
* | |||
* @param index of constant in constant pool | |||
* @param tag expected type | |||
* @return String representation | |||
*/ | |||
public String constantToString(int index, byte tag) | |||
throws ClassFormatException | |||
{ | |||
Constant c = getConstant(index, tag); | |||
return constantToString(c); | |||
public int addNameAndType(String name, String signature) { | |||
int ret = lookupNameAndType(name, signature); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
int name_index = addUtf8(name); | |||
int signature_index = addUtf8(signature); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantNameAndType(name_index, signature_index); | |||
return ret; | |||
} | |||
/** | |||
* Dump constant pool to file stream in binary format. | |||
* | |||
* @param file Output file stream | |||
* @throws IOException | |||
*/ | |||
public void dump(DataOutputStream file) throws IOException | |||
{ | |||
file.writeShort(constant_pool_count); | |||
for(int i=1; i < constant_pool_count; i++) | |||
if(constant_pool[i] != null) | |||
constant_pool[i].dump(file); | |||
public int lookupNameAndType(String searchName, String searchTypeSignature) { | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_NameAndType) { | |||
ConstantNameAndType cnat = (ConstantNameAndType)c; | |||
String name = ((ConstantUtf8)pool[cnat.getNameIndex()]).getBytes(); | |||
if (!name.equals(searchName)) continue; // not this one | |||
String typeSignature = ((ConstantUtf8)pool[cnat.getSignatureIndex()]).getBytes(); | |||
if (!typeSignature.equals(searchTypeSignature)) continue; | |||
return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* Get constant from constant pool. | |||
* | |||
* @param index Index in constant pool | |||
* @return Constant value | |||
* @see Constant | |||
*/ | |||
public Constant getConstant(int index) { | |||
if (index >= constant_pool.length || index < 0) | |||
throw new ClassFormatException("Invalid constant pool reference: " + | |||
index + ". Constant pool size is: " + | |||
constant_pool.length); | |||
return constant_pool[index]; | |||
public int addFloat(float f) { | |||
int ret= lookupFloat(f); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantFloat(f); | |||
return ret; | |||
} | |||
public int lookupFloat(float f) { | |||
int bits = Float.floatToIntBits(f); | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Float) { | |||
ConstantFloat cf = (ConstantFloat)c; | |||
if (Float.floatToIntBits(cf.getBytes())==bits) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public int addDouble(double d) { | |||
int ret= lookupDouble(d); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
ret = poolSize; | |||
pool[poolSize] = new ConstantDouble(d); | |||
poolSize+=2; | |||
return ret; | |||
} | |||
public int lookupDouble(double d) { | |||
long bits = Double.doubleToLongBits(d); | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Double) { | |||
ConstantDouble cf = (ConstantDouble)c; | |||
if (Double.doubleToLongBits(cf.getBytes())==bits) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* Get constant from constant pool and check whether it has the | |||
* expected type. | |||
* | |||
* @param index Index in constant pool | |||
* @param tag Tag of expected constant, i.e., its type | |||
* @return Constant value | |||
* @see Constant | |||
* @throws ClassFormatException | |||
*/ | |||
public Constant getConstant(int index, byte tag) | |||
throws ClassFormatException | |||
{ | |||
Constant c; | |||
c = getConstant(index); | |||
if(c == null) | |||
throw new ClassFormatException("Constant pool at index " + index + " is null."); | |||
if(c.getTag() == tag) | |||
return c; | |||
else | |||
throw new ClassFormatException("Expected class `" + Constants.CONSTANT_NAMES[tag] + | |||
"' at index " + index + " and got " + c); | |||
} | |||
public int addLong(long l) { | |||
int ret= lookupLong(l); | |||
if (ret != -1) return ret; | |||
adjustSize(); | |||
ret = poolSize; | |||
pool[poolSize] = new ConstantLong(l); | |||
poolSize+=2; | |||
return ret; | |||
} | |||
public int lookupString(String s) { | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_String) { | |||
ConstantString cs = (ConstantString)c; | |||
ConstantUtf8 cu8 = (ConstantUtf8)pool[cs.getStringIndex()]; | |||
if (cu8.getBytes().equals(s)) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
/** | |||
* @return Array of constants. | |||
* @see Constant | |||
*/ | |||
public Constant[] getConstantPool() { return constant_pool; } | |||
/** | |||
* Get string from constant pool and bypass the indirection of | |||
* `ConstantClass' and `ConstantString' objects. I.e. these classes have | |||
* an index field that points to another entry of the constant pool of | |||
* type `ConstantUtf8' which contains the real data. | |||
* | |||
* @param index Index in constant pool | |||
* @param tag Tag of expected constant, either ConstantClass or ConstantString | |||
* @return Contents of string reference | |||
* @see ConstantClass | |||
* @see ConstantString | |||
* @throws ClassFormatException | |||
*/ | |||
public String getConstantString(int index, byte tag) | |||
throws ClassFormatException | |||
{ | |||
Constant c; | |||
int i; | |||
c = getConstant(index, tag); | |||
/* This switch() is not that elegant, since the two classes have the | |||
* same contents, they just differ in the name of the index | |||
* field variable. | |||
* But we want to stick to the JVM naming conventions closely though | |||
* we could have solved these more elegantly by using the same | |||
* variable name or by subclassing. | |||
*/ | |||
switch(tag) { | |||
case Constants.CONSTANT_Class: i = ((ConstantClass)c).getNameIndex(); break; | |||
case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break; | |||
default: | |||
throw new RuntimeException("getConstantString called with illegal tag " + tag); | |||
} | |||
public int addString(String str) { | |||
int ret = lookupString(str); | |||
if (ret!=-1) return ret; | |||
int utf8 = addUtf8(str); | |||
adjustSize(); | |||
ConstantString s = new ConstantString(utf8); | |||
ret = poolSize; | |||
pool[poolSize++] = s; | |||
return ret; | |||
} | |||
public int lookupLong(long l) { | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Long) { | |||
ConstantLong cf = (ConstantLong)c; | |||
if (cf.getBytes()==l) return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
// Finally get the string from the constant pool | |||
c = getConstant(i, Constants.CONSTANT_Utf8); | |||
return ((ConstantUtf8)c).getBytes(); | |||
} | |||
/** | |||
* @return Length of constant pool. | |||
*/ | |||
public int getLength() | |||
{ | |||
return constant_pool_count; | |||
} | |||
/** | |||
* @param constant Constant to set | |||
*/ | |||
public void setConstant(int index, Constant constant) { | |||
constant_pool[index] = constant; | |||
} | |||
/** | |||
* @param constant_pool | |||
*/ | |||
public void setConstantPool(Constant[] constant_pool) { | |||
this.constant_pool = constant_pool; | |||
constant_pool_count = (constant_pool == null)? 0 : constant_pool.length; | |||
} | |||
/** | |||
* @return String representation. | |||
*/ | |||
public String toString() { | |||
StringBuffer buf = new StringBuffer(); | |||
for(int i=1; i < constant_pool_count; i++) | |||
buf.append(i + ")" + constant_pool[i] + "\n"); | |||
return buf.toString(); | |||
} | |||
public int addConstant(Constant c, ConstantPool cp) { | |||
Constant[] constants = cp.getConstantPool(); | |||
switch(c.getTag()) { | |||
/** | |||
* @return deep copy of this constant pool | |||
*/ | |||
public ConstantPool copy() { | |||
ConstantPool c = null; | |||
case Constants.CONSTANT_String: { | |||
ConstantString s = (ConstantString)c; | |||
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getStringIndex()]; | |||
return addString(u8.getBytes()); | |||
} | |||
try { | |||
c = (ConstantPool)clone(); | |||
} catch(CloneNotSupportedException e) {} | |||
case Constants.CONSTANT_Class: { | |||
ConstantClass s = (ConstantClass)c; | |||
ConstantUtf8 u8 = (ConstantUtf8)constants[s.getNameIndex()]; | |||
c.constant_pool = new Constant[constant_pool_count]; | |||
return addClass(u8.getBytes()); | |||
} | |||
for(int i=1; i < constant_pool_count; i++) { | |||
if(constant_pool[i] != null) | |||
c.constant_pool[i] = constant_pool[i].copy(); | |||
} | |||
case Constants.CONSTANT_NameAndType: { | |||
ConstantNameAndType n = (ConstantNameAndType)c; | |||
ConstantUtf8 u8 = (ConstantUtf8)constants[n.getNameIndex()]; | |||
ConstantUtf8 u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()]; | |||
return addNameAndType(u8.getBytes(), u8_2.getBytes()); | |||
} | |||
case Constants.CONSTANT_Utf8: | |||
return addUtf8(((ConstantUtf8)c).getBytes()); | |||
case Constants.CONSTANT_Double: | |||
return addDouble(((ConstantDouble)c).getBytes()); | |||
case Constants.CONSTANT_Float: | |||
return addFloat(((ConstantFloat)c).getBytes()); | |||
case Constants.CONSTANT_Long: | |||
return addLong(((ConstantLong)c).getBytes()); | |||
return c; | |||
case Constants.CONSTANT_Integer: | |||
return addInteger(((ConstantInteger)c).getBytes()); | |||
case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref: | |||
case Constants.CONSTANT_Fieldref: { | |||
ConstantCP m = (ConstantCP)c; | |||
ConstantClass clazz = (ConstantClass)constants[m.getClassIndex()]; | |||
ConstantNameAndType n = (ConstantNameAndType)constants[m.getNameAndTypeIndex()]; | |||
ConstantUtf8 u8 = (ConstantUtf8)constants[clazz.getNameIndex()]; | |||
String class_name = u8.getBytes().replace('/', '.'); | |||
u8 = (ConstantUtf8)constants[n.getNameIndex()]; | |||
String name = u8.getBytes(); | |||
u8 = (ConstantUtf8)constants[n.getSignatureIndex()]; | |||
String signature = u8.getBytes(); | |||
switch(c.getTag()) { | |||
case Constants.CONSTANT_InterfaceMethodref: | |||
return addInterfaceMethodref(class_name, name, signature); | |||
case Constants.CONSTANT_Methodref: | |||
return addMethodref(class_name, name, signature); | |||
case Constants.CONSTANT_Fieldref: | |||
return addFieldref(class_name, name, signature); | |||
default: // Never reached | |||
throw new RuntimeException("Unknown constant type " + c); | |||
} | |||
} | |||
default: // Never reached | |||
throw new RuntimeException("Unknown constant type " + c); | |||
} | |||
} | |||
public int addMethodref(String class_name, String method_name, String signature) { | |||
int ret, class_index, name_and_type_index; | |||
if((ret = lookupMethodref(class_name, method_name, signature)) != -1) | |||
return ret; // Already in CP | |||
adjustSize(); | |||
name_and_type_index = addNameAndType(method_name, signature); | |||
class_index = addClass(class_name); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantMethodref(class_index, name_and_type_index); | |||
return ret; | |||
} | |||
public int addInterfaceMethodref(String class_name, String method_name, String signature) { | |||
int ret = lookupInterfaceMethodref(class_name, method_name, signature); | |||
int class_index, name_and_type_index; | |||
if( ret != -1) return ret; | |||
adjustSize(); | |||
class_index = addClass(class_name); | |||
name_and_type_index = addNameAndType(method_name, signature); | |||
ret = poolSize; | |||
pool[poolSize++] = new ConstantInterfaceMethodref(class_index, name_and_type_index); | |||
return ret; | |||
} | |||
public int lookupInterfaceMethodref(String searchClassname, String searchMethodName, String searchSignature) { | |||
searchClassname = searchClassname.replace('.','/'); | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_InterfaceMethodref) { | |||
ConstantInterfaceMethodref cfr = (ConstantInterfaceMethodref)c; | |||
ConstantClass cc = (ConstantClass)pool[cfr.getClassIndex()]; | |||
String cName = ((ConstantUtf8)pool[cc.getNameIndex()]).getBytes(); | |||
if (!cName.equals(searchClassname)) continue; | |||
// check the name and type | |||
ConstantNameAndType cnat = (ConstantNameAndType)pool[cfr.getNameAndTypeIndex()]; | |||
String name = ((ConstantUtf8)pool[cnat.getNameIndex()]).getBytes(); | |||
if (!name.equals(searchMethodName)) continue; // not this one | |||
String typeSignature = ((ConstantUtf8)pool[cnat.getSignatureIndex()]).getBytes(); | |||
if (!typeSignature.equals(searchSignature)) continue; | |||
return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public int lookupMethodref(String searchClassname, String searchMethodName, String searchSignature) { | |||
searchClassname = searchClassname.replace('.','/'); | |||
for (int i=1;i<poolSize;i++) { | |||
Constant c = pool[i]; | |||
if (c!=null && c.tag==Constants.CONSTANT_Methodref) { | |||
ConstantMethodref cfr = (ConstantMethodref)c; | |||
ConstantNameAndType cnat = (ConstantNameAndType)pool[cfr.getNameAndTypeIndex()]; | |||
// check the class | |||
int cIndex = cfr.getClassIndex(); | |||
ConstantClass cc = (ConstantClass)pool[cIndex]; | |||
String cName = ((ConstantUtf8)pool[cc.getNameIndex()]).getBytes(); | |||
if (!cName.equals(searchClassname)) continue; | |||
// check the name and type | |||
String name = ((ConstantUtf8)pool[cnat.getNameIndex()]).getBytes(); | |||
if (!name.equals(searchMethodName)) continue; // not this one | |||
String typeSignature = ((ConstantUtf8)pool[cnat.getSignatureIndex()]).getBytes(); | |||
if (!typeSignature.equals(searchSignature)) continue; | |||
return i; | |||
} | |||
} | |||
return -1; | |||
} | |||
public ConstantPool getFinalConstantPool() { | |||
Constant[] cs = new Constant[poolSize]; // create it the exact size we need | |||
System.arraycopy(pool, 0, cs, 0, poolSize); | |||
return new ConstantPool(cs); | |||
} | |||
} |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a String object. | |||
* | |||
* @version $Id: ConstantString.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantString.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -83,7 +83,7 @@ public final class ConstantString extends Constant implements ConstantObject { | |||
*/ | |||
ConstantString(DataInputStream file) throws IOException | |||
{ | |||
this((int)file.readUnsignedShort()); | |||
this(file.readUnsignedShort()); | |||
} | |||
/** | |||
* @param string_index Index of Constant_Utf8 in constant pool | |||
@@ -100,7 +100,7 @@ public final class ConstantString extends Constant implements ConstantObject { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantString(this); | |||
} | |||
/** |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* <A HREF="org.aspectj.apache.bcel.classfile.Constant.html">Constant</A> class | |||
* and represents a reference to a Utf8 encoded string. | |||
* | |||
* @version $Id: ConstantUtf8.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantUtf8.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Constant | |||
*/ | |||
@@ -85,20 +85,15 @@ public final class ConstantUtf8 extends Constant { | |||
ConstantUtf8(DataInputStream file) throws IOException | |||
{ | |||
super(Constants.CONSTANT_Utf8); | |||
bytes = file.readUTF(); | |||
bytes=file.readUTF(); | |||
} | |||
/** | |||
* @param bytes Data | |||
*/ | |||
public ConstantUtf8(String bytes) | |||
{ | |||
super(Constants.CONSTANT_Utf8); | |||
if(bytes == null) | |||
throw new IllegalArgumentException("bytes must not be null!"); | |||
this.bytes = bytes; | |||
} | |||
@@ -109,7 +104,7 @@ public final class ConstantUtf8 extends Constant { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantUtf8(this); | |||
} | |||
@@ -128,7 +123,9 @@ public final class ConstantUtf8 extends Constant { | |||
/** | |||
* @return Data converted to string. | |||
*/ | |||
public final String getBytes() { return bytes; } | |||
public final String getBytes() { | |||
return bytes; | |||
} | |||
/** | |||
* @param bytes. |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* value, i.e., a default value for initializing a class field. | |||
* This class is instantiated by the <em>Attribute.readAttribute()</em> method. | |||
* | |||
* @version $Id: ConstantValue.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ConstantValue.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -89,7 +89,7 @@ public final class ConstantValue extends Attribute { | |||
ConstantValue(int name_index, int length, DataInputStream file, | |||
ConstantPool constant_pool) throws IOException | |||
{ | |||
this(name_index, length, (int)file.readUnsignedShort(), constant_pool); | |||
this(name_index, length, file.readUnsignedShort(), constant_pool); | |||
} | |||
/** | |||
@@ -113,7 +113,7 @@ public final class ConstantValue extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitConstantValue(this); | |||
} | |||
/** | |||
@@ -143,7 +143,7 @@ public final class ConstantValue extends Attribute { | |||
* @return String representation of constant value. | |||
*/ | |||
public final String toString() { | |||
Constant c = constant_pool.getConstant(constantvalue_index); | |||
Constant c = constantPool.getConstant(constantvalue_index); | |||
String buf; | |||
int i; | |||
@@ -156,7 +156,7 @@ public final class ConstantValue extends Attribute { | |||
case Constants.CONSTANT_Integer: buf = "" + ((ConstantInteger)c).getBytes(); break; | |||
case Constants.CONSTANT_String: | |||
i = ((ConstantString)c).getStringIndex(); | |||
c = constant_pool.getConstant(i, Constants.CONSTANT_Utf8); | |||
c = constantPool.getConstant(i, Constants.CONSTANT_Utf8); | |||
buf = "\"" + Utility.convertString(((ConstantUtf8)c).getBytes()) + "\""; | |||
break; | |||
@@ -172,7 +172,7 @@ public final class ConstantValue extends Attribute { | |||
*/ | |||
public Attribute copy(ConstantPool constant_pool) { | |||
ConstantValue c = (ConstantValue)clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* deprecated method. | |||
* It is instantiated from the <em>Attribute.readAttribute()</em> method. | |||
* | |||
* @version $Id: Deprecated.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Deprecated.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -117,7 +117,7 @@ public final class Deprecated extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitDeprecated(this); | |||
} | |||
@@ -163,7 +163,7 @@ public final class Deprecated extends Attribute { | |||
if(bytes != null) | |||
c.bytes = (byte[])bytes.clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -49,7 +49,7 @@ public class EnclosingMethod extends Attribute { | |||
methodIndex = methodIdx; | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitEnclosingMethod(this); | |||
} | |||
@@ -68,14 +68,14 @@ public class EnclosingMethod extends Attribute { | |||
public final ConstantClass getEnclosingClass() { | |||
ConstantClass c = | |||
(ConstantClass)constant_pool.getConstant(classIndex,Constants.CONSTANT_Class); | |||
(ConstantClass)constantPool.getConstant(classIndex,Constants.CONSTANT_Class); | |||
return c; | |||
} | |||
public final ConstantNameAndType getEnclosingMethod() { | |||
if (methodIndex == 0) return null; | |||
ConstantNameAndType nat = | |||
(ConstantNameAndType)constant_pool.getConstant(methodIndex,Constants.CONSTANT_NameAndType); | |||
(ConstantNameAndType)constantPool.getConstant(methodIndex,Constants.CONSTANT_NameAndType); | |||
return nat; | |||
} | |||
@@ -65,7 +65,7 @@ import java.io.*; | |||
* attribute using the name <em>Exceptions</em> (which is inconsistent | |||
* with the other classes). | |||
* | |||
* @version $Id: ExceptionTable.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: ExceptionTable.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Code | |||
*/ | |||
@@ -123,7 +123,7 @@ public final class ExceptionTable extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitExceptionTable(this); | |||
} | |||
@@ -156,7 +156,7 @@ public final class ExceptionTable extends Attribute { | |||
public final String[] getExceptionNames() { | |||
String[] names = new String[number_of_exceptions]; | |||
for(int i=0; i < number_of_exceptions; i++) | |||
names[i] = constant_pool.getConstantString(exception_index_table[i], | |||
names[i] = constantPool.getConstantString(exception_index_table[i], | |||
Constants.CONSTANT_Class). | |||
replace('/', '.'); | |||
return names; | |||
@@ -179,7 +179,7 @@ public final class ExceptionTable extends Attribute { | |||
String str; | |||
for(int i=0; i < number_of_exceptions; i++) { | |||
str = constant_pool.getConstantString(exception_index_table[i], | |||
str = constantPool.getConstantString(exception_index_table[i], | |||
Constants.CONSTANT_Class); | |||
buf.append(Utility.compactClassName(str, false)); | |||
@@ -196,7 +196,7 @@ public final class ExceptionTable extends Attribute { | |||
public Attribute copy(ConstantPool constant_pool) { | |||
ExceptionTable c = (ExceptionTable)clone(); | |||
c.exception_index_table = (int[])exception_index_table.clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -53,18 +53,27 @@ package org.aspectj.apache.bcel.classfile; | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
import java.util.List; | |||
import org.aspectj.apache.bcel.generic.Type; | |||
import java.io.*; | |||
/** | |||
* This class represents the field info structure, i.e., the representation | |||
* for a variable in the class. See JVM specification for details. | |||
* | |||
* @version $Id: Field.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Field.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class Field extends FieldOrMethod { | |||
public static final Field[] NoFields = new Field[0]; | |||
private Type fieldType = null; // lazily initialized | |||
private Field() {} | |||
/** | |||
* Initialize from another object. Note that both objects use the same | |||
* references (shallow copy). Use clone() for a physical copy. | |||
@@ -73,37 +82,15 @@ public final class Field extends FieldOrMethod { | |||
super(c); | |||
} | |||
/** | |||
* Construct object from file stream. | |||
* @param file Input stream | |||
*/ | |||
Field(DataInputStream file, ConstantPool constant_pool) | |||
throws IOException, ClassFormatException | |||
{ | |||
Field(DataInputStream file, ConstantPool constant_pool) throws IOException { | |||
super(file, constant_pool); | |||
} | |||
/** | |||
* @param access_flags Access rights of field | |||
* @param name_index Points to field name in constant pool | |||
* @param signature_index Points to encoded signature | |||
* @param attributes Collection of attributes | |||
* @param constant_pool Array of constants | |||
*/ | |||
public Field(int access_flags, int name_index, int signature_index, | |||
Attribute[] attributes, ConstantPool constant_pool) | |||
{ | |||
super(access_flags, name_index, signature_index, attributes, constant_pool); | |||
public Field(int accessflags, int nameIndex, int signatureIndex,Attribute[] attributes, ConstantPool constant_pool) { | |||
super(accessflags, nameIndex, signatureIndex, attributes, constant_pool); | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
* defined by the contents of a Java class. I.e., the hierarchy of methods, | |||
* fields, attributes, etc. spawns a tree of objects. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitField(this); | |||
} | |||
@@ -111,55 +98,47 @@ public final class Field extends FieldOrMethod { | |||
* @return constant value associated with this field (may be null) | |||
*/ | |||
public final ConstantValue getConstantValue() { | |||
for(int i=0; i < attributes_count; i++) | |||
if(attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) | |||
return (ConstantValue)attributes[i]; | |||
return null; | |||
return AttributeUtils.getConstantValueAttribute(attributes); | |||
} | |||
/** | |||
* Return string representation close to declaration format, | |||
* `public static final short MAX = 100', e.g.. | |||
* | |||
* @return String representation of field, including the signature. | |||
* Return string representation close to declaration format, eg: | |||
* 'public static final short MAX = 100' | |||
*/ | |||
public final String toString() { | |||
String name, signature, access; // Short cuts to constant pool | |||
// Get names from constant pool | |||
access = Utility.accessToString(access_flags); | |||
access = Utility.accessToString(modifiers); | |||
access = access.equals("")? "" : (access + " "); | |||
signature = Utility.signatureToString(getSignature()); | |||
name = getName(); | |||
StringBuffer buf = new StringBuffer(access + signature + " " + name); | |||
StringBuffer buf = new StringBuffer(access); | |||
buf.append(signature).append(" ").append(name); | |||
ConstantValue cv = getConstantValue(); | |||
if(cv != null) | |||
buf.append(" = " + cv); | |||
if (cv != null) buf.append(" = ").append(cv); | |||
for(int i=0; i < attributes_count; i++) { | |||
// append all attributes that are *not* "ConstantValue" | |||
for(int i=0; i < attributes.length; i++) { | |||
Attribute a = attributes[i]; | |||
if(!(a instanceof ConstantValue)) | |||
buf.append(" [" + a.toString() + "]"); | |||
if(!(a instanceof ConstantValue)) buf.append(" [").append(a.toString()).append("]"); | |||
} | |||
return buf.toString(); | |||
} | |||
/** | |||
* @return deep copy of this field | |||
*/ | |||
/** deep copy of this field */ | |||
public final Field copy(ConstantPool constant_pool) { | |||
return (Field)copy_(constant_pool); | |||
} | |||
/** | |||
* @return type of field | |||
*/ | |||
/** return the type of the field */ | |||
public Type getType() { | |||
return Type.getReturnType(getSignature()); | |||
if (fieldType==null) { | |||
fieldType = Type.getReturnType(getSignature()); | |||
} | |||
return fieldType; | |||
} | |||
} |
@@ -54,7 +54,7 @@ package org.aspectj.apache.bcel.classfile; | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.annotation.Annotation; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; | |||
import java.io.*; | |||
@@ -64,94 +64,49 @@ import java.util.List; | |||
/** | |||
* Abstract super class for fields and methods. | |||
* | |||
* @version $Id: FieldOrMethod.java,v 1.5 2005/06/26 20:27:23 acolyer Exp $ | |||
* @version $Id: FieldOrMethod.java,v 1.6 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node { | |||
protected int name_index; // Points to field name in constant pool | |||
protected int signature_index; // Points to encoded signature | |||
protected int attributes_count;// No. of attributes | |||
protected Attribute[] attributes; // Collection of attributes | |||
private Annotation[] annotations; // annotations defined on the field or method | |||
protected ConstantPool constant_pool; | |||
private String signatureAttributeString = null; | |||
public abstract class FieldOrMethod extends Modifiers implements Cloneable, Node { | |||
protected int nameIndex; | |||
protected int signatureIndex; | |||
protected Attribute[] attributes; | |||
protected int attributes_count;// No. of attributes | |||
protected ConstantPool cpool; | |||
private String name; // lazily initialized | |||
private String signature; // lazily initialized | |||
private AnnotationGen[] annotations; // lazily initialized | |||
private String signatureAttributeString = null; | |||
private boolean searchedForSignatureAttribute = false; | |||
// Annotations are collected from certain attributes, don't do it more than necessary! | |||
private boolean annotationsOutOfDate = true; | |||
FieldOrMethod() {} | |||
protected FieldOrMethod() {} | |||
/** | |||
* Initialize from another object. Note that both objects use the same | |||
* references (shallow copy). Use clone() for a physical copy. | |||
*/ | |||
protected FieldOrMethod(FieldOrMethod c) { | |||
this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(), | |||
c.getAttributes(), c.getConstantPool()); | |||
this(c.getModifiers(), c.getNameIndex(), c.getSignatureIndex(),c.getAttributes(), c.getConstantPool()); | |||
} | |||
/** | |||
* Construct object from file stream. | |||
* @param file Input stream | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) | |||
throws IOException, ClassFormatException | |||
{ | |||
this(file.readUnsignedShort(), file.readUnsignedShort(), | |||
file.readUnsignedShort(), null, constant_pool); | |||
attributes_count = file.readUnsignedShort(); | |||
attributes = new Attribute[attributes_count]; | |||
for(int i=0; i < attributes_count; i++) | |||
attributes[i] = Attribute.readAttribute(file, constant_pool); | |||
} | |||
/** | |||
* @param access_flags Access rights of method | |||
* @param name_index Points to field name in constant pool | |||
* @param signature_index Points to encoded signature | |||
* @param attributes Collection of attributes | |||
* @param constant_pool Array of constants | |||
*/ | |||
protected FieldOrMethod(int access_flags, int name_index, int signature_index, | |||
Attribute[] attributes, ConstantPool constant_pool) | |||
{ | |||
this.access_flags = access_flags; | |||
this.name_index = name_index; | |||
this.signature_index = signature_index; | |||
this.constant_pool = constant_pool; | |||
setAttributes(attributes); | |||
protected FieldOrMethod(DataInputStream file, ConstantPool cpool) throws IOException { | |||
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null, cpool); | |||
attributes = AttributeUtils.readAttributes(file,cpool); | |||
} | |||
/** | |||
* Dump object to file stream on binary format. | |||
* | |||
* @param file Output file stream | |||
* @throws IOException | |||
*/ | |||
public final void dump(DataOutputStream file) throws IOException | |||
{ | |||
file.writeShort(access_flags); | |||
file.writeShort(name_index); | |||
file.writeShort(signature_index); | |||
file.writeShort(attributes_count); | |||
for(int i=0; i < attributes_count; i++) | |||
attributes[i].dump(file); | |||
protected FieldOrMethod(int accessFlags, int nameIndex, int signatureIndex, Attribute[] attributes, ConstantPool cpool) { | |||
this.modifiers = accessFlags; | |||
this.nameIndex = nameIndex; | |||
this.signatureIndex = signatureIndex; | |||
this.cpool = cpool; | |||
this.attributes = attributes; | |||
} | |||
/** | |||
* @return Collection of object attributes. | |||
*/ | |||
public final Attribute[] getAttributes() { return attributes; } | |||
/** | |||
/** | |||
* @param attributes Collection of object attributes. | |||
*/ | |||
public void setAttributes(Attribute[] attributes) { | |||
@@ -159,60 +114,34 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No | |||
attributes_count = (attributes == null)? 0 : attributes.length; | |||
} | |||
/** | |||
* @return Constant pool used by this object. | |||
*/ | |||
public final ConstantPool getConstantPool() { return constant_pool; } | |||
/** | |||
* @param constant_pool Constant pool to be used for this object. | |||
*/ | |||
public final void setConstantPool(ConstantPool constant_pool) { | |||
this.constant_pool = constant_pool; | |||
} | |||
/** | |||
* @return Index in constant pool of object's name. | |||
*/ | |||
public final int getNameIndex() { return name_index; } | |||
/** | |||
* @param name_index Index in constant pool of object's name. | |||
*/ | |||
public final void setNameIndex(int name_index) { | |||
this.name_index = name_index; | |||
public final void dump(DataOutputStream file) throws IOException { | |||
file.writeShort(modifiers); | |||
file.writeShort(nameIndex); | |||
file.writeShort(signatureIndex); | |||
AttributeUtils.writeAttributes(attributes,file); | |||
} | |||
/** | |||
* @return Index in constant pool of field signature. | |||
*/ | |||
public final int getSignatureIndex() { return signature_index; } | |||
/** | |||
* @param signature_index Index in constant pool of field signature. | |||
*/ | |||
public final void setSignatureIndex(int signature_index) { | |||
this.signature_index = signature_index; | |||
} | |||
public final Attribute[] getAttributes() { return attributes; } | |||
public final ConstantPool getConstantPool() { return cpool; } | |||
public final int getNameIndex() { return nameIndex; } | |||
public final int getSignatureIndex() { return signatureIndex; } | |||
/** | |||
* @return Name of object, i.e., method name or field name | |||
*/ | |||
public final String getName() { | |||
ConstantUtf8 c; | |||
c = (ConstantUtf8)constant_pool.getConstant(name_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
if (name==null) { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(nameIndex,Constants.CONSTANT_Utf8); | |||
name = c.getBytes(); | |||
} | |||
return name; | |||
} | |||
/** | |||
* @return String representation of object's type signature (java style) | |||
*/ | |||
public final String getSignature() { | |||
ConstantUtf8 c; | |||
c = (ConstantUtf8)constant_pool.getConstant(signature_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
if (signature==null) { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(signatureIndex,Constants.CONSTANT_Utf8); | |||
signature = c.getBytes(); | |||
} | |||
return signature; | |||
} | |||
/** | |||
@@ -235,53 +164,34 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No | |||
c = (FieldOrMethod)clone(); | |||
} catch(CloneNotSupportedException e) {} | |||
c.constant_pool = constant_pool; | |||
c.attributes = new Attribute[attributes_count]; | |||
for(int i=0; i < attributes_count; i++) | |||
c.attributes[i] = attributes[i].copy(constant_pool); | |||
c.cpool = constant_pool; | |||
c.attributes = AttributeUtils.copy(attributes,constant_pool); | |||
return c; | |||
} | |||
/** | |||
* Ensure we have unpacked any attributes that contain annotations. | |||
* We don't remove these annotation attributes from the attributes list, they | |||
* remain there. | |||
*/ | |||
private void ensureAnnotationsUpToDate() { | |||
if (annotationsOutOfDate) { | |||
public AnnotationGen[] getAnnotations() { | |||
// Ensure we have unpacked any attributes that contain annotations. | |||
// We don't remove these annotation attributes from the attributes list, they | |||
// remain there. | |||
if (annotations==null) { | |||
// Find attributes that contain annotation data | |||
Attribute[] attrs = getAttributes(); | |||
List accumulatedAnnotations = new ArrayList(); | |||
for (int i = 0; i < attrs.length; i++) { | |||
Attribute attribute = attrs[i]; | |||
for (int i = 0; i < attributes.length; i++) { | |||
Attribute attribute = attributes[i]; | |||
if (attribute instanceof RuntimeAnnotations) { | |||
RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; | |||
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); | |||
} | |||
} | |||
annotations = (Annotation[])accumulatedAnnotations.toArray(new Annotation[]{}); | |||
annotationsOutOfDate = false; | |||
if (accumulatedAnnotations.size()==0) { | |||
annotations = AnnotationGen.NO_ANNOTATIONS; | |||
} else { | |||
annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); | |||
} | |||
} | |||
} | |||
public Annotation[] getAnnotations() { | |||
ensureAnnotationsUpToDate(); | |||
return annotations; | |||
} | |||
public void addAnnotation(Annotation a) { | |||
ensureAnnotationsUpToDate(); | |||
int len = annotations.length; | |||
Annotation[] newAnnotations = new Annotation[len+1]; | |||
System.arraycopy(annotations, 0, newAnnotations, 0, len); | |||
newAnnotations[len] = a; | |||
annotations = newAnnotations; | |||
} | |||
/** | |||
* Hunts for a signature attribute on the member and returns its contents. So where the 'regular' signature | |||
* may be (Ljava/util/Vector;)V the signature attribute may in fact say 'Ljava/lang/Vector<Ljava/lang/String>;' | |||
@@ -289,13 +199,8 @@ public abstract class FieldOrMethod extends AccessFlags implements Cloneable, No | |||
*/ | |||
public final String getGenericSignature() { | |||
if (!searchedForSignatureAttribute) { | |||
boolean found=false; | |||
for(int i=0; !found && i < attributes_count; i++) { | |||
if(attributes[i] instanceof Signature) { | |||
signatureAttributeString = ((Signature)attributes[i]).getSignature(); | |||
found=true; | |||
} | |||
} | |||
Signature sig = AttributeUtils.getSignatureAttribute(attributes); | |||
signatureAttributeString = (sig==null?null:sig.getSignature()); | |||
searchedForSignatureAttribute=true; | |||
} | |||
return signatureAttributeString; |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* indices of the inner and outer classes, the name and the attributes | |||
* of the inner class. | |||
* | |||
* @version $Id: InnerClass.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: InnerClass.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see InnerClasses | |||
*/ | |||
@@ -113,7 +113,7 @@ public final class InnerClass implements Cloneable, Node { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitInnerClass(this); | |||
} | |||
/** |
@@ -63,7 +63,7 @@ import java.io.*; | |||
* to the source file of this class. | |||
* It is instantiated from the <em>Attribute.readAttribute()</em> method. | |||
* | |||
* @version $Id: InnerClasses.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: InnerClasses.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -122,7 +122,7 @@ public final class InnerClasses extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitInnerClasses(this); | |||
} | |||
/** | |||
@@ -160,7 +160,7 @@ public final class InnerClasses extends Attribute { | |||
StringBuffer buf = new StringBuffer(); | |||
for(int i=0; i < number_of_classes; i++) | |||
buf.append(inner_classes[i].toString(constant_pool) + "\n"); | |||
buf.append(inner_classes[i].toString(constantPool) + "\n"); | |||
return buf.toString(); | |||
} | |||
@@ -175,7 +175,7 @@ public final class InnerClasses extends Attribute { | |||
for(int i=0; i < number_of_classes; i++) | |||
c.inner_classes[i] = inner_classes[i].copy(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -58,7 +58,7 @@ import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.util.SyntheticRepository; | |||
import org.aspectj.apache.bcel.util.ClassVector; | |||
import org.aspectj.apache.bcel.util.ClassQueue; | |||
import org.aspectj.apache.bcel.classfile.annotation.Annotation; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; | |||
import org.aspectj.apache.bcel.generic.Type; | |||
@@ -77,14 +77,14 @@ import java.util.StringTokenizer; | |||
* class file. Those interested in programatically generating classes | |||
* should see the <a href="../generic/ClassGen.html">ClassGen</a> class. | |||
* @version $Id: JavaClass.java,v 1.9 2005/12/02 06:56:14 acolyer Exp $ | |||
* @version $Id: JavaClass.java,v 1.10 2008/05/28 23:53:02 aclement Exp $ | |||
* @see org.aspectj.apache.bcel.generic.ClassGen | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
public class JavaClass extends Modifiers implements Cloneable, Node { | |||
private String file_name; | |||
private String package_name; | |||
private String source_file_name = "<Unknown>"; | |||
private String source_file_name; | |||
private int class_name_index; | |||
private int superclass_name_index; | |||
private String class_name; | |||
@@ -96,8 +96,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
private Field[] fields; // Fields, i.e., variables of class | |||
private Method[] methods; // methods defined in the class | |||
private Attribute[] attributes; // attributes defined in the class | |||
private Annotation[] annotations; // annotations defined on the class | |||
private byte source = HEAP; // Generated in memory | |||
private AnnotationGen[] annotations; // annotations defined on the class | |||
private boolean isGeneric = false; | |||
private boolean isAnonymous = false; | |||
private boolean isNested = false; | |||
@@ -154,39 +153,32 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
int[] interfaces, | |||
Field[] fields, | |||
Method[] methods, | |||
Attribute[] attributes, | |||
byte source) | |||
Attribute[] attributes) | |||
{ | |||
if(interfaces == null) // Allowed for backward compatibility | |||
interfaces = new int[0]; | |||
if(attributes == null) | |||
this.attributes = new Attribute[0]; | |||
if (attributes == null) this.attributes = Attribute.NoAttributes; | |||
if(fields == null) | |||
fields = new Field[0]; | |||
fields = new Field[0]; // TODO create a constant for no fields | |||
if(methods == null) | |||
methods = new Method[0]; | |||
methods = new Method[0]; // TODO create a constant for no methods | |||
this.class_name_index = class_name_index; | |||
this.superclass_name_index = superclass_name_index; | |||
this.file_name = file_name; | |||
this.major = major; | |||
this.minor = minor; | |||
this.access_flags = access_flags; | |||
this.modifiers = access_flags; | |||
this.constant_pool = constant_pool; | |||
this.interfaces = interfaces; | |||
this.fields = fields; | |||
this.methods = methods; | |||
this.attributes = attributes; | |||
annotationsOutOfDate = true; | |||
this.source = source; | |||
// Get source file name if available | |||
for(int i=0; i < attributes.length; i++) { | |||
if(attributes[i] instanceof SourceFile) { | |||
source_file_name = ((SourceFile)attributes[i]).getSourceFileName(); | |||
break; | |||
} | |||
} | |||
SourceFile sfAttribute = AttributeUtils.getSourceFileAttribute(attributes); | |||
source_file_name = (sfAttribute==null?"<Unknown>":sfAttribute.getSourceFileName()); | |||
/* According to the specification the following entries must be of type | |||
* `ConstantClass' but we check that anyway via the | |||
@@ -217,36 +209,6 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
} | |||
} | |||
/** | |||
* Constructor gets all contents as arguments. | |||
* | |||
* @param class_name_index Class name | |||
* @param superclass_name_index Superclass name | |||
* @param file_name File name | |||
* @param major Major compiler version | |||
* @param minor Minor compiler version | |||
* @param access_flags Access rights defined by bit flags | |||
* @param constant_pool Array of constants | |||
* @param interfaces Implemented interfaces | |||
* @param fields Class fields | |||
* @param methods Class methods | |||
* @param attributes Class attributes | |||
*/ | |||
public JavaClass(int class_name_index, | |||
int superclass_name_index, | |||
String file_name, | |||
int major, | |||
int minor, | |||
int access_flags, | |||
ConstantPool constant_pool, | |||
int[] interfaces, | |||
Field[] fields, | |||
Method[] methods, | |||
Attribute[] attributes) { | |||
this(class_name_index, superclass_name_index, file_name, major, minor, access_flags, | |||
constant_pool, interfaces, fields, methods, attributes, HEAP); | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
@@ -255,7 +217,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitJavaClass(this); | |||
} | |||
@@ -339,7 +301,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
constant_pool.dump(file); | |||
file.writeShort(access_flags); | |||
file.writeShort(modifiers); | |||
file.writeShort(class_name_index); | |||
file.writeShort(superclass_name_index); | |||
@@ -355,13 +317,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
for(int i=0; i < methods.length; i++) | |||
methods[i].dump(file); | |||
if(attributes != null) { | |||
file.writeShort(attributes.length); | |||
for(int i=0; i < attributes.length; i++) | |||
attributes[i].dump(file); | |||
} | |||
else | |||
file.writeShort(0); | |||
AttributeUtils.writeAttributes(attributes,file); | |||
file.close(); | |||
} | |||
@@ -371,19 +327,18 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
*/ | |||
public Attribute[] getAttributes() { return attributes; } | |||
public Annotation[] getAnnotations() { | |||
public AnnotationGen[] getAnnotations() { | |||
if (annotationsOutOfDate) { | |||
// Find attributes that contain annotation data | |||
Attribute[] attrs = getAttributes(); | |||
List accumulatedAnnotations = new ArrayList(); | |||
for (int i = 0; i < attrs.length; i++) { | |||
Attribute attribute = attrs[i]; | |||
for (int i = 0; i < attributes.length; i++) { | |||
Attribute attribute = attributes[i]; | |||
if (attribute instanceof RuntimeAnnotations) { | |||
RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations)attribute; | |||
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations()); | |||
} | |||
} | |||
annotations = (Annotation[])accumulatedAnnotations.toArray(new Annotation[]{}); | |||
annotations = (AnnotationGen[])accumulatedAnnotations.toArray(new AnnotationGen[]{}); | |||
annotationsOutOfDate = false; | |||
} | |||
return annotations; | |||
@@ -618,11 +573,11 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
* @return String representing class contents. | |||
*/ | |||
public String toString() { | |||
String access = Utility.accessToString(access_flags, true); | |||
String access = Utility.accessToString(modifiers, true); | |||
access = access.equals("")? "" : (access + " "); | |||
StringBuffer buf = new StringBuffer(access + | |||
Utility.classOrInterface(access_flags) + | |||
Utility.classOrInterface(modifiers) + | |||
" " + | |||
class_name + " extends " + | |||
Utility.compactClassName(superclass_name, | |||
@@ -644,14 +599,13 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
buf.append("filename\t\t" + file_name + '\n'); | |||
buf.append("compiled from\t\t" + source_file_name + '\n'); | |||
buf.append("compiler version\t" + major + "." + minor + '\n'); | |||
buf.append("access flags\t\t" + access_flags + '\n'); | |||
buf.append("access flags\t\t" + modifiers + '\n'); | |||
buf.append("constant pool\t\t" + constant_pool.getLength() + " entries\n"); | |||
buf.append("ACC_SUPER flag\t\t" + isSuper() + "\n"); | |||
if(attributes.length > 0) { | |||
buf.append("\nAttribute(s):\n"); | |||
for(int i=0; i < attributes.length; i++) | |||
buf.append(indent(attributes[i])); | |||
for(int i=0; i < attributes.length; i++) buf.append(indent(attributes[i])); | |||
} | |||
if (annotations!=null && annotations.length>0) { | |||
@@ -707,9 +661,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
for(int i=0; i < methods.length; i++) | |||
c.methods[i] = methods[i].copy(c.constant_pool); | |||
c.attributes = new Attribute[attributes.length]; | |||
for(int i=0; i < attributes.length; i++) | |||
c.attributes[i] = attributes[i].copy(c.constant_pool); | |||
c.attributes = AttributeUtils.copy(attributes,c.constant_pool); | |||
//J5SUPPORT: As the annotations exist as attributes against the class, copying | |||
// the attributes will copy the annotations across, so we don't have to | |||
@@ -719,11 +671,11 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
} | |||
public final boolean isSuper() { | |||
return (access_flags & Constants.ACC_SUPER) != 0; | |||
return (modifiers & Constants.ACC_SUPER) != 0; | |||
} | |||
public final boolean isClass() { | |||
return (access_flags & Constants.ACC_INTERFACE) == 0; | |||
return (modifiers & Constants.ACC_INTERFACE) == 0; | |||
} | |||
public final boolean isAnonymous() { | |||
@@ -738,9 +690,10 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
private final void computeNestedTypeStatus() { | |||
if (computedNestedTypeStatus) return; | |||
for (int i = 0; i < this.attributes.length; i++) { | |||
if (this.attributes[i] instanceof InnerClasses) { | |||
InnerClass[] innerClasses = ((InnerClasses) this.attributes[i]).getInnerClasses(); | |||
//Attribute[] attrs = attributes.getAttributes(); | |||
for (int i = 0; i <attributes.length; i++) { | |||
if (attributes[i] instanceof InnerClasses) { | |||
InnerClass[] innerClasses = ((InnerClasses) attributes[i]).getInnerClasses(); | |||
for (int j = 0; j < innerClasses.length; j++) { | |||
boolean innerClassAttributeRefersToMe = false; | |||
String inner_class_name = constant_pool.getConstantString(innerClasses[j].getInnerClassIndex(), | |||
@@ -767,20 +720,14 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
* 'public @interface blahblah' declaration | |||
*/ | |||
public final boolean isAnnotation() { | |||
return (access_flags & Constants.ACC_ANNOTATION) != 0; | |||
return (modifiers & Constants.ACC_ANNOTATION) != 0; | |||
} | |||
/** | |||
* Returns true if this class represents an enum type | |||
*/ | |||
public final boolean isEnum() { | |||
return (access_flags & Constants.ACC_ENUM) != 0; | |||
} | |||
/** @return returns either HEAP (generated), FILE, or ZIP | |||
*/ | |||
public final byte getSource() { | |||
return source; | |||
return (modifiers & Constants.ACC_ENUM) != 0; | |||
} | |||
/********************* New repository functionality *********************/ | |||
@@ -904,6 +851,7 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
/** | |||
* Get all interfaces implemented by this JavaClass (transitively). | |||
*/ | |||
// OPTIMIZE get rid of ClassQueue and ClassVector | |||
public JavaClass[] getAllInterfaces() { | |||
ClassQueue queue = new ClassQueue(); | |||
ClassVector vec = new ClassVector(); | |||
@@ -917,11 +865,11 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
JavaClass[] interfaces = clazz.getInterfaces(); | |||
if(clazz.isInterface()) { | |||
vec.addElement(clazz); | |||
} else { | |||
if(souper != null) { | |||
queue.enqueue(souper); | |||
} | |||
vec.addElement(clazz); | |||
} else { | |||
if(souper != null) { | |||
queue.enqueue(souper); | |||
} | |||
} | |||
for(int i = 0; i < interfaces.length; i++) { | |||
@@ -951,15 +899,9 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
private void loadGenericSignatureInfoIfNecessary() { | |||
if (!searchedForSignatureAttribute) { | |||
boolean found=false; | |||
for(int i=0; !found && i < attributes.length; i++) { | |||
if(attributes[i] instanceof Signature) { | |||
signatureAttribute = ((Signature)attributes[i]); | |||
signatureAttributeString = signatureAttribute.getSignature(); | |||
found=true; | |||
} | |||
} | |||
isGeneric = found && signatureAttributeString.charAt(0)=='<'; | |||
signatureAttribute = AttributeUtils.getSignatureAttribute(attributes); | |||
signatureAttributeString = signatureAttribute==null?null:signatureAttribute.getSignature(); | |||
isGeneric = signatureAttribute!=null && signatureAttributeString.charAt(0)=='<'; | |||
searchedForSignatureAttribute=true; | |||
} | |||
} | |||
@@ -971,9 +913,8 @@ public class JavaClass extends AccessFlags implements Cloneable, Node { | |||
loadGenericSignatureInfoIfNecessary(); | |||
if (signatureAttribute != null) { | |||
return signatureAttribute.asClassSignature(); | |||
} else { | |||
return null; | |||
} | |||
return null; | |||
} | |||
} |
@@ -64,7 +64,7 @@ import java.io.Serializable; | |||
* the source that corresponds to a relative address in the byte code. This | |||
* is used for debugging purposes. | |||
* | |||
* @version $Id: LineNumber.java,v 1.4 2007/02/28 13:10:32 aclement Exp $ | |||
* @version $Id: LineNumber.java,v 1.5 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see LineNumberTable | |||
*/ | |||
@@ -106,7 +106,7 @@ public final class LineNumber implements Cloneable, Node, Serializable { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitLineNumber(this); | |||
} | |||
@@ -150,7 +150,7 @@ public final class LineNumber implements Cloneable, Node, Serializable { | |||
* @return String representation | |||
*/ | |||
public final String toString() { | |||
return "LineNumber(pc=" + start_pc + ", line=" + line_number + ")"; | |||
return "LineNumber(" + start_pc + ", " + line_number + ")"; | |||
} | |||
/** |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* purposes. This attribute is used by the <em>Code</em> attribute. It | |||
* contains pairs of PCs and line numbers. | |||
* | |||
* @version $Id: LineNumberTable.java,v 1.3 2006/02/07 15:15:42 aclement Exp $ | |||
* @version $Id: LineNumberTable.java,v 1.4 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Code | |||
* | |||
@@ -144,7 +144,7 @@ public final class LineNumberTable extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
unpack(); | |||
v.visitLineNumberTable(this); | |||
} | |||
@@ -268,7 +268,7 @@ public final class LineNumberTable extends Attribute { | |||
for(int i=0; i < line_number_table_length; i++) | |||
c.line_number_table[i] = line_number_table[i].copy(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
@@ -61,7 +61,7 @@ import java.io.*; | |||
* This class represents a local variable within a method. It contains its | |||
* scope, name, signature and index on the method's frame. | |||
* | |||
* @version $Id: LocalVariable.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: LocalVariable.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see LocalVariableTable | |||
*/ | |||
@@ -127,7 +127,7 @@ public final class LocalVariable | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitLocalVariable(this); | |||
} | |||
@@ -61,7 +61,7 @@ import java.io.*; | |||
* This class represents collection of local variables in a | |||
* method. This attribute is contained in the <em>Code</em> attribute. | |||
* | |||
* @version $Id: LocalVariableTable.java,v 1.3 2006/02/15 09:15:34 aclement Exp $ | |||
* @version $Id: LocalVariableTable.java,v 1.4 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Code | |||
* @see LocalVariable | |||
@@ -128,7 +128,7 @@ public class LocalVariableTable extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
unpack(); | |||
v.visitLocalVariableTable(this); | |||
} | |||
@@ -204,7 +204,7 @@ public class LocalVariableTable extends Attribute { | |||
for(int i=0; i < localVariableTableLength; i++) | |||
c.localVariableTable[i] = localVariableTable[i].copy(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
@@ -223,7 +223,7 @@ public class LocalVariableTable extends Attribute { | |||
localVariableTableLength = (dis.readUnsignedShort()); | |||
localVariableTable = new LocalVariable[localVariableTableLength]; | |||
for (int i=0; i < localVariableTableLength; i++) | |||
localVariableTable[i] = new LocalVariable(dis,constant_pool); | |||
localVariableTable[i] = new LocalVariable(dis,constantPool); | |||
dis.close(); | |||
data = null; // throw it away now | |||
} catch (IOException e) { |
@@ -71,7 +71,7 @@ public class LocalVariableTypeTable extends Attribute { | |||
local_variable_type_table[i] = new LocalVariable(dis, cpool); | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitLocalVariableTypeTable(this); | |||
} | |||
@@ -127,7 +127,7 @@ public class LocalVariableTypeTable extends Attribute { | |||
for(int i=0; i < local_variable_type_table_length; i++) | |||
c.local_variable_type_table[i] = local_variable_type_table[i].copy(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
@@ -55,38 +55,35 @@ package org.aspectj.apache.bcel.classfile; | |||
*/ | |||
import java.io.DataInputStream; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.annotation.Annotation; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; | |||
import org.aspectj.apache.bcel.generic.Type; | |||
import java.io.*; | |||
import java.util.*; | |||
/** | |||
* This class represents the method info structure, i.e., the representation | |||
* for a method in the class. See JVM specification for details. | |||
* A method has access flags, a name, a signature and a number of attributes. | |||
* | |||
* @version $Id: Method.java,v 1.4 2008/01/25 18:33:24 aclement Exp $ | |||
* @version $Id: Method.java,v 1.5 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class Method extends FieldOrMethod { | |||
public static final Annotation[][] NO_PARAMETER_ANNOTATIONS = new Annotation[][]{}; | |||
public static final Annotation[] NO_ANNOTATIONS = new Annotation[]{}; | |||
private boolean parameterAnnotationsOutOfDate; | |||
private Annotation[][] unpackedParameterAnnotations; | |||
public static final AnnotationGen[][] NO_PARAMETER_ANNOTATIONS = new AnnotationGen[][]{}; | |||
public static final AnnotationGen[] NO_ANNOTATIONS = new AnnotationGen[]{}; | |||
public static final Method[] NoMethods = new Method[0]; | |||
private boolean parameterAnnotationsOutOfDate = true; | |||
private AnnotationGen[][] unpackedParameterAnnotations; | |||
/** | |||
* Empty constructor, all attributes have to be defined via `setXXX' | |||
* methods. Use at your own risk. | |||
*/ | |||
public Method() { | |||
parameterAnnotationsOutOfDate = true; | |||
private Method() { | |||
parameterAnnotationsOutOfDate = true; | |||
} | |||
/** | |||
@@ -98,44 +95,20 @@ public final class Method extends FieldOrMethod { | |||
parameterAnnotationsOutOfDate = true; | |||
} | |||
/** | |||
* Construct object from file stream. | |||
* @param file Input stream | |||
* @throws IOException | |||
* @throws ClassFormatException | |||
*/ | |||
Method(DataInputStream file, ConstantPool constant_pool) | |||
throws IOException, ClassFormatException | |||
{ | |||
Method(DataInputStream file, ConstantPool constant_pool) throws IOException { | |||
super(file, constant_pool); | |||
parameterAnnotationsOutOfDate = true; | |||
} | |||
/** | |||
* @param access_flags Access rights of method | |||
* @param name_index Points to field name in constant pool | |||
* @param signature_index Points to encoded signature | |||
* @param attributes Collection of attributes | |||
* @param constant_pool Array of constants | |||
*/ | |||
public Method(int access_flags, int name_index, int signature_index, | |||
Attribute[] attributes, ConstantPool constant_pool) | |||
{ | |||
public Method(int access_flags, int name_index, int signature_index, Attribute[] attributes, ConstantPool constant_pool) { | |||
super(access_flags, name_index, signature_index, attributes, constant_pool); | |||
parameterAnnotationsOutOfDate = true; | |||
} | |||
/** | |||
* Called by objects that are traversing the nodes of the tree implicitely | |||
* defined by the contents of a Java class. I.e., the hierarchy of methods, | |||
* fields, attributes, etc. spawns a tree of objects. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitMethod(this); | |||
} | |||
// CUSTARD mutable or not? | |||
public void setAttributes(Attribute[] attributes) { | |||
parameterAnnotationsOutOfDate = true; | |||
super.setAttributes(attributes); | |||
@@ -145,79 +118,59 @@ public final class Method extends FieldOrMethod { | |||
* @return Code attribute of method, if any | |||
*/ | |||
public final Code getCode() { | |||
for(int i=0; i < attributes_count; i++) | |||
if(attributes[i] instanceof Code) | |||
return (Code)attributes[i]; | |||
return null; | |||
return AttributeUtils.getCodeAttribute(attributes); | |||
} | |||
/** | |||
* @return ExceptionTable attribute of method, if any, i.e., list all | |||
* exceptions the method may throw not exception handlers! | |||
*/ | |||
public final ExceptionTable getExceptionTable() { | |||
for(int i=0; i < attributes_count; i++) | |||
if(attributes[i] instanceof ExceptionTable) | |||
return (ExceptionTable)attributes[i]; | |||
return null; | |||
return AttributeUtils.getExceptionTableAttribute(attributes); | |||
} | |||
/** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded | |||
* to the Code atribute. | |||
/** | |||
* Return LocalVariableTable of code attribute if any (the call is forwarded | |||
* to the Code attribute) | |||
*/ | |||
public final LocalVariableTable getLocalVariableTable() { | |||
Code code = getCode(); | |||
if(code != null) | |||
return code.getLocalVariableTable(); | |||
else | |||
return null; | |||
if (code != null) return code.getLocalVariableTable(); | |||
return null; | |||
} | |||
/** @return LineNumberTable of code attribute if any, i.e. the call is forwarded | |||
* to the Code atribute. | |||
/** | |||
* Return LineNumberTable of code attribute if any (the call is forwarded | |||
* to the Code attribute) | |||
*/ | |||
public final LineNumberTable getLineNumberTable() { | |||
Code code = getCode(); | |||
if(code != null) | |||
return code.getLineNumberTable(); | |||
else | |||
return null; | |||
if (code != null) return code.getLineNumberTable(); | |||
return null; | |||
} | |||
/** | |||
* Return string representation close to declaration format, | |||
* `public static void main(String[] args) throws IOException', e.g. | |||
* | |||
* @return String representation of the method. | |||
* Return string representation close to declaration format, eg: | |||
* 'public static void main(String[] args) throws IOException' | |||
*/ | |||
public final String toString() { | |||
ConstantUtf8 c; | |||
String name, signature, access; // Short cuts to constant pool | |||
StringBuffer buf; | |||
access = Utility.accessToString(access_flags); | |||
access = Utility.accessToString(modifiers); | |||
// Get name and signature from constant pool | |||
c = (ConstantUtf8)constant_pool.getConstant(signature_index, | |||
c = (ConstantUtf8)cpool.getConstant(signatureIndex, | |||
Constants.CONSTANT_Utf8); | |||
signature = c.getBytes(); | |||
c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8); | |||
c = (ConstantUtf8)cpool.getConstant(nameIndex, Constants.CONSTANT_Utf8); | |||
name = c.getBytes(); | |||
signature = Utility.methodSignatureToString(signature, name, access, true, | |||
getLocalVariableTable()); | |||
buf = new StringBuffer(signature); | |||
for(int i=0; i < attributes_count; i++) { | |||
for(int i=0; i < attributes.length; i++) { | |||
Attribute a = attributes[i]; | |||
if(!((a instanceof Code) || (a instanceof ExceptionTable))) | |||
buf.append(" [" + a.toString() + "]"); | |||
if(!((a instanceof Code) || (a instanceof ExceptionTable))) buf.append(" [" + a.toString() + "]"); | |||
} | |||
ExceptionTable e = getExceptionTable(); | |||
@@ -231,7 +184,7 @@ public final class Method extends FieldOrMethod { | |||
} | |||
/** | |||
* @return deep copy of this method | |||
* Return a deep copy of this method | |||
*/ | |||
public final Method copy(ConstantPool constant_pool) { | |||
return (Method)copy_(constant_pool); | |||
@@ -250,7 +203,7 @@ public final class Method extends FieldOrMethod { | |||
public Type[] getArgumentTypes() { | |||
return Type.getArgumentTypes(getSignature()); | |||
} | |||
private void ensureParameterAnnotationsUnpacked() { | |||
if (!parameterAnnotationsOutOfDate) return; | |||
parameterAnnotationsOutOfDate = false; | |||
@@ -264,62 +217,64 @@ public final class Method extends FieldOrMethod { | |||
RuntimeVisibleParameterAnnotations parameterAnnotationsVis = null; | |||
RuntimeInvisibleParameterAnnotations parameterAnnotationsInvis = null; | |||
// Find attributes that contain annotation data | |||
// Find attributes that contain annotation data | |||
Attribute[] attrs = getAttributes(); | |||
List accumulatedAnnotations = new ArrayList(); | |||
for (int i = 0; i < attrs.length; i++) { | |||
Attribute attribute = attrs[i]; | |||
if (attribute instanceof RuntimeVisibleParameterAnnotations) { | |||
parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; | |||
if (attribute instanceof RuntimeVisibleParameterAnnotations) { | |||
parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations)attribute; | |||
} else if (attribute instanceof RuntimeInvisibleParameterAnnotations) { | |||
parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; | |||
parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations)attribute; | |||
} | |||
} | |||
} | |||
// Build a list of annotation arrays, one per argument | |||
List annotationsForEachParameter = new ArrayList(); | |||
Annotation[] visibleOnes = null; | |||
Annotation[] invisibleOnes = null; | |||
boolean foundSome = false; | |||
for (int i=0; i<parameterCount; i++) { | |||
int count = 0; | |||
visibleOnes = new Annotation[0]; | |||
invisibleOnes = new Annotation[0]; | |||
if (parameterAnnotationsVis!=null) { | |||
visibleOnes = parameterAnnotationsVis.getAnnotationsOnParameter(i); | |||
count+=visibleOnes.length; | |||
} | |||
if (parameterAnnotationsInvis!=null){ | |||
invisibleOnes = parameterAnnotationsInvis.getAnnotationsOnParameter(i); | |||
count+=invisibleOnes.length; | |||
} | |||
Annotation[] complete = NO_ANNOTATIONS; | |||
if (count!=0) { | |||
complete = new Annotation[visibleOnes.length+invisibleOnes.length]; | |||
System.arraycopy(visibleOnes,0,complete,0,visibleOnes.length); | |||
System.arraycopy(invisibleOnes,0,complete,visibleOnes.length,invisibleOnes.length); | |||
foundSome = true; | |||
} | |||
annotationsForEachParameter.add(complete); | |||
} | |||
if (foundSome) { | |||
unpackedParameterAnnotations = (Annotation[][])annotationsForEachParameter.toArray(new Annotation[][]{}); | |||
} else { | |||
unpackedParameterAnnotations=NO_PARAMETER_ANNOTATIONS; | |||
// Build a list of annotation arrays, one per argument | |||
if (parameterAnnotationsInvis!=null || parameterAnnotationsVis!=null) { | |||
List annotationsForEachParameter = new ArrayList(); | |||
AnnotationGen[] visibleOnes = null; | |||
AnnotationGen[] invisibleOnes = null; | |||
for (int i=0; i<parameterCount; i++) { | |||
int count = 0; | |||
visibleOnes = new AnnotationGen[0]; | |||
invisibleOnes = new AnnotationGen[0]; | |||
if (parameterAnnotationsVis!=null) { | |||
visibleOnes = parameterAnnotationsVis.getAnnotationsOnParameter(i); | |||
count+=visibleOnes.length; | |||
} | |||
if (parameterAnnotationsInvis!=null){ | |||
invisibleOnes = parameterAnnotationsInvis.getAnnotationsOnParameter(i); | |||
count+=invisibleOnes.length; | |||
} | |||
AnnotationGen[] complete = NO_ANNOTATIONS; | |||
if (count!=0) { | |||
complete = new AnnotationGen[visibleOnes.length+invisibleOnes.length]; | |||
System.arraycopy(visibleOnes,0,complete,0,visibleOnes.length); | |||
System.arraycopy(invisibleOnes,0,complete,visibleOnes.length,invisibleOnes.length); | |||
foundSome = true; | |||
} | |||
annotationsForEachParameter.add(complete); | |||
} | |||
if (foundSome) { | |||
unpackedParameterAnnotations = (AnnotationGen[][])annotationsForEachParameter.toArray(new AnnotationGen[][]{}); | |||
return; | |||
} | |||
} | |||
unpackedParameterAnnotations=NO_PARAMETER_ANNOTATIONS; | |||
} | |||
public Annotation[] getAnnotationsOnParameter(int i) { | |||
public AnnotationGen[] getAnnotationsOnParameter(int i) { | |||
ensureParameterAnnotationsUnpacked(); | |||
if (unpackedParameterAnnotations==NO_PARAMETER_ANNOTATIONS) return NO_ANNOTATIONS; | |||
return unpackedParameterAnnotations[i]; | |||
} | |||
public Annotation[][] getParameterAnnotations() { | |||
public AnnotationGen[][] getParameterAnnotations() { | |||
ensureParameterAnnotationsUnpacked(); | |||
return unpackedParameterAnnotations; | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
package org.aspectj.apache.bcel.classfile; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
@@ -54,48 +54,87 @@ package org.aspectj.apache.bcel.generic; | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Denotes an unparameterized instruction to load a value from a local | |||
* variable, e.g. ILOAD. | |||
* | |||
* @version $Id: LoadInstruction.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* Super class for all objects that have modifiers like private, final, ... I.e. | |||
* classes, fields, and methods. | |||
* was AccessFlags | |||
* | |||
* @version $Id: Modifiers.java,v 1.2 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class LoadInstruction extends LocalVariableInstruction | |||
implements PushInstruction | |||
{ | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
* tag and length are defined in readInstruction and initFromFile, respectively. | |||
*/ | |||
LoadInstruction(short canon_tag, short c_tag) { | |||
super(canon_tag, c_tag); | |||
} | |||
/** | |||
* @param opcode Instruction opcode | |||
* @param c_tag Instruction number for compact version, ALOAD_0, e.g. | |||
* @param n local variable index (unsigned short) | |||
*/ | |||
protected LoadInstruction(short opcode, short c_tag, int n) { | |||
super(opcode, c_tag, n); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackProducer(this); | |||
v.visitPushInstruction(this); | |||
v.visitTypedInstruction(this); | |||
v.visitLocalVariableInstruction(this); | |||
v.visitLoadInstruction(this); | |||
} | |||
} | |||
public abstract class Modifiers { | |||
protected int modifiers; | |||
public Modifiers() { } | |||
public Modifiers(int a) { | |||
modifiers = a; | |||
} | |||
public final int getModifiers() { | |||
return modifiers; | |||
} | |||
public final void setModifiers(int modifiers) { | |||
this.modifiers = modifiers; | |||
} | |||
public final boolean isPublic() { | |||
return (modifiers & Constants.ACC_PUBLIC) != 0; | |||
} | |||
public final boolean isPrivate() { | |||
return (modifiers & Constants.ACC_PRIVATE) != 0; | |||
} | |||
public final boolean isProtected() { | |||
return (modifiers & Constants.ACC_PROTECTED) != 0; | |||
} | |||
public final boolean isStatic() { | |||
return (modifiers & Constants.ACC_STATIC) != 0; | |||
} | |||
public final boolean isFinal() { | |||
return (modifiers & Constants.ACC_FINAL) != 0; | |||
} | |||
public final boolean isSynchronized() { | |||
return (modifiers & Constants.ACC_SYNCHRONIZED) != 0; | |||
} | |||
public final boolean isVolatile() { | |||
return (modifiers & Constants.ACC_VOLATILE) != 0; | |||
} | |||
public final boolean isTransient() { | |||
return (modifiers & Constants.ACC_TRANSIENT) != 0; | |||
} | |||
public final boolean isNative() { | |||
return (modifiers & Constants.ACC_NATIVE) != 0; | |||
} | |||
public final boolean isInterface() { | |||
return (modifiers & Constants.ACC_INTERFACE) != 0; | |||
} | |||
public final boolean isAbstract() { | |||
return (modifiers & Constants.ACC_ABSTRACT) != 0; | |||
} | |||
public final boolean isStrictfp() { | |||
return (modifiers & Constants.ACC_STRICT) != 0; | |||
} | |||
public final boolean isVarargs() { | |||
return (modifiers & Constants.ACC_VARARGS) != 0; | |||
} | |||
public final boolean isBridge() { | |||
return (modifiers & Constants.ACC_BRIDGE) != 0; | |||
} | |||
} |
@@ -57,9 +57,9 @@ package org.aspectj.apache.bcel.classfile; | |||
/** | |||
* Denote class to have an accept method(); | |||
* | |||
* @version $Id: Node.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Node.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public interface Node { | |||
public void accept(Visitor obj); | |||
public void accept(ClassVisitor obj); | |||
} |
@@ -62,7 +62,7 @@ import java.io.*; | |||
* to a <a href="http://www.inf.fu-berlin.de/~bokowski/pmgjava/index.html">PMG</a> | |||
* attribute. | |||
* | |||
* @version $Id: PMGClass.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: PMGClass.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -114,7 +114,7 @@ public final class PMGClass extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
System.err.println("Visiting non-standard PMGClass object"); | |||
} | |||
@@ -159,7 +159,7 @@ public final class PMGClass extends Attribute { | |||
* @return PMG name. | |||
*/ | |||
public final String getPMGName() { | |||
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_index, | |||
ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} | |||
@@ -168,7 +168,7 @@ public final class PMGClass extends Attribute { | |||
* @return PMG class name. | |||
*/ | |||
public final String getPMGClassName() { | |||
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_class_index, | |||
ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(pmg_class_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} |
@@ -69,7 +69,7 @@ import org.aspectj.apache.bcel.Constants; | |||
* This class is derived from <em>Attribute</em> and represents a reference | |||
* to a <href="http://wwwipd.ira.uka.de/~pizza/gj/">GJ</a> attribute. | |||
* | |||
* @version $Id: Signature.java,v 1.6 2005/07/12 13:59:06 aclement Exp $ | |||
* @version $Id: Signature.java,v 1.7 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -118,7 +118,7 @@ public final class Signature extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
System.err.println("Visiting non-standard Signature object"); | |||
v.visitSignature(this); | |||
} | |||
@@ -151,7 +151,7 @@ public final class Signature extends Attribute { | |||
* @return GJ signature. | |||
*/ | |||
public final String getSignature() { | |||
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(signature_index, | |||
ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(signature_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} |
@@ -63,7 +63,7 @@ import java.io.*; | |||
* should appear per classfile. The intention of this class is that it is | |||
* instantiated from the <em>Attribute.readAttribute()</em> method. | |||
* | |||
* @version $Id: SourceFile.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: SourceFile.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -120,7 +120,7 @@ public final class SourceFile extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitSourceFile(this); | |||
} | |||
@@ -152,7 +152,7 @@ public final class SourceFile extends Attribute { | |||
* @return Source file name. | |||
*/ | |||
public final String getSourceFileName() { | |||
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index, | |||
ConstantUtf8 c = (ConstantUtf8)constantPool.getConstant(sourcefile_index, | |||
Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} |
@@ -66,7 +66,7 @@ import java.io.*; | |||
* within the Code attribute of a method. See CLDC specification | |||
* §5.3.1.2 | |||
* | |||
* @version $Id: StackMap.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: StackMap.java,v 1.3 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Code | |||
* @see StackMapEntry | |||
@@ -166,7 +166,7 @@ public final class StackMap extends Attribute implements Node { | |||
for(int i=0; i < map_length; i++) | |||
c.map[i] = map[i].copy(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
@@ -177,7 +177,7 @@ public final class StackMap extends Attribute implements Node { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitStackMap(this); | |||
} | |||
@@ -63,7 +63,7 @@ import java.io.IOException; | |||
* local variables and the the of stack items at a given byte code offset. | |||
* See CLDC specification §5.3.1.2 | |||
* | |||
* @version $Id: StackMapEntry.java,v 1.4 2004/11/22 08:31:27 aclement Exp $ | |||
* @version $Id: StackMapEntry.java,v 1.5 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see StackMap | |||
* @see StackMapType | |||
@@ -192,7 +192,7 @@ public final class StackMapEntry implements Cloneable { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitStackMapEntry(this); | |||
} | |||
@@ -61,7 +61,7 @@ import java.io.*; | |||
* This class represents the type of a local variable or item on stack | |||
* used in the StackMap entries. | |||
* | |||
* @version $Id: StackMapType.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: StackMapType.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see StackMapEntry | |||
* @see StackMap |
@@ -55,6 +55,7 @@ package org.aspectj.apache.bcel.classfile; | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
import java.io.*; | |||
/** | |||
@@ -66,7 +67,7 @@ import java.io.*; | |||
* is intended to be instantiated from the | |||
* <em>Attribute.readAttribute()</em> method. | |||
* | |||
* @version $Id: Synthetic.java,v 1.2 2004/11/19 16:45:18 aclement Exp $ | |||
* @version $Id: Synthetic.java,v 1.3 2008/05/28 23:53:02 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* @see Attribute | |||
*/ | |||
@@ -80,6 +81,13 @@ public final class Synthetic extends Attribute { | |||
public Synthetic(Synthetic c) { | |||
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); | |||
} | |||
// | |||
// public Synthetic(ConstantPoolGen cpool) { | |||
// super(Constants.ATTR_SYNTHETIC, cpool.addUtf8("Synthetic"), 0, cpool); | |||
// ConstantPoolGen cpg = myGen.getConstantPool(); | |||
// int index = ; | |||
// Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool()); | |||
// } | |||
/** | |||
* @param name_index Index in constant pool to CONSTANT_Utf8, which | |||
@@ -122,7 +130,7 @@ public final class Synthetic extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitSynthetic(this); | |||
} | |||
/** | |||
@@ -170,7 +178,7 @@ public final class Synthetic extends Attribute { | |||
if(bytes != null) | |||
c.bytes = (byte[])bytes.clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -68,9 +68,8 @@ import java.io.*; | |||
* org.aspectj.apache.bcel.classfile.AttributeReader)">Attribute.addAttributeReader</a>. | |||
* | |||
* @version $Id: Unknown.java,v 1.3 2006/03/04 10:43:17 aclement Exp $ | |||
* @version $Id: Unknown.java,v 1.4 2008/05/28 23:53:01 aclement Exp $ | |||
* @see org.aspectj.apache.bcel.classfile.Attribute | |||
* @see org.aspectj.apache.bcel.classfile.AttributeReader | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class Unknown extends Attribute { | |||
@@ -147,7 +146,7 @@ public final class Unknown extends Attribute { | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitUnknown(this); | |||
} | |||
/** | |||
@@ -207,7 +206,7 @@ public final class Unknown extends Attribute { | |||
if(bytes != null) | |||
c.bytes = (byte[])bytes.clone(); | |||
c.constant_pool = constant_pool; | |||
c.constantPool = constant_pool; | |||
return c; | |||
} | |||
} |
@@ -73,27 +73,24 @@ import java.util.zip.GZIPInputStream; | |||
import java.util.zip.GZIPOutputStream; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.annotation.Annotation; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations; | |||
import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.generic.annotation.AnnotationGen; | |||
import org.aspectj.apache.bcel.util.ByteSequence; | |||
/** | |||
* Utility functions that do not really belong to any class in particular. | |||
* | |||
* @version $Id: Utility.java,v 1.5 2006/07/19 12:06:15 aclement Exp $ | |||
* @version $Id: Utility.java,v 1.6 2008/05/28 23:53:01 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
* | |||
* modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized | |||
*/ | |||
public abstract class Utility { | |||
/* The `WIDE' instruction is used in the byte code to allow 16-bit wide indices for local | |||
/* The 'WIDE' instruction is used in the byte code to allow 16-bit wide indices for local | |||
* variables. This opcode precedes an 'ILOAD', e.g.. The opcode immediately following takes | |||
* an extra byte which is combined with the following byte to form a 16-bit value. | |||
*/ | |||
@@ -108,7 +105,6 @@ public abstract class Utility { | |||
public static final String accessToString(int access_flags) { | |||
return accessToString(access_flags, false); | |||
} | |||
/** | |||
* Convert bit field of flags into string such as 'static final'. | |||
@@ -234,11 +230,14 @@ public abstract class Utility { | |||
str = str.replace('/', '.'); // Is '/' on all systems, even DOS | |||
if (chopit) { | |||
// If string starts with 'prefix' and contains no further dots | |||
if (str.startsWith(prefix) && (str.substring(len).indexOf('.') == -1)) | |||
str = str.substring(len); | |||
// If string starts with 'prefix' and contains no further dots | |||
if (str.startsWith(prefix)) { | |||
String result = str.substring(len); | |||
if ( result.indexOf('.') == -1) { | |||
str = result; | |||
} | |||
} | |||
} | |||
return str; | |||
} | |||
@@ -257,144 +256,6 @@ public abstract class Utility { | |||
public static final String compactClassName(String str, boolean chopit) { | |||
return compactClassName(str, "java.lang.", chopit); | |||
} | |||
// bit modification | |||
/** | |||
* @return 'flag' with bit 'i' set to 1 | |||
*/ | |||
public static final int setBit(int flag, int i) { | |||
return flag | pow2(i); | |||
} | |||
/** | |||
* @return 'flag' with bit 'i' set to 0 | |||
*/ | |||
public static final int clearBit(int flag, int i) { | |||
int bit = pow2(i); | |||
return (flag & bit) == 0? flag : flag ^ bit; | |||
} | |||
/** | |||
* @return true, if bit 'i' in 'flag' is set | |||
*/ | |||
public static final boolean isSet(int flag, int i) { | |||
return (flag & pow2(i)) != 0; | |||
} | |||
/** | |||
* Converts string containing the method return and argument types | |||
* to a byte code method signature. | |||
* | |||
* @param returnType Return type of method (e.g. "char" or "java.lang.String[]") | |||
* @param methodArgs Types of method arguments | |||
* @return Byte code representation of method signature | |||
*/ | |||
public final static String methodTypeToSignature(String returnType, String[] methodArgs) throws ClassFormatException { | |||
StringBuffer buf = new StringBuffer("("); | |||
if (methodArgs != null) { | |||
for (int i=0; i < methodArgs.length; i++) { | |||
String str = getSignature(methodArgs[i]); | |||
if (str.equals("V")) // void can't be a method argument | |||
throw new ClassFormatException("Invalid type: " + methodArgs[i]); | |||
buf.append(str); | |||
} | |||
} | |||
buf.append(")" + getSignature(returnType)); | |||
return buf.toString(); | |||
} | |||
/** | |||
* @param signature Method signature | |||
* @return Array of argument types | |||
* @throws ClassFormatException | |||
*/ | |||
public static final String[] methodSignatureArgumentTypes(String signature) throws ClassFormatException { | |||
return methodSignatureArgumentTypes(signature, true); | |||
} | |||
/** | |||
* For some method signature (class file format) like '([Ljava/lang/String;Z)V' this returns an array | |||
* of strings representing the arguments in their 'normal' form, e.g. '{java.lang.String[],boolean}' | |||
* | |||
* @param signature Method signature | |||
* @param chopit Shorten class names | |||
* @return Array of argument types | |||
*/ | |||
public static final String[] methodSignatureArgumentTypes(String signature,boolean chopit) throws ClassFormatException { | |||
ArrayList vec = new ArrayList(); | |||
int index; | |||
String[] types; | |||
try { // Read all declarations between for `(' and `)' | |||
if (signature.charAt(0) != '(') | |||
throw new ClassFormatException("Invalid method signature: " + signature); | |||
index = 1; // current string position | |||
while(signature.charAt(index) != ')') { | |||
ResultHolder rh = signatureToStringInternal(signature.substring(index),chopit); | |||
vec.add(rh.getResult()); | |||
index += rh.getConsumedChars(); | |||
} | |||
} catch(StringIndexOutOfBoundsException e) { | |||
throw new ClassFormatException("Invalid method signature: " + signature); | |||
} | |||
types = new String[vec.size()]; | |||
vec.toArray(types); | |||
return types; | |||
} | |||
/** | |||
* For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns | |||
* the string representing the return type its 'normal' form, e.g. 'boolean' | |||
* | |||
* @param signature Method signature | |||
* @return return type of method | |||
* @throws ClassFormatException | |||
*/ | |||
public static final String methodSignatureReturnType(String signature) throws ClassFormatException { | |||
return methodSignatureReturnType(signature, true); | |||
} | |||
/** | |||
* For some method signature (class file format) like '([Ljava/lang/String;)Z' this returns | |||
* the string representing the return type its 'normal' form, e.g. 'boolean' | |||
* | |||
* @param signature Method signature | |||
* @param chopit Shorten class names | |||
* @return return type of method | |||
*/ | |||
public static final String methodSignatureReturnType(String signature,boolean chopit) throws ClassFormatException { | |||
int index; | |||
String type; | |||
try { | |||
// Read return type after `)' | |||
index = signature.lastIndexOf(')') + 1; | |||
type = signatureToString(signature.substring(index), chopit); | |||
} catch (StringIndexOutOfBoundsException e) { | |||
throw new ClassFormatException("Invalid method signature: " + signature); | |||
} | |||
return type; | |||
} | |||
public static final String methodSignatureToString(String signature,String name,String access) { | |||
return methodSignatureToString(signature, name, access, true); | |||
@@ -622,64 +483,6 @@ public abstract class Utility { | |||
/** | |||
* Parse Java type such as "char", or "java.lang.String[]" and return the | |||
* signature in byte code format, e.g. "C" or "[Ljava/lang/String;" respectively. | |||
* | |||
* @param type Java type | |||
* @return byte code signature | |||
*/ | |||
public static String getSignature(String type) { | |||
StringBuffer buf = new StringBuffer(); | |||
char[] chars = type.toCharArray(); | |||
boolean char_found = false, delim = false; | |||
int index = -1; | |||
loop: | |||
for (int i=0; i < chars.length; i++) { | |||
switch (chars[i]) { | |||
case ' ': case '\t': case '\n': case '\r': case '\f': | |||
if (char_found) delim = true; | |||
break; | |||
case '[': | |||
if (!char_found) throw new RuntimeException("Illegal type: " + type); | |||
index = i; | |||
break loop; | |||
default: | |||
char_found = true; | |||
if (!delim) buf.append(chars[i]); | |||
} | |||
} | |||
int brackets = 0; | |||
if(index > 0) brackets = countBrackets(type.substring(index)); | |||
type = buf.toString(); | |||
buf.setLength(0); | |||
for (int i=0; i < brackets; i++) buf.append('['); | |||
boolean found = false; | |||
for(int i=Constants.T_BOOLEAN; (i <= Constants.T_VOID) && !found; i++) { | |||
if (Constants.TYPE_NAMES[i].equals(type)) { | |||
found = true; | |||
buf.append(Constants.SHORT_TYPE_NAMES[i]); | |||
} | |||
} | |||
// Class name | |||
if (!found) buf.append('L' + type.replace('.', '/') + ';'); | |||
return buf.toString(); | |||
} | |||
/** | |||
* Return type of method signature as a byte value as defined in <em>Constants</em> | |||
* | |||
@@ -700,21 +503,6 @@ public abstract class Utility { | |||
} | |||
} | |||
/** Map opcode names to opcode numbers. E.g., return Constants.ALOAD for "aload" | |||
*/ | |||
public static short searchOpcode(String name) { | |||
name = name.toLowerCase(); | |||
for (short i=0; i < Constants.OPCODE_NAMES.length; i++) { | |||
if (Constants.OPCODE_NAMES[i].equals(name)) | |||
return i; | |||
} | |||
return -1; | |||
} | |||
/** | |||
* Convert (signed) byte to (unsigned) short value, i.e., all negative | |||
* values become positive. | |||
@@ -781,266 +569,7 @@ public abstract class Utility { | |||
else | |||
return new String(buf) + str; | |||
} | |||
static final boolean equals(byte[] a, byte[] b) { | |||
int size; | |||
if((size=a.length) != b.length) | |||
return false; | |||
for(int i=0; i < size; i++) | |||
if(a[i] != b[i]) | |||
return false; | |||
return true; | |||
} | |||
public static final void printArray(PrintStream out, Object[] obj) { | |||
out.println(printArray(obj, true)); | |||
} | |||
public static final void printArray(PrintWriter out, Object[] obj) { | |||
out.println(printArray(obj, true)); | |||
} | |||
public static final String printArray(Object[] obj) { | |||
return printArray(obj, true); | |||
} | |||
public static final String printArray(Object[] obj, boolean braces) { | |||
return printArray(obj, braces, false); | |||
} | |||
public static final String printArray(Object[] obj, boolean braces, | |||
boolean quote) { | |||
if(obj == null) | |||
return null; | |||
StringBuffer buf = new StringBuffer(); | |||
if(braces) | |||
buf.append('{'); | |||
for(int i=0; i < obj.length; i++) { | |||
if(obj[i] != null) { | |||
buf.append((quote? "\"" : "") + obj[i].toString() + (quote? "\"" : "")); | |||
} else { | |||
buf.append("null"); | |||
} | |||
if(i < obj.length - 1) { | |||
buf.append(", "); | |||
} | |||
} | |||
if(braces) | |||
buf.append('}'); | |||
return buf.toString(); | |||
} | |||
/** @return true, if character is one of (a, ... z, A, ... Z, 0, ... 9, _) | |||
*/ | |||
public static boolean isJavaIdentifierPart(char ch) { | |||
return ((ch >= 'a') && (ch <= 'z')) || | |||
((ch >= 'A') && (ch <= 'Z')) || | |||
((ch >= '0') && (ch <= '9')) || | |||
(ch == '_'); | |||
} | |||
/** | |||
* Encode byte array it into Java identifier string, i.e., a string | |||
* that only contains the following characters: (a, ... z, A, ... Z, | |||
* 0, ... 9, _, $). The encoding algorithm itself is not too | |||
* clever: if the current byte's ASCII value already is a valid Java | |||
* identifier part, leave it as it is. Otherwise it writes the | |||
* escape character($) followed by <p><ul><li> the ASCII value as a | |||
* hexadecimal string, if the value is not in the range | |||
* 200..247</li> <li>a Java identifier char not used in a lowercase | |||
* hexadecimal string, if the value is in the range | |||
* 200..247</li><ul></p> | |||
* | |||
* <p>This operation inflates the original byte array by roughly 40-50%</p> | |||
* | |||
* @param bytes the byte array to convert | |||
* @param compress use gzip to minimize string | |||
*/ | |||
public static String encode(byte[] bytes, boolean compress) throws IOException { | |||
if(compress) { | |||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
GZIPOutputStream gos = new GZIPOutputStream(baos); | |||
gos.write(bytes, 0, bytes.length); | |||
gos.close(); | |||
baos.close(); | |||
bytes = baos.toByteArray(); | |||
} | |||
CharArrayWriter caw = new CharArrayWriter(); | |||
JavaWriter jw = new JavaWriter(caw); | |||
for(int i=0; i < bytes.length; i++) { | |||
int in = bytes[i] & 0x000000ff; // Normalize to unsigned | |||
jw.write(in); | |||
} | |||
return caw.toString(); | |||
} | |||
/** Decode a string back to a byte array. | |||
* | |||
* @param bytes the byte array to convert | |||
* @param uncompress use gzip to uncompress the stream of bytes | |||
*/ | |||
public static byte[] decode(String s, boolean uncompress) throws IOException { | |||
char[] chars = s.toCharArray(); | |||
CharArrayReader car = new CharArrayReader(chars); | |||
JavaReader jr = new JavaReader(car); | |||
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |||
int ch; | |||
while((ch = jr.read()) >= 0) { | |||
bos.write(ch); | |||
} | |||
bos.close(); | |||
car.close(); | |||
jr.close(); | |||
byte[] bytes = bos.toByteArray(); | |||
if(uncompress) { | |||
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes)); | |||
byte[] tmp = new byte[bytes.length * 3]; // Rough estimate | |||
int count = 0; | |||
int b; | |||
while((b = gis.read()) >= 0) | |||
tmp[count++] = (byte)b; | |||
bytes = new byte[count]; | |||
System.arraycopy(tmp, 0, bytes, 0, count); | |||
} | |||
return bytes; | |||
} | |||
// A-Z, g-z, _, $ | |||
private static final int FREE_CHARS = 48; | |||
private static int[] CHAR_MAP = new int[FREE_CHARS]; | |||
private static int[] MAP_CHAR = new int[256]; // Reverse map | |||
private static final char ESCAPE_CHAR = '$'; | |||
static { | |||
int j = 0, k = 0; | |||
for(int i='A'; i <= 'Z'; i++) { | |||
CHAR_MAP[j] = i; | |||
MAP_CHAR[i] = j; | |||
j++; | |||
} | |||
for(int i='g'; i <= 'z'; i++) { | |||
CHAR_MAP[j] = i; | |||
MAP_CHAR[i] = j; | |||
j++; | |||
} | |||
CHAR_MAP[j] = '$'; | |||
MAP_CHAR['$'] = j; | |||
j++; | |||
CHAR_MAP[j] = '_'; | |||
MAP_CHAR['_'] = j; | |||
} | |||
/** Decode characters into bytes. | |||
* Used by <a href="Utility.html#decode(java.lang.String, boolean)">decode()</a> | |||
*/ | |||
private static class JavaReader extends FilterReader { | |||
public JavaReader(Reader in) { | |||
super(in); | |||
} | |||
public int read() throws IOException { | |||
int b = in.read(); | |||
if(b != ESCAPE_CHAR) { | |||
return b; | |||
} else { | |||
int i = in.read(); | |||
if(i < 0) | |||
return -1; | |||
if(((i >= '0') && (i <= '9')) || ((i >= 'a') && (i <= 'f'))) { // Normal escape | |||
int j = in.read(); | |||
if(j < 0) | |||
return -1; | |||
char[] tmp = { (char)i, (char)j }; | |||
int s = Integer.parseInt(new String(tmp), 16); | |||
return s; | |||
} else { // Special escape | |||
return MAP_CHAR[i]; | |||
} | |||
} | |||
} | |||
public int read(char[] cbuf, int off, int len) throws IOException { | |||
for(int i=0; i < len; i++) | |||
cbuf[off + i] = (char)read(); | |||
return len; | |||
} | |||
} | |||
/** Encode bytes into valid java identifier characters. | |||
* Used by <a href="Utility.html#encode(byte[], boolean)">encode()</a> | |||
*/ | |||
private static class JavaWriter extends FilterWriter { | |||
public JavaWriter(Writer out) { | |||
super(out); | |||
} | |||
public void write(int b) throws IOException { | |||
if(isJavaIdentifierPart((char)b) && (b != ESCAPE_CHAR)) { | |||
out.write(b); | |||
} else { | |||
out.write(ESCAPE_CHAR); // Escape character | |||
// Special escape | |||
if(b >= 0 && b < FREE_CHARS) { | |||
out.write(CHAR_MAP[b]); | |||
} else { // Normal escape | |||
char[] tmp = Integer.toHexString(b).toCharArray(); | |||
if(tmp.length == 1) { | |||
out.write('0'); | |||
out.write(tmp[0]); | |||
} else { | |||
out.write(tmp[0]); | |||
out.write(tmp[1]); | |||
} | |||
} | |||
} | |||
} | |||
public void write(char[] cbuf, int off, int len) throws IOException { | |||
for(int i=0; i < len; i++) | |||
write(cbuf[off + i]); | |||
} | |||
public void write(String str, int off, int len) throws IOException { | |||
write(str.toCharArray(), off, len); | |||
} | |||
} | |||
/** | |||
* Escape all occurences of newline chars '\n', quotes \", etc. | |||
*/ | |||
@@ -1068,17 +597,6 @@ public abstract class Utility { | |||
return buf.toString(); | |||
} | |||
public static List getListOfAnnotationNames(Annotation a) { | |||
List l = a.getValues(); | |||
List names = new ArrayList(); | |||
for (Iterator i = l.iterator(); i.hasNext();) { | |||
ElementNameValuePair element = (ElementNameValuePair) i.next(); | |||
names.add(element.getNameString()); | |||
} | |||
return names; | |||
} | |||
/** | |||
* Converts a list of AnnotationGen objects into a set of attributes | |||
* that can be attached to the class file. | |||
@@ -1086,7 +604,7 @@ public abstract class Utility { | |||
* @param cp The constant pool gen where we can create the necessary name refs | |||
* @param vec A list of AnnotationGen objects | |||
*/ | |||
public static Attribute[] getAnnotationAttributes(ConstantPoolGen cp,List vec) { | |||
public static Attribute[] getAnnotationAttributes(ConstantPool cp,List vec) { | |||
if (vec.size()==0) return null; | |||
@@ -1131,11 +649,11 @@ public abstract class Utility { | |||
List newAttributes = new ArrayList(); | |||
if (rvaData.length>2) { | |||
newAttributes.add( | |||
new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,rvaData,cp.getConstantPool())); | |||
new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,rvaData,cp)); | |||
} | |||
if (riaData.length>2) { | |||
newAttributes.add( | |||
new RuntimeInvisibleAnnotations(riaIndex,riaData.length,riaData,cp.getConstantPool())); | |||
new RuntimeInvisibleAnnotations(riaIndex,riaData.length,riaData,cp)); | |||
} | |||
return (Attribute[])newAttributes.toArray(new Attribute[]{}); | |||
@@ -1151,7 +669,8 @@ public abstract class Utility { | |||
* - RuntimeVisibleParameterAnnotations | |||
* - RuntimeInvisibleParameterAnnotations | |||
*/ | |||
public static Attribute[] getParameterAnnotationAttributes(ConstantPoolGen cp,List[] /*Array of lists, array size depends on #params */ vec) { | |||
// OPTIMIZE looks heavyweight? | |||
public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp,List[] /*Array of lists, array size depends on #params */ vec) { | |||
int visCount[] = new int[vec.length]; | |||
int totalVisCount = 0; | |||
@@ -1217,13 +736,13 @@ public abstract class Utility { | |||
if (totalVisCount>0) { | |||
newAttributes.add( | |||
new RuntimeVisibleParameterAnnotations(rvaIndex,rvaData.length,rvaData,cp.getConstantPool())); | |||
new RuntimeVisibleParameterAnnotations(rvaIndex,rvaData.length,rvaData,cp)); | |||
} | |||
if (totalInvisCount>0) { | |||
newAttributes.add( | |||
new RuntimeInvisibleParameterAnnotations(riaIndex,riaData.length,riaData,cp.getConstantPool())); | |||
new RuntimeInvisibleParameterAnnotations(riaIndex,riaData.length,riaData,cp)); | |||
} | |||
return (Attribute[])newAttributes.toArray(new Attribute[]{}); | |||
@@ -1234,16 +753,7 @@ public abstract class Utility { | |||
return null; | |||
} | |||
private static final boolean is_digit(char ch) { | |||
return (ch >= '0') && (ch <= '9'); | |||
} | |||
private static final boolean is_space(char ch) { | |||
return (ch == ' ') || (ch == '\t') || (ch == '\r') || (ch == '\n'); | |||
} | |||
private static class ResultHolder { | |||
public static class ResultHolder { | |||
private String result; | |||
private int consumed; | |||
@@ -1266,7 +776,6 @@ public abstract class Utility { | |||
public int getConsumedChars() { return consumed; } | |||
} | |||
// code below here I am happy with .... | |||
/** | |||
* Return type of signature as a byte value as defined in <em>Constants</em> | |||
@@ -1315,122 +824,6 @@ public abstract class Utility { | |||
} | |||
} | |||
public static final String readClassTypeSignatureFrom(String signature) { | |||
StringBuffer sb = new StringBuffer(); | |||
readClassTypeSignatureFrom(signature,0,sb,false); | |||
return sb.toString(); | |||
} | |||
/** | |||
* Takes a string and consumes a single complete signature from it, returning | |||
* how many chars it consumed. The chopit flag indicates whether to shorten | |||
* type references ( java/lang/String => String ) | |||
* | |||
* FIXME asc this should also create some kind of object you can query for information about whether its parameterized, what the bounds are, etc... | |||
*/ | |||
public static final int readClassTypeSignatureFrom(String signature, int posn, StringBuffer result, boolean chopit) { | |||
int idx = posn; | |||
try { | |||
switch (signature.charAt(idx)) { | |||
case 'B' : result.append("byte"); return 1; | |||
case 'C' : result.append("char"); return 1; | |||
case 'D' : result.append("double"); return 1; | |||
case 'F' : result.append("float"); return 1; | |||
case 'I' : result.append("int"); return 1; | |||
case 'J' : result.append("long"); return 1; | |||
case 'S' : result.append("short"); return 1; | |||
case 'Z' : result.append("boolean");return 1; | |||
case 'V' : result.append("void"); return 1; | |||
//FIXME ASC Need a state machine to check we are parsing the right stuff here ! | |||
case 'T' : | |||
idx++; | |||
int nextSemiIdx = signature.indexOf(';',idx); | |||
result.append(signature.substring(idx,nextSemiIdx)); | |||
return nextSemiIdx+1-posn; | |||
case '+' : | |||
result.append("? extends "); | |||
return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; | |||
case '-' : | |||
result.append("? super "); | |||
return readClassTypeSignatureFrom(signature,idx+1,result,chopit)+1; | |||
case '*' : | |||
result.append("?"); | |||
return 1; | |||
case 'L' : // Full class name | |||
boolean parameterized = false; | |||
int idxSemicolon = signature.indexOf(';',idx); // Look for closing ';' or '<' | |||
int idxAngly = signature.indexOf('<',idx); | |||
int endOfSig = idxSemicolon; | |||
if ((idxAngly!=-1) && idxAngly<endOfSig) { endOfSig = idxAngly; parameterized = true; } | |||
String p = signature.substring(idx+1,endOfSig); | |||
String t = compactClassName(p,chopit); | |||
result.append(t); | |||
idx=endOfSig; | |||
// we might have finished now, depending on whether this is a parameterized type... | |||
if (parameterized) { | |||
idx++; | |||
result.append("<"); | |||
while (signature.charAt(idx)!='>') { | |||
idx+=readClassTypeSignatureFrom(signature,idx,result,chopit); | |||
if (signature.charAt(idx)!='>') result.append(","); | |||
} | |||
result.append(">");idx++; | |||
} | |||
if (signature.charAt(idx)!=';') throw new RuntimeException("Did not find ';' at end of signature, found "+signature.charAt(idx)); | |||
idx++; | |||
return idx-posn; | |||
case '[' : // Array declaration | |||
int dim = 0; | |||
while (signature.charAt(idx)=='[') {dim++;idx++;} | |||
idx+=readClassTypeSignatureFrom(signature,idx,result,chopit); | |||
while (dim>0) {result.append("[]");dim--;} | |||
return idx-posn; | |||
default : throw new ClassFormatException("Invalid signature: `" + | |||
signature + "'"); | |||
} | |||
} catch(StringIndexOutOfBoundsException e) { // Should never occur | |||
throw new ClassFormatException("Invalid signature: " + e + ":" + signature); | |||
} | |||
} | |||
private static int countBrackets(String brackets) { | |||
char[] chars = brackets.toCharArray(); | |||
int count = 0; | |||
boolean open = false; | |||
for(int i=0; i<chars.length; i++) { | |||
switch(chars[i]) { | |||
case '[': | |||
if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||
open = true; | |||
break; | |||
case ']': | |||
if (!open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||
open = false; | |||
count++; | |||
break; | |||
default: | |||
} | |||
} | |||
if (open) throw new RuntimeException("Illegally nested brackets:" + brackets); | |||
return count; | |||
} | |||
/** | |||
* Disassemble a stream of byte codes and return the string representation. | |||
* | |||
@@ -1629,7 +1022,7 @@ public abstract class Utility { | |||
break; | |||
default: | |||
if (Constants.NO_OF_OPERANDS[opcode] > 0) { | |||
if ((Constants.iLen[opcode]-1) > 0) { | |||
for (int i=0; i < Constants.TYPE_OF_OPERANDS[opcode].length; i++) { | |||
buf.append("\t\t"); | |||
switch(Constants.TYPE_OF_OPERANDS[opcode][i]) { |
@@ -1,155 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM Corporation | |||
* | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement initial implementation | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.Utility; | |||
/** | |||
* An annotation is an immutable object (AnnotationGen is the mutable variant) - it basically contains a list | |||
* of name-value pairs. | |||
*/ | |||
public class Annotation { | |||
private int typeIndex; | |||
// OPTIMIZE don't need a new list instance for every annotation instance! | |||
private List /* ElementNameValuePair */ evs = new ArrayList(); | |||
private ConstantPool cpool; | |||
private boolean isRuntimeVisible; | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("ANNOTATION ["+getTypeSignature()+"] ["+ | |||
(isRuntimeVisible?"runtimeVisible":"runtimeInvisible")+"] ["); | |||
for (Iterator iter = evs.iterator(); iter.hasNext();) { | |||
ElementNameValuePair element = (ElementNameValuePair) iter.next(); | |||
sb.append(element.toString()); | |||
if (iter.hasNext()) sb.append(","); | |||
} | |||
sb.append("]"); | |||
return sb.toString(); | |||
} | |||
private Annotation(ConstantPool cpool) { | |||
this.cpool = cpool; | |||
} | |||
public Annotation(int index,ConstantPool cpool,boolean visible) { | |||
this.cpool = cpool; | |||
this.typeIndex = index; | |||
this.isRuntimeVisible = visible; | |||
} | |||
protected static Annotation read(DataInputStream dis,ConstantPool cpool,boolean isRuntimeVisible) throws IOException { | |||
Annotation a = new Annotation(cpool); | |||
a.typeIndex = dis.readUnsignedShort(); | |||
int elemValuePairCount = dis.readUnsignedShort(); | |||
for (int i=0;i<elemValuePairCount;i++) { | |||
int nidx = dis.readUnsignedShort(); | |||
a.addElementNameValuePair( | |||
new ElementNameValuePair(nidx,ElementValue.readElementValue(dis,cpool),cpool)); | |||
} | |||
a.isRuntimeVisible(isRuntimeVisible); | |||
return a; | |||
} | |||
protected void dump(DataOutputStream dos) throws IOException { | |||
dos.writeShort(typeIndex); // u2 index of type name in cpool | |||
dos.writeShort(evs.size()); // u2 element_value pair count | |||
for (int i = 0 ; i<evs.size();i++) { | |||
ElementNameValuePair envp = (ElementNameValuePair) evs.get(i); | |||
envp.dump(dos); | |||
} | |||
} | |||
public void addElementNameValuePair(ElementNameValuePair evp) { | |||
evs.add(evp); | |||
} | |||
public int getTypeIndex() { | |||
return typeIndex; | |||
} | |||
public String getTypeSignature() { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(typeIndex,Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} | |||
public String getTypeName() { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(typeIndex,Constants.CONSTANT_Utf8); | |||
return Utility.signatureToString(c.getBytes()); | |||
} | |||
/** | |||
* Returns list of ElementNameValuePair objects | |||
*/ | |||
public List getValues() { | |||
return evs; | |||
} | |||
protected void isRuntimeVisible(boolean b) { | |||
isRuntimeVisible = b; | |||
} | |||
public boolean isRuntimeVisible() { | |||
return isRuntimeVisible; | |||
} | |||
public String toShortString() { | |||
StringBuffer result = new StringBuffer(); | |||
result.append("@"); | |||
result.append(getTypeName()); | |||
if (getValues().size()>0) { | |||
result.append("("); | |||
for (Iterator iter = getValues().iterator(); iter.hasNext();) { | |||
ElementNameValuePair element = (ElementNameValuePair) iter.next(); | |||
result.append(element.toShortString()); | |||
} | |||
result.append(")"); | |||
} | |||
return result.toString(); | |||
} | |||
/** | |||
* Return true if the annotation has a value with the specified name (n) and value (v) | |||
*/ | |||
public boolean hasNameValuePair(String n, String v) { | |||
for (int i=0;i<evs.size();i++) { | |||
ElementNameValuePair pair = (ElementNameValuePair)evs.get(i); | |||
if (pair.getNameString().equals(n)) { | |||
if (pair.getValue().stringifyValue().equals(v)) return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Return true if the annotation has a value with the specified name (n) | |||
*/ | |||
public boolean hasNamedValue(String n) { | |||
for (int i=0;i<evs.size();i++) { | |||
ElementNameValuePair pair = (ElementNameValuePair)evs.get(i); | |||
if (pair.getNameString().equals(n)) return true; | |||
} | |||
return false; | |||
} | |||
} |
@@ -1,51 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
/** | |||
* An element value that is an annotation. | |||
*/ | |||
public class AnnotationElementValue extends ElementValue { | |||
// For annotation element values, this is the annotation | |||
private Annotation a; | |||
public AnnotationElementValue(int type, Annotation annotation, ConstantPool cpool) { | |||
super(type,cpool); | |||
if (type != ANNOTATION) | |||
throw new RuntimeException("Only element values of type annotation can be built with this ctor"); | |||
this.a = annotation; | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 type of value (ANNOTATION == '@') | |||
a.dump(dos); | |||
} | |||
public String stringifyValue() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append(a.toString()); | |||
return sb.toString(); | |||
} | |||
public String toString() { | |||
return stringifyValue(); | |||
} | |||
public Annotation getAnnotation() { return a;} | |||
} |
@@ -10,14 +10,12 @@ | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public class AnnotationElementValueGen extends ElementValueGen { | |||
@@ -25,19 +23,19 @@ public class AnnotationElementValueGen extends ElementValueGen { | |||
// For annotation element values, this is the annotation | |||
private AnnotationGen a; | |||
public AnnotationElementValueGen(AnnotationGen a,ConstantPoolGen cpool) { | |||
public AnnotationElementValueGen(AnnotationGen a,ConstantPool cpool) { | |||
super(ANNOTATION,cpool); | |||
this.a = a; | |||
} | |||
public AnnotationElementValueGen(int type, AnnotationGen annotation, ConstantPoolGen cpool) { | |||
public AnnotationElementValueGen(int type, AnnotationGen annotation, ConstantPool cpool) { | |||
super(type,cpool); | |||
if (type != ANNOTATION) | |||
throw new RuntimeException("Only element values of type annotation can be built with this ctor"); | |||
this.a = annotation; | |||
} | |||
public AnnotationElementValueGen(AnnotationElementValue value, ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
public AnnotationElementValueGen(AnnotationElementValueGen value, ConstantPool cpool,boolean copyPoolEntries) { | |||
super(ANNOTATION,cpool); | |||
a = new AnnotationGen(value.getAnnotation(),cpool,copyPoolEntries); | |||
} | |||
@@ -54,8 +52,8 @@ public class AnnotationElementValueGen extends ElementValueGen { | |||
/** | |||
* Return immutable variant of this AnnotationElementValueGen | |||
*/ | |||
public ElementValue getElementValue() { | |||
return new AnnotationElementValue(this.type,a.getAnnotation(),cpGen.getConstantPool()); | |||
public ElementValueGen getElementValue() { | |||
return new AnnotationElementValueGen(this.type,a,cpGen); | |||
} | |||
public AnnotationGen getAnnotation() { return a;} |
@@ -10,7 +10,7 @@ | |||
* Contributors: | |||
* Andy Clement initial implementation | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
@@ -20,15 +20,16 @@ import java.util.Iterator; | |||
import java.util.List; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.annotation.Annotation; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.generic.ObjectType; | |||
import org.aspectj.apache.bcel.classfile.Utility; | |||
public class AnnotationGen { | |||
public static final AnnotationGen[] NO_ANNOTATIONS = new AnnotationGen[0]; | |||
private int typeIndex; | |||
private List /* ElementNameValuePairGen */ evs; | |||
private ConstantPoolGen cpool; | |||
private ConstantPool cpool; | |||
private boolean isRuntimeVisible = false; | |||
/** | |||
@@ -39,7 +40,7 @@ public class AnnotationGen { | |||
* across. | |||
* We need to copy the type and the element name value pairs and the visibility. | |||
*/ | |||
public AnnotationGen(Annotation a,ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
public AnnotationGen(AnnotationGen a,ConstantPool cpool,boolean copyPoolEntries) { | |||
this.cpool = cpool; | |||
if (copyPoolEntries) { | |||
@@ -53,39 +54,41 @@ public class AnnotationGen { | |||
evs = copyValues(a.getValues(),cpool,copyPoolEntries); | |||
} | |||
private List copyValues(List in,ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
private List copyValues(List in,ConstantPool cpool,boolean copyPoolEntries) { | |||
List out = new ArrayList(); | |||
for (Iterator iter = in.iterator(); iter.hasNext();) { | |||
ElementNameValuePair nvp = (ElementNameValuePair) iter.next(); | |||
ElementNameValuePairGen nvp = (ElementNameValuePairGen) iter.next(); | |||
out.add(new ElementNameValuePairGen(nvp,cpool,copyPoolEntries)); | |||
} | |||
return out; | |||
} | |||
private AnnotationGen(ConstantPoolGen cpool) { | |||
private AnnotationGen(ConstantPool cpool) { | |||
this.cpool = cpool; | |||
this.evs=new ArrayList(); | |||
} | |||
/** | |||
* Retrieve an immutable version of this AnnotationGen | |||
*/ | |||
public Annotation getAnnotation() { | |||
Annotation a = new Annotation(typeIndex,cpool.getConstantPool(),isRuntimeVisible); | |||
for (Iterator iter = evs.iterator(); iter.hasNext();) { | |||
ElementNameValuePairGen element = (ElementNameValuePairGen) iter.next(); | |||
a.addElementNameValuePair(element.getElementNameValuePair()); | |||
} | |||
return a; | |||
} | |||
public AnnotationGen(ObjectType type,List /*ElementNameValuePairGen*/ elements,boolean vis,ConstantPoolGen cpool) { | |||
// public AnnotationGen getAnnotation() { | |||
// return this; | |||
//// AnnotationGen a = new AnnotationGen(typeIndex,cpool,isRuntimeVisible); | |||
//// for (Iterator iter = evs.iterator(); iter.hasNext();) { | |||
//// ElementNameValuePairGen element = (ElementNameValuePairGen) iter.next(); | |||
//// a.addElementNameValuePair(element.getElementNameValuePair()); | |||
//// } | |||
//// return a; | |||
// } | |||
public AnnotationGen(ObjectType type,List /*ElementNameValuePairGen*/ elements,boolean vis,ConstantPool cpool) { | |||
this.cpool = cpool; | |||
this.typeIndex = cpool.addUtf8(type.getSignature()); | |||
if (type!=null) this.typeIndex = cpool.addUtf8(type.getSignature()); // Only null for funky *temporary* FakeAnnotation objects | |||
evs = elements; | |||
isRuntimeVisible = vis; | |||
} | |||
public static AnnotationGen read(DataInputStream dis,ConstantPoolGen cpool,boolean b) throws IOException { | |||
public static AnnotationGen read(DataInputStream dis,ConstantPool cpool,boolean b) throws IOException { | |||
AnnotationGen a = new AnnotationGen(cpool); | |||
a.typeIndex = dis.readUnsignedShort(); | |||
int elemValuePairCount = dis.readUnsignedShort(); | |||
@@ -117,14 +120,14 @@ public class AnnotationGen { | |||
return typeIndex; | |||
} | |||
public final String getTypeSignature() { | |||
public String getTypeSignature() { | |||
// ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex); | |||
ConstantUtf8 utf8 = (ConstantUtf8)cpool.getConstant(typeIndex/*c.getNameIndex()*/); | |||
return utf8.getBytes(); | |||
} | |||
public final String getTypeName() { | |||
return getTypeSignature();// BCELBUG: Should I use this instead? Utility.signatureToString(getTypeSignature()); | |||
public String getTypeName() { | |||
return Utility.signatureToString(getTypeSignature()); | |||
} | |||
/** | |||
@@ -163,4 +166,28 @@ public class AnnotationGen { | |||
public boolean isRuntimeVisible() { | |||
return isRuntimeVisible; | |||
} | |||
/** | |||
* Return true if the annotation has a value with the specified name (n) and value (v) | |||
*/ | |||
public boolean hasNameValuePair(String n, String v) { | |||
for (int i=0;i<evs.size();i++) { | |||
ElementNameValuePairGen pair = (ElementNameValuePairGen)evs.get(i); | |||
if (pair.getNameString().equals(n)) { | |||
if (pair.getValue().stringifyValue().equals(v)) return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Return true if the annotation has a value with the specified name (n) | |||
*/ | |||
public boolean hasNamedValue(String n) { | |||
for (int i=0;i<evs.size();i++) { | |||
ElementNameValuePairGen pair = (ElementNameValuePairGen)evs.get(i); | |||
if (pair.getNameString().equals(n)) return true; | |||
} | |||
return false; | |||
} | |||
} |
@@ -1,66 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public class ArrayElementValue extends ElementValue { | |||
// For array types, this is the array | |||
private ElementValue[] evalues; | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("{"); | |||
for (int i = 0; i < evalues.length; i++) { | |||
sb.append(evalues[i].toString()); | |||
if ((i+1)<evalues.length) sb.append(","); | |||
} | |||
sb.append("}"); | |||
return sb.toString(); | |||
} | |||
public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool) { | |||
super(type,cpool); | |||
if (type != ARRAY) | |||
throw new RuntimeException("Only element values of type array can be built with this ctor"); | |||
this.evalues = datums; | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 type of value (ARRAY == '[') | |||
dos.writeShort(evalues.length); | |||
for (int i=0; i<evalues.length; i++) { | |||
evalues[i].dump(dos); | |||
} | |||
} | |||
public String stringifyValue() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("["); | |||
for(int i=0; i<evalues.length; i++) { | |||
sb.append(evalues[i].stringifyValue()); | |||
if ((i+1)<evalues.length) sb.append(","); | |||
} | |||
sb.append("]"); | |||
return sb.toString(); | |||
} | |||
public ElementValue[] getElementValuesArray() { return evalues;} | |||
public int getElementValuesArraySize() { return evalues.length;} | |||
} |
@@ -0,0 +1,93 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public class ArrayElementValueGen extends ElementValueGen { | |||
private static final ElementValueGen[] NO_VALUES = new ElementValueGen[0]; | |||
// J5TODO: Should we make this an array or a list? A list would be easier to modify ... | |||
private ElementValueGen[] evalues = NO_VALUES; | |||
public ElementValueGen[] getElementValuesArray() { return evalues;} | |||
public int getElementValuesArraySize() { return evalues.length;} | |||
public ArrayElementValueGen(ConstantPool cp) { | |||
super(ARRAY,cp); | |||
} | |||
public ArrayElementValueGen(int type, ElementValueGen[] datums, ConstantPool cpool) { | |||
super(type,cpool); | |||
if (type != ARRAY) | |||
throw new RuntimeException("Only element values of type array can be built with this ctor"); | |||
this.evalues = datums; | |||
} | |||
/** | |||
* Return immutable variant of this ArrayElementValueGen | |||
*/ | |||
public ElementValueGen getElementValue() { | |||
ElementValueGen[] immutableData = new ElementValueGen[evalues.length]; | |||
for (int i = 0; i<evalues.length;i++) { | |||
immutableData[i] = evalues[i]; | |||
} | |||
return new ArrayElementValueGen(type,immutableData,cpGen); | |||
} | |||
/** | |||
* @param value | |||
* @param cpool | |||
*/ | |||
public ArrayElementValueGen(ArrayElementValueGen value, ConstantPool cpool,boolean copyPoolEntries) { | |||
super(ARRAY,cpool); | |||
evalues = new ElementValueGen[value.getElementValuesArraySize()]; | |||
ElementValueGen[] in = value.getElementValuesArray(); | |||
for (int i = 0; i < in.length; i++) { | |||
evalues[i]=ElementValueGen.copy(in[i],cpool,copyPoolEntries); | |||
} | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 type of value (ARRAY == '[') | |||
dos.writeShort(evalues.length); | |||
for (int i =0;i<evalues.length;i++) { | |||
evalues[i].dump(dos); | |||
} | |||
} | |||
public String stringifyValue() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append("["); | |||
for (int i =0;i<evalues.length;i++) { | |||
ElementValueGen element = (ElementValueGen) evalues[i]; | |||
sb.append(element.stringifyValue()); | |||
if ((i+1)<evalues.length) sb.append(","); | |||
} | |||
sb.append("]"); | |||
return sb.toString(); | |||
} | |||
public void addElement(ElementValueGen gen) { | |||
ElementValueGen[] old = evalues; | |||
evalues = new ElementValueGen[evalues.length+1]; | |||
System.arraycopy(old,0,evalues,0,old.length); | |||
evalues[old.length]=gen; | |||
} | |||
} |
@@ -1,53 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
public class ClassElementValue extends ElementValue { | |||
// For primitive types and string type, this points to the value entry in the cpool | |||
// For 'class' this points to the class entry in the cpool | |||
private int idx; | |||
public ClassElementValue(int type,int idx,ConstantPool cpool) { | |||
super(type,cpool); | |||
this.idx = idx; | |||
} | |||
public int getIndex() { | |||
return idx; | |||
} | |||
public String getClassString() { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(idx,Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} | |||
public String stringifyValue() { | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(idx,Constants.CONSTANT_Utf8); | |||
return cu8.getBytes(); | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 kind of value | |||
dos.writeShort(idx); | |||
} | |||
} |
@@ -10,15 +10,13 @@ | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.annotation.ClassElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.generic.ObjectType; | |||
@@ -28,12 +26,12 @@ public class ClassElementValueGen extends ElementValueGen { | |||
// For 'class' this points to the class entry in the cpool | |||
private int idx; | |||
protected ClassElementValueGen(int typeIdx,ConstantPoolGen cpool) { | |||
protected ClassElementValueGen(int typeIdx,ConstantPool cpool) { | |||
super(ElementValueGen.CLASS,cpool); | |||
this.idx = typeIdx; | |||
} | |||
public ClassElementValueGen(ObjectType t,ConstantPoolGen cpool) { | |||
public ClassElementValueGen(ObjectType t,ConstantPool cpool) { | |||
super(ElementValueGen.CLASS,cpool); | |||
//this.idx = cpool.addClass(t); | |||
idx = cpool.addUtf8(t.getSignature()); | |||
@@ -42,11 +40,11 @@ public class ClassElementValueGen extends ElementValueGen { | |||
/** | |||
* Return immutable variant of this ClassElementValueGen | |||
*/ | |||
public ElementValue getElementValue() { | |||
return new ClassElementValue(type,idx,cpGen.getConstantPool()); | |||
} | |||
// public ElementValueGen getElementValue() { | |||
// return new ClassElementValueGen(type,idx,cpGen); | |||
// } | |||
public ClassElementValueGen(ClassElementValue value, ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
public ClassElementValueGen(ClassElementValueGen value, ConstantPool cpool,boolean copyPoolEntries) { | |||
super(CLASS,cpool); | |||
if (copyPoolEntries) { | |||
//idx = cpool.addClass(value.getClassString()); |
@@ -1,62 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
public class ElementNameValuePair { | |||
private int nameIdx; | |||
private ElementValue value; | |||
private ConstantPool cpool; | |||
public String toString() { | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append(getNameString()+"="+value.toString()); | |||
return sb.toString(); | |||
} | |||
public ElementNameValuePair(int idx,ElementValue value,ConstantPool cpool) { | |||
this.nameIdx = idx; | |||
this.value = value; | |||
this.cpool = cpool; | |||
} | |||
protected void dump(DataOutputStream dos) throws IOException { | |||
dos.writeShort(nameIdx); // u2 name of the element | |||
value.dump(dos); | |||
} | |||
public int getNameIndex() { | |||
return nameIdx; | |||
} | |||
public final String getNameString() { | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(nameIdx,Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} | |||
public final ElementValue getValue() { | |||
return value; | |||
} | |||
public String toShortString() { | |||
StringBuffer result = new StringBuffer(); | |||
result.append(getNameString()).append("=").append(getValue().toShortString()); | |||
return result.toString(); | |||
} | |||
} |
@@ -10,23 +10,21 @@ | |||
* Andy Clement - initial implementation | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public class ElementNameValuePairGen { | |||
private int nameIdx; | |||
private ElementValueGen value; | |||
private ConstantPoolGen cpool; | |||
private ConstantPool cpool; | |||
public ElementNameValuePairGen(ElementNameValuePair nvp, ConstantPoolGen cpool, boolean copyPoolEntries) { | |||
public ElementNameValuePairGen(ElementNameValuePairGen nvp, ConstantPool cpool, boolean copyPoolEntries) { | |||
this.cpool = cpool; | |||
// J5ASSERT: | |||
// Could assert nvp.getNameString() points to the same thing as cpool.getConstant(nvp.getNameIndex()) | |||
@@ -44,19 +42,19 @@ public class ElementNameValuePairGen { | |||
/** | |||
* Retrieve an immutable version of this ElementNameValuePairGen | |||
*/ | |||
public ElementNameValuePair getElementNameValuePair() { | |||
ElementValue immutableValue = value.getElementValue(); | |||
return new ElementNameValuePair(nameIdx,immutableValue,cpool.getConstantPool()); | |||
} | |||
// public ElementNameValuePairGen getElementNameValuePair() { | |||
// ElementValueGen immutableValue = value.getElementValue(); | |||
// return new ElementNameValuePairGen(nameIdx,immutableValue,cpool); | |||
// } | |||
protected ElementNameValuePairGen(int idx,ElementValueGen value,ConstantPoolGen cpool) { | |||
protected ElementNameValuePairGen(int idx,ElementValueGen value,ConstantPool cpool) { | |||
this.nameIdx = idx; | |||
this.value = value; | |||
this.cpool = cpool; | |||
} | |||
public ElementNameValuePairGen(String name,ElementValueGen value,ConstantPoolGen cpool) { | |||
public ElementNameValuePairGen(String name,ElementValueGen value,ConstantPool cpool) { | |||
this.nameIdx = cpool.addUtf8(name); | |||
this.value = value; | |||
this.cpool = cpool; | |||
@@ -81,6 +79,8 @@ public class ElementNameValuePairGen { | |||
} | |||
public String toString() { | |||
return "ElementNameValuePair:["+getNameString()+"="+value.stringifyValue()+"]"; | |||
StringBuffer sb = new StringBuffer(); | |||
sb.append(getNameString()+"="+value.stringifyValue()); | |||
return sb.toString(); | |||
} | |||
} |
@@ -1,112 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public abstract class ElementValue { | |||
protected int type; | |||
protected ConstantPool cpool; | |||
public String toString() { | |||
return stringifyValue(); | |||
} | |||
protected ElementValue(int type,ConstantPool cpool) { | |||
this.type = type; | |||
this.cpool = cpool; | |||
} | |||
public int getElementValueType() { | |||
return type; | |||
} | |||
public abstract String stringifyValue(); | |||
public abstract void dump(DataOutputStream dos) throws IOException; | |||
public static final int STRING = 's'; | |||
public static final int ENUM_CONSTANT = 'e'; | |||
public static final int CLASS = 'c'; | |||
public static final int ANNOTATION = '@'; | |||
public static final int ARRAY = '['; | |||
public static final int PRIMITIVE_INT = 'I'; | |||
public static final int PRIMITIVE_BYTE = 'B'; | |||
public static final int PRIMITIVE_CHAR = 'C'; | |||
public static final int PRIMITIVE_DOUBLE = 'D'; | |||
public static final int PRIMITIVE_FLOAT = 'F'; | |||
public static final int PRIMITIVE_LONG = 'J'; | |||
public static final int PRIMITIVE_SHORT = 'S'; | |||
public static final int PRIMITIVE_BOOLEAN= 'Z'; | |||
public static ElementValue readElementValue(DataInputStream dis,ConstantPool cpool) throws IOException { | |||
int type= dis.readUnsignedByte(); | |||
switch (type) { | |||
case 'B': // byte | |||
return new SimpleElementValue(PRIMITIVE_BYTE,dis.readUnsignedShort(),cpool); | |||
case 'C': // char | |||
return new SimpleElementValue(PRIMITIVE_CHAR,dis.readUnsignedShort(),cpool); | |||
case 'D': // double | |||
return new SimpleElementValue(PRIMITIVE_DOUBLE,dis.readUnsignedShort(),cpool); | |||
case 'F': // float | |||
return new SimpleElementValue(PRIMITIVE_FLOAT,dis.readUnsignedShort(),cpool); | |||
case 'I': // int | |||
return new SimpleElementValue(PRIMITIVE_INT,dis.readUnsignedShort(),cpool); | |||
case 'J': // long | |||
return new SimpleElementValue(PRIMITIVE_LONG,dis.readUnsignedShort(),cpool); | |||
case 'S': // short | |||
return new SimpleElementValue(PRIMITIVE_SHORT,dis.readUnsignedShort(),cpool); | |||
case 'Z': // boolean | |||
return new SimpleElementValue(PRIMITIVE_BOOLEAN,dis.readUnsignedShort(),cpool); | |||
case 's': // String | |||
return new SimpleElementValue(STRING,dis.readUnsignedShort(),cpool); | |||
case 'e': // Enum constant | |||
return new EnumElementValue(ENUM_CONSTANT,dis.readUnsignedShort(),dis.readUnsignedShort(),cpool); | |||
case 'c': // Class | |||
return new ClassElementValue(CLASS,dis.readUnsignedShort(),cpool); | |||
//J5TODO: Should it be 'true' in the next statement? What difference does it make? Should it be | |||
// the same as the 'super annotation' in which we are contained? | |||
case '@': // Annotation | |||
return new AnnotationElementValue(ANNOTATION,Annotation.read(dis,cpool,true),cpool); | |||
case '[': // Array | |||
int numArrayVals = dis.readUnsignedShort(); | |||
List arrayVals = new ArrayList(); | |||
ElementValue[] evalues = new ElementValue[numArrayVals]; | |||
for (int j=0;j<numArrayVals;j++) { | |||
evalues[j] = ElementValue.readElementValue(dis,cpool); | |||
} | |||
return new ArrayElementValue(ARRAY,evalues,cpool); | |||
default: | |||
throw new RuntimeException("Unexpected element value kind in annotation: "+type); | |||
} | |||
} | |||
public String toShortString() { | |||
StringBuffer result = new StringBuffer(); | |||
result.append(stringifyValue()); | |||
return result.toString(); | |||
} | |||
} |
@@ -10,35 +10,29 @@ | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.classfile.annotation.AnnotationElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ClassElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public abstract class ElementValueGen { | |||
protected int type; | |||
protected ConstantPoolGen cpGen; | |||
protected ConstantPool cpGen; | |||
protected ElementValueGen(int type,ConstantPoolGen cpGen) { | |||
protected ElementValueGen(int type,ConstantPool cpGen) { | |||
this.type = type; | |||
this.cpGen = cpGen; | |||
} | |||
/** | |||
* Subtypes return an immutable variant of the ElementValueGen | |||
*/ | |||
public abstract ElementValue getElementValue(); | |||
// /** | |||
// * Subtypes return an immutable variant of the ElementValueGen | |||
// */ | |||
// public abstract ElementValueGen getElementValue(); | |||
public int getElementValueType() { | |||
return type; | |||
@@ -62,7 +56,7 @@ public abstract class ElementValueGen { | |||
public static final int PRIMITIVE_SHORT = 'S'; | |||
public static final int PRIMITIVE_BOOLEAN= 'Z'; | |||
public static ElementValueGen readElementValue(DataInputStream dis,ConstantPoolGen cpGen) throws IOException { | |||
public static ElementValueGen readElementValue(DataInputStream dis,ConstantPool cpGen) throws IOException { | |||
int type= dis.readUnsignedByte(); | |||
switch (type) { | |||
case 'B': // byte | |||
@@ -89,32 +83,32 @@ public abstract class ElementValueGen { | |||
case 'c': // Class | |||
return new ClassElementValueGen(dis.readUnsignedShort(),cpGen); | |||
// | |||
// case '@': // Annotation | |||
// return new AnnotationElementValueGen(ANNOTATION,Annotation.read(dis,cpGen),cpGen); | |||
// | |||
// case '[': // Array | |||
// int numArrayVals = dis.readUnsignedShort(); | |||
// List arrayVals = new ArrayList(); | |||
// ElementValue[] evalues = new ElementValue[numArrayVals]; | |||
// for (int j=0;j<numArrayVals;j++) { | |||
// evalues[j] = ElementValue.readElementValue(dis,cpGen); | |||
// } | |||
// return new ArrayElementValue(ARRAY,evalues,cpGen); | |||
// FIXME should this be true here? or should it be the value for the containing annotation? | |||
case '@': // Annotation | |||
return new AnnotationElementValueGen(ANNOTATION,AnnotationGen.read(dis,cpGen,true),cpGen); | |||
case '[': // Array | |||
int numArrayVals = dis.readUnsignedShort(); | |||
ElementValueGen[] evalues = new ElementValueGen[numArrayVals]; | |||
for (int j=0;j<numArrayVals;j++) { | |||
evalues[j] = ElementValueGen.readElementValue(dis,cpGen); | |||
} | |||
return new ArrayElementValueGen(ARRAY,evalues,cpGen); | |||
default: | |||
throw new RuntimeException("Unexpected element value kind in annotation: "+type); | |||
} | |||
} | |||
protected ConstantPoolGen getConstantPool() { | |||
protected ConstantPool getConstantPool() { | |||
return cpGen; | |||
} | |||
/** | |||
* Creates an (modifiable) ElementValueGen copy of an (immutable) ElementValue - constant pool is assumed correct. | |||
*/ | |||
public static ElementValueGen copy(ElementValue value,ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
public static ElementValueGen copy(ElementValueGen value,ConstantPool cpool,boolean copyPoolEntries) { | |||
switch (value.getElementValueType()) { | |||
case 'B': // byte | |||
case 'C': // char | |||
@@ -125,19 +119,19 @@ public abstract class ElementValueGen { | |||
case 'S': // short | |||
case 'Z': // boolean | |||
case 's': // String | |||
return new SimpleElementValueGen((SimpleElementValue)value,cpool,copyPoolEntries); | |||
return new SimpleElementValueGen((SimpleElementValueGen)value,cpool,copyPoolEntries); | |||
case 'e': // Enum constant | |||
return new EnumElementValueGen((EnumElementValue)value,cpool,copyPoolEntries); | |||
return new EnumElementValueGen((EnumElementValueGen)value,cpool,copyPoolEntries); | |||
case '@': // Annotation | |||
return new AnnotationElementValueGen((AnnotationElementValue)value,cpool,copyPoolEntries); | |||
return new AnnotationElementValueGen((AnnotationElementValueGen)value,cpool,copyPoolEntries); | |||
case '[': // Array | |||
return new ArrayElementValueGen((ArrayElementValue)value,cpool,copyPoolEntries); | |||
return new ArrayElementValueGen((ArrayElementValueGen)value,cpool,copyPoolEntries); | |||
case 'c': // Class | |||
return new ClassElementValueGen((ClassElementValue)value,cpool,copyPoolEntries); | |||
return new ClassElementValueGen((ClassElementValueGen)value,cpool,copyPoolEntries); | |||
default: | |||
throw new RuntimeException("Not implemented yet! ("+value.getElementValueType()+")"); |
@@ -1,69 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
public class EnumElementValue extends ElementValue { | |||
// For enum types, these two indices point to the type and value | |||
private int typeIdx; | |||
private int valueIdx; | |||
public EnumElementValue(int type,int typeIdx,int valueIdx,ConstantPool cpool) { | |||
super(type,cpool); | |||
if (type != ENUM_CONSTANT) | |||
throw new RuntimeException("Only element values of type enum can be built with this ctor"); | |||
this.typeIdx = typeIdx; | |||
this.valueIdx= valueIdx; | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e') | |||
dos.writeShort(typeIdx); // u2 | |||
dos.writeShort(valueIdx); // u2 | |||
} | |||
/** | |||
* return signature and value, something like Lp/Color;RED | |||
*/ | |||
public String stringifyValue() { | |||
StringBuffer sb = new StringBuffer(); | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(typeIdx,Constants.CONSTANT_Utf8); | |||
sb.append(cu8.getBytes()); | |||
cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8); | |||
sb.append(cu8.getBytes()); | |||
return sb.toString(); | |||
} | |||
public String getEnumTypeString() { | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(typeIdx,Constants.CONSTANT_Utf8); | |||
return cu8.getBytes();//Utility.signatureToString(cu8.getBytes()); | |||
} | |||
public String getEnumValueString() { | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8); | |||
return cu8.getBytes(); | |||
} | |||
public int getValueIndex() { return valueIdx;} | |||
public int getTypeIndex() { return typeIdx; } | |||
} |
@@ -10,15 +10,14 @@ | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.generic.ObjectType; | |||
@@ -32,7 +31,7 @@ public class EnumElementValueGen extends ElementValueGen { | |||
* This ctor assumes the constant pool already contains the right type and value - | |||
* as indicated by typeIdx and valueIdx. This ctor is used for deserialization | |||
*/ | |||
protected EnumElementValueGen(int typeIdx,int valueIdx,ConstantPoolGen cpool) { | |||
protected EnumElementValueGen(int typeIdx,int valueIdx,ConstantPool cpool) { | |||
super(ElementValueGen.ENUM_CONSTANT,cpool); | |||
if (type != ENUM_CONSTANT) | |||
throw new RuntimeException("Only element values of type enum can be built with this ctor"); | |||
@@ -40,21 +39,21 @@ public class EnumElementValueGen extends ElementValueGen { | |||
this.valueIdx= valueIdx; | |||
} | |||
/** | |||
* Return immutable variant of this EnumElementValue | |||
*/ | |||
public ElementValue getElementValue() { | |||
System.err.println("Duplicating value: "+getEnumTypeString()+":"+getEnumValueString()); | |||
return new EnumElementValue(type,typeIdx,valueIdx,cpGen.getConstantPool()); | |||
} | |||
// /** | |||
// * Return immutable variant of this EnumElementValue | |||
// */ | |||
// public ElementValueGen getElementValue() { | |||
// System.err.println("Duplicating value: "+getEnumTypeString()+":"+getEnumValueString()); | |||
// return new EnumElementValueGen(type,typeIdx,valueIdx,cpGen); | |||
// } | |||
public EnumElementValueGen(ObjectType t,String value,ConstantPoolGen cpool) { | |||
public EnumElementValueGen(ObjectType t,String value,ConstantPool cpool) { | |||
super(ElementValueGen.ENUM_CONSTANT,cpool); | |||
typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t); | |||
valueIdx= cpool.addUtf8(value);// was addString(value); | |||
} | |||
public EnumElementValueGen(EnumElementValue value, ConstantPoolGen cpool, boolean copyPoolEntries) { | |||
public EnumElementValueGen(EnumElementValueGen value, ConstantPool cpool, boolean copyPoolEntries) { | |||
super(ENUM_CONSTANT,cpool); | |||
if (copyPoolEntries) { | |||
typeIdx = cpool.addUtf8(value.getEnumTypeString());// was addClass(value.getEnumTypeString()); | |||
@@ -71,12 +70,18 @@ public class EnumElementValueGen extends ElementValueGen { | |||
dos.writeShort(valueIdx); // u2 | |||
} | |||
/** | |||
* return signature and value, something like Lp/Color;RED | |||
*/ | |||
public String stringifyValue() { | |||
ConstantUtf8 cu8 = (ConstantUtf8)getConstantPool().getConstant(valueIdx); | |||
return cu8.getBytes(); | |||
// ConstantString cu8 = (ConstantString)getConstantPool().getConstant(valueIdx); | |||
// return ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes(); | |||
StringBuffer sb = new StringBuffer(); | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpGen.getConstant(typeIdx,Constants.CONSTANT_Utf8); | |||
sb.append(cu8.getBytes()); | |||
cu8 = (ConstantUtf8)cpGen.getConstant(valueIdx,Constants.CONSTANT_Utf8); | |||
sb.append(cu8.getBytes()); | |||
return sb.toString(); | |||
} | |||
// BCELBUG: Should we need to call utility.signatureToString() on the output here? |
@@ -11,6 +11,7 @@ import java.util.List; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
public abstract class RuntimeAnnotations extends Attribute { | |||
private List /*Annotation*/ annotations; | |||
@@ -48,13 +49,25 @@ public abstract class RuntimeAnnotations extends Attribute { | |||
annotation_data = new byte[length]; | |||
dis.read(annotation_data,0,length); | |||
} | |||
protected void writeAnnotations(DataOutputStream dos) throws IOException { | |||
if (!inflated) { | |||
dos.write(annotation_data,0,length); | |||
} else { | |||
dos.writeShort(annotations.size()); | |||
for (Iterator i = annotations.iterator(); i.hasNext();) { | |||
AnnotationGen ann = (AnnotationGen) i.next(); | |||
ann.dump(dos); | |||
} | |||
} | |||
} | |||
private void inflate() { | |||
try { | |||
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data)); | |||
int numberOfAnnotations = dis.readUnsignedShort(); | |||
for (int i = 0 ;i<numberOfAnnotations;i++) { | |||
annotations.add(Annotation.read(dis,getConstantPool(),visible)); | |||
annotations.add(AnnotationGen.read(dis,getConstantPool(),visible)); | |||
} | |||
dis.close(); | |||
inflated = true; | |||
@@ -63,18 +76,6 @@ public abstract class RuntimeAnnotations extends Attribute { | |||
} | |||
} | |||
protected void writeAnnotations(DataOutputStream dos) throws IOException { | |||
if (!inflated) { | |||
dos.write(annotation_data,0,length); | |||
} else { | |||
dos.writeShort(annotations.size()); | |||
for (Iterator i = annotations.iterator(); i.hasNext();) { | |||
Annotation ann = (Annotation) i.next(); | |||
ann.dump(dos); | |||
} | |||
} | |||
} | |||
/** FOR TESTING ONLY: Tells you if the annotations have been inflated to an object graph */ | |||
public boolean isInflated() { | |||
return inflated; |
@@ -7,7 +7,7 @@ import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.Visitor; | |||
import org.aspectj.apache.bcel.classfile.ClassVisitor; | |||
public class RuntimeInvisibleAnnotations extends RuntimeAnnotations { | |||
@@ -25,7 +25,7 @@ public class RuntimeInvisibleAnnotations extends RuntimeAnnotations { | |||
super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS,false,nameIndex,len,rvaData,cpool); | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitRuntimeInvisibleAnnotations(this); | |||
} | |||
@@ -6,7 +6,7 @@ import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.Visitor; | |||
import org.aspectj.apache.bcel.classfile.ClassVisitor; | |||
public class RuntimeInvisibleParameterAnnotations extends RuntimeParameterAnnotations { | |||
@@ -24,7 +24,7 @@ public class RuntimeInvisibleParameterAnnotations extends RuntimeParameterAnnota | |||
super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,false,nameIndex,len,rvaData,cpool); | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitRuntimeInvisibleParameterAnnotations(this); | |||
} | |||
@@ -50,9 +50,9 @@ public abstract class RuntimeParameterAnnotations extends Attribute { | |||
return parameterAnnotations; | |||
} | |||
public Annotation[] getAnnotationsOnParameter(int parameterIndex) { | |||
public AnnotationGen[] getAnnotationsOnParameter(int parameterIndex) { | |||
if (!inflated) inflate(); | |||
return (Annotation[])parameterAnnotations.get(parameterIndex); | |||
return (AnnotationGen[])parameterAnnotations.get(parameterIndex); | |||
} | |||
public boolean areVisible() { | |||
@@ -70,9 +70,9 @@ public abstract class RuntimeParameterAnnotations extends Attribute { | |||
int numParameters = dis.readUnsignedByte(); | |||
for (int i=0; i<numParameters; i++) { | |||
int numAnnotations = dis.readUnsignedShort(); | |||
Annotation[] annotations = new Annotation[numAnnotations]; | |||
AnnotationGen[] annotations = new AnnotationGen[numAnnotations]; | |||
for (int j=0; j<numAnnotations; j++) { | |||
annotations[j] = Annotation.read(dis,getConstantPool(),visible); | |||
annotations[j] = AnnotationGen.read(dis,getConstantPool(),visible); | |||
} | |||
parameterAnnotations.add(annotations); | |||
} | |||
@@ -89,7 +89,7 @@ public abstract class RuntimeParameterAnnotations extends Attribute { | |||
} else { | |||
dos.writeByte(parameterAnnotations.size()); | |||
for (int i=0; i<parameterAnnotations.size(); i++) { | |||
Annotation[] annotations = (Annotation[])parameterAnnotations.get(i); | |||
AnnotationGen[] annotations = (AnnotationGen[])parameterAnnotations.get(i); | |||
dos.writeShort(annotations.length); | |||
for (int j=0; j<annotations.length;j++) { | |||
annotations[j].dump(dos); |
@@ -7,7 +7,7 @@ import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.Visitor; | |||
import org.aspectj.apache.bcel.classfile.ClassVisitor; | |||
public class RuntimeVisibleAnnotations extends RuntimeAnnotations { | |||
@@ -25,7 +25,7 @@ public class RuntimeVisibleAnnotations extends RuntimeAnnotations { | |||
super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS,true,nameIndex,len,rvaData,cpool); | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitRuntimeVisibleAnnotations(this); | |||
} | |||
@@ -6,7 +6,7 @@ import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.Attribute; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.Visitor; | |||
import org.aspectj.apache.bcel.classfile.ClassVisitor; | |||
public class RuntimeVisibleParameterAnnotations extends RuntimeParameterAnnotations { | |||
@@ -24,7 +24,7 @@ public class RuntimeVisibleParameterAnnotations extends RuntimeParameterAnnotati | |||
readParameterAnnotations(dis,cpool); | |||
} | |||
public void accept(Visitor v) { | |||
public void accept(ClassVisitor v) { | |||
v.visitRuntimeVisibleParameterAnnotations(this); | |||
} | |||
@@ -1,169 +0,0 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2004 IBM | |||
* All rights reserved. | |||
* This program and the accompanying materials are made available | |||
* under the terms of the Eclipse Public License v1.0 | |||
* which accompanies this distribution and is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
import org.aspectj.apache.bcel.Constants; | |||
import org.aspectj.apache.bcel.classfile.ConstantDouble; | |||
import org.aspectj.apache.bcel.classfile.ConstantFloat; | |||
import org.aspectj.apache.bcel.classfile.ConstantInteger; | |||
import org.aspectj.apache.bcel.classfile.ConstantLong; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
/** | |||
* An element value representing a primitive or string value. | |||
*/ | |||
public class SimpleElementValue extends ElementValue { | |||
// For primitive types and string type, this points to the value entry in the cpool | |||
// For 'class' this points to the class entry in the cpool | |||
private int idx; | |||
public SimpleElementValue(int type,int idx,ConstantPool cpool) { | |||
super(type,cpool); | |||
this.idx = idx; | |||
} | |||
public int getIndex() { | |||
return idx; | |||
} | |||
public String getValueString() { | |||
if (type != STRING) | |||
throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue"); | |||
ConstantUtf8 c = (ConstantUtf8)cpool.getConstant(idx,Constants.CONSTANT_Utf8); | |||
return c.getBytes(); | |||
} | |||
public int getValueInt() { | |||
if (type != PRIMITIVE_INT) | |||
throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue"); | |||
ConstantInteger c = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return c.getBytes(); | |||
} | |||
public byte getValueByte() { | |||
if (type != PRIMITIVE_BYTE) | |||
throw new RuntimeException("Dont call getValueByte() on a non BYTE ElementValue"); | |||
ConstantInteger c = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return (byte)c.getBytes(); | |||
} | |||
public char getValueChar() { | |||
if (type != PRIMITIVE_CHAR) | |||
throw new RuntimeException("Dont call getValueChar() on a non CHAR ElementValue"); | |||
ConstantInteger c = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return (char)c.getBytes(); | |||
} | |||
public long getValueLong() { | |||
if (type != PRIMITIVE_LONG) | |||
throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue"); | |||
ConstantLong j = (ConstantLong)cpool.getConstant(idx); | |||
return j.getBytes(); | |||
} | |||
public float getValueFloat() { | |||
if (type != PRIMITIVE_FLOAT) | |||
throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue"); | |||
ConstantFloat f = (ConstantFloat)cpool.getConstant(idx); | |||
return f.getBytes(); | |||
} | |||
public double getValueDouble() { | |||
if (type != PRIMITIVE_DOUBLE) | |||
throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue"); | |||
ConstantDouble d = (ConstantDouble)cpool.getConstant(idx); | |||
return d.getBytes(); | |||
} | |||
public boolean getValueBoolean() { | |||
if (type != PRIMITIVE_BOOLEAN) | |||
throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue"); | |||
ConstantInteger bo = (ConstantInteger)cpool.getConstant(idx); | |||
return (bo.getBytes()!=0); | |||
} | |||
public short getValueShort() { | |||
if (type != PRIMITIVE_SHORT) | |||
throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue"); | |||
ConstantInteger s = (ConstantInteger)cpool.getConstant(idx); | |||
return (short)s.getBytes(); | |||
} | |||
public String toString() { | |||
return stringifyValue(); | |||
} | |||
// Whatever kind of value it is, return it as a string | |||
public String stringifyValue() { | |||
switch (type) { | |||
case PRIMITIVE_INT: | |||
ConstantInteger c = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return Integer.toString(c.getBytes()); | |||
case PRIMITIVE_LONG: | |||
ConstantLong j = (ConstantLong)cpool.getConstant(idx,Constants.CONSTANT_Long); | |||
return Long.toString(j.getBytes()); | |||
case PRIMITIVE_DOUBLE: | |||
ConstantDouble d = (ConstantDouble)cpool.getConstant(idx,Constants.CONSTANT_Double); | |||
return Double.toString(d.getBytes()); | |||
case PRIMITIVE_FLOAT: | |||
ConstantFloat f = (ConstantFloat)cpool.getConstant(idx,Constants.CONSTANT_Float); | |||
return Float.toString(f.getBytes()); | |||
case PRIMITIVE_SHORT: | |||
ConstantInteger s = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return Integer.toString(s.getBytes()); | |||
case PRIMITIVE_BYTE: | |||
ConstantInteger b = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return Integer.toString(b.getBytes()); | |||
case PRIMITIVE_CHAR: | |||
ConstantInteger ch = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
return new Character((char)ch.getBytes()).toString(); | |||
case PRIMITIVE_BOOLEAN: | |||
ConstantInteger bo = (ConstantInteger)cpool.getConstant(idx,Constants.CONSTANT_Integer); | |||
if (bo.getBytes() == 0) return "false"; | |||
if (bo.getBytes() != 0) return "true"; | |||
case STRING: | |||
ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(idx,Constants.CONSTANT_Utf8); | |||
return cu8.getBytes(); | |||
default: | |||
throw new RuntimeException("SimpleElementValue class does not know how to stringify type "+type); | |||
} | |||
} | |||
public void dump(DataOutputStream dos) throws IOException { | |||
dos.writeByte(type); // u1 kind of value | |||
switch (type) { | |||
case PRIMITIVE_INT: | |||
case PRIMITIVE_BYTE: | |||
case PRIMITIVE_CHAR: | |||
case PRIMITIVE_FLOAT: | |||
case PRIMITIVE_LONG: | |||
case PRIMITIVE_BOOLEAN: | |||
case PRIMITIVE_SHORT: | |||
case PRIMITIVE_DOUBLE: | |||
case STRING: | |||
dos.writeShort(idx); | |||
break; | |||
default: | |||
throw new RuntimeException("SimpleElementValue doesnt know how to write out type "+type); | |||
} | |||
} | |||
} |
@@ -10,7 +10,7 @@ | |||
* Andy Clement - initial implementation {date} | |||
* ******************************************************************/ | |||
package org.aspectj.apache.bcel.generic.annotation; | |||
package org.aspectj.apache.bcel.classfile.annotation; | |||
import java.io.DataOutputStream; | |||
import java.io.IOException; | |||
@@ -20,10 +20,8 @@ import org.aspectj.apache.bcel.classfile.ConstantFloat; | |||
import org.aspectj.apache.bcel.classfile.ConstantInteger; | |||
import org.aspectj.apache.bcel.classfile.ConstantLong; | |||
import org.aspectj.apache.bcel.classfile.ConstantUtf8; | |||
import org.aspectj.apache.bcel.classfile.annotation.ElementValue; | |||
import org.aspectj.apache.bcel.classfile.annotation.SimpleElementValue; | |||
import org.aspectj.apache.bcel.generic.ConstantPoolGen; | |||
import org.aspectj.apache.bcel.classfile.ConstantPool; | |||
import org.aspectj.apache.bcel.Constants; | |||
public class SimpleElementValueGen extends ElementValueGen { | |||
@@ -39,63 +37,113 @@ public class SimpleElementValueGen extends ElementValueGen { | |||
* Protected ctor used for deserialization, doesn't *put* an entry in the constant pool, | |||
* assumes the one at the supplied index is correct. | |||
*/ | |||
protected SimpleElementValueGen(int type,int idx,ConstantPoolGen cpGen) { | |||
protected SimpleElementValueGen(int type,int idx,ConstantPool cpGen) { | |||
super(type,cpGen); | |||
this.idx = idx; | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,int value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,int value) { | |||
super(type,cpGen); | |||
idx = cpGen.addInteger(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,long value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,long value) { | |||
super(type,cpGen); | |||
idx = cpGen.addLong(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,double value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,double value) { | |||
super(type,cpGen); | |||
idx = cpGen.addDouble(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,float value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,float value) { | |||
super(type,cpGen); | |||
idx = cpGen.addFloat(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,short value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,short value) { | |||
super(type,cpGen); | |||
idx = cpGen.addInteger(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,byte value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,byte value) { | |||
super(type,cpGen); | |||
idx = cpGen.addInteger(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,char value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,char value) { | |||
super(type,cpGen); | |||
idx = cpGen.addInteger(value); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,boolean value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,boolean value) { | |||
super(type,cpGen); | |||
if (value) idx = cpGen.addInteger(1); | |||
else idx = cpGen.addInteger(0); | |||
} | |||
public SimpleElementValueGen(int type,ConstantPoolGen cpGen,String value) { | |||
public SimpleElementValueGen(int type,ConstantPool cpGen,String value) { | |||
super(type,cpGen); | |||
idx = cpGen.addUtf8(value); | |||
} | |||
public byte getValueByte() { | |||
if (type != PRIMITIVE_BYTE) | |||
throw new RuntimeException("Dont call getValueByte() on a non BYTE ElementValue"); | |||
ConstantInteger c = (ConstantInteger)cpGen.getConstant(idx,Constants.CONSTANT_Integer); | |||
return (byte)c.getBytes(); | |||
} | |||
public char getValueChar() { | |||
if (type != PRIMITIVE_CHAR) | |||
throw new RuntimeException("Dont call getValueChar() on a non CHAR ElementValue"); | |||
ConstantInteger c = (ConstantInteger)cpGen.getConstant(idx,Constants.CONSTANT_Integer); | |||
return (char)c.getBytes(); | |||
} | |||
public long getValueLong() { | |||
if (type != PRIMITIVE_LONG) | |||
throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue"); | |||
ConstantLong j = (ConstantLong)cpGen.getConstant(idx); | |||
return j.getBytes(); | |||
} | |||
public float getValueFloat() { | |||
if (type != PRIMITIVE_FLOAT) | |||
throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue"); | |||
ConstantFloat f = (ConstantFloat)cpGen.getConstant(idx); | |||
return f.getBytes(); | |||
} | |||
public double getValueDouble() { | |||
if (type != PRIMITIVE_DOUBLE) | |||
throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue"); | |||
ConstantDouble d = (ConstantDouble)cpGen.getConstant(idx); | |||
return d.getBytes(); | |||
} | |||
public boolean getValueBoolean() { | |||
if (type != PRIMITIVE_BOOLEAN) | |||
throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue"); | |||
ConstantInteger bo = (ConstantInteger)cpGen.getConstant(idx); | |||
return (bo.getBytes()!=0); | |||
} | |||
public short getValueShort() { | |||
if (type != PRIMITIVE_SHORT) | |||
throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue"); | |||
ConstantInteger s = (ConstantInteger)cpGen.getConstant(idx); | |||
return (short)s.getBytes(); | |||
} | |||
/** | |||
* The boolean controls whether we copy info from the 'old' constant pool | |||
* to the 'new'. You need to use this ctor if the annotation is | |||
* being copied from one file to another. | |||
*/ | |||
public SimpleElementValueGen(SimpleElementValue value,ConstantPoolGen cpool,boolean copyPoolEntries) { | |||
public SimpleElementValueGen(SimpleElementValueGen value,ConstantPool cpool,boolean copyPoolEntries) { | |||
super(value.getElementValueType(),cpool); | |||
if (!copyPoolEntries) { | |||
// J5ASSERT: Could assert value.stringifyValue() is the same as | |||
@@ -125,8 +173,8 @@ public class SimpleElementValueGen extends ElementValueGen { | |||
/** | |||
* Return immutable variant | |||
*/ | |||
public ElementValue getElementValue() { | |||
return new SimpleElementValue(type,idx,cpGen.getConstantPool()); | |||
public ElementValueGen getElementValue() { | |||
return new SimpleElementValueGen(type,idx,cpGen); | |||
} | |||
public int getIndex() { | |||
@@ -170,7 +218,7 @@ public class SimpleElementValueGen extends ElementValueGen { | |||
return Integer.toString(b.getBytes()); | |||
case PRIMITIVE_CHAR: | |||
ConstantInteger ch = (ConstantInteger)cpGen.getConstant(idx); | |||
return Integer.toString(ch.getBytes()); | |||
return new Character((char)ch.getBytes()).toString(); | |||
case PRIMITIVE_BOOLEAN: | |||
ConstantInteger bo = (ConstantInteger)cpGen.getConstant(idx); | |||
if (bo.getBytes() == 0) return "false"; |
@@ -1,14 +0,0 @@ | |||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> | |||
<html> | |||
<head> | |||
<!-- | |||
$Id: package.html,v 1.6 2008/04/25 17:58:22 aclement Exp $ | |||
--> | |||
</head> | |||
<body bgcolor="white"> | |||
<p> | |||
This package contains the classes that describe the structure of a | |||
Java class file and a class file parser. | |||
</p> | |||
</body> | |||
</html> |
@@ -1,87 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* AALOAD - Load reference from array | |||
* <PRE>Stack: ..., arrayref, index -> value</PRE> | |||
* | |||
* @version $Id: AALOAD.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class AALOAD extends ArrayInstruction implements StackProducer { | |||
/** Load reference from array | |||
*/ | |||
public AALOAD() { | |||
super(org.aspectj.apache.bcel.Constants.AALOAD); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackProducer(this); | |||
v.visitExceptionThrower(this); | |||
v.visitTypedInstruction(this); | |||
v.visitArrayInstruction(this); | |||
v.visitAALOAD(this); | |||
} | |||
} |
@@ -1,87 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* AASTORE - Store into reference array | |||
* <PRE>Stack: ..., arrayref, index, value -> ...</PRE> | |||
* | |||
* @version $Id: AASTORE.java,v 1.6 2008/04/25 17:58:22 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class AASTORE extends ArrayInstruction implements StackConsumer { | |||
/** Store into reference array | |||
*/ | |||
public AASTORE() { | |||
super(org.aspectj.apache.bcel.Constants.AASTORE); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackConsumer(this); | |||
v.visitExceptionThrower(this); | |||
v.visitTypedInstruction(this); | |||
v.visitArrayInstruction(this); | |||
v.visitAASTORE(this); | |||
} | |||
} |
@@ -1,94 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ACONST_NULL - Push null reference | |||
* <PRE>Stack: ... -> ..., null</PRE> | |||
* | |||
* @version $Id: ACONST_NULL.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ACONST_NULL extends Instruction | |||
implements PushInstruction, TypedInstruction { | |||
/** | |||
* Push null reference | |||
*/ | |||
public ACONST_NULL() { | |||
super(org.aspectj.apache.bcel.Constants.ACONST_NULL, (short)1); | |||
} | |||
/** @return Type.NULL | |||
*/ | |||
public Type getType(ConstantPoolGen cp) { | |||
return Type.NULL; | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackProducer(this); | |||
v.visitPushInstruction(this); | |||
v.visitTypedInstruction(this); | |||
v.visitACONST_NULL(this); | |||
} | |||
} |
@@ -1,92 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ALOAD - Load reference from local variable | |||
* <PRE>Stack: ... -> ..., objectref</PRE> | |||
* | |||
* @version $Id: ALOAD.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ALOAD extends LoadInstruction { | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
ALOAD() { | |||
super(org.aspectj.apache.bcel.Constants.ALOAD, org.aspectj.apache.bcel.Constants.ALOAD_0); | |||
} | |||
/** Load reference from local variable | |||
* @param n index of local variable | |||
*/ | |||
public ALOAD(int n) { | |||
super(org.aspectj.apache.bcel.Constants.ALOAD, org.aspectj.apache.bcel.Constants.ALOAD_0, n); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
super.accept(v); | |||
v.visitALOAD(this); | |||
} | |||
} |
@@ -1,114 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.ExceptionConstants; | |||
/** | |||
* ANEWARRAY - Create new array of references | |||
* <PRE>Stack: ..., count -> ..., arrayref</PRE> | |||
* | |||
* @version $Id: ANEWARRAY.java,v 1.6 2008/04/25 17:58:21 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ANEWARRAY extends CPInstruction | |||
implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer { | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
ANEWARRAY() {} | |||
public ANEWARRAY(int index) { | |||
super(org.aspectj.apache.bcel.Constants.ANEWARRAY, index); | |||
} | |||
public Class[] getExceptions(){ | |||
Class[] cs = new Class[1 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; | |||
System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, | |||
cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); | |||
cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = | |||
ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; | |||
return cs; | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitLoadClass(this); | |||
v.visitAllocationInstruction(this); | |||
v.visitExceptionThrower(this); | |||
v.visitStackProducer(this); | |||
v.visitTypedInstruction(this); | |||
v.visitCPInstruction(this); | |||
v.visitANEWARRAY(this); | |||
} | |||
public ObjectType getLoadClassType(ConstantPoolGen cpg) { | |||
Type t = getType(cpg); | |||
if (t instanceof ArrayType){ | |||
t = ((ArrayType) t).getBasicType(); | |||
} | |||
return (t instanceof ObjectType)? (ObjectType) t : null; | |||
} | |||
} |
@@ -1,88 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ARETURN - Return reference from method | |||
* <PRE>Stack: ..., objectref -> <empty></PRE> | |||
* | |||
* @version $Id: ARETURN.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ARETURN extends ReturnInstruction { | |||
/** | |||
* Return reference from method | |||
*/ | |||
public ARETURN() { | |||
super(org.aspectj.apache.bcel.Constants.ARETURN); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitExceptionThrower(this); | |||
v.visitTypedInstruction(this); | |||
v.visitStackConsumer(this); | |||
v.visitReturnInstruction(this); | |||
v.visitARETURN(this); | |||
} | |||
} |
@@ -1,92 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ARRAYLENGTH - Get length of array | |||
* <PRE>Stack: ..., arrayref -> ..., length</PRE> | |||
* | |||
* @version $Id: ARRAYLENGTH.java,v 1.6 2008/04/25 17:58:21 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ARRAYLENGTH extends Instruction | |||
implements ExceptionThrower, StackProducer { | |||
/** Get length of array | |||
*/ | |||
public ARRAYLENGTH() { | |||
super(org.aspectj.apache.bcel.Constants.ARRAYLENGTH, (short)1); | |||
} | |||
/** @return exceptions this instruction may cause | |||
*/ | |||
public Class[] getExceptions() { | |||
return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitExceptionThrower(this); | |||
v.visitStackProducer(this); | |||
v.visitARRAYLENGTH(this); | |||
} | |||
} |
@@ -1,92 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ASTORE - Store reference into local variable | |||
* <PRE>Stack ..., objectref -> ... </PRE> | |||
* | |||
* @version $Id: ASTORE.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ASTORE extends StoreInstruction { | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
ASTORE() { | |||
super(org.aspectj.apache.bcel.Constants.ASTORE, org.aspectj.apache.bcel.Constants.ASTORE_0); | |||
} | |||
/** Store reference into local variable | |||
* @param n index of local variable | |||
*/ | |||
public ASTORE(int n) { | |||
super(org.aspectj.apache.bcel.Constants.ASTORE, org.aspectj.apache.bcel.Constants.ASTORE_0, n); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
super.accept(v); | |||
v.visitASTORE(this); | |||
} | |||
} |
@@ -1,92 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* ATHROW - Throw exception | |||
* <PRE>Stack: ..., objectref -> objectref</PRE> | |||
* | |||
* @version $Id: ATHROW.java,v 1.6 2008/04/25 17:58:21 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower { | |||
/** | |||
* Throw exception | |||
*/ | |||
public ATHROW() { | |||
super(org.aspectj.apache.bcel.Constants.ATHROW, (short)1); | |||
} | |||
/** @return exceptions this instruction may cause | |||
*/ | |||
public Class[] getExceptions() { | |||
return new Class[] { org.aspectj.apache.bcel.ExceptionConstants.THROWABLE }; | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitUnconditionalBranch(this); | |||
v.visitExceptionThrower(this); | |||
v.visitATHROW(this); | |||
} | |||
} |
@@ -1,64 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* Denote family of instructions that allocates space in the heap. | |||
* | |||
* @version $Id: AllocationInstruction.java,v 1.6 2008/04/25 17:58:21 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public interface AllocationInstruction {} | |||
@@ -1,106 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Super class for the family of arithmetic instructions. | |||
* | |||
* @version $Id: ArithmeticInstruction.java,v 1.6 2008/04/25 17:58:22 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class ArithmeticInstruction extends Instruction | |||
implements TypedInstruction, StackProducer, StackConsumer { | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
ArithmeticInstruction() {} | |||
/** | |||
* @param opcode of instruction | |||
*/ | |||
protected ArithmeticInstruction(short opcode) { | |||
super(opcode, (short)1); | |||
} | |||
/** @return type associated with the instruction | |||
*/ | |||
public Type getType(ConstantPoolGen cp) { | |||
switch(opcode) { | |||
case Constants.DADD: case Constants.DDIV: case Constants.DMUL: | |||
case Constants.DNEG: case Constants.DREM: case Constants.DSUB: | |||
return Type.DOUBLE; | |||
case Constants.FADD: case Constants.FDIV: case Constants.FMUL: | |||
case Constants.FNEG: case Constants.FREM: case Constants.FSUB: | |||
return Type.FLOAT; | |||
case Constants.IADD: case Constants.IAND: case Constants.IDIV: | |||
case Constants.IMUL: case Constants.INEG: case Constants.IOR: case Constants.IREM: | |||
case Constants.ISHL: case Constants.ISHR: case Constants.ISUB: | |||
case Constants.IUSHR: case Constants.IXOR: | |||
return Type.INT; | |||
case Constants.LADD: case Constants.LAND: case Constants.LDIV: | |||
case Constants.LMUL: case Constants.LNEG: case Constants.LOR: case Constants.LREM: | |||
case Constants.LSHL: case Constants.LSHR: case Constants.LSUB: | |||
case Constants.LUSHR: case Constants.LXOR: | |||
return Type.LONG; | |||
default: // Never reached | |||
throw new ClassGenException("Unknown type " + opcode); | |||
} | |||
} | |||
} |
@@ -1,106 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* Super class for instructions dealing with array access such as IALOAD. | |||
* | |||
* @version $Id: ArrayInstruction.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public abstract class ArrayInstruction extends Instruction | |||
implements ExceptionThrower, TypedInstruction { | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
ArrayInstruction() {} | |||
/** | |||
* @param opcode of instruction | |||
*/ | |||
protected ArrayInstruction(short opcode) { | |||
super(opcode, (short)1); | |||
} | |||
public Class[] getExceptions() { | |||
return org.aspectj.apache.bcel.ExceptionConstants.EXCS_ARRAY_EXCEPTION; | |||
} | |||
/** @return type associated with the instruction | |||
*/ | |||
public Type getType(ConstantPoolGen cp) { | |||
switch(opcode) { | |||
case org.aspectj.apache.bcel.Constants.IALOAD: case org.aspectj.apache.bcel.Constants.IASTORE: | |||
return Type.INT; | |||
case org.aspectj.apache.bcel.Constants.CALOAD: case org.aspectj.apache.bcel.Constants.CASTORE: | |||
return Type.CHAR; | |||
case org.aspectj.apache.bcel.Constants.BALOAD: case org.aspectj.apache.bcel.Constants.BASTORE: | |||
return Type.BYTE; | |||
case org.aspectj.apache.bcel.Constants.SALOAD: case org.aspectj.apache.bcel.Constants.SASTORE: | |||
return Type.SHORT; | |||
case org.aspectj.apache.bcel.Constants.LALOAD: case org.aspectj.apache.bcel.Constants.LASTORE: | |||
return Type.LONG; | |||
case org.aspectj.apache.bcel.Constants.DALOAD: case org.aspectj.apache.bcel.Constants.DASTORE: | |||
return Type.DOUBLE; | |||
case org.aspectj.apache.bcel.Constants.FALOAD: case org.aspectj.apache.bcel.Constants.FASTORE: | |||
return Type.FLOAT; | |||
case org.aspectj.apache.bcel.Constants.AALOAD: case org.aspectj.apache.bcel.Constants.AASTORE: | |||
return Type.OBJECT; | |||
default: throw new ClassGenException("Oops: unknown case in switch" + opcode); | |||
} | |||
} | |||
} |
@@ -58,7 +58,7 @@ import org.aspectj.apache.bcel.Constants; | |||
/** | |||
* Denotes array type, such as int[][] | |||
* | |||
* @version $Id: ArrayType.java,v 1.2 2004/11/19 16:45:19 aclement Exp $ | |||
* @version $Id: ArrayType.java,v 1.3 2008/05/28 23:52:57 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public final class ArrayType extends ReferenceType { |
@@ -1,87 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* BALOAD - Load byte or boolean from array | |||
* <PRE>Stack: ..., arrayref, index -> ..., value</PRE> | |||
* | |||
* @version $Id: BALOAD.java,v 1.6 2008/04/25 17:58:20 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class BALOAD extends ArrayInstruction implements StackProducer { | |||
/** Load byte or boolean from array | |||
*/ | |||
public BALOAD() { | |||
super(org.aspectj.apache.bcel.Constants.BALOAD); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackProducer(this); | |||
v.visitExceptionThrower(this); | |||
v.visitTypedInstruction(this); | |||
v.visitArrayInstruction(this); | |||
v.visitBALOAD(this); | |||
} | |||
} |
@@ -1,87 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
/** | |||
* BASTORE - Store into byte or boolean array | |||
* <PRE>Stack: ..., arrayref, index, value -> ...</PRE> | |||
* | |||
* @version $Id: BASTORE.java,v 1.6 2008/04/25 17:58:22 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class BASTORE extends ArrayInstruction implements StackConsumer { | |||
/** Store byte or boolean into array | |||
*/ | |||
public BASTORE() { | |||
super(org.aspectj.apache.bcel.Constants.BASTORE); | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitStackConsumer(this); | |||
v.visitExceptionThrower(this); | |||
v.visitTypedInstruction(this); | |||
v.visitArrayInstruction(this); | |||
v.visitBASTORE(this); | |||
} | |||
} |
@@ -1,131 +0,0 @@ | |||
package org.aspectj.apache.bcel.generic; | |||
/* ==================================================================== | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2001 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, | |||
* if any, must include the following acknowledgment: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowledgment may appear in the software itself, | |||
* if and wherever such third-party acknowledgments normally appear. | |||
* | |||
* 4. The names "Apache" and "Apache Software Foundation" and | |||
* "Apache BCEL" must not be used to endorse or promote products | |||
* derived from this software without prior written permission. For | |||
* written permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache", | |||
* "Apache BCEL", nor may "Apache" appear in their name, without | |||
* prior written permission of the Apache Software Foundation. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
import java.io.*; | |||
import org.aspectj.apache.bcel.util.ByteSequence; | |||
/** | |||
* BIPUSH - Push byte on stack | |||
* | |||
* <PRE>Stack: ... -> ..., value</PRE> | |||
* | |||
* @version $Id: BIPUSH.java,v 1.6 2008/04/25 17:58:21 aclement Exp $ | |||
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> | |||
*/ | |||
public class BIPUSH extends Instruction implements ConstantPushInstruction { | |||
private byte b; | |||
/** | |||
* Empty constructor needed for the Class.newInstance() statement in | |||
* Instruction.readInstruction(). Not to be used otherwise. | |||
*/ | |||
BIPUSH() {} | |||
/** Push byte on stack | |||
*/ | |||
public BIPUSH(byte b) { | |||
super(org.aspectj.apache.bcel.Constants.BIPUSH, (short)2); | |||
this.b = b; | |||
} | |||
/** | |||
* Dump instruction as byte code to stream out. | |||
*/ | |||
public void dump(DataOutputStream out) throws IOException { | |||
super.dump(out); | |||
out.writeByte(b); | |||
} | |||
/** | |||
* @return mnemonic for instruction | |||
*/ | |||
public String toString(boolean verbose) { | |||
return super.toString(verbose) + " " + b; | |||
} | |||
/** | |||
* Read needed data (e.g. index) from file. | |||
*/ | |||
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException | |||
{ | |||
length = 2; | |||
b = bytes.readByte(); | |||
} | |||
public Number getValue() { return new Integer(b); } | |||
/** @return Type.BYTE | |||
*/ | |||
public Type getType(ConstantPoolGen cp) { | |||
return Type.BYTE; | |||
} | |||
/** | |||
* Call corresponding visitor method(s). The order is: | |||
* Call visitor methods of implemented interfaces first, then | |||
* call methods according to the class hierarchy in descending order, | |||
* i.e., the most specific visitXXX() call comes last. | |||
* | |||
* @param v Visitor object | |||
*/ | |||
public void accept(Visitor v) { | |||
v.visitPushInstruction(this); | |||
v.visitStackProducer(this); | |||
v.visitTypedInstruction(this); | |||
v.visitConstantPushInstruction(this); | |||
v.visitBIPUSH(this); | |||
} | |||
} |