Search in sources :

Example 36 with InstructionList

use of org.apache.bcel.generic.InstructionList in project qpid-broker-j by apache.

the class LDAPSSLSocketFactoryGenerator method createGetDefaultStaticMethod.

/**
 * Create a static method 'getDefault' returning {@link SocketFactory}
 * that creates a new instance of the sub-class and calls its no-argument
 * constructor, the newly created is returned to the caller.
 *
 * @param classGen
 * @param constantPoolGen
 * @param instructionFactory
 */
private static void createGetDefaultStaticMethod(ClassGen classGen, ConstantPoolGen constantPoolGen, InstructionFactory instructionFactory) {
    InstructionList il = new InstructionList();
    String methodName = "getDefault";
    MethodGen mg = new // access flags
    MethodGen(// access flags
    ACC_STATIC | ACC_PUBLIC, // return type
    Type.getType(SSLSocketFactory.class), // argument types - no args
    new Type[0], // arg names - no args
    new String[0], methodName, // method, class
    classGen.getClassName(), il, constantPoolGen);
    il.append(instructionFactory.createNew(classGen.getClassName()));
    il.append(InstructionConstants.DUP);
    il.append(instructionFactory.createInvoke(classGen.getClassName(), "<init>", Type.VOID, new Type[] {}, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ARETURN);
    mg.setMaxStack();
    classGen.addMethod(mg.getMethod());
    il.dispose();
}
Also used : Type(org.apache.bcel.generic.Type) InstructionList(org.apache.bcel.generic.InstructionList) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) MethodGen(org.apache.bcel.generic.MethodGen)

Example 37 with InstructionList

use of org.apache.bcel.generic.InstructionList in project contribution by checkstyle.

the class VisitorSet method visitCode.

/**
 * @see org.apache.bcel.classfile.Visitor#visitCode
 */
public void visitCode(Code aCode) {
    for (Iterator iter = mVisitors.iterator(); iter.hasNext(); ) {
        IDeepVisitor visitor = (IDeepVisitor) iter.next();
        Visitor v = visitor.getClassFileVisitor();
        aCode.accept(v);
    }
    // perform a deep visit
    final byte[] code = aCode.getCode();
    final InstructionList list = new InstructionList(code);
    final Iterator it = list.iterator();
    for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        InstructionHandle instruction = (InstructionHandle) iter.next();
        visitInstructionHandle(instruction);
    }
}
Also used : Visitor(org.apache.bcel.classfile.Visitor) EmptyVisitor(org.apache.bcel.classfile.EmptyVisitor) InstructionList(org.apache.bcel.generic.InstructionList) Iterator(java.util.Iterator) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

InstructionList (org.apache.bcel.generic.InstructionList)37 InstructionHandle (org.apache.bcel.generic.InstructionHandle)27 Iterator (java.util.Iterator)9 MethodGen (org.apache.bcel.generic.MethodGen)8 Instruction (org.apache.bcel.generic.Instruction)7 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)7 Type (org.apache.bcel.generic.Type)7 InstructionFinder (org.apache.bcel.util.InstructionFinder)7 MethodCode (com.jopdesign.common.MethodCode)6 CPInstruction (org.apache.bcel.generic.CPInstruction)6 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)6 FieldInstruction (org.apache.bcel.generic.FieldInstruction)6 MethodInfo (com.jopdesign.common.MethodInfo)5 NOP (org.apache.bcel.generic.NOP)5 BranchInstruction (org.apache.bcel.generic.BranchInstruction)4 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)4 ClassInfo (com.jopdesign.common.ClassInfo)3 InvokeSite (com.jopdesign.common.code.InvokeSite)3 Constant (org.apache.bcel.classfile.Constant)3 JavaClass (org.apache.bcel.classfile.JavaClass)3