ObjectVariableInfo(ConstantPool cp, TypeDesc desc) { mClassInfo = cp.addConstantClass(desc); }
/** * Add an interface that this class implements. * * @param interfaceName Full interface name. */ public void addInterface(String interfaceName) { if (!mInterfaceSet.contains(interfaceName)) { mInterfaces.add(mCp.addConstantClass(interfaceName)); mInterfaceSet.add(interfaceName); } }
public void instanceOf(TypeDesc type) { ConstantInfo info = mCp.addConstantClass(type); addInstruction(0, TypeDesc.INT, Opcode.INSTANCEOF, info); }
public void checkCast(TypeDesc type) { ConstantInfo info = mCp.addConstantClass(type); addInstruction(0, TypeDesc.VOID, Opcode.CHECKCAST, info); }
/** * By default, the ClassFile defines public, non-final, concrete classes. * <p> * Use the {@link #setModifiers} method to change the access modifiers of * this class or to turn it into an interface. * * @param className Full class name of the form ex: "java.lang.String". * @param superClassName Full super class name. */ public ClassFile(String className, String superClassName) { if (superClassName == null) { if (!className.equals(Object.class.getName())) { superClassName = Object.class.getName(); } } mCp = new ConstantPool(); // public, non-final, concrete class mModifiers = Modifiers.PUBLIC; mThisClass = mCp.addConstantClass(className); mSuperClass = mCp.addConstantClass(superClassName); mClassName = className; mSuperClassName = superClassName; }
public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
/** * Get or create a constant from the constant pool representing a field in * any class. */ public ConstantFieldInfo addConstantField(String className, String fieldName, TypeDesc type) { ConstantInfo ci = new ConstantFieldInfo (addConstantClass(className), addConstantNameAndType(fieldName, type)); return (ConstantFieldInfo)addConstant(ci); }
/** * Add a declared exception that this method may throw. */ public void addException(TypeDesc type) { if (mExceptions == null) { addAttribute(new ExceptionsAttr(mCp)); } // TODO: Special handling for generics ConstantClassInfo cci = mCp.addConstantClass(type); mExceptions.addException(cci); }
/** * @param inner The full inner class name * @param outer The full outer class name * @param name The simple name of the inner class, or null if anonymous * @param modifiers Modifiers for the inner class */ public void addInnerClass(String inner, String outer, String name, Modifiers modifiers) { ConstantClassInfo innerInfo = getConstantPool().addConstantClass(inner); ConstantClassInfo outerInfo; if (outer == null) { outerInfo = null; } else { outerInfo = getConstantPool().addConstantClass(outer); } ConstantUTFInfo nameInfo; if (name == null) { nameInfo = null; } else { nameInfo = getConstantPool().addConstantUTF(name); } mInnerClasses.add(new Info(innerInfo, outerInfo, nameInfo, modifiers)); }
public void newObject(TypeDesc type, int dimensions) { if (dimensions <= 0) { // If type refers to an array, then this code is bogus. mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); return; } TypeDesc componentType = type.getComponentType(); if (dimensions == 1) { if (componentType.isPrimitive()) { addInstruction(0, type, Opcode.NEWARRAY, (byte)componentType.getTypeCode()); return; } addInstruction(0, type, Opcode.ANEWARRAY, mCp.addConstantClass(componentType)); return; } int stackAdjust = -(dimensions - 1); ConstantInfo info = mCp.addConstantClass(type); byte[] bytes = new byte[4]; bytes[0] = Opcode.MULTIANEWARRAY; //bytes[1] = (byte)0; //bytes[2] = (byte)0; bytes[3] = (byte)dimensions; mInstructions.new ConstantOperandInstruction(stackAdjust, type, bytes, info); }
public void exceptionHandler(Location startLocation, Location endLocation, String catchClassName) { if (!(startLocation instanceof InstructionList.LabelInstruction)) { throw new IllegalArgumentException("Start location is not a label instruction"); } if (!(endLocation instanceof InstructionList.LabelInstruction)) { throw new IllegalArgumentException("End location is not a label instruction"); } Location catchLocation = createLabel().setLocation(); ConstantClassInfo catchClass; if (catchClassName == null) { catchClass = null; } else { catchClass = mCp.addConstantClass(catchClassName); } ExceptionHandler<InstructionList.LabelInstruction> handler = new ExceptionHandler<InstructionList.LabelInstruction> ((InstructionList.LabelInstruction)startLocation, (InstructionList.LabelInstruction)endLocation, (InstructionList.LabelInstruction)catchLocation, catchClass); mInstructions.addExceptionHandler(handler); }
/** * Get or create a constant from the constant pool representing a method * in any class. If the method returns void, set ret to null. */ public ConstantMethodInfo addConstantMethod(String className, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); ConstantInfo ci = new ConstantMethodInfo (addConstantClass(className), addConstantNameAndType(methodName, md)); return (ConstantMethodInfo)addConstant(ci); }
/** * Get or create a constant from the constant pool representing an * interface method in any interface. */ public ConstantInterfaceMethodInfo addConstantInterfaceMethod(String className, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); ConstantInfo ci = new ConstantInterfaceMethodInfo (addConstantClass(className), addConstantNameAndType(methodName, md)); return (ConstantInterfaceMethodInfo)addConstant(ci); }
public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
/** * Add an inner class to this method. * * @param innerClassName Optional short inner class name. * @param superClassName Full super class name. */ public ClassFile addInnerClass(String innerClassName, String superClassName) { ClassFile inner; if (innerClassName == null) { inner = mParent.addInnerClass(null, null, superClassName); } else { String fullInnerClassName = mParent.getClassName() + '$' + (++mAnonymousInnerClassCount) + innerClassName; inner = mParent.addInnerClass(fullInnerClassName, innerClassName, superClassName); } if (mParent.getMajorVersion() >= 49) { inner.addAttribute(new EnclosingMethodAttr (mCp, mCp.addConstantClass(mParent.getClassName()), mCp.addConstantNameAndType(mNameConstant, mDescriptorConstant))); } return inner; }
/** * Add an interface that this class implements. * * @param interfaceName Full interface name. */ public void addInterface(String interfaceName) { if (!mInterfaceSet.contains(interfaceName)) { mInterfaces.add(mCp.addConstantClass(interfaceName)); mInterfaceSet.add(interfaceName); } }
/** * Get or create a constant from the constant pool representing a field in * any class. */ public ConstantFieldInfo addConstantField(String className, String fieldName, TypeDesc type) { ConstantInfo ci = new ConstantFieldInfo (addConstantClass(className), addConstantNameAndType(fieldName, type)); return (ConstantFieldInfo)addConstant(ci); }
/** * Add a declared exception that this method may throw. */ public void addException(TypeDesc type) { if (mExceptions == null) { addAttribute(new ExceptionsAttr(mCp)); } // TODO: Special handling for generics ConstantClassInfo cci = mCp.addConstantClass(type); mExceptions.addException(cci); }
public void newObject(TypeDesc type) { if (type.isArray()) { newObject(type, 1); } else { mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); } }
/** * Get or create a constant from the constant pool representing a method * in any class. If the method returns void, set ret to null. */ public ConstantMethodInfo addConstantMethod(String className, String methodName, TypeDesc ret, TypeDesc[] params) { MethodDesc md = MethodDesc.forArguments(ret, params); ConstantInfo ci = new ConstantMethodInfo (addConstantClass(className), addConstantNameAndType(methodName, md)); return (ConstantMethodInfo)addConstant(ci); }