first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
799
rus/WEB-INF/lib/xalan-2.7.1_src/org/apache/bcel/Constants.java
Normal file
799
rus/WEB-INF/lib/xalan-2.7.1_src/org/apache/bcel/Constants.java
Normal file
|
|
@ -0,0 +1,799 @@
|
|||
package org.apache.bcel;
|
||||
|
||||
public interface Constants {
|
||||
public static final short MAJOR_1_1 = 45;
|
||||
|
||||
public static final short MINOR_1_1 = 3;
|
||||
|
||||
public static final short MAJOR_1_2 = 46;
|
||||
|
||||
public static final short MINOR_1_2 = 0;
|
||||
|
||||
public static final short MAJOR_1_3 = 47;
|
||||
|
||||
public static final short MINOR_1_3 = 0;
|
||||
|
||||
public static final short MAJOR = 45;
|
||||
|
||||
public static final short MINOR = 3;
|
||||
|
||||
public static final int MAX_SHORT = 65535;
|
||||
|
||||
public static final int MAX_BYTE = 255;
|
||||
|
||||
public static final short ACC_PUBLIC = 1;
|
||||
|
||||
public static final short ACC_PRIVATE = 2;
|
||||
|
||||
public static final short ACC_PROTECTED = 4;
|
||||
|
||||
public static final short ACC_STATIC = 8;
|
||||
|
||||
public static final short ACC_FINAL = 16;
|
||||
|
||||
public static final short ACC_SYNCHRONIZED = 32;
|
||||
|
||||
public static final short ACC_VOLATILE = 64;
|
||||
|
||||
public static final short ACC_TRANSIENT = 128;
|
||||
|
||||
public static final short ACC_NATIVE = 256;
|
||||
|
||||
public static final short ACC_INTERFACE = 512;
|
||||
|
||||
public static final short ACC_ABSTRACT = 1024;
|
||||
|
||||
public static final short ACC_STRICT = 2048;
|
||||
|
||||
public static final short ACC_SUPER = 32;
|
||||
|
||||
public static final short MAX_ACC_FLAG = 1024;
|
||||
|
||||
public static final String[] ACCESS_NAMES = new String[] {
|
||||
"public", "private", "protected", "static", "final", "synchronized", "volatile", "transient", "native", "interface",
|
||||
"abstract" };
|
||||
|
||||
public static final byte CONSTANT_Utf8 = 1;
|
||||
|
||||
public static final byte CONSTANT_Integer = 3;
|
||||
|
||||
public static final byte CONSTANT_Float = 4;
|
||||
|
||||
public static final byte CONSTANT_Long = 5;
|
||||
|
||||
public static final byte CONSTANT_Double = 6;
|
||||
|
||||
public static final byte CONSTANT_Class = 7;
|
||||
|
||||
public static final byte CONSTANT_Fieldref = 9;
|
||||
|
||||
public static final byte CONSTANT_String = 8;
|
||||
|
||||
public static final byte CONSTANT_Methodref = 10;
|
||||
|
||||
public static final byte CONSTANT_InterfaceMethodref = 11;
|
||||
|
||||
public static final byte CONSTANT_NameAndType = 12;
|
||||
|
||||
public static final String[] CONSTANT_NAMES = new String[] {
|
||||
"", "CONSTANT_Utf8", "", "CONSTANT_Integer", "CONSTANT_Float", "CONSTANT_Long", "CONSTANT_Double", "CONSTANT_Class", "CONSTANT_String", "CONSTANT_Fieldref",
|
||||
"CONSTANT_Methodref", "CONSTANT_InterfaceMethodref", "CONSTANT_NameAndType" };
|
||||
|
||||
public static final String STATIC_INITIALIZER_NAME = "<clinit>";
|
||||
|
||||
public static final String CONSTRUCTOR_NAME = "<init>";
|
||||
|
||||
public static final String[] INTERFACES_IMPLEMENTED_BY_ARRAYS = new String[] { "java.lang.Cloneable", "java.io.Serializable" };
|
||||
|
||||
public static final int MAX_CP_ENTRIES = 65535;
|
||||
|
||||
public static final int MAX_CODE_SIZE = 65536;
|
||||
|
||||
public static final short NOP = 0;
|
||||
|
||||
public static final short ACONST_NULL = 1;
|
||||
|
||||
public static final short ICONST_M1 = 2;
|
||||
|
||||
public static final short ICONST_0 = 3;
|
||||
|
||||
public static final short ICONST_1 = 4;
|
||||
|
||||
public static final short ICONST_2 = 5;
|
||||
|
||||
public static final short ICONST_3 = 6;
|
||||
|
||||
public static final short ICONST_4 = 7;
|
||||
|
||||
public static final short ICONST_5 = 8;
|
||||
|
||||
public static final short LCONST_0 = 9;
|
||||
|
||||
public static final short LCONST_1 = 10;
|
||||
|
||||
public static final short FCONST_0 = 11;
|
||||
|
||||
public static final short FCONST_1 = 12;
|
||||
|
||||
public static final short FCONST_2 = 13;
|
||||
|
||||
public static final short DCONST_0 = 14;
|
||||
|
||||
public static final short DCONST_1 = 15;
|
||||
|
||||
public static final short BIPUSH = 16;
|
||||
|
||||
public static final short SIPUSH = 17;
|
||||
|
||||
public static final short LDC = 18;
|
||||
|
||||
public static final short LDC_W = 19;
|
||||
|
||||
public static final short LDC2_W = 20;
|
||||
|
||||
public static final short ILOAD = 21;
|
||||
|
||||
public static final short LLOAD = 22;
|
||||
|
||||
public static final short FLOAD = 23;
|
||||
|
||||
public static final short DLOAD = 24;
|
||||
|
||||
public static final short ALOAD = 25;
|
||||
|
||||
public static final short ILOAD_0 = 26;
|
||||
|
||||
public static final short ILOAD_1 = 27;
|
||||
|
||||
public static final short ILOAD_2 = 28;
|
||||
|
||||
public static final short ILOAD_3 = 29;
|
||||
|
||||
public static final short LLOAD_0 = 30;
|
||||
|
||||
public static final short LLOAD_1 = 31;
|
||||
|
||||
public static final short LLOAD_2 = 32;
|
||||
|
||||
public static final short LLOAD_3 = 33;
|
||||
|
||||
public static final short FLOAD_0 = 34;
|
||||
|
||||
public static final short FLOAD_1 = 35;
|
||||
|
||||
public static final short FLOAD_2 = 36;
|
||||
|
||||
public static final short FLOAD_3 = 37;
|
||||
|
||||
public static final short DLOAD_0 = 38;
|
||||
|
||||
public static final short DLOAD_1 = 39;
|
||||
|
||||
public static final short DLOAD_2 = 40;
|
||||
|
||||
public static final short DLOAD_3 = 41;
|
||||
|
||||
public static final short ALOAD_0 = 42;
|
||||
|
||||
public static final short ALOAD_1 = 43;
|
||||
|
||||
public static final short ALOAD_2 = 44;
|
||||
|
||||
public static final short ALOAD_3 = 45;
|
||||
|
||||
public static final short IALOAD = 46;
|
||||
|
||||
public static final short LALOAD = 47;
|
||||
|
||||
public static final short FALOAD = 48;
|
||||
|
||||
public static final short DALOAD = 49;
|
||||
|
||||
public static final short AALOAD = 50;
|
||||
|
||||
public static final short BALOAD = 51;
|
||||
|
||||
public static final short CALOAD = 52;
|
||||
|
||||
public static final short SALOAD = 53;
|
||||
|
||||
public static final short ISTORE = 54;
|
||||
|
||||
public static final short LSTORE = 55;
|
||||
|
||||
public static final short FSTORE = 56;
|
||||
|
||||
public static final short DSTORE = 57;
|
||||
|
||||
public static final short ASTORE = 58;
|
||||
|
||||
public static final short ISTORE_0 = 59;
|
||||
|
||||
public static final short ISTORE_1 = 60;
|
||||
|
||||
public static final short ISTORE_2 = 61;
|
||||
|
||||
public static final short ISTORE_3 = 62;
|
||||
|
||||
public static final short LSTORE_0 = 63;
|
||||
|
||||
public static final short LSTORE_1 = 64;
|
||||
|
||||
public static final short LSTORE_2 = 65;
|
||||
|
||||
public static final short LSTORE_3 = 66;
|
||||
|
||||
public static final short FSTORE_0 = 67;
|
||||
|
||||
public static final short FSTORE_1 = 68;
|
||||
|
||||
public static final short FSTORE_2 = 69;
|
||||
|
||||
public static final short FSTORE_3 = 70;
|
||||
|
||||
public static final short DSTORE_0 = 71;
|
||||
|
||||
public static final short DSTORE_1 = 72;
|
||||
|
||||
public static final short DSTORE_2 = 73;
|
||||
|
||||
public static final short DSTORE_3 = 74;
|
||||
|
||||
public static final short ASTORE_0 = 75;
|
||||
|
||||
public static final short ASTORE_1 = 76;
|
||||
|
||||
public static final short ASTORE_2 = 77;
|
||||
|
||||
public static final short ASTORE_3 = 78;
|
||||
|
||||
public static final short IASTORE = 79;
|
||||
|
||||
public static final short LASTORE = 80;
|
||||
|
||||
public static final short FASTORE = 81;
|
||||
|
||||
public static final short DASTORE = 82;
|
||||
|
||||
public static final short AASTORE = 83;
|
||||
|
||||
public static final short BASTORE = 84;
|
||||
|
||||
public static final short CASTORE = 85;
|
||||
|
||||
public static final short SASTORE = 86;
|
||||
|
||||
public static final short POP = 87;
|
||||
|
||||
public static final short POP2 = 88;
|
||||
|
||||
public static final short DUP = 89;
|
||||
|
||||
public static final short DUP_X1 = 90;
|
||||
|
||||
public static final short DUP_X2 = 91;
|
||||
|
||||
public static final short DUP2 = 92;
|
||||
|
||||
public static final short DUP2_X1 = 93;
|
||||
|
||||
public static final short DUP2_X2 = 94;
|
||||
|
||||
public static final short SWAP = 95;
|
||||
|
||||
public static final short IADD = 96;
|
||||
|
||||
public static final short LADD = 97;
|
||||
|
||||
public static final short FADD = 98;
|
||||
|
||||
public static final short DADD = 99;
|
||||
|
||||
public static final short ISUB = 100;
|
||||
|
||||
public static final short LSUB = 101;
|
||||
|
||||
public static final short FSUB = 102;
|
||||
|
||||
public static final short DSUB = 103;
|
||||
|
||||
public static final short IMUL = 104;
|
||||
|
||||
public static final short LMUL = 105;
|
||||
|
||||
public static final short FMUL = 106;
|
||||
|
||||
public static final short DMUL = 107;
|
||||
|
||||
public static final short IDIV = 108;
|
||||
|
||||
public static final short LDIV = 109;
|
||||
|
||||
public static final short FDIV = 110;
|
||||
|
||||
public static final short DDIV = 111;
|
||||
|
||||
public static final short IREM = 112;
|
||||
|
||||
public static final short LREM = 113;
|
||||
|
||||
public static final short FREM = 114;
|
||||
|
||||
public static final short DREM = 115;
|
||||
|
||||
public static final short INEG = 116;
|
||||
|
||||
public static final short LNEG = 117;
|
||||
|
||||
public static final short FNEG = 118;
|
||||
|
||||
public static final short DNEG = 119;
|
||||
|
||||
public static final short ISHL = 120;
|
||||
|
||||
public static final short LSHL = 121;
|
||||
|
||||
public static final short ISHR = 122;
|
||||
|
||||
public static final short LSHR = 123;
|
||||
|
||||
public static final short IUSHR = 124;
|
||||
|
||||
public static final short LUSHR = 125;
|
||||
|
||||
public static final short IAND = 126;
|
||||
|
||||
public static final short LAND = 127;
|
||||
|
||||
public static final short IOR = 128;
|
||||
|
||||
public static final short LOR = 129;
|
||||
|
||||
public static final short IXOR = 130;
|
||||
|
||||
public static final short LXOR = 131;
|
||||
|
||||
public static final short IINC = 132;
|
||||
|
||||
public static final short I2L = 133;
|
||||
|
||||
public static final short I2F = 134;
|
||||
|
||||
public static final short I2D = 135;
|
||||
|
||||
public static final short L2I = 136;
|
||||
|
||||
public static final short L2F = 137;
|
||||
|
||||
public static final short L2D = 138;
|
||||
|
||||
public static final short F2I = 139;
|
||||
|
||||
public static final short F2L = 140;
|
||||
|
||||
public static final short F2D = 141;
|
||||
|
||||
public static final short D2I = 142;
|
||||
|
||||
public static final short D2L = 143;
|
||||
|
||||
public static final short D2F = 144;
|
||||
|
||||
public static final short I2B = 145;
|
||||
|
||||
public static final short INT2BYTE = 145;
|
||||
|
||||
public static final short I2C = 146;
|
||||
|
||||
public static final short INT2CHAR = 146;
|
||||
|
||||
public static final short I2S = 147;
|
||||
|
||||
public static final short INT2SHORT = 147;
|
||||
|
||||
public static final short LCMP = 148;
|
||||
|
||||
public static final short FCMPL = 149;
|
||||
|
||||
public static final short FCMPG = 150;
|
||||
|
||||
public static final short DCMPL = 151;
|
||||
|
||||
public static final short DCMPG = 152;
|
||||
|
||||
public static final short IFEQ = 153;
|
||||
|
||||
public static final short IFNE = 154;
|
||||
|
||||
public static final short IFLT = 155;
|
||||
|
||||
public static final short IFGE = 156;
|
||||
|
||||
public static final short IFGT = 157;
|
||||
|
||||
public static final short IFLE = 158;
|
||||
|
||||
public static final short IF_ICMPEQ = 159;
|
||||
|
||||
public static final short IF_ICMPNE = 160;
|
||||
|
||||
public static final short IF_ICMPLT = 161;
|
||||
|
||||
public static final short IF_ICMPGE = 162;
|
||||
|
||||
public static final short IF_ICMPGT = 163;
|
||||
|
||||
public static final short IF_ICMPLE = 164;
|
||||
|
||||
public static final short IF_ACMPEQ = 165;
|
||||
|
||||
public static final short IF_ACMPNE = 166;
|
||||
|
||||
public static final short GOTO = 167;
|
||||
|
||||
public static final short JSR = 168;
|
||||
|
||||
public static final short RET = 169;
|
||||
|
||||
public static final short TABLESWITCH = 170;
|
||||
|
||||
public static final short LOOKUPSWITCH = 171;
|
||||
|
||||
public static final short IRETURN = 172;
|
||||
|
||||
public static final short LRETURN = 173;
|
||||
|
||||
public static final short FRETURN = 174;
|
||||
|
||||
public static final short DRETURN = 175;
|
||||
|
||||
public static final short ARETURN = 176;
|
||||
|
||||
public static final short RETURN = 177;
|
||||
|
||||
public static final short GETSTATIC = 178;
|
||||
|
||||
public static final short PUTSTATIC = 179;
|
||||
|
||||
public static final short GETFIELD = 180;
|
||||
|
||||
public static final short PUTFIELD = 181;
|
||||
|
||||
public static final short INVOKEVIRTUAL = 182;
|
||||
|
||||
public static final short INVOKESPECIAL = 183;
|
||||
|
||||
public static final short INVOKENONVIRTUAL = 183;
|
||||
|
||||
public static final short INVOKESTATIC = 184;
|
||||
|
||||
public static final short INVOKEINTERFACE = 185;
|
||||
|
||||
public static final short NEW = 187;
|
||||
|
||||
public static final short NEWARRAY = 188;
|
||||
|
||||
public static final short ANEWARRAY = 189;
|
||||
|
||||
public static final short ARRAYLENGTH = 190;
|
||||
|
||||
public static final short ATHROW = 191;
|
||||
|
||||
public static final short CHECKCAST = 192;
|
||||
|
||||
public static final short INSTANCEOF = 193;
|
||||
|
||||
public static final short MONITORENTER = 194;
|
||||
|
||||
public static final short MONITOREXIT = 195;
|
||||
|
||||
public static final short WIDE = 196;
|
||||
|
||||
public static final short MULTIANEWARRAY = 197;
|
||||
|
||||
public static final short IFNULL = 198;
|
||||
|
||||
public static final short IFNONNULL = 199;
|
||||
|
||||
public static final short GOTO_W = 200;
|
||||
|
||||
public static final short JSR_W = 201;
|
||||
|
||||
public static final short BREAKPOINT = 202;
|
||||
|
||||
public static final short LDC_QUICK = 203;
|
||||
|
||||
public static final short LDC_W_QUICK = 204;
|
||||
|
||||
public static final short LDC2_W_QUICK = 205;
|
||||
|
||||
public static final short GETFIELD_QUICK = 206;
|
||||
|
||||
public static final short PUTFIELD_QUICK = 207;
|
||||
|
||||
public static final short GETFIELD2_QUICK = 208;
|
||||
|
||||
public static final short PUTFIELD2_QUICK = 209;
|
||||
|
||||
public static final short GETSTATIC_QUICK = 210;
|
||||
|
||||
public static final short PUTSTATIC_QUICK = 211;
|
||||
|
||||
public static final short GETSTATIC2_QUICK = 212;
|
||||
|
||||
public static final short PUTSTATIC2_QUICK = 213;
|
||||
|
||||
public static final short INVOKEVIRTUAL_QUICK = 214;
|
||||
|
||||
public static final short INVOKENONVIRTUAL_QUICK = 215;
|
||||
|
||||
public static final short INVOKESUPER_QUICK = 216;
|
||||
|
||||
public static final short INVOKESTATIC_QUICK = 217;
|
||||
|
||||
public static final short INVOKEINTERFACE_QUICK = 218;
|
||||
|
||||
public static final short INVOKEVIRTUALOBJECT_QUICK = 219;
|
||||
|
||||
public static final short NEW_QUICK = 221;
|
||||
|
||||
public static final short ANEWARRAY_QUICK = 222;
|
||||
|
||||
public static final short MULTIANEWARRAY_QUICK = 223;
|
||||
|
||||
public static final short CHECKCAST_QUICK = 224;
|
||||
|
||||
public static final short INSTANCEOF_QUICK = 225;
|
||||
|
||||
public static final short INVOKEVIRTUAL_QUICK_W = 226;
|
||||
|
||||
public static final short GETFIELD_QUICK_W = 227;
|
||||
|
||||
public static final short PUTFIELD_QUICK_W = 228;
|
||||
|
||||
public static final short IMPDEP1 = 254;
|
||||
|
||||
public static final short IMPDEP2 = 255;
|
||||
|
||||
public static final short PUSH = 4711;
|
||||
|
||||
public static final short SWITCH = 4712;
|
||||
|
||||
public static final short UNDEFINED = -1;
|
||||
|
||||
public static final short UNPREDICTABLE = -2;
|
||||
|
||||
public static final short RESERVED = -3;
|
||||
|
||||
public static final String ILLEGAL_OPCODE = "<illegal opcode>";
|
||||
|
||||
public static final String ILLEGAL_TYPE = "<illegal type>";
|
||||
|
||||
public static final byte T_BOOLEAN = 4;
|
||||
|
||||
public static final byte T_CHAR = 5;
|
||||
|
||||
public static final byte T_FLOAT = 6;
|
||||
|
||||
public static final byte T_DOUBLE = 7;
|
||||
|
||||
public static final byte T_BYTE = 8;
|
||||
|
||||
public static final byte T_SHORT = 9;
|
||||
|
||||
public static final byte T_INT = 10;
|
||||
|
||||
public static final byte T_LONG = 11;
|
||||
|
||||
public static final byte T_VOID = 12;
|
||||
|
||||
public static final byte T_ARRAY = 13;
|
||||
|
||||
public static final byte T_OBJECT = 14;
|
||||
|
||||
public static final byte T_REFERENCE = 14;
|
||||
|
||||
public static final byte T_UNKNOWN = 15;
|
||||
|
||||
public static final byte T_ADDRESS = 16;
|
||||
|
||||
public static final String[] TYPE_NAMES = new String[] {
|
||||
"<illegal type>", "<illegal type>", "<illegal type>", "<illegal type>", "boolean", "char", "float", "double", "byte", "short",
|
||||
"int", "long", "void", "array", "object", "unknown" };
|
||||
|
||||
public static final String[] SHORT_TYPE_NAMES = new String[] {
|
||||
"<illegal type>", "<illegal type>", "<illegal type>", "<illegal type>", "Z", "C", "F", "D", "B", "S",
|
||||
"I", "J", "V", "<illegal type>", "<illegal type>", "<illegal type>" };
|
||||
|
||||
public static final short[] NO_OF_OPERANDS = new short[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 2, 1, 2,
|
||||
2, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
|
||||
-2, -2, 0, 0, 0, 0, 0, 0, 2, 2,
|
||||
2, 2, 2, 2, 2, 4, -1, 2, 1, 2,
|
||||
0, 0, 2, 2, 0, 0, -2, 3, 2, 2,
|
||||
4, 4, 0, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -3, -3 };
|
||||
|
||||
public static final short[][] TYPE_OF_OPERANDS = new short[][] {
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, new short[] { 8 }, new short[] { 9 }, new short[] { 8 }, new short[] { 9 },
|
||||
new short[] { 9 }, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, new short[] { 8 }, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, new short[] { 8, 8 }, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 },
|
||||
new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 8 },
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, new short[] { 9 }, new short[] { 9 },
|
||||
new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9 }, new short[] { 9, 8, 8 }, {}, new short[] { 9 }, new short[] { 8 }, new short[] { 9 },
|
||||
{}, {}, new short[] { 9 }, new short[] { 9 }, {}, {}, new short[] { 8 }, new short[] { 9, 8 }, new short[] { 9 }, new short[] { 9 },
|
||||
new short[] { 10 }, new short[] { 10 }, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {}, {}, {}, {}, {},
|
||||
{}, {}, {}, {}, {}, {} };
|
||||
|
||||
public static final String[] OPCODE_NAMES = new String[] {
|
||||
"nop", "aconst_null", "iconst_m1", "iconst_0", "iconst_1", "iconst_2", "iconst_3", "iconst_4", "iconst_5", "lconst_0",
|
||||
"lconst_1", "fconst_0", "fconst_1", "fconst_2", "dconst_0", "dconst_1", "bipush", "sipush", "ldc", "ldc_w",
|
||||
"ldc2_w", "iload", "lload", "fload", "dload", "aload", "iload_0", "iload_1", "iload_2", "iload_3",
|
||||
"lload_0", "lload_1", "lload_2", "lload_3", "fload_0", "fload_1", "fload_2", "fload_3", "dload_0", "dload_1",
|
||||
"dload_2", "dload_3", "aload_0", "aload_1", "aload_2", "aload_3", "iaload", "laload", "faload", "daload",
|
||||
"aaload", "baload", "caload", "saload", "istore", "lstore", "fstore", "dstore", "astore", "istore_0",
|
||||
"istore_1", "istore_2", "istore_3", "lstore_0", "lstore_1", "lstore_2", "lstore_3", "fstore_0", "fstore_1", "fstore_2",
|
||||
"fstore_3", "dstore_0", "dstore_1", "dstore_2", "dstore_3", "astore_0", "astore_1", "astore_2", "astore_3", "iastore",
|
||||
"lastore", "fastore", "dastore", "aastore", "bastore", "castore", "sastore", "pop", "pop2", "dup",
|
||||
"dup_x1", "dup_x2", "dup2", "dup2_x1", "dup2_x2", "swap", "iadd", "ladd", "fadd", "dadd",
|
||||
"isub", "lsub", "fsub", "dsub", "imul", "lmul", "fmul", "dmul", "idiv", "ldiv",
|
||||
"fdiv", "ddiv", "irem", "lrem", "frem", "drem", "ineg", "lneg", "fneg", "dneg",
|
||||
"ishl", "lshl", "ishr", "lshr", "iushr", "lushr", "iand", "land", "ior", "lor",
|
||||
"ixor", "lxor", "iinc", "i2l", "i2f", "i2d", "l2i", "l2f", "l2d", "f2i",
|
||||
"f2l", "f2d", "d2i", "d2l", "d2f", "i2b", "i2c", "i2s", "lcmp", "fcmpl",
|
||||
"fcmpg", "dcmpl", "dcmpg", "ifeq", "ifne", "iflt", "ifge", "ifgt", "ifle", "if_icmpeq",
|
||||
"if_icmpne", "if_icmplt", "if_icmpge", "if_icmpgt", "if_icmple", "if_acmpeq", "if_acmpne", "goto", "jsr", "ret",
|
||||
"tableswitch", "lookupswitch", "ireturn", "lreturn", "freturn", "dreturn", "areturn", "return", "getstatic", "putstatic",
|
||||
"getfield", "putfield", "invokevirtual", "invokespecial", "invokestatic", "invokeinterface", "<illegal opcode>", "new", "newarray", "anewarray",
|
||||
"arraylength", "athrow", "checkcast", "instanceof", "monitorenter", "monitorexit", "wide", "multianewarray", "ifnull", "ifnonnull",
|
||||
"goto_w", "jsr_w", "breakpoint", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>",
|
||||
"<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>",
|
||||
"<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>",
|
||||
"<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>",
|
||||
"<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>",
|
||||
"<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "<illegal opcode>", "impdep1", "impdep2" };
|
||||
|
||||
public static final int[] CONSUME_STACK = new int[] {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 1, 2, 1, 2, 1, 1,
|
||||
1, 1, 1, 2, 2, 2, 2, 1, 1, 1,
|
||||
1, 2, 2, 2, 2, 1, 1, 1, 1, 3,
|
||||
4, 3, 4, 3, 3, 3, 3, 1, 2, 1,
|
||||
2, 3, 2, 3, 4, 2, 2, 4, 2, 4,
|
||||
2, 4, 2, 4, 2, 4, 2, 4, 2, 4,
|
||||
2, 4, 2, 4, 2, 4, 1, 2, 1, 2,
|
||||
2, 3, 2, 3, 2, 3, 2, 4, 2, 4,
|
||||
2, 4, 0, 1, 1, 1, 2, 2, 2, 1,
|
||||
1, 1, 2, 2, 2, 1, 1, 1, 4, 2,
|
||||
2, 4, 4, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 0, 0, 0,
|
||||
1, 1, 1, 2, 1, 2, 1, 0, 0, -2,
|
||||
1, -2, -2, -2, -2, -2, -1, 0, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 0, -2, 1, 1,
|
||||
0, 0, 0, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -2, -2 };
|
||||
|
||||
public static final int[] PRODUCE_STACK = new int[] {
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 2,
|
||||
2, 1, 1, 1, 2, 2, 1, 1, 1, 1,
|
||||
2, 1, 2, 1, 2, 1, 1, 1, 1, 1,
|
||||
2, 2, 2, 2, 1, 1, 1, 1, 2, 2,
|
||||
2, 2, 1, 1, 1, 1, 1, 2, 1, 2,
|
||||
1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
|
||||
3, 4, 4, 5, 6, 2, 1, 2, 1, 2,
|
||||
1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
|
||||
1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
|
||||
1, 2, 1, 2, 1, 2, 1, 2, 1, 2,
|
||||
1, 2, 0, 2, 1, 2, 1, 1, 2, 1,
|
||||
2, 2, 1, 2, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, -2, 0,
|
||||
-2, 0, -2, -2, -2, -2, -1, 1, 1, 1,
|
||||
1, 1, 1, 1, 0, 0, 0, 1, 0, 0,
|
||||
0, 1, 0, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -2, -2 };
|
||||
|
||||
public static final byte ATTR_UNKNOWN = -1;
|
||||
|
||||
public static final byte ATTR_SOURCE_FILE = 0;
|
||||
|
||||
public static final byte ATTR_CONSTANT_VALUE = 1;
|
||||
|
||||
public static final byte ATTR_CODE = 2;
|
||||
|
||||
public static final byte ATTR_EXCEPTIONS = 3;
|
||||
|
||||
public static final byte ATTR_LINE_NUMBER_TABLE = 4;
|
||||
|
||||
public static final byte ATTR_LOCAL_VARIABLE_TABLE = 5;
|
||||
|
||||
public static final byte ATTR_INNER_CLASSES = 6;
|
||||
|
||||
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;
|
||||
|
||||
public static final byte ATTR_STACK_MAP = 11;
|
||||
|
||||
public static final short KNOWN_ATTRIBUTES = 12;
|
||||
|
||||
public static final String[] ATTRIBUTE_NAMES = new String[] {
|
||||
"SourceFile", "ConstantValue", "Code", "Exceptions", "LineNumberTable", "LocalVariableTable", "InnerClasses", "Synthetic", "Deprecated", "PMGClass",
|
||||
"Signature", "StackMap" };
|
||||
|
||||
public static final byte ITEM_Bogus = 0;
|
||||
|
||||
public static final byte ITEM_Integer = 1;
|
||||
|
||||
public static final byte ITEM_Float = 2;
|
||||
|
||||
public static final byte ITEM_Double = 3;
|
||||
|
||||
public static final byte ITEM_Long = 4;
|
||||
|
||||
public static final byte ITEM_Null = 5;
|
||||
|
||||
public static final byte ITEM_InitObject = 6;
|
||||
|
||||
public static final byte ITEM_Object = 7;
|
||||
|
||||
public static final byte ITEM_NewObject = 8;
|
||||
|
||||
public static final String[] ITEM_NAMES = new String[] { "Bogus", "Integer", "Float", "Double", "Long", "Null", "InitObject", "Object", "NewObject" };
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.bcel;
|
||||
|
||||
public interface ExceptionConstants {
|
||||
public static final Class THROWABLE = (null.class$java$lang$Throwable == null) ? (null.class$java$lang$Throwable = null.class$("java.lang.Throwable")) : null.class$java$lang$Throwable;
|
||||
|
||||
public static final Class RUNTIME_EXCEPTION = (null.class$java$lang$RuntimeException == null) ? (null.class$java$lang$RuntimeException = null.class$("java.lang.RuntimeException")) : null.class$java$lang$RuntimeException;
|
||||
|
||||
public static final Class LINKING_EXCEPTION = (null.class$java$lang$LinkageError == null) ? (null.class$java$lang$LinkageError = null.class$("java.lang.LinkageError")) : null.class$java$lang$LinkageError;
|
||||
|
||||
public static final Class CLASS_CIRCULARITY_ERROR = (null.class$java$lang$ClassCircularityError == null) ? (null.class$java$lang$ClassCircularityError = null.class$("java.lang.ClassCircularityError")) : null.class$java$lang$ClassCircularityError;
|
||||
|
||||
public static final Class CLASS_FORMAT_ERROR = (null.class$java$lang$ClassFormatError == null) ? (null.class$java$lang$ClassFormatError = null.class$("java.lang.ClassFormatError")) : null.class$java$lang$ClassFormatError;
|
||||
|
||||
public static final Class EXCEPTION_IN_INITIALIZER_ERROR = (null.class$java$lang$ExceptionInInitializerError == null) ? (null.class$java$lang$ExceptionInInitializerError = null.class$("java.lang.ExceptionInInitializerError")) : null.class$java$lang$ExceptionInInitializerError;
|
||||
|
||||
public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = (null.class$java$lang$IncompatibleClassChangeError == null) ? (null.class$java$lang$IncompatibleClassChangeError = null.class$("java.lang.IncompatibleClassChangeError")) : null.class$java$lang$IncompatibleClassChangeError;
|
||||
|
||||
public static final Class ABSTRACT_METHOD_ERROR = (null.class$java$lang$AbstractMethodError == null) ? (null.class$java$lang$AbstractMethodError = null.class$("java.lang.AbstractMethodError")) : null.class$java$lang$AbstractMethodError;
|
||||
|
||||
public static final Class ILLEGAL_ACCESS_ERROR = (null.class$java$lang$IllegalAccessError == null) ? (null.class$java$lang$IllegalAccessError = null.class$("java.lang.IllegalAccessError")) : null.class$java$lang$IllegalAccessError;
|
||||
|
||||
public static final Class INSTANTIATION_ERROR = (null.class$java$lang$InstantiationError == null) ? (null.class$java$lang$InstantiationError = null.class$("java.lang.InstantiationError")) : null.class$java$lang$InstantiationError;
|
||||
|
||||
public static final Class NO_SUCH_FIELD_ERROR = (null.class$java$lang$NoSuchFieldError == null) ? (null.class$java$lang$NoSuchFieldError = null.class$("java.lang.NoSuchFieldError")) : null.class$java$lang$NoSuchFieldError;
|
||||
|
||||
public static final Class NO_SUCH_METHOD_ERROR = (null.class$java$lang$NoSuchMethodError == null) ? (null.class$java$lang$NoSuchMethodError = null.class$("java.lang.NoSuchMethodError")) : null.class$java$lang$NoSuchMethodError;
|
||||
|
||||
public static final Class NO_CLASS_DEF_FOUND_ERROR = (null.class$java$lang$NoClassDefFoundError == null) ? (null.class$java$lang$NoClassDefFoundError = null.class$("java.lang.NoClassDefFoundError")) : null.class$java$lang$NoClassDefFoundError;
|
||||
|
||||
public static final Class UNSATISFIED_LINK_ERROR = (null.class$java$lang$UnsatisfiedLinkError == null) ? (null.class$java$lang$UnsatisfiedLinkError = null.class$("java.lang.UnsatisfiedLinkError")) : null.class$java$lang$UnsatisfiedLinkError;
|
||||
|
||||
public static final Class VERIFY_ERROR = (null.class$java$lang$VerifyError == null) ? (null.class$java$lang$VerifyError = null.class$("java.lang.VerifyError")) : null.class$java$lang$VerifyError;
|
||||
|
||||
public static final Class NULL_POINTER_EXCEPTION = (null.class$java$lang$NullPointerException == null) ? (null.class$java$lang$NullPointerException = null.class$("java.lang.NullPointerException")) : null.class$java$lang$NullPointerException;
|
||||
|
||||
public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = (null.class$java$lang$ArrayIndexOutOfBoundsException == null) ? (null.class$java$lang$ArrayIndexOutOfBoundsException = null.class$("java.lang.ArrayIndexOutOfBoundsException")) : null.class$java$lang$ArrayIndexOutOfBoundsException;
|
||||
|
||||
public static final Class ARITHMETIC_EXCEPTION = (null.class$java$lang$ArithmeticException == null) ? (null.class$java$lang$ArithmeticException = null.class$("java.lang.ArithmeticException")) : null.class$java$lang$ArithmeticException;
|
||||
|
||||
public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = (null.class$java$lang$NegativeArraySizeException == null) ? (null.class$java$lang$NegativeArraySizeException = null.class$("java.lang.NegativeArraySizeException")) : null.class$java$lang$NegativeArraySizeException;
|
||||
|
||||
public static final Class CLASS_CAST_EXCEPTION = (null.class$java$lang$ClassCastException == null) ? (null.class$java$lang$ClassCastException = null.class$("java.lang.ClassCastException")) : null.class$java$lang$ClassCastException;
|
||||
|
||||
public static final Class ILLEGAL_MONITOR_STATE = (null.class$java$lang$IllegalMonitorStateException == null) ? (null.class$java$lang$IllegalMonitorStateException = null.class$("java.lang.IllegalMonitorStateException")) : null.class$java$lang$IllegalMonitorStateException;
|
||||
|
||||
public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = new Class[] { NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR };
|
||||
|
||||
public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = new Class[] { NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR };
|
||||
|
||||
public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0];
|
||||
|
||||
public static final Class[] EXCS_STRING_RESOLUTION = new Class[0];
|
||||
|
||||
public static final Class[] EXCS_ARRAY_EXCEPTION = new Class[] { NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION };
|
||||
}
|
||||
163
rus/WEB-INF/lib/xalan-2.7.1_src/org/apache/bcel/Repository.java
Normal file
163
rus/WEB-INF/lib/xalan-2.7.1_src/org/apache/bcel/Repository.java
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
package org.apache.bcel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import org.apache.bcel.classfile.ClassParser;
|
||||
import org.apache.bcel.classfile.JavaClass;
|
||||
import org.apache.bcel.util.ClassPath;
|
||||
import org.apache.bcel.util.ClassQueue;
|
||||
import org.apache.bcel.util.ClassVector;
|
||||
|
||||
public abstract class Repository {
|
||||
private static ClassPath class_path = new ClassPath();
|
||||
|
||||
private static HashMap classes;
|
||||
|
||||
private static JavaClass OBJECT;
|
||||
|
||||
static {
|
||||
clearCache();
|
||||
}
|
||||
|
||||
public static JavaClass lookupClass(String class_name) {
|
||||
if (class_name == null || class_name.equals(""))
|
||||
throw new RuntimeException("Invalid class name");
|
||||
class_name = class_name.replace('/', '.');
|
||||
JavaClass clazz = (JavaClass)classes.get(class_name);
|
||||
if (clazz == null) {
|
||||
try {
|
||||
InputStream is = class_path.getInputStream(class_name);
|
||||
clazz = new ClassParser(is, class_name).parse();
|
||||
class_name = clazz.getClassName();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
classes.put(class_name, clazz);
|
||||
}
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public static ClassPath.ClassFile lookupClassFile(String class_name) {
|
||||
try {
|
||||
return class_path.getClassFile(class_name);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
classes = new HashMap();
|
||||
OBJECT = lookupClass("java.lang.Object");
|
||||
if (OBJECT == null) {
|
||||
System.err.println("Warning: java.lang.Object not found on CLASSPATH!");
|
||||
} else {
|
||||
classes.put("java.lang.Object", OBJECT);
|
||||
}
|
||||
}
|
||||
|
||||
public static JavaClass addClass(JavaClass clazz) {
|
||||
String name = clazz.getClassName();
|
||||
JavaClass cl = (JavaClass)classes.get(name);
|
||||
if (cl == null)
|
||||
classes.put(name, cl = clazz);
|
||||
return cl;
|
||||
}
|
||||
|
||||
public static void removeClass(String clazz) {
|
||||
classes.remove(clazz);
|
||||
}
|
||||
|
||||
public static void removeClass(JavaClass clazz) {
|
||||
removeClass(clazz.getClassName());
|
||||
}
|
||||
|
||||
private static final JavaClass getSuperClass(JavaClass clazz) {
|
||||
if (clazz == OBJECT)
|
||||
return null;
|
||||
return lookupClass(clazz.getSuperclassName());
|
||||
}
|
||||
|
||||
public static JavaClass[] getSuperClasses(JavaClass clazz) {
|
||||
ClassVector vec = new ClassVector();
|
||||
for (clazz = getSuperClass(clazz); clazz != null; clazz = getSuperClass(clazz))
|
||||
vec.addElement(clazz);
|
||||
return vec.toArray();
|
||||
}
|
||||
|
||||
public static JavaClass[] getSuperClasses(String class_name) {
|
||||
JavaClass jc = lookupClass(class_name);
|
||||
return (jc == null) ? null : getSuperClasses(jc);
|
||||
}
|
||||
|
||||
public static JavaClass[] getInterfaces(JavaClass clazz) {
|
||||
ClassVector vec = new ClassVector();
|
||||
ClassQueue queue = new ClassQueue();
|
||||
queue.enqueue(clazz);
|
||||
while (!queue.empty()) {
|
||||
clazz = queue.dequeue();
|
||||
String s = clazz.getSuperclassName();
|
||||
String[] interfaces = clazz.getInterfaceNames();
|
||||
if (clazz.isInterface()) {
|
||||
vec.addElement(clazz);
|
||||
} else if (!s.equals("java.lang.Object")) {
|
||||
queue.enqueue(lookupClass(s));
|
||||
}
|
||||
for (int i = 0; i < interfaces.length; i++)
|
||||
queue.enqueue(lookupClass(interfaces[i]));
|
||||
}
|
||||
return vec.toArray();
|
||||
}
|
||||
|
||||
public static JavaClass[] getInterfaces(String class_name) {
|
||||
return getInterfaces(lookupClass(class_name));
|
||||
}
|
||||
|
||||
public static boolean instanceOf(JavaClass clazz, JavaClass super_class) {
|
||||
if (clazz == super_class)
|
||||
return true;
|
||||
JavaClass[] super_classes = getSuperClasses(clazz);
|
||||
for (int i = 0; i < super_classes.length; i++) {
|
||||
if (super_classes[i] == super_class)
|
||||
return true;
|
||||
}
|
||||
if (super_class.isInterface())
|
||||
return implementationOf(clazz, super_class);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean instanceOf(String clazz, String super_class) {
|
||||
return instanceOf(lookupClass(clazz), lookupClass(super_class));
|
||||
}
|
||||
|
||||
public static boolean instanceOf(JavaClass clazz, String super_class) {
|
||||
return instanceOf(clazz, lookupClass(super_class));
|
||||
}
|
||||
|
||||
public static boolean instanceOf(String clazz, JavaClass super_class) {
|
||||
return instanceOf(lookupClass(clazz), super_class);
|
||||
}
|
||||
|
||||
public static boolean implementationOf(JavaClass clazz, JavaClass inter) {
|
||||
if (clazz == inter)
|
||||
return true;
|
||||
JavaClass[] super_interfaces = getInterfaces(clazz);
|
||||
for (int i = 0; i < super_interfaces.length; i++) {
|
||||
if (super_interfaces[i] == inter)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean implementationOf(String clazz, String inter) {
|
||||
return implementationOf(lookupClass(clazz), lookupClass(inter));
|
||||
}
|
||||
|
||||
public static boolean implementationOf(JavaClass clazz, String inter) {
|
||||
return implementationOf(clazz, lookupClass(inter));
|
||||
}
|
||||
|
||||
public static boolean implementationOf(String clazz, JavaClass inter) {
|
||||
return implementationOf(lookupClass(clazz), inter);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
public abstract class AccessFlags {
|
||||
protected int access_flags;
|
||||
|
||||
public AccessFlags() {}
|
||||
|
||||
public AccessFlags(int a) {
|
||||
this.access_flags = a;
|
||||
}
|
||||
|
||||
public final int getAccessFlags() {
|
||||
return this.access_flags;
|
||||
}
|
||||
|
||||
public final void setAccessFlags(int access_flags) {
|
||||
this.access_flags = access_flags;
|
||||
}
|
||||
|
||||
private final void setFlag(int flag, boolean set) {
|
||||
if ((this.access_flags & flag) != 0) {
|
||||
if (!set)
|
||||
this.access_flags ^= flag;
|
||||
} else if (set) {
|
||||
this.access_flags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
public final void isPublic(boolean flag) {
|
||||
setFlag(1, flag);
|
||||
}
|
||||
|
||||
public final boolean isPublic() {
|
||||
return ((this.access_flags & 0x1) != 0);
|
||||
}
|
||||
|
||||
public final void isPrivate(boolean flag) {
|
||||
setFlag(2, flag);
|
||||
}
|
||||
|
||||
public final boolean isPrivate() {
|
||||
return ((this.access_flags & 0x2) != 0);
|
||||
}
|
||||
|
||||
public final void isProtected(boolean flag) {
|
||||
setFlag(4, flag);
|
||||
}
|
||||
|
||||
public final boolean isProtected() {
|
||||
return ((this.access_flags & 0x4) != 0);
|
||||
}
|
||||
|
||||
public final void isStatic(boolean flag) {
|
||||
setFlag(8, flag);
|
||||
}
|
||||
|
||||
public final boolean isStatic() {
|
||||
return ((this.access_flags & 0x8) != 0);
|
||||
}
|
||||
|
||||
public final void isFinal(boolean flag) {
|
||||
setFlag(16, flag);
|
||||
}
|
||||
|
||||
public final boolean isFinal() {
|
||||
return ((this.access_flags & 0x10) != 0);
|
||||
}
|
||||
|
||||
public final void isSynchronized(boolean flag) {
|
||||
setFlag(32, flag);
|
||||
}
|
||||
|
||||
public final boolean isSynchronized() {
|
||||
return ((this.access_flags & 0x20) != 0);
|
||||
}
|
||||
|
||||
public final void isVolatile(boolean flag) {
|
||||
setFlag(64, flag);
|
||||
}
|
||||
|
||||
public final boolean isVolatile() {
|
||||
return ((this.access_flags & 0x40) != 0);
|
||||
}
|
||||
|
||||
public final void isTransient(boolean flag) {
|
||||
setFlag(128, flag);
|
||||
}
|
||||
|
||||
public final boolean isTransient() {
|
||||
return ((this.access_flags & 0x80) != 0);
|
||||
}
|
||||
|
||||
public final void isNative(boolean flag) {
|
||||
setFlag(256, flag);
|
||||
}
|
||||
|
||||
public final boolean isNative() {
|
||||
return ((this.access_flags & 0x100) != 0);
|
||||
}
|
||||
|
||||
public final void isInterface(boolean flag) {
|
||||
setFlag(512, flag);
|
||||
}
|
||||
|
||||
public final boolean isInterface() {
|
||||
return ((this.access_flags & 0x200) != 0);
|
||||
}
|
||||
|
||||
public final void isAbstract(boolean flag) {
|
||||
setFlag(1024, flag);
|
||||
}
|
||||
|
||||
public final boolean isAbstract() {
|
||||
return ((this.access_flags & 0x400) != 0);
|
||||
}
|
||||
|
||||
public final void isStrictfp(boolean flag) {
|
||||
setFlag(2048, flag);
|
||||
}
|
||||
|
||||
public final boolean isStrictfp() {
|
||||
return ((this.access_flags & 0x800) != 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public abstract class Attribute implements Cloneable, Node {
|
||||
protected int name_index;
|
||||
|
||||
protected int length;
|
||||
|
||||
protected byte tag;
|
||||
|
||||
protected ConstantPool constant_pool;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public abstract void accept(Visitor paramVisitor);
|
||||
|
||||
public void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.name_index);
|
||||
file.writeInt(this.length);
|
||||
}
|
||||
|
||||
private static HashMap readers = new HashMap();
|
||||
|
||||
public static void addAttributeReader(String name, AttributeReader r) {
|
||||
readers.put(name, r);
|
||||
}
|
||||
|
||||
public static void removeAttributeReader(String name) {
|
||||
readers.remove(name);
|
||||
}
|
||||
|
||||
static final Attribute readAttribute(DataInputStream file, ConstantPool constant_pool) throws IOException, ClassFormatError, InternalError {
|
||||
AttributeReader r;
|
||||
byte tag = -1;
|
||||
int name_index = file.readUnsignedShort();
|
||||
ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(name_index, (byte)1);
|
||||
String name = c.getBytes();
|
||||
int length = file.readInt();
|
||||
for (byte i = 0; i < 12; i = (byte)(i + 1)) {
|
||||
if (name.equals(Constants.ATTRIBUTE_NAMES[i])) {
|
||||
tag = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (tag) {
|
||||
case -1:
|
||||
r = (AttributeReader)readers.get(name);
|
||||
if (r != null)
|
||||
return r.createAttribute(name_index, length, file, constant_pool);
|
||||
return new Unknown(name_index, length, file, constant_pool);
|
||||
case 1:
|
||||
return new ConstantValue(name_index, length, file, constant_pool);
|
||||
case 0:
|
||||
return new SourceFile(name_index, length, file, constant_pool);
|
||||
case 2:
|
||||
return new Code(name_index, length, file, constant_pool);
|
||||
case 3:
|
||||
return new ExceptionTable(name_index, length, file, constant_pool);
|
||||
case 4:
|
||||
return new LineNumberTable(name_index, length, file, constant_pool);
|
||||
case 5:
|
||||
return new LocalVariableTable(name_index, length, file, constant_pool);
|
||||
case 6:
|
||||
return new InnerClasses(name_index, length, file, constant_pool);
|
||||
case 7:
|
||||
return new Synthetic(name_index, length, file, constant_pool);
|
||||
case 8:
|
||||
return new Deprecated(name_index, length, file, constant_pool);
|
||||
case 9:
|
||||
return new PMGClass(name_index, length, file, constant_pool);
|
||||
case 10:
|
||||
return new Signature(name_index, length, file, constant_pool);
|
||||
case 11:
|
||||
return new StackMap(name_index, length, file, constant_pool);
|
||||
}
|
||||
throw new InternalError("Ooops! default case reached.");
|
||||
}
|
||||
|
||||
public final int getLength() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public final void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public final void setNameIndex(int name_index) {
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public final int getNameIndex() {
|
||||
return this.name_index;
|
||||
}
|
||||
|
||||
public final byte getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
public final ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public final void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
Object o = null;
|
||||
try {
|
||||
o = super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
public abstract Attribute copy(ConstantPool paramConstantPool);
|
||||
|
||||
public String toString() {
|
||||
return Constants.ATTRIBUTE_NAMES[this.tag];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
public interface AttributeReader {
|
||||
Attribute createAttribute(int paramInt1, int paramInt2, DataInputStream paramDataInputStream, ConstantPool paramConstantPool);
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public final class ClassParser {
|
||||
private DataInputStream file;
|
||||
|
||||
private ZipFile zip;
|
||||
|
||||
private String file_name;
|
||||
|
||||
private int class_name_index;
|
||||
|
||||
private int superclass_name_index;
|
||||
|
||||
private int major;
|
||||
|
||||
private int minor;
|
||||
|
||||
private int access_flags;
|
||||
|
||||
private int[] interfaces;
|
||||
|
||||
private ConstantPool constant_pool;
|
||||
|
||||
private Field[] fields;
|
||||
|
||||
private Method[] methods;
|
||||
|
||||
private Attribute[] attributes;
|
||||
|
||||
private boolean is_zip;
|
||||
|
||||
private static final int BUFSIZE = 8192;
|
||||
|
||||
public ClassParser(InputStream file, String file_name) {
|
||||
this.file_name = file_name;
|
||||
String clazz = file.getClass().getName();
|
||||
this.is_zip = (clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar."));
|
||||
if (file instanceof DataInputStream) {
|
||||
this.file = (DataInputStream)file;
|
||||
} else {
|
||||
this.file = new DataInputStream(new BufferedInputStream(file, 8192));
|
||||
}
|
||||
}
|
||||
|
||||
public ClassParser(String file_name) throws IOException {
|
||||
this.is_zip = false;
|
||||
this.file_name = file_name;
|
||||
this.file = new DataInputStream(new BufferedInputStream(new FileInputStream(file_name), 8192));
|
||||
}
|
||||
|
||||
public ClassParser(String zip_file, String file_name) throws IOException {
|
||||
this.is_zip = true;
|
||||
this.zip = new ZipFile(zip_file);
|
||||
ZipEntry entry = this.zip.getEntry(file_name);
|
||||
this.file_name = file_name;
|
||||
this.file = new DataInputStream(new BufferedInputStream(this.zip.getInputStream(entry), 8192));
|
||||
}
|
||||
|
||||
public JavaClass parse() throws IOException, ClassFormatError {
|
||||
readID();
|
||||
readVersion();
|
||||
readConstantPool();
|
||||
readClassInfo();
|
||||
readInterfaces();
|
||||
readFields();
|
||||
readMethods();
|
||||
readAttributes();
|
||||
this.file.close();
|
||||
if (this.zip != null)
|
||||
this.zip.close();
|
||||
return new JavaClass(this.class_name_index, this.superclass_name_index, this.file_name, this.major, this.minor, this.access_flags, this.constant_pool, this.interfaces, this.fields, this.methods, this.attributes, (byte)(this.is_zip ? 3 : 2));
|
||||
}
|
||||
|
||||
private final void readAttributes() throws IOException, ClassFormatError {
|
||||
int attributes_count = this.file.readUnsignedShort();
|
||||
this.attributes = new Attribute[attributes_count];
|
||||
for (int i = 0; i < attributes_count; i++)
|
||||
this.attributes[i] = Attribute.readAttribute(this.file, this.constant_pool);
|
||||
}
|
||||
|
||||
private final void readClassInfo() throws IOException, ClassFormatError {
|
||||
this.access_flags = this.file.readUnsignedShort();
|
||||
if ((this.access_flags & 0x200) != 0)
|
||||
this.access_flags |= 0x400;
|
||||
if ((this.access_flags & 0x400) != 0 && (this.access_flags & 0x10) != 0)
|
||||
throw new ClassFormatError("Class can't be both final and abstract");
|
||||
this.class_name_index = this.file.readUnsignedShort();
|
||||
this.superclass_name_index = this.file.readUnsignedShort();
|
||||
}
|
||||
|
||||
private final void readConstantPool() throws IOException, ClassFormatError {
|
||||
this.constant_pool = new ConstantPool(this.file);
|
||||
}
|
||||
|
||||
private final void readFields() throws IOException, ClassFormatError {
|
||||
int fields_count = this.file.readUnsignedShort();
|
||||
this.fields = new Field[fields_count];
|
||||
for (int i = 0; i < fields_count; i++)
|
||||
this.fields[i] = new Field(this.file, this.constant_pool);
|
||||
}
|
||||
|
||||
private final void readID() throws IOException, ClassFormatError {
|
||||
int magic = -889275714;
|
||||
if (this.file.readInt() != magic)
|
||||
throw new ClassFormatError(this.file_name + " is not a Java .class file");
|
||||
}
|
||||
|
||||
private final void readInterfaces() throws IOException, ClassFormatError {
|
||||
int interfaces_count = this.file.readUnsignedShort();
|
||||
this.interfaces = new int[interfaces_count];
|
||||
for (int i = 0; i < interfaces_count; i++)
|
||||
this.interfaces[i] = this.file.readUnsignedShort();
|
||||
}
|
||||
|
||||
private final void readMethods() throws IOException, ClassFormatError {
|
||||
int methods_count = this.file.readUnsignedShort();
|
||||
this.methods = new Method[methods_count];
|
||||
for (int i = 0; i < methods_count; i++)
|
||||
this.methods[i] = new Method(this.file, this.constant_pool);
|
||||
}
|
||||
|
||||
private final void readVersion() throws IOException, ClassFormatError {
|
||||
this.minor = this.file.readUnsignedShort();
|
||||
this.major = this.file.readUnsignedShort();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Code extends Attribute {
|
||||
private int max_stack;
|
||||
|
||||
private int max_locals;
|
||||
|
||||
private int code_length;
|
||||
|
||||
private byte[] code;
|
||||
|
||||
private int exception_table_length;
|
||||
|
||||
private CodeException[] exception_table;
|
||||
|
||||
private int attributes_count;
|
||||
|
||||
private Attribute[] attributes;
|
||||
|
||||
public Code(Code c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), c.getCode(), c.getExceptionTable(), c.getAttributes(), c.getConstantPool());
|
||||
}
|
||||
|
||||
Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), null, null, null, constant_pool);
|
||||
this.code_length = file.readInt();
|
||||
this.code = new byte[this.code_length];
|
||||
file.readFully(this.code);
|
||||
this.exception_table_length = file.readUnsignedShort();
|
||||
this.exception_table = new CodeException[this.exception_table_length];
|
||||
for (int i = 0; i < this.exception_table_length; i++)
|
||||
this.exception_table[i] = new CodeException(file);
|
||||
this.attributes_count = file.readUnsignedShort();
|
||||
this.attributes = new Attribute[this.attributes_count];
|
||||
for (int j = 0; j < this.attributes_count; j++)
|
||||
this.attributes[j] = Attribute.readAttribute(file, constant_pool);
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public Code(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) {
|
||||
super((byte)2, name_index, length, constant_pool);
|
||||
this.max_stack = max_stack;
|
||||
this.max_locals = max_locals;
|
||||
setCode(code);
|
||||
setExceptionTable(exception_table);
|
||||
setAttributes(attributes);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitCode(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.max_stack);
|
||||
file.writeShort(this.max_locals);
|
||||
file.writeInt(this.code_length);
|
||||
file.write(this.code, 0, this.code_length);
|
||||
file.writeShort(this.exception_table_length);
|
||||
for (int i = 0; i < this.exception_table_length; i++)
|
||||
this.exception_table[i].dump(file);
|
||||
file.writeShort(this.attributes_count);
|
||||
for (int j = 0; j < this.attributes_count; j++)
|
||||
this.attributes[j].dump(file);
|
||||
}
|
||||
|
||||
public final Attribute[] getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
public LineNumberTable getLineNumberTable() {
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
if (this.attributes[i] instanceof LineNumberTable)
|
||||
return (LineNumberTable)this.attributes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LocalVariableTable getLocalVariableTable() {
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
if (this.attributes[i] instanceof LocalVariableTable)
|
||||
return (LocalVariableTable)this.attributes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final byte[] getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public final CodeException[] getExceptionTable() {
|
||||
return this.exception_table;
|
||||
}
|
||||
|
||||
public final int getMaxLocals() {
|
||||
return this.max_locals;
|
||||
}
|
||||
|
||||
public final int getMaxStack() {
|
||||
return this.max_stack;
|
||||
}
|
||||
|
||||
private final int getInternalLength() {
|
||||
return 8 + this.code_length + 2 + 8 * this.exception_table_length + 2;
|
||||
}
|
||||
|
||||
private final int calculateLength() {
|
||||
int len = 0;
|
||||
for (int i = 0; i < this.attributes_count; i++)
|
||||
len += (this.attributes[i]).length + 6;
|
||||
return len + getInternalLength();
|
||||
}
|
||||
|
||||
public final void setAttributes(Attribute[] attributes) {
|
||||
this.attributes = attributes;
|
||||
this.attributes_count = (attributes == null) ? 0 : attributes.length;
|
||||
this.length = calculateLength();
|
||||
}
|
||||
|
||||
public final void setCode(byte[] code) {
|
||||
this.code = code;
|
||||
this.code_length = (code == null) ? 0 : code.length;
|
||||
}
|
||||
|
||||
public final void setExceptionTable(CodeException[] exception_table) {
|
||||
this.exception_table = exception_table;
|
||||
this.exception_table_length = (exception_table == null) ? 0 : exception_table.length;
|
||||
}
|
||||
|
||||
public final void setMaxLocals(int max_locals) {
|
||||
this.max_locals = max_locals;
|
||||
}
|
||||
|
||||
public final void setMaxStack(int max_stack) {
|
||||
this.max_stack = max_stack;
|
||||
}
|
||||
|
||||
public final String toString(boolean verbose) {
|
||||
StringBuffer buf = new StringBuffer("Code(max_stack = " + this.max_stack + ", max_locals = " + this.max_locals + ", code_length = " + this.code_length + ")\n" + Utility.codeToString(this.code, this.constant_pool, 0, -1, verbose));
|
||||
if (this.exception_table_length > 0) {
|
||||
buf.append("\nException handler(s) = \nFrom\tTo\tHandler\tType\n");
|
||||
for (int i = 0; i < this.exception_table_length; i++)
|
||||
buf.append(this.exception_table[i].toString(this.constant_pool, verbose) + "\n");
|
||||
}
|
||||
if (this.attributes_count > 0) {
|
||||
buf.append("\nAttribute(s) = \n");
|
||||
for (int i = 0; i < this.attributes_count; i++)
|
||||
buf.append(this.attributes[i].toString() + "\n");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
Code c = (Code)clone();
|
||||
c.code = (byte[])this.code.clone();
|
||||
c.constant_pool = constant_pool;
|
||||
c.exception_table = new CodeException[this.exception_table_length];
|
||||
for (int i = 0; i < this.exception_table_length; i++)
|
||||
c.exception_table[i] = this.exception_table[i].copy();
|
||||
c.attributes = new Attribute[this.attributes_count];
|
||||
for (int j = 0; j < this.attributes_count; j++)
|
||||
c.attributes[j] = this.attributes[j].copy(constant_pool);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public final class CodeException implements Cloneable, Constants, Node {
|
||||
private int start_pc;
|
||||
|
||||
private int end_pc;
|
||||
|
||||
private int handler_pc;
|
||||
|
||||
private int catch_type;
|
||||
|
||||
public CodeException(CodeException c) {
|
||||
this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType());
|
||||
}
|
||||
|
||||
CodeException(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitCodeException(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.start_pc);
|
||||
file.writeShort(this.end_pc);
|
||||
file.writeShort(this.handler_pc);
|
||||
file.writeShort(this.catch_type);
|
||||
}
|
||||
|
||||
public final int getCatchType() {
|
||||
return this.catch_type;
|
||||
}
|
||||
|
||||
public final int getEndPC() {
|
||||
return this.end_pc;
|
||||
}
|
||||
|
||||
public final int getHandlerPC() {
|
||||
return this.handler_pc;
|
||||
}
|
||||
|
||||
public final int getStartPC() {
|
||||
return this.start_pc;
|
||||
}
|
||||
|
||||
public final void setCatchType(int catch_type) {
|
||||
this.catch_type = catch_type;
|
||||
}
|
||||
|
||||
public final void setEndPC(int end_pc) {
|
||||
this.end_pc = end_pc;
|
||||
}
|
||||
|
||||
public final void setHandlerPC(int handler_pc) {
|
||||
this.handler_pc = handler_pc;
|
||||
}
|
||||
|
||||
public final void setStartPC(int start_pc) {
|
||||
this.start_pc = start_pc;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "CodeException(start_pc = " + this.start_pc + ", end_pc = " + this.end_pc + ", handler_pc = " + this.handler_pc + ", catch_type = " + this.catch_type + ")";
|
||||
}
|
||||
|
||||
public final String toString(ConstantPool cp, boolean verbose) {
|
||||
String str;
|
||||
if (this.catch_type == 0) {
|
||||
str = "<Any exception>(0)";
|
||||
} else {
|
||||
str = Utility.compactClassName(cp.getConstantString(this.catch_type, (byte)7), false) + (verbose ? ("(" + this.catch_type + ")") : "");
|
||||
}
|
||||
return this.start_pc + "\t" + this.end_pc + "\t" + this.handler_pc + "\t" + str;
|
||||
}
|
||||
|
||||
public final String toString(ConstantPool cp) {
|
||||
return toString(cp, true);
|
||||
}
|
||||
|
||||
public CodeException copy() {
|
||||
try {
|
||||
return (CodeException)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public abstract class Constant implements Cloneable, Node {
|
||||
protected byte tag;
|
||||
|
||||
Constant(byte tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public abstract void accept(Visitor paramVisitor);
|
||||
|
||||
public abstract void dump(DataOutputStream paramDataOutputStream) throws IOException;
|
||||
|
||||
public final byte getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Constants.CONSTANT_NAMES[this.tag] + "[" + this.tag + "]";
|
||||
}
|
||||
|
||||
public Constant copy() {
|
||||
try {
|
||||
return (Constant)super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatError {
|
||||
byte b = file.readByte();
|
||||
switch (b) {
|
||||
case 7:
|
||||
return new ConstantClass(file);
|
||||
case 9:
|
||||
return new ConstantFieldref(file);
|
||||
case 10:
|
||||
return new ConstantMethodref(file);
|
||||
case 11:
|
||||
return new ConstantInterfaceMethodref(file);
|
||||
case 8:
|
||||
return new ConstantString(file);
|
||||
case 3:
|
||||
return new ConstantInteger(file);
|
||||
case 4:
|
||||
return new ConstantFloat(file);
|
||||
case 5:
|
||||
return new ConstantLong(file);
|
||||
case 6:
|
||||
return new ConstantDouble(file);
|
||||
case 12:
|
||||
return new ConstantNameAndType(file);
|
||||
case 1:
|
||||
return new ConstantUtf8(file);
|
||||
}
|
||||
throw new ClassFormatError("Invalid byte tag in constant pool: " + b);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class ConstantCP extends Constant {
|
||||
protected int class_index;
|
||||
|
||||
protected int name_and_type_index;
|
||||
|
||||
public ConstantCP(ConstantCP c) {
|
||||
this(c.getTag(), c.getClassIndex(), c.getNameAndTypeIndex());
|
||||
}
|
||||
|
||||
ConstantCP(byte tag, DataInputStream file) throws IOException {
|
||||
this(tag, file.readUnsignedShort(), file.readUnsignedShort());
|
||||
}
|
||||
|
||||
protected ConstantCP(byte tag, int class_index, int name_and_type_index) {
|
||||
super(tag);
|
||||
this.class_index = class_index;
|
||||
this.name_and_type_index = name_and_type_index;
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeShort(this.class_index);
|
||||
file.writeShort(this.name_and_type_index);
|
||||
}
|
||||
|
||||
public final int getClassIndex() {
|
||||
return this.class_index;
|
||||
}
|
||||
|
||||
public final int getNameAndTypeIndex() {
|
||||
return this.name_and_type_index;
|
||||
}
|
||||
|
||||
public final void setClassIndex(int class_index) {
|
||||
this.class_index = class_index;
|
||||
}
|
||||
|
||||
public String getClass(ConstantPool cp) {
|
||||
return cp.constantToString(this.class_index, (byte)7);
|
||||
}
|
||||
|
||||
public final void setNameAndTypeIndex(int name_and_type_index) {
|
||||
this.name_and_type_index = name_and_type_index;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(class_index = " + this.class_index + ", name_and_type_index = " + this.name_and_type_index + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantClass extends Constant implements ConstantObject {
|
||||
private int name_index;
|
||||
|
||||
public ConstantClass(ConstantClass c) {
|
||||
this(c.getNameIndex());
|
||||
}
|
||||
|
||||
ConstantClass(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort());
|
||||
}
|
||||
|
||||
public ConstantClass(int name_index) {
|
||||
super((byte)7);
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantClass(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeShort(this.name_index);
|
||||
}
|
||||
|
||||
public final int getNameIndex() {
|
||||
return this.name_index;
|
||||
}
|
||||
|
||||
public final void setNameIndex(int name_index) {
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
Constant c = cp.getConstant(this.name_index, (byte)1);
|
||||
return ((ConstantUtf8)c).getBytes();
|
||||
}
|
||||
|
||||
public String getBytes(ConstantPool cp) {
|
||||
return (String)getConstantValue(cp);
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(name_index = " + this.name_index + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantDouble extends Constant implements ConstantObject {
|
||||
private double bytes;
|
||||
|
||||
public ConstantDouble(double bytes) {
|
||||
super((byte)6);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public ConstantDouble(ConstantDouble c) {
|
||||
this(c.getBytes());
|
||||
}
|
||||
|
||||
ConstantDouble(DataInputStream file) throws IOException {
|
||||
this(file.readDouble());
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantDouble(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeDouble(this.bytes);
|
||||
}
|
||||
|
||||
public final double getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(double bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(bytes = " + this.bytes + ")";
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
return new Double(this.bytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantFieldref extends ConstantCP {
|
||||
public ConstantFieldref(ConstantFieldref c) {
|
||||
super((byte)9, c.getClassIndex(), c.getNameAndTypeIndex());
|
||||
}
|
||||
|
||||
ConstantFieldref(DataInputStream file) throws IOException {
|
||||
super((byte)9, file);
|
||||
}
|
||||
|
||||
public ConstantFieldref(int class_index, int name_and_type_index) {
|
||||
super((byte)9, class_index, name_and_type_index);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantFieldref(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantFloat extends Constant implements ConstantObject {
|
||||
private float bytes;
|
||||
|
||||
public ConstantFloat(float bytes) {
|
||||
super((byte)4);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public ConstantFloat(ConstantFloat c) {
|
||||
this(c.getBytes());
|
||||
}
|
||||
|
||||
ConstantFloat(DataInputStream file) throws IOException {
|
||||
this(file.readFloat());
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantFloat(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeFloat(this.bytes);
|
||||
}
|
||||
|
||||
public final float getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(float bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(bytes = " + this.bytes + ")";
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
return new Float(this.bytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantInteger extends Constant implements ConstantObject {
|
||||
private int bytes;
|
||||
|
||||
public ConstantInteger(int bytes) {
|
||||
super((byte)3);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public ConstantInteger(ConstantInteger c) {
|
||||
this(c.getBytes());
|
||||
}
|
||||
|
||||
ConstantInteger(DataInputStream file) throws IOException {
|
||||
this(file.readInt());
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantInteger(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeInt(this.bytes);
|
||||
}
|
||||
|
||||
public final int getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(int bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(bytes = " + this.bytes + ")";
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
return new Integer(this.bytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantInterfaceMethodref extends ConstantCP {
|
||||
public ConstantInterfaceMethodref(ConstantInterfaceMethodref c) {
|
||||
super((byte)11, c.getClassIndex(), c.getNameAndTypeIndex());
|
||||
}
|
||||
|
||||
ConstantInterfaceMethodref(DataInputStream file) throws IOException {
|
||||
super((byte)11, file);
|
||||
}
|
||||
|
||||
public ConstantInterfaceMethodref(int class_index, int name_and_type_index) {
|
||||
super((byte)11, class_index, name_and_type_index);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantInterfaceMethodref(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantLong extends Constant implements ConstantObject {
|
||||
private long bytes;
|
||||
|
||||
public ConstantLong(long bytes) {
|
||||
super((byte)5);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public ConstantLong(ConstantLong c) {
|
||||
this(c.getBytes());
|
||||
}
|
||||
|
||||
ConstantLong(DataInputStream file) throws IOException {
|
||||
this(file.readLong());
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantLong(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeLong(this.bytes);
|
||||
}
|
||||
|
||||
public final long getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(long bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(bytes = " + this.bytes + ")";
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
return new Long(this.bytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantMethodref extends ConstantCP {
|
||||
public ConstantMethodref(ConstantMethodref c) {
|
||||
super((byte)10, c.getClassIndex(), c.getNameAndTypeIndex());
|
||||
}
|
||||
|
||||
ConstantMethodref(DataInputStream file) throws IOException {
|
||||
super((byte)10, file);
|
||||
}
|
||||
|
||||
public ConstantMethodref(int class_index, int name_and_type_index) {
|
||||
super((byte)10, class_index, name_and_type_index);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantMethodref(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantNameAndType extends Constant {
|
||||
private int name_index;
|
||||
|
||||
private int signature_index;
|
||||
|
||||
public ConstantNameAndType(ConstantNameAndType c) {
|
||||
this(c.getNameIndex(), c.getSignatureIndex());
|
||||
}
|
||||
|
||||
ConstantNameAndType(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort());
|
||||
}
|
||||
|
||||
public ConstantNameAndType(int name_index, int signature_index) {
|
||||
super((byte)12);
|
||||
this.name_index = name_index;
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantNameAndType(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeShort(this.name_index);
|
||||
file.writeShort(this.signature_index);
|
||||
}
|
||||
|
||||
public final int getNameIndex() {
|
||||
return this.name_index;
|
||||
}
|
||||
|
||||
public final String getName(ConstantPool cp) {
|
||||
return cp.constantToString(getNameIndex(), (byte)1);
|
||||
}
|
||||
|
||||
public final int getSignatureIndex() {
|
||||
return this.signature_index;
|
||||
}
|
||||
|
||||
public final String getSignature(ConstantPool cp) {
|
||||
return cp.constantToString(getSignatureIndex(), (byte)1);
|
||||
}
|
||||
|
||||
public final void setNameIndex(int name_index) {
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public final void setSignatureIndex(int signature_index) {
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(name_index = " + this.name_index + ", signature_index = " + this.signature_index + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
public interface ConstantObject {
|
||||
Object getConstantValue(ConstantPool paramConstantPool);
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public class ConstantPool implements Cloneable, Node {
|
||||
private int constant_pool_count;
|
||||
|
||||
private Constant[] constant_pool;
|
||||
|
||||
public ConstantPool(Constant[] constant_pool) {
|
||||
setConstantPool(constant_pool);
|
||||
}
|
||||
|
||||
ConstantPool(DataInputStream file) throws IOException, ClassFormatError {
|
||||
this.constant_pool_count = file.readUnsignedShort();
|
||||
this.constant_pool = new Constant[this.constant_pool_count];
|
||||
for (int i = 1; i < this.constant_pool_count; i++) {
|
||||
this.constant_pool[i] = Constant.readConstant(file);
|
||||
byte tag = this.constant_pool[i].getTag();
|
||||
if (tag == 6 || tag == 5)
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantPool(this);
|
||||
}
|
||||
|
||||
public String constantToString(Constant c) throws ClassFormatError {
|
||||
String str;
|
||||
int i;
|
||||
byte tag = c.getTag();
|
||||
switch (tag) {
|
||||
case 7:
|
||||
i = ((ConstantClass)c).getNameIndex();
|
||||
c = getConstant(i, (byte)1);
|
||||
str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
|
||||
break;
|
||||
case 8:
|
||||
i = ((ConstantString)c).getStringIndex();
|
||||
c = getConstant(i, (byte)1);
|
||||
str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
|
||||
break;
|
||||
case 1:
|
||||
str = ((ConstantUtf8)c).getBytes();
|
||||
break;
|
||||
case 6:
|
||||
str = "" + ((ConstantDouble)c).getBytes();
|
||||
break;
|
||||
case 4:
|
||||
str = "" + ((ConstantFloat)c).getBytes();
|
||||
break;
|
||||
case 5:
|
||||
str = "" + ((ConstantLong)c).getBytes();
|
||||
break;
|
||||
case 3:
|
||||
str = "" + ((ConstantInteger)c).getBytes();
|
||||
break;
|
||||
case 12:
|
||||
str = constantToString(((ConstantNameAndType)c).getNameIndex(), (byte)1) + " " + constantToString(((ConstantNameAndType)c).getSignatureIndex(), (byte)1);
|
||||
break;
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
str = constantToString(((ConstantCP)c).getClassIndex(), (byte)7) + "." + constantToString(((ConstantCP)c).getNameAndTypeIndex(), (byte)12);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown constant type " + 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]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String constantToString(int index, byte tag) throws ClassFormatError {
|
||||
Constant c = getConstant(index, tag);
|
||||
return constantToString(c);
|
||||
}
|
||||
|
||||
public void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.constant_pool_count);
|
||||
for (int i = 1; i < this.constant_pool_count; i++) {
|
||||
if (this.constant_pool[i] != null)
|
||||
this.constant_pool[i].dump(file);
|
||||
}
|
||||
}
|
||||
|
||||
public Constant getConstant(int index) {
|
||||
if (index >= this.constant_pool.length || index < 0)
|
||||
throw new ClassFormatError("Invalid constant pool reference: " + index + ". Constant pool size is: " + this.constant_pool.length);
|
||||
return this.constant_pool[index];
|
||||
}
|
||||
|
||||
public Constant getConstant(int index, byte tag) throws ClassFormatError {
|
||||
Constant c = getConstant(index);
|
||||
if (c == null)
|
||||
throw new ClassFormatError("Constant pool at index " + index + " is null.");
|
||||
if (c.getTag() == tag)
|
||||
return c;
|
||||
throw new ClassFormatError("Expected class `" + Constants.CONSTANT_NAMES[tag] + "' at index " + index + " and got " + c);
|
||||
}
|
||||
|
||||
public Constant[] getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public String getConstantString(int index, byte tag) throws ClassFormatError {
|
||||
int i;
|
||||
Constant c = getConstant(index, tag);
|
||||
switch (tag) {
|
||||
case 7:
|
||||
i = ((ConstantClass)c).getNameIndex();
|
||||
break;
|
||||
case 8:
|
||||
i = ((ConstantString)c).getStringIndex();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("getConstantString called with illegal tag " + tag);
|
||||
}
|
||||
c = getConstant(i, (byte)1);
|
||||
return ((ConstantUtf8)c).getBytes();
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return this.constant_pool_count;
|
||||
}
|
||||
|
||||
public void setConstant(int index, Constant constant) {
|
||||
this.constant_pool[index] = constant;
|
||||
}
|
||||
|
||||
public void setConstantPool(Constant[] constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
this.constant_pool_count = (constant_pool == null) ? 0 : constant_pool.length;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 1; i < this.constant_pool_count; i++)
|
||||
buf.append(i + ")" + this.constant_pool[i] + "\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public ConstantPool copy() {
|
||||
ConstantPool c = null;
|
||||
try {
|
||||
c = (ConstantPool)clone();
|
||||
} catch (CloneNotSupportedException e) {}
|
||||
c.constant_pool = new Constant[this.constant_pool_count];
|
||||
for (int i = 1; i < this.constant_pool_count; i++) {
|
||||
if (this.constant_pool[i] != null)
|
||||
c.constant_pool[i] = this.constant_pool[i].copy();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantString extends Constant implements ConstantObject {
|
||||
private int string_index;
|
||||
|
||||
public ConstantString(ConstantString c) {
|
||||
this(c.getStringIndex());
|
||||
}
|
||||
|
||||
ConstantString(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort());
|
||||
}
|
||||
|
||||
public ConstantString(int string_index) {
|
||||
super((byte)8);
|
||||
this.string_index = string_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantString(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeShort(this.string_index);
|
||||
}
|
||||
|
||||
public final int getStringIndex() {
|
||||
return this.string_index;
|
||||
}
|
||||
|
||||
public final void setStringIndex(int string_index) {
|
||||
this.string_index = string_index;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(string_index = " + this.string_index + ")";
|
||||
}
|
||||
|
||||
public Object getConstantValue(ConstantPool cp) {
|
||||
Constant c = cp.getConstant(this.string_index, (byte)1);
|
||||
return ((ConstantUtf8)c).getBytes();
|
||||
}
|
||||
|
||||
public String getBytes(ConstantPool cp) {
|
||||
return (String)getConstantValue(cp);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantUtf8 extends Constant {
|
||||
private String bytes;
|
||||
|
||||
public ConstantUtf8(ConstantUtf8 c) {
|
||||
this(c.getBytes());
|
||||
}
|
||||
|
||||
ConstantUtf8(DataInputStream file) throws IOException {
|
||||
super((byte)1);
|
||||
this.bytes = file.readUTF();
|
||||
}
|
||||
|
||||
public ConstantUtf8(String bytes) {
|
||||
super((byte)1);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantUtf8(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.tag);
|
||||
file.writeUTF(this.bytes);
|
||||
}
|
||||
|
||||
public final String getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(String bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return super.toString() + "(\"" + Utility.replace(this.bytes, "\n", "\\n") + "\")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ConstantValue extends Attribute {
|
||||
private int constantvalue_index;
|
||||
|
||||
public ConstantValue(ConstantValue c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getConstantValueIndex(), c.getConstantPool());
|
||||
}
|
||||
|
||||
ConstantValue(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, file.readUnsignedShort(), constant_pool);
|
||||
}
|
||||
|
||||
public ConstantValue(int name_index, int length, int constantvalue_index, ConstantPool constant_pool) {
|
||||
super((byte)1, name_index, length, constant_pool);
|
||||
this.constantvalue_index = constantvalue_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitConstantValue(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.constantvalue_index);
|
||||
}
|
||||
|
||||
public final int getConstantValueIndex() {
|
||||
return this.constantvalue_index;
|
||||
}
|
||||
|
||||
public final void setConstantValueIndex(int constantvalue_index) {
|
||||
this.constantvalue_index = constantvalue_index;
|
||||
}
|
||||
|
||||
public final String toString() throws InternalError {
|
||||
String buf;
|
||||
int i;
|
||||
Constant c = this.constant_pool.getConstant(this.constantvalue_index);
|
||||
switch (c.getTag()) {
|
||||
case 5:
|
||||
buf = "" + ((ConstantLong)c).getBytes();
|
||||
break;
|
||||
case 4:
|
||||
buf = "" + ((ConstantFloat)c).getBytes();
|
||||
break;
|
||||
case 6:
|
||||
buf = "" + ((ConstantDouble)c).getBytes();
|
||||
break;
|
||||
case 3:
|
||||
buf = "" + ((ConstantInteger)c).getBytes();
|
||||
break;
|
||||
case 8:
|
||||
i = ((ConstantString)c).getStringIndex();
|
||||
c = this.constant_pool.getConstant(i, (byte)1);
|
||||
buf = "\"" + convertString(((ConstantUtf8)c).getBytes()) + "\"";
|
||||
break;
|
||||
default:
|
||||
throw new InternalError("Type of ConstValue invalid: " + c);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
private static final String convertString(String label) {
|
||||
char[] ch = label.toCharArray();
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < ch.length; i++) {
|
||||
switch (ch[i]) {
|
||||
case '\n':
|
||||
buf.append("\\n");
|
||||
break;
|
||||
case '\r':
|
||||
buf.append("\\r");
|
||||
break;
|
||||
case '"':
|
||||
buf.append("\\\"");
|
||||
break;
|
||||
case '\'':
|
||||
buf.append("\\'");
|
||||
break;
|
||||
case '\\':
|
||||
buf.append("\\\\");
|
||||
break;
|
||||
default:
|
||||
buf.append(ch[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
ConstantValue c = (ConstantValue)clone();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public final class Deprecated extends Attribute {
|
||||
private byte[] bytes;
|
||||
|
||||
public Deprecated(Deprecated c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public Deprecated(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
|
||||
super((byte)8, name_index, length, constant_pool);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
Deprecated(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (byte[])null, constant_pool);
|
||||
if (length > 0) {
|
||||
this.bytes = new byte[length];
|
||||
file.readFully(this.bytes);
|
||||
System.err.println("Deprecated attribute with length > 0");
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitDeprecated(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
if (this.length > 0)
|
||||
file.write(this.bytes, 0, this.length);
|
||||
}
|
||||
|
||||
public final byte[] getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return Constants.ATTRIBUTE_NAMES[8];
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
Deprecated c = (Deprecated)clone();
|
||||
if (this.bytes != null)
|
||||
c.bytes = (byte[])this.bytes.clone();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
public class DescendingVisitor implements Visitor {
|
||||
private JavaClass clazz;
|
||||
|
||||
private Visitor visitor;
|
||||
|
||||
private Stack stack = new Stack();
|
||||
|
||||
public Object predecessor() {
|
||||
return predecessor(0);
|
||||
}
|
||||
|
||||
public Object predecessor(int level) {
|
||||
int size = this.stack.size();
|
||||
if (size < 2 || level < 0)
|
||||
return null;
|
||||
return this.stack.elementAt(size - (level + 2));
|
||||
}
|
||||
|
||||
public Object current() {
|
||||
return this.stack.peek();
|
||||
}
|
||||
|
||||
public DescendingVisitor(JavaClass clazz, Visitor visitor) {
|
||||
this.clazz = clazz;
|
||||
this.visitor = visitor;
|
||||
}
|
||||
|
||||
public void visit() {
|
||||
this.clazz.accept(this);
|
||||
}
|
||||
|
||||
public void visitJavaClass(JavaClass clazz) {
|
||||
this.stack.push(clazz);
|
||||
clazz.accept(this.visitor);
|
||||
Field[] fields = clazz.getFields();
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
fields[i].accept(this);
|
||||
Method[] methods = clazz.getMethods();
|
||||
for (int j = 0; j < methods.length; j++)
|
||||
methods[j].accept(this);
|
||||
Attribute[] attributes = clazz.getAttributes();
|
||||
for (int k = 0; k < attributes.length; k++)
|
||||
attributes[k].accept(this);
|
||||
clazz.getConstantPool().accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitField(Field field) {
|
||||
this.stack.push(field);
|
||||
field.accept(this.visitor);
|
||||
Attribute[] attributes = field.getAttributes();
|
||||
for (int i = 0; i < attributes.length; i++)
|
||||
attributes[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantValue(ConstantValue cv) {
|
||||
this.stack.push(cv);
|
||||
cv.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitMethod(Method method) {
|
||||
this.stack.push(method);
|
||||
method.accept(this.visitor);
|
||||
Attribute[] attributes = method.getAttributes();
|
||||
for (int i = 0; i < attributes.length; i++)
|
||||
attributes[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitExceptionTable(ExceptionTable table) {
|
||||
this.stack.push(table);
|
||||
table.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitCode(Code code) {
|
||||
this.stack.push(code);
|
||||
code.accept(this.visitor);
|
||||
CodeException[] table = code.getExceptionTable();
|
||||
for (int i = 0; i < table.length; i++)
|
||||
table[i].accept(this);
|
||||
Attribute[] attributes = code.getAttributes();
|
||||
for (int j = 0; j < attributes.length; j++)
|
||||
attributes[j].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitCodeException(CodeException ce) {
|
||||
this.stack.push(ce);
|
||||
ce.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitLineNumberTable(LineNumberTable table) {
|
||||
this.stack.push(table);
|
||||
table.accept(this.visitor);
|
||||
LineNumber[] numbers = table.getLineNumberTable();
|
||||
for (int i = 0; i < numbers.length; i++)
|
||||
numbers[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitLineNumber(LineNumber number) {
|
||||
this.stack.push(number);
|
||||
number.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitLocalVariableTable(LocalVariableTable table) {
|
||||
this.stack.push(table);
|
||||
table.accept(this.visitor);
|
||||
LocalVariable[] vars = table.getLocalVariableTable();
|
||||
for (int i = 0; i < vars.length; i++)
|
||||
vars[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitStackMap(StackMap table) {
|
||||
this.stack.push(table);
|
||||
table.accept(this.visitor);
|
||||
StackMapEntry[] vars = table.getStackMap();
|
||||
for (int i = 0; i < vars.length; i++)
|
||||
vars[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitStackMapEntry(StackMapEntry var) {
|
||||
this.stack.push(var);
|
||||
var.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitLocalVariable(LocalVariable var) {
|
||||
this.stack.push(var);
|
||||
var.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantPool(ConstantPool cp) {
|
||||
this.stack.push(cp);
|
||||
cp.accept(this.visitor);
|
||||
Constant[] constants = cp.getConstantPool();
|
||||
for (int i = 1; i < constants.length; i++) {
|
||||
if (constants[i] != null)
|
||||
constants[i].accept(this);
|
||||
}
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantClass(ConstantClass constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantDouble(ConstantDouble constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantFieldref(ConstantFieldref constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantFloat(ConstantFloat constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantInteger(ConstantInteger constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantLong(ConstantLong constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantMethodref(ConstantMethodref constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantNameAndType(ConstantNameAndType constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantString(ConstantString constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitConstantUtf8(ConstantUtf8 constant) {
|
||||
this.stack.push(constant);
|
||||
constant.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitInnerClasses(InnerClasses ic) {
|
||||
this.stack.push(ic);
|
||||
ic.accept(this.visitor);
|
||||
InnerClass[] ics = ic.getInnerClasses();
|
||||
for (int i = 0; i < ics.length; i++)
|
||||
ics[i].accept(this);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitInnerClass(InnerClass inner) {
|
||||
this.stack.push(inner);
|
||||
inner.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitDeprecated(Deprecated attribute) {
|
||||
this.stack.push(attribute);
|
||||
attribute.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitSourceFile(SourceFile attribute) {
|
||||
this.stack.push(attribute);
|
||||
attribute.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitSynthetic(Synthetic attribute) {
|
||||
this.stack.push(attribute);
|
||||
attribute.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
|
||||
public void visitUnknown(Unknown attribute) {
|
||||
this.stack.push(attribute);
|
||||
attribute.accept(this.visitor);
|
||||
this.stack.pop();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
public class EmptyVisitor implements Visitor {
|
||||
public void visitCode(Code obj) {}
|
||||
|
||||
public void visitCodeException(CodeException obj) {}
|
||||
|
||||
public void visitConstantClass(ConstantClass obj) {}
|
||||
|
||||
public void visitConstantDouble(ConstantDouble obj) {}
|
||||
|
||||
public void visitConstantFieldref(ConstantFieldref obj) {}
|
||||
|
||||
public void visitConstantFloat(ConstantFloat obj) {}
|
||||
|
||||
public void visitConstantInteger(ConstantInteger obj) {}
|
||||
|
||||
public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj) {}
|
||||
|
||||
public void visitConstantLong(ConstantLong obj) {}
|
||||
|
||||
public void visitConstantMethodref(ConstantMethodref obj) {}
|
||||
|
||||
public void visitConstantNameAndType(ConstantNameAndType obj) {}
|
||||
|
||||
public void visitConstantPool(ConstantPool obj) {}
|
||||
|
||||
public void visitConstantString(ConstantString obj) {}
|
||||
|
||||
public void visitConstantUtf8(ConstantUtf8 obj) {}
|
||||
|
||||
public void visitConstantValue(ConstantValue obj) {}
|
||||
|
||||
public void visitDeprecated(Deprecated obj) {}
|
||||
|
||||
public void visitExceptionTable(ExceptionTable obj) {}
|
||||
|
||||
public void visitField(Field obj) {}
|
||||
|
||||
public void visitInnerClass(InnerClass obj) {}
|
||||
|
||||
public void visitInnerClasses(InnerClasses obj) {}
|
||||
|
||||
public void visitJavaClass(JavaClass obj) {}
|
||||
|
||||
public void visitLineNumber(LineNumber obj) {}
|
||||
|
||||
public void visitLineNumberTable(LineNumberTable obj) {}
|
||||
|
||||
public void visitLocalVariable(LocalVariable obj) {}
|
||||
|
||||
public void visitLocalVariableTable(LocalVariableTable obj) {}
|
||||
|
||||
public void visitMethod(Method obj) {}
|
||||
|
||||
public void visitSourceFile(SourceFile obj) {}
|
||||
|
||||
public void visitSynthetic(Synthetic obj) {}
|
||||
|
||||
public void visitUnknown(Unknown obj) {}
|
||||
|
||||
public void visitStackMap(StackMap obj) {}
|
||||
|
||||
public void visitStackMapEntry(StackMapEntry obj) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class ExceptionTable extends Attribute {
|
||||
private int number_of_exceptions;
|
||||
|
||||
private int[] exception_index_table;
|
||||
|
||||
public ExceptionTable(ExceptionTable c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public ExceptionTable(int name_index, int length, int[] exception_index_table, ConstantPool constant_pool) {
|
||||
super((byte)3, name_index, length, constant_pool);
|
||||
setExceptionIndexTable(exception_index_table);
|
||||
}
|
||||
|
||||
ExceptionTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (int[])null, constant_pool);
|
||||
this.number_of_exceptions = file.readUnsignedShort();
|
||||
this.exception_index_table = new int[this.number_of_exceptions];
|
||||
for (int i = 0; i < this.number_of_exceptions; i++)
|
||||
this.exception_index_table[i] = file.readUnsignedShort();
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitExceptionTable(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.number_of_exceptions);
|
||||
for (int i = 0; i < this.number_of_exceptions; i++)
|
||||
file.writeShort(this.exception_index_table[i]);
|
||||
}
|
||||
|
||||
public final int[] getExceptionIndexTable() {
|
||||
return this.exception_index_table;
|
||||
}
|
||||
|
||||
public final int getNumberOfExceptions() {
|
||||
return this.number_of_exceptions;
|
||||
}
|
||||
|
||||
public final String[] getExceptionNames() {
|
||||
String[] names = new String[this.number_of_exceptions];
|
||||
for (int i = 0; i < this.number_of_exceptions; i++)
|
||||
names[i] = this.constant_pool.getConstantString(this.exception_index_table[i], (byte)7).replace('/', '.');
|
||||
return names;
|
||||
}
|
||||
|
||||
public final void setExceptionIndexTable(int[] exception_index_table) {
|
||||
this.exception_index_table = exception_index_table;
|
||||
this.number_of_exceptions = (exception_index_table == null) ? 0 : exception_index_table.length;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer("");
|
||||
for (int i = 0; i < this.number_of_exceptions; i++) {
|
||||
String str = this.constant_pool.getConstantString(this.exception_index_table[i], (byte)7);
|
||||
buf.append(Utility.compactClassName(str, false));
|
||||
if (i < this.number_of_exceptions - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
ExceptionTable c = (ExceptionTable)clone();
|
||||
c.exception_index_table = (int[])this.exception_index_table.clone();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Field extends FieldOrMethod {
|
||||
public Field(Field c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
Field(DataInputStream file, ConstantPool constant_pool) throws IOException, ClassFormatError {
|
||||
super(file, constant_pool);
|
||||
}
|
||||
|
||||
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 void accept(Visitor v) {
|
||||
v.visitField(this);
|
||||
}
|
||||
|
||||
public final ConstantValue getConstantValue() {
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
if (this.attributes[i].getTag() == 1)
|
||||
return (ConstantValue)this.attributes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
String access = Utility.accessToString(this.access_flags);
|
||||
access = access.equals("") ? "" : (access + " ");
|
||||
String signature = Utility.signatureToString(getSignature());
|
||||
String name = getName();
|
||||
StringBuffer buf = new StringBuffer(access + signature + " " + name);
|
||||
ConstantValue cv = getConstantValue();
|
||||
if (cv != null)
|
||||
buf.append(" = " + cv);
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
Attribute a = this.attributes[i];
|
||||
if (!(a instanceof ConstantValue))
|
||||
buf.append(" [" + a.toString() + "]");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public final Field copy(ConstantPool constant_pool) {
|
||||
return (Field)copy_(constant_pool);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class FieldOrMethod extends AccessFlags implements Cloneable, Node {
|
||||
protected int name_index;
|
||||
|
||||
protected int signature_index;
|
||||
|
||||
protected int attributes_count;
|
||||
|
||||
protected Attribute[] attributes;
|
||||
|
||||
protected ConstantPool constant_pool;
|
||||
|
||||
FieldOrMethod() {}
|
||||
|
||||
protected FieldOrMethod(FieldOrMethod c) {
|
||||
this(c.getAccessFlags(), c.getNameIndex(), c.getSignatureIndex(), c.getAttributes(), c.getConstantPool());
|
||||
}
|
||||
|
||||
protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) throws IOException, ClassFormatError {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null, constant_pool);
|
||||
this.attributes_count = file.readUnsignedShort();
|
||||
this.attributes = new Attribute[this.attributes_count];
|
||||
for (int i = 0; i < this.attributes_count; i++)
|
||||
this.attributes[i] = Attribute.readAttribute(file, constant_pool);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.access_flags);
|
||||
file.writeShort(this.name_index);
|
||||
file.writeShort(this.signature_index);
|
||||
file.writeShort(this.attributes_count);
|
||||
for (int i = 0; i < this.attributes_count; i++)
|
||||
this.attributes[i].dump(file);
|
||||
}
|
||||
|
||||
public final Attribute[] getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
public final void setAttributes(Attribute[] attributes) {
|
||||
this.attributes = attributes;
|
||||
this.attributes_count = (attributes == null) ? 0 : attributes.length;
|
||||
}
|
||||
|
||||
public final ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public final void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public final int getNameIndex() {
|
||||
return this.name_index;
|
||||
}
|
||||
|
||||
public final void setNameIndex(int name_index) {
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public final int getSignatureIndex() {
|
||||
return this.signature_index;
|
||||
}
|
||||
|
||||
public final void setSignatureIndex(int signature_index) {
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.name_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final String getSignature() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.signature_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
protected FieldOrMethod copy_(ConstantPool constant_pool) {
|
||||
FieldOrMethod c = null;
|
||||
try {
|
||||
c = (FieldOrMethod)clone();
|
||||
} catch (CloneNotSupportedException e) {}
|
||||
c.constant_pool = constant_pool;
|
||||
c.attributes = new Attribute[this.attributes_count];
|
||||
for (int i = 0; i < this.attributes_count; i++)
|
||||
c.attributes[i] = this.attributes[i].copy(constant_pool);
|
||||
return c;
|
||||
}
|
||||
|
||||
public abstract void accept(Visitor paramVisitor);
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class InnerClass implements Cloneable, Node {
|
||||
private int inner_class_index;
|
||||
|
||||
private int outer_class_index;
|
||||
|
||||
private int inner_name_index;
|
||||
|
||||
private int inner_access_flags;
|
||||
|
||||
public InnerClass(InnerClass c) {
|
||||
this(c.getInnerClassIndex(), c.getOuterClassIndex(), c.getInnerNameIndex(), c.getInnerAccessFlags());
|
||||
}
|
||||
|
||||
InnerClass(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort());
|
||||
}
|
||||
|
||||
public InnerClass(int inner_class_index, int outer_class_index, int inner_name_index, int inner_access_flags) {
|
||||
this.inner_class_index = inner_class_index;
|
||||
this.outer_class_index = outer_class_index;
|
||||
this.inner_name_index = inner_name_index;
|
||||
this.inner_access_flags = inner_access_flags;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitInnerClass(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.inner_class_index);
|
||||
file.writeShort(this.outer_class_index);
|
||||
file.writeShort(this.inner_name_index);
|
||||
file.writeShort(this.inner_access_flags);
|
||||
}
|
||||
|
||||
public final int getInnerAccessFlags() {
|
||||
return this.inner_access_flags;
|
||||
}
|
||||
|
||||
public final int getInnerClassIndex() {
|
||||
return this.inner_class_index;
|
||||
}
|
||||
|
||||
public final int getInnerNameIndex() {
|
||||
return this.inner_name_index;
|
||||
}
|
||||
|
||||
public final int getOuterClassIndex() {
|
||||
return this.outer_class_index;
|
||||
}
|
||||
|
||||
public final void setInnerAccessFlags(int inner_access_flags) {
|
||||
this.inner_access_flags = inner_access_flags;
|
||||
}
|
||||
|
||||
public final void setInnerClassIndex(int inner_class_index) {
|
||||
this.inner_class_index = inner_class_index;
|
||||
}
|
||||
|
||||
public final void setInnerNameIndex(int inner_name_index) {
|
||||
this.inner_name_index = inner_name_index;
|
||||
}
|
||||
|
||||
public final void setOuterClassIndex(int outer_class_index) {
|
||||
this.outer_class_index = outer_class_index;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "InnerClass(" + this.inner_class_index + ", " + this.outer_class_index + ", " + this.inner_name_index + ", " + this.inner_access_flags + ")";
|
||||
}
|
||||
|
||||
public final String toString(ConstantPool constant_pool) {
|
||||
String str1, str2;
|
||||
String inner_class_name = constant_pool.getConstantString(this.inner_class_index, (byte)7);
|
||||
inner_class_name = Utility.compactClassName(inner_class_name);
|
||||
if (this.outer_class_index != 0) {
|
||||
str1 = constant_pool.getConstantString(this.outer_class_index, (byte)7);
|
||||
str1 = Utility.compactClassName(str1);
|
||||
} else {
|
||||
str1 = "<not a member>";
|
||||
}
|
||||
if (this.inner_name_index != 0) {
|
||||
str2 = ((ConstantUtf8)constant_pool.getConstant(this.inner_name_index, (byte)1)).getBytes();
|
||||
} else {
|
||||
str2 = "<anonymous>";
|
||||
}
|
||||
String access = Utility.accessToString(this.inner_access_flags, true);
|
||||
access = access.equals("") ? "" : (access + " ");
|
||||
return "InnerClass:" + access + inner_class_name + "(\"" + str1 + "\", \"" + str2 + "\")";
|
||||
}
|
||||
|
||||
public InnerClass copy() {
|
||||
try {
|
||||
return (InnerClass)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class InnerClasses extends Attribute {
|
||||
private InnerClass[] inner_classes;
|
||||
|
||||
private int number_of_classes;
|
||||
|
||||
public InnerClasses(InnerClasses c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public InnerClasses(int name_index, int length, InnerClass[] inner_classes, ConstantPool constant_pool) {
|
||||
super((byte)6, name_index, length, constant_pool);
|
||||
setInnerClasses(inner_classes);
|
||||
}
|
||||
|
||||
InnerClasses(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (InnerClass[])null, constant_pool);
|
||||
this.number_of_classes = file.readUnsignedShort();
|
||||
this.inner_classes = new InnerClass[this.number_of_classes];
|
||||
for (int i = 0; i < this.number_of_classes; i++)
|
||||
this.inner_classes[i] = new InnerClass(file);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitInnerClasses(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.number_of_classes);
|
||||
for (int i = 0; i < this.number_of_classes; i++)
|
||||
this.inner_classes[i].dump(file);
|
||||
}
|
||||
|
||||
public final InnerClass[] getInnerClasses() {
|
||||
return this.inner_classes;
|
||||
}
|
||||
|
||||
public final void setInnerClasses(InnerClass[] inner_classes) {
|
||||
this.inner_classes = inner_classes;
|
||||
this.number_of_classes = (inner_classes == null) ? 0 : inner_classes.length;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < this.number_of_classes; i++)
|
||||
buf.append(this.inner_classes[i].toString(this.constant_pool) + "\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
InnerClasses c = (InnerClasses)clone();
|
||||
c.inner_classes = new InnerClass[this.number_of_classes];
|
||||
for (int i = 0; i < this.number_of_classes; i++)
|
||||
c.inner_classes[i] = this.inner_classes[i].copy();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,381 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.StringTokenizer;
|
||||
import org.apache.bcel.Repository;
|
||||
|
||||
public class JavaClass extends AccessFlags implements Cloneable, Node {
|
||||
private String file_name;
|
||||
|
||||
private String package_name;
|
||||
|
||||
private String source_file_name = "<Unknown>";
|
||||
|
||||
private int class_name_index;
|
||||
|
||||
private int superclass_name_index;
|
||||
|
||||
private String class_name;
|
||||
|
||||
private String superclass_name;
|
||||
|
||||
private int major;
|
||||
|
||||
private int minor;
|
||||
|
||||
private ConstantPool constant_pool;
|
||||
|
||||
private int[] interfaces;
|
||||
|
||||
private String[] interface_names;
|
||||
|
||||
private Field[] fields;
|
||||
|
||||
private Method[] methods;
|
||||
|
||||
private Attribute[] attributes;
|
||||
|
||||
private byte source = 1;
|
||||
|
||||
public static final byte HEAP = 1;
|
||||
|
||||
public static final byte FILE = 2;
|
||||
|
||||
public static final byte ZIP = 3;
|
||||
|
||||
static boolean debug = false;
|
||||
|
||||
static char sep = '/';
|
||||
|
||||
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, byte source) {
|
||||
if (interfaces == null)
|
||||
interfaces = new int[0];
|
||||
if (attributes == null)
|
||||
this.attributes = new Attribute[0];
|
||||
if (fields == null)
|
||||
fields = new Field[0];
|
||||
if (methods == null)
|
||||
methods = new Method[0];
|
||||
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.constant_pool = constant_pool;
|
||||
this.interfaces = interfaces;
|
||||
this.fields = fields;
|
||||
this.methods = methods;
|
||||
this.attributes = attributes;
|
||||
this.source = source;
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
if (attributes[i] instanceof SourceFile) {
|
||||
this.source_file_name = ((SourceFile)attributes[i]).getSourceFileName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.class_name = constant_pool.getConstantString(class_name_index, (byte)7);
|
||||
this.class_name = Utility.compactClassName(this.class_name, false);
|
||||
int index = this.class_name.lastIndexOf('.');
|
||||
if (index < 0) {
|
||||
this.package_name = "";
|
||||
} else {
|
||||
this.package_name = this.class_name.substring(0, index);
|
||||
}
|
||||
if (superclass_name_index > 0) {
|
||||
this.superclass_name = constant_pool.getConstantString(superclass_name_index, (byte)7);
|
||||
this.superclass_name = Utility.compactClassName(this.superclass_name, false);
|
||||
} else {
|
||||
this.superclass_name = "java.lang.Object";
|
||||
}
|
||||
this.interface_names = new String[interfaces.length];
|
||||
for (int j = 0; j < interfaces.length; j++) {
|
||||
String str = constant_pool.getConstantString(interfaces[j], (byte)7);
|
||||
this.interface_names[j] = Utility.compactClassName(str, false);
|
||||
}
|
||||
}
|
||||
|
||||
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, (byte)1);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitJavaClass(this);
|
||||
}
|
||||
|
||||
static final void Debug(String str) {
|
||||
if (debug)
|
||||
System.out.println(str);
|
||||
}
|
||||
|
||||
public void dump(File file) throws IOException {
|
||||
String parent = file.getParent();
|
||||
if (parent != null) {
|
||||
File dir = new File(parent);
|
||||
if (dir != null)
|
||||
dir.mkdirs();
|
||||
}
|
||||
dump(new DataOutputStream(new FileOutputStream(file)));
|
||||
}
|
||||
|
||||
public void dump(String file_name) throws IOException {
|
||||
dump(new File(file_name));
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
||||
DataOutputStream ds = new DataOutputStream(s);
|
||||
try {
|
||||
dump(ds);
|
||||
ds.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return s.toByteArray();
|
||||
}
|
||||
|
||||
public void dump(OutputStream file) throws IOException {
|
||||
dump(new DataOutputStream(file));
|
||||
}
|
||||
|
||||
public void dump(DataOutputStream file) throws IOException {
|
||||
file.writeInt(-889275714);
|
||||
file.writeShort(this.minor);
|
||||
file.writeShort(this.major);
|
||||
this.constant_pool.dump(file);
|
||||
file.writeShort(this.access_flags);
|
||||
file.writeShort(this.class_name_index);
|
||||
file.writeShort(this.superclass_name_index);
|
||||
file.writeShort(this.interfaces.length);
|
||||
for (int i = 0; i < this.interfaces.length; i++)
|
||||
file.writeShort(this.interfaces[i]);
|
||||
file.writeShort(this.fields.length);
|
||||
for (int j = 0; j < this.fields.length; j++)
|
||||
this.fields[j].dump(file);
|
||||
file.writeShort(this.methods.length);
|
||||
for (int k = 0; k < this.methods.length; k++)
|
||||
this.methods[k].dump(file);
|
||||
if (this.attributes != null) {
|
||||
file.writeShort(this.attributes.length);
|
||||
for (int m = 0; m < this.attributes.length; m++)
|
||||
this.attributes[m].dump(file);
|
||||
} else {
|
||||
file.writeShort(0);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
public Attribute[] getAttributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return this.class_name;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return this.package_name;
|
||||
}
|
||||
|
||||
public int getClassNameIndex() {
|
||||
return this.class_name_index;
|
||||
}
|
||||
|
||||
public ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public Field[] getFields() {
|
||||
return this.fields;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.file_name;
|
||||
}
|
||||
|
||||
public String[] getInterfaceNames() {
|
||||
return this.interface_names;
|
||||
}
|
||||
|
||||
public int[] getInterfaces() {
|
||||
return this.interfaces;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return this.major;
|
||||
}
|
||||
|
||||
public Method[] getMethods() {
|
||||
return this.methods;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return this.minor;
|
||||
}
|
||||
|
||||
public String getSourceFileName() {
|
||||
return this.source_file_name;
|
||||
}
|
||||
|
||||
public String getSuperclassName() {
|
||||
return this.superclass_name;
|
||||
}
|
||||
|
||||
public int getSuperclassNameIndex() {
|
||||
return this.superclass_name_index;
|
||||
}
|
||||
|
||||
static {
|
||||
String debug = System.getProperty("JavaClass.debug");
|
||||
if (debug != null)
|
||||
JavaClass.debug = new Boolean(debug).booleanValue();
|
||||
String sep = System.getProperty("file.separator");
|
||||
if (sep != null)
|
||||
try {
|
||||
JavaClass.sep = sep.charAt(0);
|
||||
} catch (StringIndexOutOfBoundsException e) {}
|
||||
}
|
||||
|
||||
public void setAttributes(Attribute[] attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public void setClassName(String class_name) {
|
||||
this.class_name = class_name;
|
||||
}
|
||||
|
||||
public void setClassNameIndex(int class_name_index) {
|
||||
this.class_name_index = class_name_index;
|
||||
}
|
||||
|
||||
public void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public void setFields(Field[] fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public void setFileName(String file_name) {
|
||||
this.file_name = file_name;
|
||||
}
|
||||
|
||||
public void setInterfaceNames(String[] interface_names) {
|
||||
this.interface_names = interface_names;
|
||||
}
|
||||
|
||||
public void setInterfaces(int[] interfaces) {
|
||||
this.interfaces = interfaces;
|
||||
}
|
||||
|
||||
public void setMajor(int major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public void setMethods(Method[] methods) {
|
||||
this.methods = methods;
|
||||
}
|
||||
|
||||
public void setMinor(int minor) {
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public void setSourceFileName(String source_file_name) {
|
||||
this.source_file_name = source_file_name;
|
||||
}
|
||||
|
||||
public void setSuperclassName(String superclass_name) {
|
||||
this.superclass_name = superclass_name;
|
||||
}
|
||||
|
||||
public void setSuperclassNameIndex(int superclass_name_index) {
|
||||
this.superclass_name_index = superclass_name_index;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String access = Utility.accessToString(this.access_flags, true);
|
||||
access = access.equals("") ? "" : (access + " ");
|
||||
StringBuffer buf = new StringBuffer(access + Utility.classOrInterface(this.access_flags) + " " + this.class_name + " extends " + Utility.compactClassName(this.superclass_name, false) + '\n');
|
||||
int size = this.interfaces.length;
|
||||
if (size > 0) {
|
||||
buf.append("implements\t\t");
|
||||
for (int i = 0; i < size; i++) {
|
||||
buf.append(this.interface_names[i]);
|
||||
if (i < size - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append('\n');
|
||||
}
|
||||
buf.append("filename\t\t" + this.file_name + '\n');
|
||||
buf.append("compiled from\t\t" + this.source_file_name + '\n');
|
||||
buf.append("compiler version\t" + this.major + "." + this.minor + '\n');
|
||||
buf.append("access flags\t\t" + this.access_flags + '\n');
|
||||
buf.append("constant pool\t\t" + this.constant_pool.getLength() + " entries\n");
|
||||
buf.append("ACC_SUPER flag\t\t" + isSuper() + "\n");
|
||||
if (this.attributes.length > 0) {
|
||||
buf.append("\nAttribute(s):\n");
|
||||
for (int i = 0; i < this.attributes.length; i++)
|
||||
buf.append(indent(this.attributes[i]));
|
||||
}
|
||||
if (this.fields.length > 0) {
|
||||
buf.append("\n" + this.fields.length + " fields:\n");
|
||||
for (int i = 0; i < this.fields.length; i++)
|
||||
buf.append("\t" + this.fields[i] + '\n');
|
||||
}
|
||||
if (this.methods.length > 0) {
|
||||
buf.append("\n" + this.methods.length + " methods:\n");
|
||||
for (int i = 0; i < this.methods.length; i++)
|
||||
buf.append("\t" + this.methods[i] + '\n');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static final String indent(Object obj) {
|
||||
StringTokenizer tok = new StringTokenizer(obj.toString(), "\n");
|
||||
StringBuffer buf = new StringBuffer();
|
||||
while (tok.hasMoreTokens())
|
||||
buf.append("\t" + tok.nextToken() + "\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public JavaClass copy() {
|
||||
JavaClass c = null;
|
||||
try {
|
||||
c = (JavaClass)clone();
|
||||
} catch (CloneNotSupportedException e) {}
|
||||
c.constant_pool = this.constant_pool.copy();
|
||||
c.interfaces = (int[])this.interfaces.clone();
|
||||
c.interface_names = (String[])this.interface_names.clone();
|
||||
c.fields = new Field[this.fields.length];
|
||||
for (int i = 0; i < this.fields.length; i++)
|
||||
c.fields[i] = this.fields[i].copy(c.constant_pool);
|
||||
c.methods = new Method[this.methods.length];
|
||||
for (int j = 0; j < this.methods.length; j++)
|
||||
c.methods[j] = this.methods[j].copy(c.constant_pool);
|
||||
c.attributes = new Attribute[this.attributes.length];
|
||||
for (int k = 0; k < this.attributes.length; k++)
|
||||
c.attributes[k] = this.attributes[k].copy(c.constant_pool);
|
||||
return c;
|
||||
}
|
||||
|
||||
public final boolean instanceOf(JavaClass super_class) {
|
||||
return Repository.instanceOf(this, super_class);
|
||||
}
|
||||
|
||||
public final boolean isSuper() {
|
||||
return ((this.access_flags & 0x20) != 0);
|
||||
}
|
||||
|
||||
public final boolean isClass() {
|
||||
return ((this.access_flags & 0x200) == 0);
|
||||
}
|
||||
|
||||
public final byte getSource() {
|
||||
return this.source;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LineNumber implements Cloneable, Node {
|
||||
private int start_pc;
|
||||
|
||||
private int line_number;
|
||||
|
||||
public LineNumber(LineNumber c) {
|
||||
this(c.getStartPC(), c.getLineNumber());
|
||||
}
|
||||
|
||||
LineNumber(DataInputStream file) throws IOException {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort());
|
||||
}
|
||||
|
||||
public LineNumber(int start_pc, int line_number) {
|
||||
this.start_pc = start_pc;
|
||||
this.line_number = line_number;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitLineNumber(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.start_pc);
|
||||
file.writeShort(this.line_number);
|
||||
}
|
||||
|
||||
public final int getLineNumber() {
|
||||
return this.line_number;
|
||||
}
|
||||
|
||||
public final int getStartPC() {
|
||||
return this.start_pc;
|
||||
}
|
||||
|
||||
public final void setLineNumber(int line_number) {
|
||||
this.line_number = line_number;
|
||||
}
|
||||
|
||||
public final void setStartPC(int start_pc) {
|
||||
this.start_pc = start_pc;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "LineNumber(" + this.start_pc + ", " + this.line_number + ")";
|
||||
}
|
||||
|
||||
public LineNumber copy() {
|
||||
try {
|
||||
return (LineNumber)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LineNumberTable extends Attribute {
|
||||
private int line_number_table_length;
|
||||
|
||||
private LineNumber[] line_number_table;
|
||||
|
||||
public LineNumberTable(LineNumberTable c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getLineNumberTable(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public LineNumberTable(int name_index, int length, LineNumber[] line_number_table, ConstantPool constant_pool) {
|
||||
super((byte)4, name_index, length, constant_pool);
|
||||
setLineNumberTable(line_number_table);
|
||||
}
|
||||
|
||||
LineNumberTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (LineNumber[])null, constant_pool);
|
||||
this.line_number_table_length = file.readUnsignedShort();
|
||||
this.line_number_table = new LineNumber[this.line_number_table_length];
|
||||
for (int i = 0; i < this.line_number_table_length; i++)
|
||||
this.line_number_table[i] = new LineNumber(file);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitLineNumberTable(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.line_number_table_length);
|
||||
for (int i = 0; i < this.line_number_table_length; i++)
|
||||
this.line_number_table[i].dump(file);
|
||||
}
|
||||
|
||||
public final LineNumber[] getLineNumberTable() {
|
||||
return this.line_number_table;
|
||||
}
|
||||
|
||||
public final void setLineNumberTable(LineNumber[] line_number_table) {
|
||||
this.line_number_table = line_number_table;
|
||||
this.line_number_table_length = (line_number_table == null) ? 0 : line_number_table.length;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
StringBuffer line = new StringBuffer();
|
||||
for (int i = 0; i < this.line_number_table_length; i++) {
|
||||
line.append(this.line_number_table[i].toString());
|
||||
if (i < this.line_number_table_length - 1)
|
||||
line.append(", ");
|
||||
if (line.length() > 72) {
|
||||
line.append('\n');
|
||||
buf.append((Object)line);
|
||||
line.setLength(0);
|
||||
}
|
||||
}
|
||||
buf.append((Object)line);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public int getSourceLine(int pos) {
|
||||
int l = 0, r = this.line_number_table_length - 1;
|
||||
if (r < 0)
|
||||
return -1;
|
||||
int min_index = -1, min = -1;
|
||||
do {
|
||||
int i = (l + r) / 2;
|
||||
int j = this.line_number_table[i].getStartPC();
|
||||
if (j == pos)
|
||||
return this.line_number_table[i].getLineNumber();
|
||||
if (pos < j) {
|
||||
r = i - 1;
|
||||
} else {
|
||||
l = i + 1;
|
||||
}
|
||||
if (j >= pos || j <= min)
|
||||
continue;
|
||||
min = j;
|
||||
min_index = i;
|
||||
} while (l <= r);
|
||||
return this.line_number_table[min_index].getLineNumber();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
LineNumberTable c = (LineNumberTable)clone();
|
||||
c.line_number_table = new LineNumber[this.line_number_table_length];
|
||||
for (int i = 0; i < this.line_number_table_length; i++)
|
||||
c.line_number_table[i] = this.line_number_table[i].copy();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
|
||||
public final int getTableLength() {
|
||||
return this.line_number_table_length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public final class LocalVariable implements Constants, Cloneable, Node {
|
||||
private int start_pc;
|
||||
|
||||
private int length;
|
||||
|
||||
private int name_index;
|
||||
|
||||
private int signature_index;
|
||||
|
||||
private int index;
|
||||
|
||||
private ConstantPool constant_pool;
|
||||
|
||||
public LocalVariable(LocalVariable c) {
|
||||
this(c.getStartPC(), c.getLength(), c.getNameIndex(), c.getSignatureIndex(), c.getIndex(), c.getConstantPool());
|
||||
}
|
||||
|
||||
LocalVariable(DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
|
||||
}
|
||||
|
||||
public LocalVariable(int start_pc, int length, int name_index, int signature_index, int index, ConstantPool constant_pool) {
|
||||
this.start_pc = start_pc;
|
||||
this.length = length;
|
||||
this.name_index = name_index;
|
||||
this.signature_index = signature_index;
|
||||
this.index = index;
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitLocalVariable(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.start_pc);
|
||||
file.writeShort(this.length);
|
||||
file.writeShort(this.name_index);
|
||||
file.writeShort(this.signature_index);
|
||||
file.writeShort(this.index);
|
||||
}
|
||||
|
||||
public final ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public final int getLength() {
|
||||
return this.length;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.name_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final int getNameIndex() {
|
||||
return this.name_index;
|
||||
}
|
||||
|
||||
public final String getSignature() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.signature_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final int getSignatureIndex() {
|
||||
return this.signature_index;
|
||||
}
|
||||
|
||||
public final int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public final int getStartPC() {
|
||||
return this.start_pc;
|
||||
}
|
||||
|
||||
public final void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public final void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public final void setNameIndex(int name_index) {
|
||||
this.name_index = name_index;
|
||||
}
|
||||
|
||||
public final void setSignatureIndex(int signature_index) {
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public final void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public final void setStartPC(int start_pc) {
|
||||
this.start_pc = start_pc;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
String name = getName(), signature = Utility.signatureToString(getSignature());
|
||||
return "LocalVariable(start_pc = " + this.start_pc + ", length = " + this.length + ", index = " + this.index + ":" + signature + " " + name + ")";
|
||||
}
|
||||
|
||||
public LocalVariable copy() {
|
||||
try {
|
||||
return (LocalVariable)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LocalVariableTable extends Attribute {
|
||||
private int local_variable_table_length;
|
||||
|
||||
private LocalVariable[] local_variable_table;
|
||||
|
||||
public LocalVariableTable(LocalVariableTable c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getLocalVariableTable(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public LocalVariableTable(int name_index, int length, LocalVariable[] local_variable_table, ConstantPool constant_pool) {
|
||||
super((byte)5, name_index, length, constant_pool);
|
||||
setLocalVariableTable(local_variable_table);
|
||||
}
|
||||
|
||||
LocalVariableTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (LocalVariable[])null, constant_pool);
|
||||
this.local_variable_table_length = file.readUnsignedShort();
|
||||
this.local_variable_table = new LocalVariable[this.local_variable_table_length];
|
||||
for (int i = 0; i < this.local_variable_table_length; i++)
|
||||
this.local_variable_table[i] = new LocalVariable(file, constant_pool);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitLocalVariableTable(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.local_variable_table_length);
|
||||
for (int i = 0; i < this.local_variable_table_length; i++)
|
||||
this.local_variable_table[i].dump(file);
|
||||
}
|
||||
|
||||
public final LocalVariable[] getLocalVariableTable() {
|
||||
return this.local_variable_table;
|
||||
}
|
||||
|
||||
public final LocalVariable getLocalVariable(int index) {
|
||||
for (int i = 0; i < this.local_variable_table_length; i++) {
|
||||
if (this.local_variable_table[i].getIndex() == index)
|
||||
return this.local_variable_table[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final void setLocalVariableTable(LocalVariable[] local_variable_table) {
|
||||
this.local_variable_table = local_variable_table;
|
||||
this.local_variable_table_length = (local_variable_table == null) ? 0 : local_variable_table.length;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer("");
|
||||
for (int i = 0; i < this.local_variable_table_length; i++) {
|
||||
buf.append(this.local_variable_table[i].toString());
|
||||
if (i < this.local_variable_table_length - 1)
|
||||
buf.append('\n');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
LocalVariableTable c = (LocalVariableTable)clone();
|
||||
c.local_variable_table = new LocalVariable[this.local_variable_table_length];
|
||||
for (int i = 0; i < this.local_variable_table_length; i++)
|
||||
c.local_variable_table[i] = this.local_variable_table[i].copy();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
|
||||
public final int getTableLength() {
|
||||
return this.local_variable_table_length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Method extends FieldOrMethod {
|
||||
public Method() {}
|
||||
|
||||
public Method(Method c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
Method(DataInputStream file, ConstantPool constant_pool) throws IOException, ClassFormatError {
|
||||
super(file, 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);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitMethod(this);
|
||||
}
|
||||
|
||||
public final Code getCode() {
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
if (this.attributes[i] instanceof Code)
|
||||
return (Code)this.attributes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final ExceptionTable getExceptionTable() {
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
if (this.attributes[i] instanceof ExceptionTable)
|
||||
return (ExceptionTable)this.attributes[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final LocalVariableTable getLocalVariableTable() {
|
||||
Code code = getCode();
|
||||
if (code != null)
|
||||
return code.getLocalVariableTable();
|
||||
return null;
|
||||
}
|
||||
|
||||
public final LineNumberTable getLineNumberTable() {
|
||||
Code code = getCode();
|
||||
if (code != null)
|
||||
return code.getLineNumberTable();
|
||||
return null;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
String access = Utility.accessToString(this.access_flags);
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.signature_index, (byte)1);
|
||||
String signature = c.getBytes();
|
||||
c = (ConstantUtf8)this.constant_pool.getConstant(this.name_index, (byte)1);
|
||||
String name = c.getBytes();
|
||||
signature = Utility.methodSignatureToString(signature, name, access, true, getLocalVariableTable());
|
||||
StringBuffer buf = new StringBuffer(signature);
|
||||
for (int i = 0; i < this.attributes_count; i++) {
|
||||
Attribute a = this.attributes[i];
|
||||
if (!(a instanceof Code) && !(a instanceof ExceptionTable))
|
||||
buf.append(" [" + a.toString() + "]");
|
||||
}
|
||||
ExceptionTable e = getExceptionTable();
|
||||
if (e != null) {
|
||||
String str = e.toString();
|
||||
if (!str.equals(""))
|
||||
buf.append("\n\t\tthrows " + str);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public final Method copy(ConstantPool constant_pool) {
|
||||
return (Method)copy_(constant_pool);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
public interface Node {
|
||||
void accept(Visitor paramVisitor);
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class PMGClass extends Attribute {
|
||||
private int pmg_class_index;
|
||||
|
||||
private int pmg_index;
|
||||
|
||||
public PMGClass(PMGClass c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), c.getConstantPool());
|
||||
}
|
||||
|
||||
PMGClass(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
|
||||
}
|
||||
|
||||
public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index, ConstantPool constant_pool) {
|
||||
super((byte)9, name_index, length, constant_pool);
|
||||
this.pmg_index = pmg_index;
|
||||
this.pmg_class_index = pmg_class_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
System.err.println("Visiting non-standard PMGClass object");
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.pmg_index);
|
||||
file.writeShort(this.pmg_class_index);
|
||||
}
|
||||
|
||||
public final int getPMGClassIndex() {
|
||||
return this.pmg_class_index;
|
||||
}
|
||||
|
||||
public final void setPMGClassIndex(int pmg_class_index) {
|
||||
this.pmg_class_index = pmg_class_index;
|
||||
}
|
||||
|
||||
public final int getPMGIndex() {
|
||||
return this.pmg_index;
|
||||
}
|
||||
|
||||
public final void setPMGIndex(int pmg_index) {
|
||||
this.pmg_index = pmg_index;
|
||||
}
|
||||
|
||||
public final String getPMGName() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.pmg_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final String getPMGClassName() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.pmg_class_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")";
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
return (PMGClass)clone();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Signature extends Attribute {
|
||||
private int signature_index;
|
||||
|
||||
public Signature(Signature c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool());
|
||||
}
|
||||
|
||||
Signature(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, file.readUnsignedShort(), constant_pool);
|
||||
}
|
||||
|
||||
public Signature(int name_index, int length, int signature_index, ConstantPool constant_pool) {
|
||||
super((byte)10, name_index, length, constant_pool);
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
System.err.println("Visiting non-standard Signature object");
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.signature_index);
|
||||
}
|
||||
|
||||
public final int getSignatureIndex() {
|
||||
return this.signature_index;
|
||||
}
|
||||
|
||||
public final void setSignatureIndex(int signature_index) {
|
||||
this.signature_index = signature_index;
|
||||
}
|
||||
|
||||
public final String getSignature() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.signature_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
private static final class MyByteArrayInputStream extends ByteArrayInputStream {
|
||||
MyByteArrayInputStream(String data) {
|
||||
super(data.getBytes());
|
||||
}
|
||||
|
||||
final int mark() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
final String getData() {
|
||||
return new String(this.buf);
|
||||
}
|
||||
|
||||
final void reset(int p) {
|
||||
this.pos = p;
|
||||
}
|
||||
|
||||
final void unread() {
|
||||
if (this.pos > 0)
|
||||
this.pos--;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean identStart(int ch) {
|
||||
return (ch == 84 || ch == 76);
|
||||
}
|
||||
|
||||
private static boolean identPart(int ch) {
|
||||
return (ch == 47 || ch == 59);
|
||||
}
|
||||
|
||||
private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) {
|
||||
int ch;
|
||||
if ((ch = in.read()) == -1)
|
||||
throw new RuntimeException("Illegal signature: " + in.getData() + " no ident, reaching EOF");
|
||||
if (!identStart(ch)) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
int count = 1;
|
||||
while (Character.isJavaIdentifierPart((char)ch)) {
|
||||
stringBuffer.append((char)ch);
|
||||
count++;
|
||||
ch = in.read();
|
||||
}
|
||||
if (ch == 58) {
|
||||
in.skip((long)"Ljava/lang/Object".length());
|
||||
buf.append((Object)stringBuffer);
|
||||
ch = in.read();
|
||||
in.unread();
|
||||
} else {
|
||||
for (int i = 0; i < count; i++)
|
||||
in.unread();
|
||||
}
|
||||
return;
|
||||
}
|
||||
StringBuffer buf2 = new StringBuffer();
|
||||
ch = in.read();
|
||||
do {
|
||||
buf2.append((char)ch);
|
||||
ch = in.read();
|
||||
} while (ch != -1 && (Character.isJavaIdentifierPart((char)ch) || ch == 47));
|
||||
buf.append(buf2.toString().replace('/', '.'));
|
||||
if (ch != -1)
|
||||
in.unread();
|
||||
}
|
||||
|
||||
private static final void matchGJIdent(MyByteArrayInputStream in, StringBuffer buf) {
|
||||
matchIdent(in, buf);
|
||||
int ch = in.read();
|
||||
if (ch == 60 || ch == 40) {
|
||||
buf.append((char)ch);
|
||||
matchGJIdent(in, buf);
|
||||
while ((ch = in.read()) != 62 && ch != 41) {
|
||||
if (ch == -1)
|
||||
throw new RuntimeException("Illegal signature: " + in.getData() + " reaching EOF");
|
||||
buf.append(", ");
|
||||
in.unread();
|
||||
matchGJIdent(in, buf);
|
||||
}
|
||||
buf.append((char)ch);
|
||||
} else {
|
||||
in.unread();
|
||||
}
|
||||
ch = in.read();
|
||||
if (identStart(ch)) {
|
||||
in.unread();
|
||||
matchGJIdent(in, buf);
|
||||
} else {
|
||||
if (ch == 41) {
|
||||
in.unread();
|
||||
return;
|
||||
}
|
||||
if (ch != 59)
|
||||
throw new RuntimeException("Illegal signature: " + in.getData() + " read " + (char)ch);
|
||||
}
|
||||
}
|
||||
|
||||
public static String translate(String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
matchGJIdent(new MyByteArrayInputStream(s), buf);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static final boolean isFormalParameterList(String s) {
|
||||
return (s.startsWith("<") && s.indexOf(':') > 0);
|
||||
}
|
||||
|
||||
public static final boolean isActualParameterList(String s) {
|
||||
return (s.startsWith("L") && s.endsWith(">;"));
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
String s = getSignature();
|
||||
return "Signature(" + s + ")";
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
return (Signature)clone();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class SourceFile extends Attribute {
|
||||
private int sourcefile_index;
|
||||
|
||||
public SourceFile(SourceFile c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), c.getConstantPool());
|
||||
}
|
||||
|
||||
SourceFile(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, file.readUnsignedShort(), constant_pool);
|
||||
}
|
||||
|
||||
public SourceFile(int name_index, int length, int sourcefile_index, ConstantPool constant_pool) {
|
||||
super((byte)0, name_index, length, constant_pool);
|
||||
this.sourcefile_index = sourcefile_index;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitSourceFile(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.sourcefile_index);
|
||||
}
|
||||
|
||||
public final int getSourceFileIndex() {
|
||||
return this.sourcefile_index;
|
||||
}
|
||||
|
||||
public final void setSourceFileIndex(int sourcefile_index) {
|
||||
this.sourcefile_index = sourcefile_index;
|
||||
}
|
||||
|
||||
public final String getSourceFileName() {
|
||||
ConstantUtf8 c = (ConstantUtf8)this.constant_pool.getConstant(this.sourcefile_index, (byte)1);
|
||||
return c.getBytes();
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "SourceFile(" + getSourceFileName() + ")";
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
return (SourceFile)clone();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class StackMap extends Attribute implements Node {
|
||||
private int map_length;
|
||||
|
||||
private StackMapEntry[] map;
|
||||
|
||||
public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) {
|
||||
super((byte)11, name_index, length, constant_pool);
|
||||
setStackMap(map);
|
||||
}
|
||||
|
||||
StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (StackMapEntry[])null, constant_pool);
|
||||
this.map_length = file.readUnsignedShort();
|
||||
this.map = new StackMapEntry[this.map_length];
|
||||
for (int i = 0; i < this.map_length; i++)
|
||||
this.map[i] = new StackMapEntry(file, constant_pool);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
file.writeShort(this.map_length);
|
||||
for (int i = 0; i < this.map_length; i++)
|
||||
this.map[i].dump(file);
|
||||
}
|
||||
|
||||
public final StackMapEntry[] getStackMap() {
|
||||
return this.map;
|
||||
}
|
||||
|
||||
public final void setStackMap(StackMapEntry[] map) {
|
||||
this.map = map;
|
||||
this.map_length = (map == null) ? 0 : map.length;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer("StackMap(");
|
||||
for (int i = 0; i < this.map_length; i++) {
|
||||
buf.append(this.map[i].toString());
|
||||
if (i < this.map_length - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(')');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
StackMap c = (StackMap)clone();
|
||||
c.map = new StackMapEntry[this.map_length];
|
||||
for (int i = 0; i < this.map_length; i++)
|
||||
c.map[i] = this.map[i].copy();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackMap(this);
|
||||
}
|
||||
|
||||
public final int getMapLength() {
|
||||
return this.map_length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class StackMapEntry implements Cloneable {
|
||||
private int byte_code_offset;
|
||||
|
||||
private int number_of_locals;
|
||||
|
||||
private StackMapType[] types_of_locals;
|
||||
|
||||
private int number_of_stack_items;
|
||||
|
||||
private StackMapType[] types_of_stack_items;
|
||||
|
||||
private ConstantPool constant_pool;
|
||||
|
||||
StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(file.readShort(), file.readShort(), null, -1, null, constant_pool);
|
||||
this.types_of_locals = new StackMapType[this.number_of_locals];
|
||||
for (int i = 0; i < this.number_of_locals; i++)
|
||||
this.types_of_locals[i] = new StackMapType(file, constant_pool);
|
||||
this.number_of_stack_items = file.readShort();
|
||||
this.types_of_stack_items = new StackMapType[this.number_of_stack_items];
|
||||
for (int j = 0; j < this.number_of_stack_items; j++)
|
||||
this.types_of_stack_items[j] = new StackMapType(file, constant_pool);
|
||||
}
|
||||
|
||||
public StackMapEntry(int byte_code_offset, int number_of_locals, StackMapType[] types_of_locals, int number_of_stack_items, StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
|
||||
this.byte_code_offset = byte_code_offset;
|
||||
this.number_of_locals = number_of_locals;
|
||||
this.types_of_locals = types_of_locals;
|
||||
this.number_of_stack_items = number_of_stack_items;
|
||||
this.types_of_stack_items = types_of_stack_items;
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeShort(this.byte_code_offset);
|
||||
file.writeShort(this.number_of_locals);
|
||||
for (int i = 0; i < this.number_of_locals; i++)
|
||||
this.types_of_locals[i].dump(file);
|
||||
file.writeShort(this.number_of_stack_items);
|
||||
for (int j = 0; j < this.number_of_stack_items; j++)
|
||||
this.types_of_stack_items[j].dump(file);
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer("(offset=" + this.byte_code_offset);
|
||||
if (this.number_of_locals > 0) {
|
||||
buf.append(", locals={");
|
||||
for (int i = 0; i < this.number_of_locals; i++) {
|
||||
buf.append(this.types_of_locals[i]);
|
||||
if (i < this.number_of_locals - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append("}");
|
||||
}
|
||||
if (this.number_of_stack_items > 0) {
|
||||
buf.append(", stack items={");
|
||||
for (int i = 0; i < this.number_of_stack_items; i++) {
|
||||
buf.append(this.types_of_stack_items[i]);
|
||||
if (i < this.number_of_stack_items - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append("}");
|
||||
}
|
||||
buf.append(")");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public void setByteCodeOffset(int b) {
|
||||
this.byte_code_offset = b;
|
||||
}
|
||||
|
||||
public int getByteCodeOffset() {
|
||||
return this.byte_code_offset;
|
||||
}
|
||||
|
||||
public void setNumberOfLocals(int n) {
|
||||
this.number_of_locals = n;
|
||||
}
|
||||
|
||||
public int getNumberOfLocals() {
|
||||
return this.number_of_locals;
|
||||
}
|
||||
|
||||
public void setTypesOfLocals(StackMapType[] t) {
|
||||
this.types_of_locals = t;
|
||||
}
|
||||
|
||||
public StackMapType[] getTypesOfLocals() {
|
||||
return this.types_of_locals;
|
||||
}
|
||||
|
||||
public void setNumberOfStackItems(int n) {
|
||||
this.number_of_stack_items = n;
|
||||
}
|
||||
|
||||
public int getNumberOfStackItems() {
|
||||
return this.number_of_stack_items;
|
||||
}
|
||||
|
||||
public void setTypesOfStackItems(StackMapType[] t) {
|
||||
this.types_of_stack_items = t;
|
||||
}
|
||||
|
||||
public StackMapType[] getTypesOfStackItems() {
|
||||
return this.types_of_stack_items;
|
||||
}
|
||||
|
||||
public StackMapEntry copy() {
|
||||
try {
|
||||
return (StackMapEntry)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackMapEntry(this);
|
||||
}
|
||||
|
||||
public final ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public final void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public final class StackMapType implements Cloneable {
|
||||
private byte type;
|
||||
|
||||
private int index = -1;
|
||||
|
||||
private ConstantPool constant_pool;
|
||||
|
||||
StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(file.readByte(), -1, constant_pool);
|
||||
if (hasIndex())
|
||||
setIndex(file.readShort());
|
||||
setConstantPool(constant_pool);
|
||||
}
|
||||
|
||||
public StackMapType(byte type, int index, ConstantPool constant_pool) {
|
||||
setType(type);
|
||||
setIndex(index);
|
||||
setConstantPool(constant_pool);
|
||||
}
|
||||
|
||||
public void setType(byte t) {
|
||||
if (t < 0 || t > 8)
|
||||
throw new RuntimeException("Illegal type for StackMapType: " + t);
|
||||
this.type = t;
|
||||
}
|
||||
|
||||
public byte getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setIndex(int t) {
|
||||
this.index = t;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
file.writeByte(this.type);
|
||||
if (hasIndex())
|
||||
file.writeShort(getIndex());
|
||||
}
|
||||
|
||||
public final boolean hasIndex() {
|
||||
return (this.type == 7 || this.type == 8);
|
||||
}
|
||||
|
||||
private String printIndex() {
|
||||
if (this.type == 7)
|
||||
return ", class=" + this.constant_pool.constantToString(this.index, (byte)7);
|
||||
if (this.type == 8)
|
||||
return ", offset=" + this.index;
|
||||
return "";
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
return "(type=" + Constants.ITEM_NAMES[this.type] + printIndex() + ")";
|
||||
}
|
||||
|
||||
public StackMapType copy() {
|
||||
try {
|
||||
return (StackMapType)clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public final ConstantPool getConstantPool() {
|
||||
return this.constant_pool;
|
||||
}
|
||||
|
||||
public final void setConstantPool(ConstantPool constant_pool) {
|
||||
this.constant_pool = constant_pool;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public final class Synthetic extends Attribute {
|
||||
private byte[] bytes;
|
||||
|
||||
public Synthetic(Synthetic c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public Synthetic(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
|
||||
super((byte)7, name_index, length, constant_pool);
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (byte[])null, constant_pool);
|
||||
if (length > 0) {
|
||||
this.bytes = new byte[length];
|
||||
file.readFully(this.bytes);
|
||||
System.err.println("Synthetic attribute with length > 0");
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitSynthetic(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
if (this.length > 0)
|
||||
file.write(this.bytes, 0, this.length);
|
||||
}
|
||||
|
||||
public final byte[] getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
StringBuffer buf = new StringBuffer("Synthetic");
|
||||
if (this.length > 0)
|
||||
buf.append(" " + Utility.toHexString(this.bytes));
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
Synthetic c = (Synthetic)clone();
|
||||
if (this.bytes != null)
|
||||
c.bytes = (byte[])this.bytes.clone();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class Unknown extends Attribute {
|
||||
private byte[] bytes;
|
||||
|
||||
private String name;
|
||||
|
||||
private static HashMap unknown_attributes = new HashMap();
|
||||
|
||||
static Unknown[] getUnknownAttributes() {
|
||||
Unknown[] unknowns = new Unknown[unknown_attributes.size()];
|
||||
Iterator entries = unknown_attributes.values().iterator();
|
||||
for (int i = 0; entries.hasNext(); i++)
|
||||
unknowns[i] = (Unknown)entries.next();
|
||||
unknown_attributes.clear();
|
||||
return unknowns;
|
||||
}
|
||||
|
||||
public Unknown(Unknown c) {
|
||||
this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
|
||||
}
|
||||
|
||||
public Unknown(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
|
||||
super((byte)-1, name_index, length, constant_pool);
|
||||
this.bytes = bytes;
|
||||
this.name = ((ConstantUtf8)constant_pool.getConstant(name_index, (byte)1)).getBytes();
|
||||
unknown_attributes.put(this.name, this);
|
||||
}
|
||||
|
||||
Unknown(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
|
||||
this(name_index, length, (byte[])null, constant_pool);
|
||||
if (length > 0) {
|
||||
this.bytes = new byte[length];
|
||||
file.readFully(this.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitUnknown(this);
|
||||
}
|
||||
|
||||
public final void dump(DataOutputStream file) throws IOException {
|
||||
super.dump(file);
|
||||
if (this.length > 0)
|
||||
file.write(this.bytes, 0, this.length);
|
||||
}
|
||||
|
||||
public final byte[] getBytes() {
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public final String toString() {
|
||||
String str;
|
||||
if (this.length == 0 || this.bytes == null)
|
||||
return "(Unknown attribute " + this.name + ")";
|
||||
if (this.length > 10) {
|
||||
byte[] tmp = new byte[10];
|
||||
System.arraycopy(this.bytes, 0, tmp, 0, 10);
|
||||
str = Utility.toHexString(tmp) + "... (truncated)";
|
||||
} else {
|
||||
str = Utility.toHexString(this.bytes);
|
||||
}
|
||||
return "(Unknown attribute " + this.name + ": " + str + ")";
|
||||
}
|
||||
|
||||
public Attribute copy(ConstantPool constant_pool) {
|
||||
Unknown c = (Unknown)clone();
|
||||
if (this.bytes != null)
|
||||
c.bytes = (byte[])this.bytes.clone();
|
||||
c.constant_pool = constant_pool;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,789 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.FilterReader;
|
||||
import java.io.FilterWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import org.apache.bcel.Constants;
|
||||
import org.apache.bcel.util.ByteSequence;
|
||||
|
||||
public abstract class Utility {
|
||||
private static int consumed_chars;
|
||||
|
||||
private static boolean wide = false;
|
||||
|
||||
private static final int FREE_CHARS = 48;
|
||||
|
||||
public static final String accessToString(int access_flags) {
|
||||
return accessToString(access_flags, false);
|
||||
}
|
||||
|
||||
public static final String accessToString(int access_flags, boolean for_class) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int p = 0;
|
||||
for (int i = 0; p < 1024; i++) {
|
||||
p = pow2(i);
|
||||
if ((access_flags & p) != 0)
|
||||
if (!for_class || (p != 32 && p != 512))
|
||||
buf.append(Constants.ACCESS_NAMES[i] + " ");
|
||||
}
|
||||
return buf.toString().trim();
|
||||
}
|
||||
|
||||
public static final String classOrInterface(int access_flags) {
|
||||
return ((access_flags & 0x200) != 0) ? "interface" : "class";
|
||||
}
|
||||
|
||||
public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length, boolean verbose) {
|
||||
StringBuffer buf = new StringBuffer(code.length * 20);
|
||||
ByteSequence stream = new ByteSequence(code);
|
||||
try {
|
||||
for (int i = 0; i < index; i++)
|
||||
codeToString(stream, constant_pool, verbose);
|
||||
for (int j = 0; stream.available() > 0; j++) {
|
||||
if (length < 0 || j < length) {
|
||||
String indices = fillup(stream.getIndex() + ":", 6, true, ' ');
|
||||
buf.append(indices + codeToString(stream, constant_pool, verbose) + '\n');
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(buf.toString());
|
||||
e.printStackTrace();
|
||||
throw new ClassFormatError("Byte code error: " + e);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static final String codeToString(byte[] code, ConstantPool constant_pool, int index, int length) {
|
||||
return codeToString(code, constant_pool, index, length, true);
|
||||
}
|
||||
|
||||
public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool, boolean verbose) throws IOException {
|
||||
int low, high, npairs, index, j, k, match[], jump_table[], offset, i, m, nargs, dimensions;
|
||||
short opcode = (short)bytes.readUnsignedByte();
|
||||
int default_offset = 0;
|
||||
int no_pad_bytes = 0;
|
||||
StringBuffer buf = new StringBuffer(Constants.OPCODE_NAMES[opcode]);
|
||||
if (opcode == 170 || opcode == 171) {
|
||||
int remainder = bytes.getIndex() % 4;
|
||||
no_pad_bytes = (remainder == 0) ? 0 : (4 - remainder);
|
||||
for (int n = 0; n < no_pad_bytes; n++) {
|
||||
byte b;
|
||||
if ((b = bytes.readByte()) != 0)
|
||||
System.err.println("Warning: Padding byte != 0 in " + Constants.OPCODE_NAMES[opcode] + ":" + b);
|
||||
}
|
||||
default_offset = bytes.readInt();
|
||||
}
|
||||
switch (opcode) {
|
||||
case 170:
|
||||
low = bytes.readInt();
|
||||
high = bytes.readInt();
|
||||
offset = bytes.getIndex() - 12 - no_pad_bytes - 1;
|
||||
default_offset += offset;
|
||||
buf.append("\tdefault = " + default_offset + ", low = " + low + ", high = " + high + "(");
|
||||
jump_table = new int[high - low + 1];
|
||||
for (i = 0; i < jump_table.length; i++) {
|
||||
jump_table[i] = offset + bytes.readInt();
|
||||
buf.append(jump_table[i]);
|
||||
if (i < jump_table.length - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(")");
|
||||
break;
|
||||
case 171:
|
||||
npairs = bytes.readInt();
|
||||
offset = bytes.getIndex() - 8 - no_pad_bytes - 1;
|
||||
match = new int[npairs];
|
||||
jump_table = new int[npairs];
|
||||
default_offset += offset;
|
||||
buf.append("\tdefault = " + default_offset + ", npairs = " + npairs + " (");
|
||||
for (m = 0; m < npairs; m++) {
|
||||
match[m] = bytes.readInt();
|
||||
jump_table[m] = offset + bytes.readInt();
|
||||
buf.append("(" + match[m] + ", " + jump_table[m] + ")");
|
||||
if (m < npairs - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(")");
|
||||
break;
|
||||
case 153:
|
||||
case 154:
|
||||
case 155:
|
||||
case 156:
|
||||
case 157:
|
||||
case 158:
|
||||
case 159:
|
||||
case 160:
|
||||
case 161:
|
||||
case 162:
|
||||
case 163:
|
||||
case 164:
|
||||
case 165:
|
||||
case 166:
|
||||
case 167:
|
||||
case 168:
|
||||
case 198:
|
||||
case 199:
|
||||
buf.append("\t\t#" + (bytes.getIndex() - 1 + bytes.readShort()));
|
||||
break;
|
||||
case 200:
|
||||
case 201:
|
||||
buf.append("\t\t#" + (bytes.getIndex() - 1 + bytes.readInt()));
|
||||
break;
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 54:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 169:
|
||||
if (wide) {
|
||||
j = bytes.readUnsignedShort();
|
||||
wide = false;
|
||||
} else {
|
||||
j = bytes.readUnsignedByte();
|
||||
}
|
||||
buf.append("\t\t%" + j);
|
||||
break;
|
||||
case 196:
|
||||
wide = true;
|
||||
buf.append("\t(wide)");
|
||||
break;
|
||||
case 188:
|
||||
buf.append("\t\t<" + Constants.TYPE_NAMES[bytes.readByte()] + ">");
|
||||
break;
|
||||
case 178:
|
||||
case 179:
|
||||
case 180:
|
||||
case 181:
|
||||
index = bytes.readUnsignedShort();
|
||||
buf.append("\t\t" + constant_pool.constantToString(index, (byte)9) + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 187:
|
||||
case 192:
|
||||
buf.append("\t");
|
||||
case 193:
|
||||
index = bytes.readUnsignedShort();
|
||||
buf.append("\t<" + constant_pool.constantToString(index, (byte)7) + ">" + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 182:
|
||||
case 183:
|
||||
case 184:
|
||||
index = bytes.readUnsignedShort();
|
||||
buf.append("\t" + constant_pool.constantToString(index, (byte)10) + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 185:
|
||||
index = bytes.readUnsignedShort();
|
||||
nargs = bytes.readUnsignedByte();
|
||||
buf.append("\t" + constant_pool.constantToString(index, (byte)11) + (verbose ? (" (" + index + ")\t") : "") + nargs + "\t" + bytes.readUnsignedByte());
|
||||
break;
|
||||
case 19:
|
||||
case 20:
|
||||
index = bytes.readUnsignedShort();
|
||||
buf.append("\t\t" + constant_pool.constantToString(index, constant_pool.getConstant(index).getTag()) + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 18:
|
||||
index = bytes.readUnsignedByte();
|
||||
buf.append("\t\t" + constant_pool.constantToString(index, constant_pool.getConstant(index).getTag()) + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 189:
|
||||
index = bytes.readUnsignedShort();
|
||||
buf.append("\t\t<" + compactClassName(constant_pool.getConstantString(index, (byte)7), false) + ">" + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 197:
|
||||
index = bytes.readUnsignedShort();
|
||||
dimensions = bytes.readUnsignedByte();
|
||||
buf.append("\t<" + compactClassName(constant_pool.getConstantString(index, (byte)7), false) + ">\t" + dimensions + (verbose ? (" (" + index + ")") : ""));
|
||||
break;
|
||||
case 132:
|
||||
if (wide) {
|
||||
j = bytes.readUnsignedShort();
|
||||
k = bytes.readShort();
|
||||
wide = false;
|
||||
} else {
|
||||
j = bytes.readUnsignedByte();
|
||||
k = bytes.readByte();
|
||||
}
|
||||
buf.append("\t\t%" + j + "\t" + k);
|
||||
break;
|
||||
default:
|
||||
if (Constants.NO_OF_OPERANDS[opcode] > 0)
|
||||
for (int n = 0; n < (Constants.TYPE_OF_OPERANDS[opcode]).length; n++) {
|
||||
buf.append("\t\t");
|
||||
switch (Constants.TYPE_OF_OPERANDS[opcode][n]) {
|
||||
case 8:
|
||||
buf.append(bytes.readByte());
|
||||
break;
|
||||
case 9:
|
||||
buf.append(bytes.readShort());
|
||||
break;
|
||||
case 10:
|
||||
buf.append(bytes.readInt());
|
||||
break;
|
||||
default:
|
||||
System.err.println("Unreachable default case reached!");
|
||||
System.exit(-1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static final String codeToString(ByteSequence bytes, ConstantPool constant_pool) throws IOException {
|
||||
return codeToString(bytes, constant_pool, true);
|
||||
}
|
||||
|
||||
public static final String compactClassName(String str) {
|
||||
return compactClassName(str, true);
|
||||
}
|
||||
|
||||
public static final String compactClassName(String str, String prefix, boolean chopit) {
|
||||
int len = prefix.length();
|
||||
str = str.replace('/', '.');
|
||||
if (chopit)
|
||||
if (str.startsWith(prefix) && str.substring(len).indexOf('.') == -1)
|
||||
str = str.substring(len);
|
||||
return str;
|
||||
}
|
||||
|
||||
public static final String compactClassName(String str, boolean chopit) {
|
||||
return compactClassName(str, "java.lang.", chopit);
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public static final int setBit(int flag, int i) {
|
||||
return flag | pow2(i);
|
||||
}
|
||||
|
||||
public static final int clearBit(int flag, int i) {
|
||||
int bit = pow2(i);
|
||||
return ((flag & bit) == 0) ? flag : (flag ^ bit);
|
||||
}
|
||||
|
||||
public static final boolean isSet(int flag, int i) {
|
||||
return ((flag & pow2(i)) != 0);
|
||||
}
|
||||
|
||||
public static final String methodTypeToSignature(String ret, String[] argv) throws ClassFormatError {
|
||||
StringBuffer buf = new StringBuffer("(");
|
||||
if (argv != null)
|
||||
for (int i = 0; i < argv.length; i++) {
|
||||
String str1 = getSignature(argv[i]);
|
||||
if (str1.endsWith("V"))
|
||||
throw new ClassFormatError("Invalid type: " + argv[i]);
|
||||
buf.append(str1);
|
||||
}
|
||||
String str = getSignature(ret);
|
||||
buf.append(")" + str);
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static final String[] methodSignatureArgumentTypes(String signature) throws ClassFormatError {
|
||||
return methodSignatureArgumentTypes(signature, true);
|
||||
}
|
||||
|
||||
public static final String[] methodSignatureArgumentTypes(String signature, boolean chopit) throws ClassFormatError {
|
||||
ArrayList vec = new ArrayList();
|
||||
try {
|
||||
if (signature.charAt(0) != '(')
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
int index = 1;
|
||||
while (signature.charAt(index) != ')') {
|
||||
vec.add(signatureToString(signature.substring(index), chopit));
|
||||
index += consumed_chars;
|
||||
}
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
}
|
||||
String[] types = new String[vec.size()];
|
||||
vec.toArray(types);
|
||||
return types;
|
||||
}
|
||||
|
||||
public static final String methodSignatureReturnType(String signature) throws ClassFormatError {
|
||||
return methodSignatureReturnType(signature, true);
|
||||
}
|
||||
|
||||
public static final String methodSignatureReturnType(String signature, boolean chopit) throws ClassFormatError {
|
||||
String type;
|
||||
try {
|
||||
int index = signature.lastIndexOf(')') + 1;
|
||||
type = signatureToString(signature.substring(index), chopit);
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
public static final String methodSignatureToString(String signature, String name, String access) {
|
||||
return methodSignatureToString(signature, name, access, true);
|
||||
}
|
||||
|
||||
public static final String methodSignatureToString(String signature, String name, String access, boolean chopit) {
|
||||
return methodSignatureToString(signature, name, access, chopit, null);
|
||||
}
|
||||
|
||||
public static final String methodSignatureToString(String signature, String name, String access, boolean chopit, LocalVariableTable vars) throws ClassFormatError {
|
||||
String type;
|
||||
StringBuffer buf = new StringBuffer("(");
|
||||
int var_index = (access.indexOf("static") >= 0) ? 0 : 1;
|
||||
try {
|
||||
if (signature.charAt(0) != '(')
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
int index = 1;
|
||||
while (signature.charAt(index) != ')') {
|
||||
buf.append(signatureToString(signature.substring(index), chopit));
|
||||
if (vars != null) {
|
||||
LocalVariable l = vars.getLocalVariable(var_index);
|
||||
if (l != null)
|
||||
buf.append(" " + l.getName());
|
||||
} else {
|
||||
buf.append(" arg" + var_index);
|
||||
}
|
||||
var_index++;
|
||||
buf.append(", ");
|
||||
index += consumed_chars;
|
||||
}
|
||||
index++;
|
||||
type = signatureToString(signature.substring(index), chopit);
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
}
|
||||
if (buf.length() > 1)
|
||||
buf.setLength(buf.length() - 2);
|
||||
buf.append(")");
|
||||
return access + ((access.length() > 0) ? " " : "") + type + " " + name + buf.toString();
|
||||
}
|
||||
|
||||
private static final int pow2(int n) {
|
||||
return 1 << n;
|
||||
}
|
||||
|
||||
public static final String replace(String str, String old, String new_) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
try {
|
||||
int index;
|
||||
if ((index = str.indexOf(old)) != -1) {
|
||||
int old_index = 0;
|
||||
while ((index = str.indexOf(old, old_index)) != -1) {
|
||||
buf.append(str.substring(old_index, index));
|
||||
buf.append(new_);
|
||||
old_index = index + old.length();
|
||||
}
|
||||
buf.append(str.substring(old_index));
|
||||
str = buf.toString();
|
||||
}
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static final String signatureToString(String signature) {
|
||||
return signatureToString(signature, true);
|
||||
}
|
||||
|
||||
public static final String signatureToString(String signature, boolean chopit) {
|
||||
Utility.consumed_chars = 1;
|
||||
try {
|
||||
int index, n;
|
||||
StringBuffer brackets;
|
||||
String type;
|
||||
int consumed_chars;
|
||||
switch (signature.charAt(0)) {
|
||||
case 'B':
|
||||
return "byte";
|
||||
case 'C':
|
||||
return "char";
|
||||
case 'D':
|
||||
return "double";
|
||||
case 'F':
|
||||
return "float";
|
||||
case 'I':
|
||||
return "int";
|
||||
case 'J':
|
||||
return "long";
|
||||
case 'L':
|
||||
index = signature.indexOf(';');
|
||||
if (index < 0)
|
||||
throw new ClassFormatError("Invalid signature: " + signature);
|
||||
Utility.consumed_chars = index + 1;
|
||||
return compactClassName(signature.substring(1, index), chopit);
|
||||
case 'S':
|
||||
return "short";
|
||||
case 'Z':
|
||||
return "boolean";
|
||||
case '[':
|
||||
brackets = new StringBuffer();
|
||||
for (n = 0; signature.charAt(n) == '['; n++)
|
||||
brackets.append("[]");
|
||||
consumed_chars = n;
|
||||
type = signatureToString(signature.substring(n), chopit);
|
||||
Utility.consumed_chars += consumed_chars;
|
||||
return type + brackets.toString();
|
||||
case 'V':
|
||||
return "void";
|
||||
}
|
||||
throw new ClassFormatError("Invalid signature: `" + signature + "'");
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid signature: " + e + ":" + signature);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSignature(String type) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
char[] chars = type.toCharArray();
|
||||
boolean char_found = false, delim = false;
|
||||
int index = -1;
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
switch (chars[i]) {
|
||||
case '\t':
|
||||
case '\n':
|
||||
case '\f':
|
||||
case '\r':
|
||||
case ' ':
|
||||
if (char_found)
|
||||
delim = true;
|
||||
break;
|
||||
case '[':
|
||||
if (!char_found)
|
||||
throw new RuntimeException("Illegal type: " + type);
|
||||
index = i;
|
||||
break;
|
||||
default:
|
||||
char_found = true;
|
||||
if (!delim)
|
||||
buf.append(chars[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int brackets = 0;
|
||||
if (index > 0)
|
||||
brackets = countBrackets(type.substring(index));
|
||||
type = buf.toString();
|
||||
buf.setLength(0);
|
||||
for (int j = 0; j < brackets; j++)
|
||||
buf.append('[');
|
||||
boolean found = false;
|
||||
for (int k = 4; k <= 12 && !found; k++) {
|
||||
if (Constants.TYPE_NAMES[k].equals(type)) {
|
||||
found = true;
|
||||
buf.append(Constants.SHORT_TYPE_NAMES[k]);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
buf.append('L' + type.replace('.', '/') + ';');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (open)
|
||||
throw new RuntimeException("Illegally nested brackets:" + brackets);
|
||||
return count;
|
||||
}
|
||||
|
||||
public static final byte typeOfMethodSignature(String signature) throws ClassFormatError {
|
||||
try {
|
||||
if (signature.charAt(0) != '(')
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
int index = signature.lastIndexOf(')') + 1;
|
||||
return typeOfSignature(signature.substring(index));
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
}
|
||||
}
|
||||
|
||||
public static final byte typeOfSignature(String signature) throws ClassFormatError {
|
||||
try {
|
||||
switch (signature.charAt(0)) {
|
||||
case 'B':
|
||||
return 8;
|
||||
case 'C':
|
||||
return 5;
|
||||
case 'D':
|
||||
return 7;
|
||||
case 'F':
|
||||
return 6;
|
||||
case 'I':
|
||||
return 10;
|
||||
case 'J':
|
||||
return 11;
|
||||
case 'L':
|
||||
return 14;
|
||||
case '[':
|
||||
return 13;
|
||||
case 'V':
|
||||
return 12;
|
||||
case 'Z':
|
||||
return 4;
|
||||
case 'S':
|
||||
return 9;
|
||||
}
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new ClassFormatError("Invalid method signature: " + signature);
|
||||
}
|
||||
}
|
||||
|
||||
public static short searchOpcode(String name) {
|
||||
name = name.toLowerCase();
|
||||
for (short i = 0; i < Constants.OPCODE_NAMES.length; i = (short)(i + 1)) {
|
||||
if (Constants.OPCODE_NAMES[i].equals(name))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static final short byteToShort(byte b) {
|
||||
return (b < 0) ? (short)(256 + b) : (short)b;
|
||||
}
|
||||
|
||||
public static final String toHexString(byte[] bytes) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
short b = byteToShort(bytes[i]);
|
||||
String hex = Integer.toString(b, 16);
|
||||
if (b < 16)
|
||||
buf.append('0');
|
||||
buf.append(hex);
|
||||
if (i < bytes.length - 1)
|
||||
buf.append(' ');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static final String format(int i, int length, boolean left_justify, char fill) {
|
||||
return fillup(Integer.toString(i), length, left_justify, fill);
|
||||
}
|
||||
|
||||
public static final String fillup(String str, int length, boolean left_justify, char fill) {
|
||||
int len = length - str.length();
|
||||
char[] buf = new char[(len < 0) ? 0 : len];
|
||||
for (int j = 0; j < buf.length; j++)
|
||||
buf[j] = fill;
|
||||
if (left_justify)
|
||||
return str + new String(buf);
|
||||
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) {
|
||||
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(obj[i].toString());
|
||||
} else {
|
||||
buf.append("null");
|
||||
}
|
||||
if (i < obj.length - 1)
|
||||
buf.append(", ");
|
||||
}
|
||||
if (braces)
|
||||
buf.append('}');
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static boolean isJavaIdentifierPart(char ch) {
|
||||
return ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_');
|
||||
}
|
||||
|
||||
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] & 0xFF;
|
||||
jw.write(in);
|
||||
}
|
||||
return caw.toString();
|
||||
}
|
||||
|
||||
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];
|
||||
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;
|
||||
}
|
||||
|
||||
private static int[] CHAR_MAP = new int[48];
|
||||
|
||||
private static int[] MAP_CHAR = new int[256];
|
||||
|
||||
private static final char ESCAPE_CHAR = '$';
|
||||
|
||||
static {
|
||||
int j = 0, k = 0;
|
||||
for (int i = 65; i <= 90; i++) {
|
||||
CHAR_MAP[j] = i;
|
||||
MAP_CHAR[i] = j;
|
||||
j++;
|
||||
}
|
||||
for (int m = 103; m <= 122; m++) {
|
||||
CHAR_MAP[j] = m;
|
||||
MAP_CHAR[m] = j;
|
||||
j++;
|
||||
}
|
||||
CHAR_MAP[j] = 36;
|
||||
MAP_CHAR[36] = j;
|
||||
j++;
|
||||
CHAR_MAP[j] = 95;
|
||||
MAP_CHAR[95] = j;
|
||||
}
|
||||
|
||||
private static class JavaReader extends FilterReader {
|
||||
public JavaReader(Reader in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
int b = this.in.read();
|
||||
if (b != 36)
|
||||
return b;
|
||||
int i = this.in.read();
|
||||
if (i < 0)
|
||||
return -1;
|
||||
if ((i >= 48 && i <= 57) || (i >= 97 && i <= 102)) {
|
||||
int j = this.in.read();
|
||||
if (j < 0)
|
||||
return -1;
|
||||
char[] tmp = { (char)i, (char)j };
|
||||
int s = Integer.parseInt(new String(tmp), 16);
|
||||
return s;
|
||||
}
|
||||
return Utility.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;
|
||||
}
|
||||
}
|
||||
|
||||
private static class JavaWriter extends FilterWriter {
|
||||
public JavaWriter(Writer out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
if (Utility.isJavaIdentifierPart((char)b) && b != 36) {
|
||||
this.out.write(b);
|
||||
} else {
|
||||
this.out.write(36);
|
||||
if (b >= 0 && b < 48) {
|
||||
this.out.write(Utility.CHAR_MAP[b]);
|
||||
} else {
|
||||
char[] tmp = Integer.toHexString(b).toCharArray();
|
||||
if (tmp.length == 1) {
|
||||
this.out.write(48);
|
||||
this.out.write(tmp[0]);
|
||||
} else {
|
||||
this.out.write(tmp[0]);
|
||||
this.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package org.apache.bcel.classfile;
|
||||
|
||||
public interface Visitor {
|
||||
void visitCode(Code paramCode);
|
||||
|
||||
void visitCodeException(CodeException paramCodeException);
|
||||
|
||||
void visitConstantClass(ConstantClass paramConstantClass);
|
||||
|
||||
void visitConstantDouble(ConstantDouble paramConstantDouble);
|
||||
|
||||
void visitConstantFieldref(ConstantFieldref paramConstantFieldref);
|
||||
|
||||
void visitConstantFloat(ConstantFloat paramConstantFloat);
|
||||
|
||||
void visitConstantInteger(ConstantInteger paramConstantInteger);
|
||||
|
||||
void visitConstantInterfaceMethodref(ConstantInterfaceMethodref paramConstantInterfaceMethodref);
|
||||
|
||||
void visitConstantLong(ConstantLong paramConstantLong);
|
||||
|
||||
void visitConstantMethodref(ConstantMethodref paramConstantMethodref);
|
||||
|
||||
void visitConstantNameAndType(ConstantNameAndType paramConstantNameAndType);
|
||||
|
||||
void visitConstantPool(ConstantPool paramConstantPool);
|
||||
|
||||
void visitConstantString(ConstantString paramConstantString);
|
||||
|
||||
void visitConstantUtf8(ConstantUtf8 paramConstantUtf8);
|
||||
|
||||
void visitConstantValue(ConstantValue paramConstantValue);
|
||||
|
||||
void visitDeprecated(Deprecated paramDeprecated);
|
||||
|
||||
void visitExceptionTable(ExceptionTable paramExceptionTable);
|
||||
|
||||
void visitField(Field paramField);
|
||||
|
||||
void visitInnerClass(InnerClass paramInnerClass);
|
||||
|
||||
void visitInnerClasses(InnerClasses paramInnerClasses);
|
||||
|
||||
void visitJavaClass(JavaClass paramJavaClass);
|
||||
|
||||
void visitLineNumber(LineNumber paramLineNumber);
|
||||
|
||||
void visitLineNumberTable(LineNumberTable paramLineNumberTable);
|
||||
|
||||
void visitLocalVariable(LocalVariable paramLocalVariable);
|
||||
|
||||
void visitLocalVariableTable(LocalVariableTable paramLocalVariableTable);
|
||||
|
||||
void visitMethod(Method paramMethod);
|
||||
|
||||
void visitSourceFile(SourceFile paramSourceFile);
|
||||
|
||||
void visitSynthetic(Synthetic paramSynthetic);
|
||||
|
||||
void visitUnknown(Unknown paramUnknown);
|
||||
|
||||
void visitStackMap(StackMap paramStackMap);
|
||||
|
||||
void visitStackMapEntry(StackMapEntry paramStackMapEntry);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class AALOAD extends ArrayInstruction implements StackProducer {
|
||||
public AALOAD() {
|
||||
super((short)50);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitAALOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class AASTORE extends ArrayInstruction implements StackConsumer {
|
||||
public AASTORE() {
|
||||
super((short)83);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackConsumer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitAASTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class ACONST_NULL extends Instruction implements PushInstruction, TypedInstruction {
|
||||
public ACONST_NULL() {
|
||||
super((short)1, (short)1);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
return Type.NULL;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitPushInstruction(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitACONST_NULL(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class ALOAD extends LoadInstruction {
|
||||
ALOAD() {
|
||||
super((short)25, (short)42);
|
||||
}
|
||||
|
||||
public ALOAD(int n) {
|
||||
super((short)25, (short)42, n);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
super.accept(v);
|
||||
v.visitALOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.ExceptionConstants;
|
||||
|
||||
public class ANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower, StackProducer {
|
||||
ANEWARRAY() {}
|
||||
|
||||
public ANEWARRAY(int index) {
|
||||
super((short)189, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class ARETURN extends ReturnInstruction {
|
||||
public ARETURN() {
|
||||
super((short)176);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitReturnInstruction(this);
|
||||
v.visitARETURN(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.ExceptionConstants;
|
||||
|
||||
public class ARRAYLENGTH extends Instruction implements ExceptionThrower, StackProducer {
|
||||
public ARRAYLENGTH() {
|
||||
super((short)190, (short)1);
|
||||
}
|
||||
|
||||
public Class[] getExceptions() {
|
||||
return new Class[] { ExceptionConstants.NULL_POINTER_EXCEPTION };
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitARRAYLENGTH(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class ASTORE extends StoreInstruction {
|
||||
ASTORE() {
|
||||
super((short)58, (short)75);
|
||||
}
|
||||
|
||||
public ASTORE(int n) {
|
||||
super((short)58, (short)75, n);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
super.accept(v);
|
||||
v.visitASTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.ExceptionConstants;
|
||||
|
||||
public class ATHROW extends Instruction implements UnconditionalBranch, ExceptionThrower {
|
||||
public ATHROW() {
|
||||
super((short)191, (short)1);
|
||||
}
|
||||
|
||||
public Class[] getExceptions() {
|
||||
return new Class[] { ExceptionConstants.THROWABLE };
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitUnconditionalBranch(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitATHROW(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public interface AllocationInstruction {}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public abstract class ArithmeticInstruction extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
|
||||
ArithmeticInstruction() {}
|
||||
|
||||
protected ArithmeticInstruction(short opcode) {
|
||||
super(opcode, (short)1);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
switch (this.opcode) {
|
||||
case 99:
|
||||
case 103:
|
||||
case 107:
|
||||
case 111:
|
||||
case 115:
|
||||
case 119:
|
||||
return Type.DOUBLE;
|
||||
case 98:
|
||||
case 102:
|
||||
case 106:
|
||||
case 110:
|
||||
case 114:
|
||||
case 118:
|
||||
return Type.FLOAT;
|
||||
case 96:
|
||||
case 100:
|
||||
case 104:
|
||||
case 108:
|
||||
case 112:
|
||||
case 116:
|
||||
case 120:
|
||||
case 122:
|
||||
case 124:
|
||||
case 126:
|
||||
case 128:
|
||||
case 130:
|
||||
return Type.INT;
|
||||
case 97:
|
||||
case 101:
|
||||
case 105:
|
||||
case 109:
|
||||
case 113:
|
||||
case 117:
|
||||
case 121:
|
||||
case 123:
|
||||
case 125:
|
||||
case 127:
|
||||
case 129:
|
||||
case 131:
|
||||
return Type.LONG;
|
||||
}
|
||||
throw new ClassGenException("Unknown type " + this.opcode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.ExceptionConstants;
|
||||
|
||||
public abstract class ArrayInstruction extends Instruction implements ExceptionThrower, TypedInstruction {
|
||||
ArrayInstruction() {}
|
||||
|
||||
protected ArrayInstruction(short opcode) {
|
||||
super(opcode, (short)1);
|
||||
}
|
||||
|
||||
public Class[] getExceptions() {
|
||||
return ExceptionConstants.EXCS_ARRAY_EXCEPTION;
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
switch (this.opcode) {
|
||||
case 46:
|
||||
case 79:
|
||||
return Type.INT;
|
||||
case 52:
|
||||
case 85:
|
||||
return Type.CHAR;
|
||||
case 51:
|
||||
case 84:
|
||||
return Type.BYTE;
|
||||
case 53:
|
||||
case 86:
|
||||
return Type.SHORT;
|
||||
case 47:
|
||||
case 80:
|
||||
return Type.LONG;
|
||||
case 49:
|
||||
case 82:
|
||||
return Type.DOUBLE;
|
||||
case 48:
|
||||
case 81:
|
||||
return Type.FLOAT;
|
||||
case 50:
|
||||
case 83:
|
||||
return Type.OBJECT;
|
||||
}
|
||||
throw new ClassGenException("Oops: unknown case in switch" + this.opcode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public final class ArrayType extends ReferenceType {
|
||||
private int dimensions;
|
||||
|
||||
private Type basic_type;
|
||||
|
||||
public ArrayType(byte type, int dimensions) {
|
||||
this(BasicType.getType(type), dimensions);
|
||||
}
|
||||
|
||||
public ArrayType(String class_name, int dimensions) {
|
||||
this(new ObjectType(class_name), dimensions);
|
||||
}
|
||||
|
||||
public ArrayType(Type type, int dimensions) {
|
||||
super((byte)13, "<dummy>");
|
||||
ArrayType array;
|
||||
if (dimensions < 1 || dimensions > 255)
|
||||
throw new ClassGenException("Invalid number of dimensions: " + dimensions);
|
||||
switch (type.getType()) {
|
||||
case 13:
|
||||
array = (ArrayType)type;
|
||||
this.dimensions = dimensions + array.dimensions;
|
||||
this.basic_type = array.basic_type;
|
||||
break;
|
||||
case 12:
|
||||
throw new ClassGenException("Invalid type: void[]");
|
||||
default:
|
||||
this.dimensions = dimensions;
|
||||
this.basic_type = type;
|
||||
break;
|
||||
}
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < this.dimensions; i++)
|
||||
buf.append('[');
|
||||
buf.append(this.basic_type.getSignature());
|
||||
this.signature = buf.toString();
|
||||
}
|
||||
|
||||
public Type getBasicType() {
|
||||
return this.basic_type;
|
||||
}
|
||||
|
||||
public Type getElementType() {
|
||||
if (this.dimensions == 1)
|
||||
return this.basic_type;
|
||||
return new ArrayType(this.basic_type, this.dimensions - 1);
|
||||
}
|
||||
|
||||
public int getDimensions() {
|
||||
return this.dimensions;
|
||||
}
|
||||
|
||||
public int hashcode() {
|
||||
return this.basic_type.hashCode() ^ this.dimensions;
|
||||
}
|
||||
|
||||
public boolean equals(Object type) {
|
||||
if (type instanceof ArrayType) {
|
||||
ArrayType array = (ArrayType)type;
|
||||
return (array.dimensions == this.dimensions && array.basic_type.equals(this.basic_type));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class BALOAD extends ArrayInstruction implements StackProducer {
|
||||
public BALOAD() {
|
||||
super((short)51);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitBALOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class BASTORE extends ArrayInstruction implements StackConsumer {
|
||||
public BASTORE() {
|
||||
super((short)84);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackConsumer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitBASTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.util.ByteSequence;
|
||||
|
||||
public class BIPUSH extends Instruction implements ConstantPushInstruction {
|
||||
private byte b;
|
||||
|
||||
BIPUSH() {}
|
||||
|
||||
public BIPUSH(byte b) {
|
||||
super((short)16, (short)2);
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public void dump(DataOutputStream out) throws IOException {
|
||||
super.dump(out);
|
||||
out.writeByte(this.b);
|
||||
}
|
||||
|
||||
public String toString(boolean verbose) {
|
||||
return super.toString(verbose) + " " + this.b;
|
||||
}
|
||||
|
||||
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException {
|
||||
this.length = 2;
|
||||
this.b = bytes.readByte();
|
||||
}
|
||||
|
||||
public Number getValue() {
|
||||
return new Integer(this.b);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
return Type.BYTE;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitPushInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitConstantPushInstruction(this);
|
||||
v.visitBIPUSH(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class BREAKPOINT extends Instruction {
|
||||
public BREAKPOINT() {
|
||||
super((short)202, (short)1);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitBREAKPOINT(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.Constants;
|
||||
|
||||
public final class BasicType extends Type {
|
||||
BasicType(byte type) {
|
||||
super(type, Constants.SHORT_TYPE_NAMES[type]);
|
||||
if (type < 4 || type > 12)
|
||||
throw new ClassGenException("Invalid type: " + type);
|
||||
}
|
||||
|
||||
public static final BasicType getType(byte type) {
|
||||
switch (type) {
|
||||
case 12:
|
||||
return Type.VOID;
|
||||
case 4:
|
||||
return Type.BOOLEAN;
|
||||
case 8:
|
||||
return Type.BYTE;
|
||||
case 9:
|
||||
return Type.SHORT;
|
||||
case 5:
|
||||
return Type.CHAR;
|
||||
case 10:
|
||||
return Type.INT;
|
||||
case 11:
|
||||
return Type.LONG;
|
||||
case 7:
|
||||
return Type.DOUBLE;
|
||||
case 6:
|
||||
return Type.FLOAT;
|
||||
}
|
||||
throw new ClassGenException("Invalid type: " + type);
|
||||
}
|
||||
|
||||
public boolean equals(Object type) {
|
||||
return (type instanceof BasicType) ? ((((BasicType)type).type == this.type)) : false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public final class BranchHandle extends InstructionHandle {
|
||||
private BranchInstruction bi;
|
||||
|
||||
private BranchHandle(BranchInstruction i) {
|
||||
super(i);
|
||||
this.bi = i;
|
||||
}
|
||||
|
||||
private static BranchHandle bh_list = null;
|
||||
|
||||
static final BranchHandle getBranchHandle(BranchInstruction i) {
|
||||
if (bh_list == null)
|
||||
return new BranchHandle(i);
|
||||
BranchHandle bh = bh_list;
|
||||
bh_list = (BranchHandle)bh.next;
|
||||
bh.setInstruction(i);
|
||||
return bh;
|
||||
}
|
||||
|
||||
protected void addHandle() {
|
||||
this.next = bh_list;
|
||||
bh_list = this;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return this.bi.position;
|
||||
}
|
||||
|
||||
void setPosition(int pos) {
|
||||
this.i_position = this.bi.position = pos;
|
||||
}
|
||||
|
||||
protected int updatePosition(int offset, int max_offset) {
|
||||
int x = this.bi.updatePosition(offset, max_offset);
|
||||
this.i_position = this.bi.position;
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setTarget(InstructionHandle ih) {
|
||||
this.bi.setTarget(ih);
|
||||
}
|
||||
|
||||
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
|
||||
this.bi.updateTarget(old_ih, new_ih);
|
||||
}
|
||||
|
||||
public InstructionHandle getTarget() {
|
||||
return this.bi.getTarget();
|
||||
}
|
||||
|
||||
public void setInstruction(Instruction i) {
|
||||
super.setInstruction(i);
|
||||
if (!(i instanceof BranchInstruction))
|
||||
throw new ClassGenException("Assigning " + i + " to branch handle which is not a branch instruction");
|
||||
this.bi = (BranchInstruction)i;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.util.ByteSequence;
|
||||
|
||||
public abstract class BranchInstruction extends Instruction implements InstructionTargeter {
|
||||
protected int index;
|
||||
|
||||
protected InstructionHandle target;
|
||||
|
||||
protected int position;
|
||||
|
||||
BranchInstruction() {}
|
||||
|
||||
protected BranchInstruction(short opcode, InstructionHandle target) {
|
||||
super(opcode, (short)3);
|
||||
setTarget(target);
|
||||
}
|
||||
|
||||
public void dump(DataOutputStream out) throws IOException {
|
||||
out.writeByte(this.opcode);
|
||||
this.index = getTargetOffset();
|
||||
if (Math.abs(this.index) >= 32767)
|
||||
throw new ClassGenException("Branch target offset too large for short");
|
||||
out.writeShort(this.index);
|
||||
}
|
||||
|
||||
protected int getTargetOffset(InstructionHandle target) {
|
||||
if (target == null)
|
||||
throw new ClassGenException("Target of " + super.toString(true) + " is invalid null handle");
|
||||
int t = target.getPosition();
|
||||
if (t < 0)
|
||||
throw new ClassGenException("Invalid branch target position offset for " + super.toString(true) + ":" + t + ":" + target);
|
||||
return t - this.position;
|
||||
}
|
||||
|
||||
protected int getTargetOffset() {
|
||||
return getTargetOffset(this.target);
|
||||
}
|
||||
|
||||
protected int updatePosition(int offset, int max_offset) {
|
||||
this.position += offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String toString(boolean verbose) {
|
||||
String s = super.toString(verbose);
|
||||
String t = "null";
|
||||
if (verbose) {
|
||||
if (this.target != null)
|
||||
if (this.target.getInstruction() == this) {
|
||||
t = "<points to itself>";
|
||||
} else if (this.target.getInstruction() == null) {
|
||||
t = "<null instruction!!!?>";
|
||||
} else {
|
||||
t = this.target.getInstruction().toString(false);
|
||||
}
|
||||
} else if (this.target != null) {
|
||||
this.index = getTargetOffset();
|
||||
t = "" + (this.index + this.position);
|
||||
}
|
||||
return s + " -> " + t;
|
||||
}
|
||||
|
||||
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException {
|
||||
this.length = 3;
|
||||
this.index = bytes.readShort();
|
||||
}
|
||||
|
||||
public final int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public InstructionHandle getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public void setTarget(InstructionHandle target) {
|
||||
notifyTarget(this.target, target, this);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
static final void notifyTarget(InstructionHandle old_ih, InstructionHandle new_ih, InstructionTargeter t) {
|
||||
if (old_ih != null)
|
||||
old_ih.removeTargeter(t);
|
||||
if (new_ih != null)
|
||||
new_ih.addTargeter(t);
|
||||
}
|
||||
|
||||
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
|
||||
if (this.target == old_ih) {
|
||||
setTarget(new_ih);
|
||||
} else {
|
||||
throw new ClassGenException("Not targeting " + old_ih + ", but " + this.target);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsTarget(InstructionHandle ih) {
|
||||
return (this.target == ih);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
setTarget(null);
|
||||
this.index = -1;
|
||||
this.position = -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class CALOAD extends ArrayInstruction implements StackProducer {
|
||||
public CALOAD() {
|
||||
super((short)52);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitCALOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class CASTORE extends ArrayInstruction implements StackConsumer {
|
||||
public CASTORE() {
|
||||
super((short)85);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackConsumer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitCASTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.ExceptionConstants;
|
||||
|
||||
public class CHECKCAST extends CPInstruction implements LoadClass, ExceptionThrower, StackProducer, StackConsumer {
|
||||
CHECKCAST() {}
|
||||
|
||||
public CHECKCAST(int index) {
|
||||
super((short)192, 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.CLASS_CAST_EXCEPTION;
|
||||
return cs;
|
||||
}
|
||||
|
||||
public ObjectType getLoadClassType(ConstantPoolGen cpg) {
|
||||
Type t = getType(cpg);
|
||||
if (t instanceof ArrayType)
|
||||
t = ((ArrayType)t).getBasicType();
|
||||
return (t instanceof ObjectType) ? (ObjectType)t : null;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitLoadClass(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitCPInstruction(this);
|
||||
v.visitCHECKCAST(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import org.apache.bcel.Constants;
|
||||
import org.apache.bcel.classfile.Constant;
|
||||
import org.apache.bcel.classfile.ConstantPool;
|
||||
import org.apache.bcel.util.ByteSequence;
|
||||
|
||||
public abstract class CPInstruction extends Instruction implements TypedInstruction, IndexedInstruction {
|
||||
protected int index;
|
||||
|
||||
CPInstruction() {}
|
||||
|
||||
protected CPInstruction(short opcode, int index) {
|
||||
super(opcode, (short)3);
|
||||
setIndex(index);
|
||||
}
|
||||
|
||||
public void dump(DataOutputStream out) throws IOException {
|
||||
out.writeByte(this.opcode);
|
||||
out.writeShort(this.index);
|
||||
}
|
||||
|
||||
public String toString(boolean verbose) {
|
||||
return super.toString(verbose) + " " + this.index;
|
||||
}
|
||||
|
||||
public String toString(ConstantPool cp) {
|
||||
Constant c = cp.getConstant(this.index);
|
||||
String str = cp.constantToString(c);
|
||||
if (c instanceof org.apache.bcel.classfile.ConstantClass)
|
||||
str = str.replace('.', '/');
|
||||
return Constants.OPCODE_NAMES[this.opcode] + " " + str;
|
||||
}
|
||||
|
||||
protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException {
|
||||
setIndex(bytes.readUnsignedShort());
|
||||
this.length = 3;
|
||||
}
|
||||
|
||||
public final int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
if (index < 0)
|
||||
throw new ClassGenException("Negative index value: " + index);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cpg) {
|
||||
ConstantPool cp = cpg.getConstantPool();
|
||||
String name = cp.getConstantString(this.index, (byte)7);
|
||||
if (!name.startsWith("["))
|
||||
name = "L" + name + ";";
|
||||
return Type.getType(name);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import org.apache.bcel.classfile.AccessFlags;
|
||||
import org.apache.bcel.classfile.Attribute;
|
||||
import org.apache.bcel.classfile.ConstantPool;
|
||||
import org.apache.bcel.classfile.Field;
|
||||
import org.apache.bcel.classfile.JavaClass;
|
||||
import org.apache.bcel.classfile.Method;
|
||||
import org.apache.bcel.classfile.SourceFile;
|
||||
|
||||
public class ClassGen extends AccessFlags implements Cloneable {
|
||||
private String class_name;
|
||||
|
||||
private String super_class_name;
|
||||
|
||||
private String file_name;
|
||||
|
||||
private int class_name_index = -1, superclass_name_index = -1;
|
||||
|
||||
private int major = 45;
|
||||
|
||||
private int minor = 3;
|
||||
|
||||
private ConstantPoolGen cp;
|
||||
|
||||
private ArrayList field_vec = new ArrayList();
|
||||
|
||||
private ArrayList method_vec = new ArrayList();
|
||||
|
||||
private ArrayList attribute_vec = new ArrayList();
|
||||
|
||||
private ArrayList interface_vec = new ArrayList();
|
||||
|
||||
private ArrayList observers;
|
||||
|
||||
public ClassGen(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces) {
|
||||
this.class_name = class_name;
|
||||
this.super_class_name = super_class_name;
|
||||
this.file_name = file_name;
|
||||
this.access_flags = access_flags;
|
||||
this.cp = new ConstantPoolGen();
|
||||
addAttribute(new SourceFile(this.cp.addUtf8("SourceFile"), 2, this.cp.addUtf8(file_name), this.cp.getConstantPool()));
|
||||
this.class_name_index = this.cp.addClass(class_name);
|
||||
this.superclass_name_index = this.cp.addClass(super_class_name);
|
||||
if (interfaces != null)
|
||||
for (int i = 0; i < interfaces.length; i++)
|
||||
addInterface(interfaces[i]);
|
||||
}
|
||||
|
||||
public ClassGen(JavaClass clazz) {
|
||||
this.class_name_index = clazz.getClassNameIndex();
|
||||
this.superclass_name_index = clazz.getSuperclassNameIndex();
|
||||
this.class_name = clazz.getClassName();
|
||||
this.super_class_name = clazz.getSuperclassName();
|
||||
this.file_name = clazz.getSourceFileName();
|
||||
this.access_flags = clazz.getAccessFlags();
|
||||
this.cp = new ConstantPoolGen(clazz.getConstantPool());
|
||||
this.major = clazz.getMajor();
|
||||
this.minor = clazz.getMinor();
|
||||
Attribute[] attributes = clazz.getAttributes();
|
||||
Method[] methods = clazz.getMethods();
|
||||
Field[] fields = clazz.getFields();
|
||||
String[] interfaces = clazz.getInterfaceNames();
|
||||
for (int i = 0; i < interfaces.length; i++)
|
||||
addInterface(interfaces[i]);
|
||||
for (int j = 0; j < attributes.length; j++)
|
||||
addAttribute(attributes[j]);
|
||||
for (int k = 0; k < methods.length; k++)
|
||||
addMethod(methods[k]);
|
||||
for (int m = 0; m < fields.length; m++)
|
||||
addField(fields[m]);
|
||||
}
|
||||
|
||||
public JavaClass getJavaClass() {
|
||||
int[] interfaces = getInterfaces();
|
||||
Field[] fields = getFields();
|
||||
Method[] methods = getMethods();
|
||||
Attribute[] attributes = getAttributes();
|
||||
ConstantPool cp = this.cp.getFinalConstantPool();
|
||||
return new JavaClass(this.class_name_index, this.superclass_name_index, this.file_name, this.major, this.minor, this.access_flags, cp, interfaces, fields, methods, attributes);
|
||||
}
|
||||
|
||||
public void addInterface(String name) {
|
||||
this.interface_vec.add(name);
|
||||
}
|
||||
|
||||
public void removeInterface(String name) {
|
||||
this.interface_vec.remove(name);
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return this.major;
|
||||
}
|
||||
|
||||
public void setMajor(int major) {
|
||||
this.major = major;
|
||||
}
|
||||
|
||||
public void setMinor(int minor) {
|
||||
this.minor = minor;
|
||||
}
|
||||
|
||||
public int getMinor() {
|
||||
return this.minor;
|
||||
}
|
||||
|
||||
public void addAttribute(Attribute a) {
|
||||
this.attribute_vec.add(a);
|
||||
}
|
||||
|
||||
public void addMethod(Method m) {
|
||||
this.method_vec.add(m);
|
||||
}
|
||||
|
||||
public void addEmptyConstructor(int access_flags) {
|
||||
InstructionList il = new InstructionList();
|
||||
il.append(InstructionConstants.THIS);
|
||||
il.append(new INVOKESPECIAL(this.cp.addMethodref(this.super_class_name, "<init>", "()V")));
|
||||
il.append(InstructionConstants.RETURN);
|
||||
MethodGen mg = new MethodGen(access_flags, Type.VOID, Type.NO_ARGS, null, "<init>", this.class_name, il, this.cp);
|
||||
mg.setMaxStack(1);
|
||||
addMethod(mg.getMethod());
|
||||
}
|
||||
|
||||
public void addField(Field f) {
|
||||
this.field_vec.add(f);
|
||||
}
|
||||
|
||||
public boolean containsField(Field f) {
|
||||
return this.field_vec.contains(f);
|
||||
}
|
||||
|
||||
public Field containsField(String name) {
|
||||
for (Iterator e = this.field_vec.iterator(); e.hasNext(); ) {
|
||||
Field f = (Field)e.next();
|
||||
if (f.getName().equals(name))
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Method containsMethod(String name, String signature) {
|
||||
for (Iterator e = this.method_vec.iterator(); e.hasNext(); ) {
|
||||
Method m = (Method)e.next();
|
||||
if (m.getName().equals(name) && m.getSignature().equals(signature))
|
||||
return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeAttribute(Attribute a) {
|
||||
this.attribute_vec.remove(a);
|
||||
}
|
||||
|
||||
public void removeMethod(Method m) {
|
||||
this.method_vec.remove(m);
|
||||
}
|
||||
|
||||
public void replaceMethod(Method old, Method new_) {
|
||||
if (new_ == null)
|
||||
throw new ClassGenException("Replacement method must not be null");
|
||||
int i = this.method_vec.indexOf(old);
|
||||
if (i < 0) {
|
||||
this.method_vec.add(new_);
|
||||
} else {
|
||||
this.method_vec.set(i, new_);
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceField(Field old, Field new_) {
|
||||
if (new_ == null)
|
||||
throw new ClassGenException("Replacement method must not be null");
|
||||
int i = this.field_vec.indexOf(old);
|
||||
if (i < 0) {
|
||||
this.field_vec.add(new_);
|
||||
} else {
|
||||
this.field_vec.set(i, new_);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeField(Field f) {
|
||||
this.field_vec.remove(f);
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return this.class_name;
|
||||
}
|
||||
|
||||
public String getSuperclassName() {
|
||||
return this.super_class_name;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return this.file_name;
|
||||
}
|
||||
|
||||
public void setClassName(String name) {
|
||||
this.class_name = name.replace('/', '.');
|
||||
this.class_name_index = this.cp.addClass(name);
|
||||
}
|
||||
|
||||
public void setSuperclassName(String name) {
|
||||
this.super_class_name = name.replace('/', '.');
|
||||
this.superclass_name_index = this.cp.addClass(name);
|
||||
}
|
||||
|
||||
public Method[] getMethods() {
|
||||
Method[] methods = new Method[this.method_vec.size()];
|
||||
this.method_vec.toArray(methods);
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void setMethods(Method[] methods) {
|
||||
this.method_vec.clear();
|
||||
for (int m = 0; m < methods.length; m++)
|
||||
addMethod(methods[m]);
|
||||
}
|
||||
|
||||
public void setMethodAt(Method method, int pos) {
|
||||
this.method_vec.set(pos, method);
|
||||
}
|
||||
|
||||
public Method getMethodAt(int pos) {
|
||||
return (Method)this.method_vec.get(pos);
|
||||
}
|
||||
|
||||
public String[] getInterfaceNames() {
|
||||
int size = this.interface_vec.size();
|
||||
String[] interfaces = new String[size];
|
||||
this.interface_vec.toArray(interfaces);
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public int[] getInterfaces() {
|
||||
int size = this.interface_vec.size();
|
||||
int[] interfaces = new int[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
interfaces[i] = this.cp.addClass((String)this.interface_vec.get(i));
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
public Field[] getFields() {
|
||||
Field[] fields = new Field[this.field_vec.size()];
|
||||
this.field_vec.toArray(fields);
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Attribute[] getAttributes() {
|
||||
Attribute[] attributes = new Attribute[this.attribute_vec.size()];
|
||||
this.attribute_vec.toArray(attributes);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public ConstantPoolGen getConstantPool() {
|
||||
return this.cp;
|
||||
}
|
||||
|
||||
public void setConstantPool(ConstantPoolGen constant_pool) {
|
||||
this.cp = constant_pool;
|
||||
}
|
||||
|
||||
public void setClassNameIndex(int class_name_index) {
|
||||
this.class_name_index = class_name_index;
|
||||
this.class_name = this.cp.getConstantPool().getConstantString(class_name_index, (byte)7).replace('/', '.');
|
||||
}
|
||||
|
||||
public void setSuperclassNameIndex(int superclass_name_index) {
|
||||
this.superclass_name_index = superclass_name_index;
|
||||
this.super_class_name = this.cp.getConstantPool().getConstantString(superclass_name_index, (byte)7).replace('/', '.');
|
||||
}
|
||||
|
||||
public int getSuperclassNameIndex() {
|
||||
return this.superclass_name_index;
|
||||
}
|
||||
|
||||
public int getClassNameIndex() {
|
||||
return this.class_name_index;
|
||||
}
|
||||
|
||||
public void addObserver(ClassObserver o) {
|
||||
if (this.observers == null)
|
||||
this.observers = new ArrayList();
|
||||
this.observers.add(o);
|
||||
}
|
||||
|
||||
public void removeObserver(ClassObserver o) {
|
||||
if (this.observers != null)
|
||||
this.observers.remove(o);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (this.observers != null)
|
||||
for (Iterator e = this.observers.iterator(); e.hasNext();)
|
||||
((ClassObserver)e.next()).notify(this);
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
System.err.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class ClassGenException extends RuntimeException {
|
||||
public ClassGenException() {}
|
||||
|
||||
public ClassGenException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public interface ClassObserver {
|
||||
void notify(ClassGen paramClassGen);
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import org.apache.bcel.classfile.CodeException;
|
||||
|
||||
public final class CodeExceptionGen implements InstructionTargeter, Cloneable {
|
||||
private InstructionHandle start_pc;
|
||||
|
||||
private InstructionHandle end_pc;
|
||||
|
||||
private InstructionHandle handler_pc;
|
||||
|
||||
private ObjectType catch_type;
|
||||
|
||||
public CodeExceptionGen(InstructionHandle start_pc, InstructionHandle end_pc, InstructionHandle handler_pc, ObjectType catch_type) {
|
||||
setStartPC(start_pc);
|
||||
setEndPC(end_pc);
|
||||
setHandlerPC(handler_pc);
|
||||
this.catch_type = catch_type;
|
||||
}
|
||||
|
||||
public CodeException getCodeException(ConstantPoolGen cp) {
|
||||
return new CodeException(this.start_pc.getPosition(), this.end_pc.getPosition() + this.end_pc.getInstruction().getLength(), this.handler_pc.getPosition(), (this.catch_type == null) ? 0 : cp.addClass(this.catch_type));
|
||||
}
|
||||
|
||||
public void setStartPC(InstructionHandle start_pc) {
|
||||
BranchInstruction.notifyTarget(this.start_pc, start_pc, this);
|
||||
this.start_pc = start_pc;
|
||||
}
|
||||
|
||||
public void setEndPC(InstructionHandle end_pc) {
|
||||
BranchInstruction.notifyTarget(this.end_pc, end_pc, this);
|
||||
this.end_pc = end_pc;
|
||||
}
|
||||
|
||||
public void setHandlerPC(InstructionHandle handler_pc) {
|
||||
BranchInstruction.notifyTarget(this.handler_pc, handler_pc, this);
|
||||
this.handler_pc = handler_pc;
|
||||
}
|
||||
|
||||
public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
|
||||
boolean targeted = false;
|
||||
if (this.start_pc == old_ih) {
|
||||
targeted = true;
|
||||
setStartPC(new_ih);
|
||||
}
|
||||
if (this.end_pc == old_ih) {
|
||||
targeted = true;
|
||||
setEndPC(new_ih);
|
||||
}
|
||||
if (this.handler_pc == old_ih) {
|
||||
targeted = true;
|
||||
setHandlerPC(new_ih);
|
||||
}
|
||||
if (!targeted)
|
||||
throw new ClassGenException("Not targeting " + old_ih + ", but {" + this.start_pc + ", " + this.end_pc + ", " + this.handler_pc + "}");
|
||||
}
|
||||
|
||||
public boolean containsTarget(InstructionHandle ih) {
|
||||
return (this.start_pc == ih || this.end_pc == ih || this.handler_pc == ih);
|
||||
}
|
||||
|
||||
public void setCatchType(ObjectType catch_type) {
|
||||
this.catch_type = catch_type;
|
||||
}
|
||||
|
||||
public ObjectType getCatchType() {
|
||||
return this.catch_type;
|
||||
}
|
||||
|
||||
public InstructionHandle getStartPC() {
|
||||
return this.start_pc;
|
||||
}
|
||||
|
||||
public InstructionHandle getEndPC() {
|
||||
return this.end_pc;
|
||||
}
|
||||
|
||||
public InstructionHandle getHandlerPC() {
|
||||
return this.handler_pc;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "CodeExceptionGen(" + this.start_pc + ", " + this.end_pc + ", " + this.handler_pc + ")";
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
return super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
System.err.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public interface CompoundInstruction {
|
||||
InstructionList getInstructionList();
|
||||
}
|
||||
|
|
@ -0,0 +1,441 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.apache.bcel.classfile.Constant;
|
||||
import org.apache.bcel.classfile.ConstantCP;
|
||||
import org.apache.bcel.classfile.ConstantClass;
|
||||
import org.apache.bcel.classfile.ConstantDouble;
|
||||
import org.apache.bcel.classfile.ConstantFieldref;
|
||||
import org.apache.bcel.classfile.ConstantFloat;
|
||||
import org.apache.bcel.classfile.ConstantInteger;
|
||||
import org.apache.bcel.classfile.ConstantInterfaceMethodref;
|
||||
import org.apache.bcel.classfile.ConstantLong;
|
||||
import org.apache.bcel.classfile.ConstantMethodref;
|
||||
import org.apache.bcel.classfile.ConstantNameAndType;
|
||||
import org.apache.bcel.classfile.ConstantPool;
|
||||
import org.apache.bcel.classfile.ConstantString;
|
||||
import org.apache.bcel.classfile.ConstantUtf8;
|
||||
|
||||
public class ConstantPoolGen {
|
||||
protected int size = 1024;
|
||||
|
||||
protected Constant[] constants = new Constant[this.size];
|
||||
|
||||
protected int index = 1;
|
||||
|
||||
private static final String METHODREF_DELIM = ":";
|
||||
|
||||
private static final String IMETHODREF_DELIM = "#";
|
||||
|
||||
private static final String FIELDREF_DELIM = "&";
|
||||
|
||||
private static final String NAT_DELIM = "%";
|
||||
|
||||
private static class Index {
|
||||
int index;
|
||||
|
||||
Index(int i) {
|
||||
this.index = i;
|
||||
}
|
||||
}
|
||||
|
||||
public ConstantPoolGen(Constant[] cs) {
|
||||
if (cs.length > this.size) {
|
||||
this.size = cs.length;
|
||||
this.constants = new Constant[this.size];
|
||||
}
|
||||
System.arraycopy(cs, 0, this.constants, 0, cs.length);
|
||||
if (cs.length > 0)
|
||||
this.index = cs.length;
|
||||
for (int i = 1; i < this.index; i++) {
|
||||
Constant c = this.constants[i];
|
||||
if (c instanceof ConstantString) {
|
||||
ConstantString s = (ConstantString)c;
|
||||
ConstantUtf8 u8 = (ConstantUtf8)this.constants[s.getStringIndex()];
|
||||
this.string_table.put(u8.getBytes(), new Index(i));
|
||||
} else if (c instanceof ConstantClass) {
|
||||
ConstantClass s = (ConstantClass)c;
|
||||
ConstantUtf8 u8 = (ConstantUtf8)this.constants[s.getNameIndex()];
|
||||
this.class_table.put(u8.getBytes(), new Index(i));
|
||||
} else if (c instanceof ConstantNameAndType) {
|
||||
ConstantNameAndType n = (ConstantNameAndType)c;
|
||||
ConstantUtf8 u8 = (ConstantUtf8)this.constants[n.getNameIndex()];
|
||||
ConstantUtf8 u8_2 = (ConstantUtf8)this.constants[n.getSignatureIndex()];
|
||||
this.n_a_t_table.put(u8.getBytes() + "%" + u8_2.getBytes(), new Index(i));
|
||||
} else if (c instanceof ConstantUtf8) {
|
||||
ConstantUtf8 u = (ConstantUtf8)c;
|
||||
this.utf8_table.put(u.getBytes(), new Index(i));
|
||||
} else if (c instanceof ConstantCP) {
|
||||
ConstantCP m = (ConstantCP)c;
|
||||
ConstantClass clazz = (ConstantClass)this.constants[m.getClassIndex()];
|
||||
ConstantNameAndType n = (ConstantNameAndType)this.constants[m.getNameAndTypeIndex()];
|
||||
ConstantUtf8 u8 = (ConstantUtf8)this.constants[clazz.getNameIndex()];
|
||||
String class_name = u8.getBytes().replace('/', '.');
|
||||
u8 = (ConstantUtf8)this.constants[n.getNameIndex()];
|
||||
String method_name = u8.getBytes();
|
||||
u8 = (ConstantUtf8)this.constants[n.getSignatureIndex()];
|
||||
String signature = u8.getBytes();
|
||||
String delim = ":";
|
||||
if (c instanceof ConstantInterfaceMethodref) {
|
||||
delim = "#";
|
||||
} else if (c instanceof ConstantFieldref) {
|
||||
delim = "&";
|
||||
}
|
||||
this.cp_table.put(class_name + delim + method_name + delim + signature, new Index(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConstantPoolGen(ConstantPool cp) {
|
||||
this(cp.getConstantPool());
|
||||
}
|
||||
|
||||
public ConstantPoolGen() {}
|
||||
|
||||
protected void adjustSize() {
|
||||
if (this.index + 3 >= this.size) {
|
||||
Constant[] cs = this.constants;
|
||||
this.size *= 2;
|
||||
this.constants = new Constant[this.size];
|
||||
System.arraycopy(cs, 0, this.constants, 0, this.index);
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap string_table = new HashMap();
|
||||
|
||||
public int lookupString(String str) {
|
||||
Index index = (Index)this.string_table.get(str);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int addString(String str) {
|
||||
int ret;
|
||||
if ((ret = lookupString(str)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ConstantUtf8 u8 = new ConstantUtf8(str);
|
||||
ConstantString s = new ConstantString(this.index);
|
||||
this.constants[this.index++] = u8;
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = s;
|
||||
this.string_table.put(str, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
private HashMap class_table = new HashMap();
|
||||
|
||||
public int lookupClass(String str) {
|
||||
Index index = (Index)this.class_table.get(str.replace('.', '/'));
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
private int addClass_(String clazz) {
|
||||
int ret;
|
||||
if ((ret = lookupClass(clazz)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ConstantClass c = new ConstantClass(addUtf8(clazz));
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = c;
|
||||
this.class_table.put(clazz, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int addClass(String str) {
|
||||
return addClass_(str.replace('.', '/'));
|
||||
}
|
||||
|
||||
public int addClass(ObjectType type) {
|
||||
return addClass(type.getClassName());
|
||||
}
|
||||
|
||||
public int addArrayClass(ArrayType type) {
|
||||
return addClass_(type.getSignature());
|
||||
}
|
||||
|
||||
public int lookupInteger(int n) {
|
||||
for (int i = 1; i < this.index; i++) {
|
||||
if (this.constants[i] instanceof ConstantInteger) {
|
||||
ConstantInteger c = (ConstantInteger)this.constants[i];
|
||||
if (c.getBytes() == n)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int addInteger(int n) {
|
||||
int ret;
|
||||
if ((ret = lookupInteger(n)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantInteger(n);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int lookupFloat(float n) {
|
||||
for (int i = 1; i < this.index; i++) {
|
||||
if (this.constants[i] instanceof ConstantFloat) {
|
||||
ConstantFloat c = (ConstantFloat)this.constants[i];
|
||||
if (c.getBytes() == n)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int addFloat(float n) {
|
||||
int ret;
|
||||
if ((ret = lookupFloat(n)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantFloat(n);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private HashMap utf8_table = new HashMap();
|
||||
|
||||
public int lookupUtf8(String n) {
|
||||
Index index = (Index)this.utf8_table.get(n);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int addUtf8(String n) {
|
||||
int ret;
|
||||
if ((ret = lookupUtf8(n)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantUtf8(n);
|
||||
this.utf8_table.put(n, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int lookupLong(long n) {
|
||||
for (int i = 1; i < this.index; i++) {
|
||||
if (this.constants[i] instanceof ConstantLong) {
|
||||
ConstantLong c = (ConstantLong)this.constants[i];
|
||||
if (c.getBytes() == n)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int addLong(long n) {
|
||||
int ret;
|
||||
if ((ret = lookupLong(n)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ret = this.index;
|
||||
this.constants[this.index] = new ConstantLong(n);
|
||||
this.index += 2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int lookupDouble(double n) {
|
||||
for (int i = 1; i < this.index; i++) {
|
||||
if (this.constants[i] instanceof ConstantDouble) {
|
||||
ConstantDouble c = (ConstantDouble)this.constants[i];
|
||||
if (c.getBytes() == n)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int addDouble(double n) {
|
||||
int ret;
|
||||
if ((ret = lookupDouble(n)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
ret = this.index;
|
||||
this.constants[this.index] = new ConstantDouble(n);
|
||||
this.index += 2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private HashMap n_a_t_table = new HashMap();
|
||||
|
||||
public int lookupNameAndType(String name, String signature) {
|
||||
Index index = (Index)this.n_a_t_table.get(name + "%" + signature);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int addNameAndType(String name, String signature) {
|
||||
int ret;
|
||||
if ((ret = lookupNameAndType(name, signature)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
int name_index = addUtf8(name);
|
||||
int signature_index = addUtf8(signature);
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantNameAndType(name_index, signature_index);
|
||||
this.n_a_t_table.put(name + "%" + signature, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
private HashMap cp_table = new HashMap();
|
||||
|
||||
public int lookupMethodref(String class_name, String method_name, String signature) {
|
||||
Index index = (Index)this.cp_table.get(class_name + ":" + method_name + ":" + signature);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int lookupMethodref(MethodGen method) {
|
||||
return lookupMethodref(method.getClassName(), method.getName(), method.getSignature());
|
||||
}
|
||||
|
||||
public int addMethodref(String class_name, String method_name, String signature) {
|
||||
int ret;
|
||||
if ((ret = lookupMethodref(class_name, method_name, signature)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
int name_and_type_index = addNameAndType(method_name, signature);
|
||||
int class_index = addClass(class_name);
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantMethodref(class_index, name_and_type_index);
|
||||
this.cp_table.put(class_name + ":" + method_name + ":" + signature, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int addMethodref(MethodGen method) {
|
||||
return addMethodref(method.getClassName(), method.getName(), method.getSignature());
|
||||
}
|
||||
|
||||
public int lookupInterfaceMethodref(String class_name, String method_name, String signature) {
|
||||
Index index = (Index)this.cp_table.get(class_name + "#" + method_name + "#" + signature);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int lookupInterfaceMethodref(MethodGen method) {
|
||||
return lookupInterfaceMethodref(method.getClassName(), method.getName(), method.getSignature());
|
||||
}
|
||||
|
||||
public int addInterfaceMethodref(String class_name, String method_name, String signature) {
|
||||
int ret;
|
||||
if ((ret = lookupInterfaceMethodref(class_name, method_name, signature)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
int class_index = addClass(class_name);
|
||||
int name_and_type_index = addNameAndType(method_name, signature);
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantInterfaceMethodref(class_index, name_and_type_index);
|
||||
this.cp_table.put(class_name + "#" + method_name + "#" + signature, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int addInterfaceMethodref(MethodGen method) {
|
||||
return addInterfaceMethodref(method.getClassName(), method.getName(), method.getSignature());
|
||||
}
|
||||
|
||||
public int lookupFieldref(String class_name, String field_name, String signature) {
|
||||
Index index = (Index)this.cp_table.get(class_name + "&" + field_name + "&" + signature);
|
||||
return (index != null) ? index.index : -1;
|
||||
}
|
||||
|
||||
public int addFieldref(String class_name, String field_name, String signature) {
|
||||
int ret;
|
||||
if ((ret = lookupFieldref(class_name, field_name, signature)) != -1)
|
||||
return ret;
|
||||
adjustSize();
|
||||
int class_index = addClass(class_name);
|
||||
int name_and_type_index = addNameAndType(field_name, signature);
|
||||
ret = this.index;
|
||||
this.constants[this.index++] = new ConstantFieldref(class_index, name_and_type_index);
|
||||
this.cp_table.put(class_name + "&" + field_name + "&" + signature, new Index(ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Constant getConstant(int i) {
|
||||
return this.constants[i];
|
||||
}
|
||||
|
||||
public void setConstant(int i, Constant c) {
|
||||
this.constants[i] = c;
|
||||
}
|
||||
|
||||
public ConstantPool getConstantPool() {
|
||||
return new ConstantPool(this.constants);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public ConstantPool getFinalConstantPool() {
|
||||
Constant[] cs = new Constant[this.index];
|
||||
System.arraycopy(this.constants, 0, cs, 0, this.index);
|
||||
return new ConstantPool(cs);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 1; i < this.index; i++)
|
||||
buf.append(i + ")" + this.constants[i] + "\n");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public int addConstant(Constant c, ConstantPoolGen cp) {
|
||||
ConstantString constantString;
|
||||
ConstantClass s;
|
||||
ConstantNameAndType n;
|
||||
ConstantCP m;
|
||||
ConstantUtf8 u8;
|
||||
ConstantClass clazz;
|
||||
ConstantUtf8 u8_2;
|
||||
ConstantNameAndType constantNameAndType1;
|
||||
ConstantUtf8 constantUtf81;
|
||||
String class_name, name, signature;
|
||||
Constant[] constants = cp.getConstantPool().getConstantPool();
|
||||
switch (c.getTag()) {
|
||||
case 8:
|
||||
constantString = (ConstantString)c;
|
||||
u8 = (ConstantUtf8)constants[constantString.getStringIndex()];
|
||||
return addString(u8.getBytes());
|
||||
case 7:
|
||||
s = (ConstantClass)c;
|
||||
u8 = (ConstantUtf8)constants[s.getNameIndex()];
|
||||
return addClass(u8.getBytes());
|
||||
case 12:
|
||||
n = (ConstantNameAndType)c;
|
||||
u8 = (ConstantUtf8)constants[n.getNameIndex()];
|
||||
u8_2 = (ConstantUtf8)constants[n.getSignatureIndex()];
|
||||
return addNameAndType(u8.getBytes(), u8_2.getBytes());
|
||||
case 1:
|
||||
return addUtf8(((ConstantUtf8)c).getBytes());
|
||||
case 6:
|
||||
return addDouble(((ConstantDouble)c).getBytes());
|
||||
case 4:
|
||||
return addFloat(((ConstantFloat)c).getBytes());
|
||||
case 5:
|
||||
return addLong(((ConstantLong)c).getBytes());
|
||||
case 3:
|
||||
return addInteger(((ConstantInteger)c).getBytes());
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
m = (ConstantCP)c;
|
||||
clazz = (ConstantClass)constants[m.getClassIndex()];
|
||||
constantNameAndType1 = (ConstantNameAndType)constants[m.getNameAndTypeIndex()];
|
||||
constantUtf81 = (ConstantUtf8)constants[clazz.getNameIndex()];
|
||||
class_name = constantUtf81.getBytes().replace('/', '.');
|
||||
constantUtf81 = (ConstantUtf8)constants[constantNameAndType1.getNameIndex()];
|
||||
name = constantUtf81.getBytes();
|
||||
constantUtf81 = (ConstantUtf8)constants[constantNameAndType1.getSignatureIndex()];
|
||||
signature = constantUtf81.getBytes();
|
||||
switch (c.getTag()) {
|
||||
case 11:
|
||||
return addInterfaceMethodref(class_name, name, signature);
|
||||
case 10:
|
||||
return addMethodref(class_name, name, signature);
|
||||
case 9:
|
||||
return addFieldref(class_name, name, signature);
|
||||
}
|
||||
throw new RuntimeException("Unknown constant type " + c);
|
||||
}
|
||||
throw new RuntimeException("Unknown constant type " + c);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public interface ConstantPushInstruction extends PushInstruction, TypedInstruction {
|
||||
Number getValue();
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public abstract class ConversionInstruction extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
|
||||
ConversionInstruction() {}
|
||||
|
||||
protected ConversionInstruction(short opcode) {
|
||||
super(opcode, (short)1);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
switch (this.opcode) {
|
||||
case 136:
|
||||
case 139:
|
||||
case 142:
|
||||
return Type.INT;
|
||||
case 134:
|
||||
case 137:
|
||||
case 144:
|
||||
return Type.FLOAT;
|
||||
case 133:
|
||||
case 140:
|
||||
case 143:
|
||||
return Type.LONG;
|
||||
case 135:
|
||||
case 138:
|
||||
case 141:
|
||||
return Type.DOUBLE;
|
||||
case 145:
|
||||
return Type.BYTE;
|
||||
case 146:
|
||||
return Type.CHAR;
|
||||
case 147:
|
||||
return Type.SHORT;
|
||||
}
|
||||
throw new ClassGenException("Unknown type " + this.opcode);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class D2F extends ConversionInstruction {
|
||||
public D2F() {
|
||||
super((short)144);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitConversionInstruction(this);
|
||||
v.visitD2F(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class D2I extends ConversionInstruction {
|
||||
public D2I() {
|
||||
super((short)142);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitConversionInstruction(this);
|
||||
v.visitD2I(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class D2L extends ConversionInstruction {
|
||||
public D2L() {
|
||||
super((short)143);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitConversionInstruction(this);
|
||||
v.visitD2L(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DADD extends ArithmeticInstruction {
|
||||
public DADD() {
|
||||
super((short)99);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDADD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DALOAD extends ArrayInstruction implements StackProducer {
|
||||
public DALOAD() {
|
||||
super((short)49);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitDALOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DASTORE extends ArrayInstruction implements StackConsumer {
|
||||
public DASTORE() {
|
||||
super((short)82);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackConsumer(this);
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitArrayInstruction(this);
|
||||
v.visitDASTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DCMPG extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
|
||||
public DCMPG() {
|
||||
super((short)152, (short)1);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
return Type.DOUBLE;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitDCMPG(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DCMPL extends Instruction implements TypedInstruction, StackProducer, StackConsumer {
|
||||
public DCMPL() {
|
||||
super((short)151, (short)1);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
return Type.DOUBLE;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitDCMPL(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DCONST extends Instruction implements ConstantPushInstruction, TypedInstruction {
|
||||
private double value;
|
||||
|
||||
DCONST() {}
|
||||
|
||||
public DCONST(double f) {
|
||||
super((short)14, (short)1);
|
||||
if (f == 0.0D) {
|
||||
this.opcode = 14;
|
||||
} else if (f == 1.0D) {
|
||||
this.opcode = 15;
|
||||
} else {
|
||||
throw new ClassGenException("DCONST can be used only for 0.0 and 1.0: " + f);
|
||||
}
|
||||
this.value = f;
|
||||
}
|
||||
|
||||
public Number getValue() {
|
||||
return new Double(this.value);
|
||||
}
|
||||
|
||||
public Type getType(ConstantPoolGen cp) {
|
||||
return Type.DOUBLE;
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitPushInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitConstantPushInstruction(this);
|
||||
v.visitDCONST(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DDIV extends ArithmeticInstruction {
|
||||
public DDIV() {
|
||||
super((short)111);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDDIV(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DLOAD extends LoadInstruction {
|
||||
DLOAD() {
|
||||
super((short)24, (short)38);
|
||||
}
|
||||
|
||||
public DLOAD(int n) {
|
||||
super((short)24, (short)38, n);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
super.accept(v);
|
||||
v.visitDLOAD(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DMUL extends ArithmeticInstruction {
|
||||
public DMUL() {
|
||||
super((short)107);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDMUL(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DNEG extends ArithmeticInstruction {
|
||||
public DNEG() {
|
||||
super((short)119);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDNEG(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DREM extends ArithmeticInstruction {
|
||||
public DREM() {
|
||||
super((short)115);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDREM(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DRETURN extends ReturnInstruction {
|
||||
public DRETURN() {
|
||||
super((short)175);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitExceptionThrower(this);
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitReturnInstruction(this);
|
||||
v.visitDRETURN(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DSTORE extends StoreInstruction {
|
||||
DSTORE() {
|
||||
super((short)57, (short)71);
|
||||
}
|
||||
|
||||
public DSTORE(int n) {
|
||||
super((short)57, (short)71, n);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
super.accept(v);
|
||||
v.visitDSTORE(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DSUB extends ArithmeticInstruction {
|
||||
public DSUB() {
|
||||
super((short)103);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitTypedInstruction(this);
|
||||
v.visitStackProducer(this);
|
||||
v.visitStackConsumer(this);
|
||||
v.visitArithmeticInstruction(this);
|
||||
v.visitDSUB(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.apache.bcel.generic;
|
||||
|
||||
public class DUP extends StackInstruction implements PushInstruction {
|
||||
public DUP() {
|
||||
super((short)89);
|
||||
}
|
||||
|
||||
public void accept(Visitor v) {
|
||||
v.visitStackProducer(this);
|
||||
v.visitPushInstruction(this);
|
||||
v.visitStackInstruction(this);
|
||||
v.visitDUP(this);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue