Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Code


                            .getEffectiveTypeQualifierAnnotation(xmethod, i, nonnullTypeQualifierValue);
                    boolean implicitNullCheckForEquals = false;
                    if (directTypeQualifierAnnotation == null && method.getName().equals("equals")
                            && method.getSignature().equals("(Ljava/lang/Object;)Z") && !method.isStatic()) {
                        implicitNullCheckForEquals = true;
                        Code code = method.getCode();
                        ConstantPool cp = jclass.getConstantPool();
                        byte codeBytes[] = code.getCode();
                        for (CodeException e : code.getExceptionTable()) {
                            ConstantClass cl = (ConstantClass) cp.getConstant(e.getCatchType());
                            int endPC = e.getEndPC();
                            int startPC = e.getStartPC();
                            int handlerPC = e.getHandlerPC();
                            if (startPC == 0 && endPC + 1 == handlerPC && handlerPC == codeBytes.length - 3
View Full Code Here


                } else if (definedInClass(superClass).containsAll(definedInClass(clazz))) {
                    priority = NORMAL_PRIORITY;
                } else {
                    priority = HIGH_PRIORITY;
                }
                Code code = null;
                for (Attribute a : obj.getAttributes()) {
                    if (a instanceof Code) {
                        code = (Code) a;
                        break;
                    }
                }
                if (code != null && code.getLength() == 1) {
                    priority++;
                }

                pendingBug = new BugInstance(this, "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", priority).addClassAndMethod(this);
                potentialSuperCall = null;
View Full Code Here

   */
  public static void printCode(Method[] methods, boolean verbose) {
    for(int i=0; i < methods.length; i++) {
      System.out.println(methods[i]);
     
      Code code = methods[i].getCode();
      if(code != null) {
        System.out.println(code.toString(verbose));
    }
    }
  }
View Full Code Here

  /**
   * Patch a method.
   */
  private static Method helloifyMethod(Method m) {
    Code   code  = m.getCode();
    int    flags = m.getAccessFlags();
    String name  = m.getName();
   
    // Sanity check
    if(m.isNative() || m.isAbstract() || (code == null)) {
        return m;
    }
   
    /* Create instruction list to be inserted at method start.
     */
    String mesg = "Hello from " + Utility.methodSignatureToString(m.getSignature(),
                  name,
                  Utility.accessToString(flags));
    InstructionList patch  = new InstructionList();
    patch.append(new GETSTATIC(out));
    patch.append(new PUSH(cp, mesg));
    patch.append(new INVOKEVIRTUAL(println));
   
    MethodGen           mg  = new MethodGen(m, class_name, cp);
    InstructionList     il  = mg.getInstructionList();
    InstructionHandle[] ihs = il.getInstructionHandles();

    if(name.equals("<init>")) { // First let the super or other constructor be called
      for(int j=1; j < ihs.length; j++) {
  if(ihs[j].getInstruction() instanceof INVOKESPECIAL) {
    il.append(ihs[j], patch); // Should check: method name == "<init>"
    break;
  }
      }
    } else {
        il.insert(ihs[0], patch);
    }

    /* Stack size must be at least 2, since the println method takes 2 argument.
     */
    if(code.getMaxStack() < 2) {
        mg.setMaxStack(2);
    }

    m = mg.getMethod();

View Full Code Here

*/
public class LVTTRemover {

    public static void removeLVTTs( Method m, ConstantPoolGen constPoolGen ) {
       
        Code code = m.getCode();
       
        List<Attribute> attrs = new ArrayList<Attribute>();
       
        for( Attribute cAttr : code.getAttributes() ) {
           
            if( !((ConstantUtf8)constPoolGen.getConstant(
                    cAttr.getNameIndex() )).getBytes().equals(
                            "LocalVariableTypeTable" ) ) {
                attrs.add( cAttr );
            }
           
        }
       
        if( code.getAttributes().length != attrs.size() ) {
            code.setAttributes(
                attrs.toArray( new Attribute[attrs.size()] ) );
        }
    }
View Full Code Here

        Make a method abstract.
        @param m The method
    */
    private Method abstractifyMethod (Method m, String className, ConstantPoolGen cp)
    {
        Code code = m.getCode();
        if (m.isNative() ||  m.isAbstract() ||  m.isStatic() || m.isPrivate() ||
            (code == null)) {
            return m;
        }
            //it's illegal to have an empty constructor. Must at least call super.<init>()
View Full Code Here

        return m;
    }

    private static Method removeCodeExceptReturn (Method m, String className, ConstantPoolGen cp)
    {
        Code   code  = m.getCode();
        int    flags = m.getAccessFlags();
        String name  = m.getName();

        InstructionList patch  = new InstructionList();
        MethodGen           mg  = new MethodGen(m, className, cp);
View Full Code Here

        // Obtain the exact method we're interested in.
        if (method == null)
            return null;

        // Get the Code object, which contains the local variable table.
        Code code = method.getCode();
        if (code == null)
            return null;

        LocalVariableTable attr = method.getLocalVariableTable();
        if (attr == null)
View Full Code Here

                result.append(n);
            }

            // Append a code.
            if (printCode) {
                Code code = m.getCode();
                // If the method is not abstract.
                if (code != null) {
                    result.append(indentString(indent * 2, "Code: "));
                    result.append(n);

                    if (verbose) {
                        result.append(indentString(indent * 3, "Max stack="));
                        result.append(code.getMaxStack());
                        result.append(", Max locals=");
                        result.append(code.getMaxLocals());
                        result.append(n);
                    }

                    // Append the code string.
                    result.append(indentString(
                            indent * 3,
                            Utility.codeToString(
                                    code.getCode(), constPool, 0, -1, verbose
                            ))
                    );
                }
            }

View Full Code Here

    }

    private void addCode(Method[] methods) {

        for (int i = 0; i < methods.length; i++) {
            Code code = methods[i].getCode();
            if(code != null) {
                int header = 0;
                int maxLocals = code.getMaxLocals();
                int maxStack = code.getMaxStack();
                CodeException[] exceptions = code.getExceptionTable();
                int handlers = exceptions.length;
                if(handlers <= 2) {
                    if (handlers == 0) {
                        if(maxLocals < 11 && maxStack < 11) {
                            header = 12*maxLocals + maxStack + 1;
                        }
                    } else if (handlers == 1) {
                        if(maxLocals < 7 && maxStack < 7) {
                            header = 8*maxLocals + maxStack + 145;
                        }
                    } else if (handlers == 2) {
                        if(maxLocals < 6 && maxStack < 6) {
                            header = 7*maxLocals + maxStack + 209;
                        }
                    }
                }
                codeHeaders.add(new Integer(header));
                if(header == 0) {
                    codeMaxStack.add(new Integer(maxStack));
                    codeMaxLocals.add(new Integer(maxLocals));
                    codeHandlerCount.add(new Integer(handlers));
                }
                for (int j = 0; j < exceptions.length; j++) {
                    int startPC = exceptions[j].getStartPC();
                    int endPC = exceptions[j].getEndPC();
                    int catchPC = exceptions[j].getHandlerPC();
                    int[] renumbered = renumberBCI(code.getCode());
                    int renumberedStart = renumbered[startPC];
                    int renumberedEnd = renumbered[endPC] - renumberedStart;
                    int renumberedCatch = renumbered[catchPC] - renumberedEnd;
                    codeHandlerStartP.add(new Integer(renumberedStart));
                    codeHandlerEndPO.add(new Integer(renumberedEnd));
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Code

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.