Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.MethodGen


  private void initialize() {
    if (returnType != null) {
      return;
    }

    MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPool(), true);

    this.returnType = gen.getReturnType();
    this.argumentTypes = gen.getArgumentTypes();
    this.declaredExceptions = gen.getExceptions();
    this.attributes = gen.getAttributes();
    // this.annotations = gen.getAnnotations();
    this.maxLocals = gen.getMaxLocals();

    // this.returnType = BcelWorld.makeBcelType(memberView.getReturnType());
    // this.argumentTypes =
    // BcelWorld.makeBcelTypes(memberView.getParameterTypes());
    //
    // this.declaredExceptions =
    // UnresolvedType.getNames(memberView.getExceptions());
    // //gen.getExceptions();
    // this.attributes = new Attribute[0]; //gen.getAttributes();
    // this.maxLocals = savedMethod.getCode().getMaxLocals();

    if (gen.isAbstract() || gen.isNative()) {
      body = null;
    } else {
      // body = new InstructionList(savedMethod.getCode().getCode());
      body = gen.getInstructionList();
      unpackHandlers(gen);
      ensureAllLineNumberSetup();
      highestLineNumber = gen.getHighestlinenumber();
    }
    assertGoodBody();
  }
View Full Code Here


      return savedMethod; // ??? this relies on gentle treatment of
      // constant pool
    }

    try {
      MethodGen gen = pack();
      savedMethod = gen.getMethod();
      return savedMethod;
    } catch (ClassGenException e) {
      enclosingClass.getBcelObjectType().getResolvedTypeX().getWorld().showMessage(
          IMessage.ERROR,
          WeaverMessages.format(WeaverMessages.PROBLEM_GENERATING_METHOD, this.getClassName(), this.getName(), e
              .getMessage()), this.getMemberView() == null ? null : this.getMemberView().getSourceLocation(), null);
      // throw e; PR 70201.... let the normal problem reporting
      // infrastructure deal with this rather than crashing.
      body = null;
      MethodGen gen = pack();
      return gen.getMethod();
    }
  }
View Full Code Here

    int flags = getAccessFlags();
    if (enclosingClass.getWorld().isJoinpointSynchronizationEnabled()
        && enclosingClass.getWorld().areSynchronizationPointcutsInUse()) {
      flags = getAccessFlagsWithoutSynchronized();
    }
    MethodGen gen = new MethodGen(flags, getReturnType(), getArgumentTypes(), null, // getArgumentNames(),
        getName(), getEnclosingClass().getName(), new InstructionList(), getEnclosingClass().getConstantPool());
    for (int i = 0, len = declaredExceptions.length; i < len; i++) {
      gen.addException(declaredExceptions[i]);
    }

    for (Attribute attr : attributes) {
      gen.addAttribute(attr);
    }

    if (newAnnotations != null) {
      for (AnnotationAJ element : newAnnotations) {
        gen.addAnnotation(new AnnotationGen(((BcelAnnotation) element).getBcelAnnotation(), gen.getConstantPool(), true));
      }
    }

    if (newParameterAnnotations != null) {
      for (int i = 0; i < newParameterAnnotations.length; i++) {
        AnnotationAJ[] annos = newParameterAnnotations[i];
        for (int j = 0; j < annos.length; j++) {
          gen.addParameterAnnotation(i, new AnnotationGen(((BcelAnnotation) annos[j]).getBcelAnnotation(), gen
              .getConstantPool(), true));
        }
      }
    }

    if (memberView != null && memberView.getAnnotations() != null && memberView.getAnnotations().length != 0) {
      AnnotationAJ[] ans = memberView.getAnnotations();
      for (int i = 0, len = ans.length; i < len; i++) {
        AnnotationGen a = ((BcelAnnotation) ans[i]).getBcelAnnotation();
        gen.addAnnotation(new AnnotationGen(a, gen.getConstantPool(), true));
      }
    }

    if (isSynthetic) {
      if (enclosingClass.getWorld().isInJava5Mode()) {
        gen.setModifiers(gen.getModifiers() | ACC_SYNTHETIC);
      }
      // belt and braces, do the attribute even on Java 5 in addition to
      // the modifier flag
      ConstantPool cpg = gen.getConstantPool();
      int index = cpg.addUtf8("Synthetic");
      gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg));
    }

    if (hasBody()) {
      if (this.enclosingClass.getWorld().shouldFastPackMethods()) {
        if (isAdviceMethod() || getName().equals("<clinit>")) {
          packBody(gen);
        } else {
          optimizedPackBody(gen);
        }
      } else {
        packBody(gen);
      }
      gen.setMaxLocals();
      gen.setMaxStack();
    } else {
      gen.setInstructionList(null);
    }
    return gen;
  }
View Full Code Here

            }
            worthRetrying.removeAll(forRemoval);
          }
          if (annotationsToAdd != null) {
            Method oldMethod = mg.getMethod();
            MethodGen myGen = new MethodGen(oldMethod, clazz.getClassName(), clazz.getConstantPool(), false);
            for (AnnotationGen a : annotationsToAdd) {
              myGen.addAnnotation(a);
            }
            Method newMethod = myGen.getMethod();
            members.set(memberCounter, new LazyMethodGen(newMethod, clazz));
          }

        }
      }
View Full Code Here

                  }
                 
                  Annotation a = decaM.getAnnotationX().getBcelAnnotation();
                  AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
                  Method oldMethod = mg.getMethod();
                  MethodGen myGen = new MethodGen(oldMethod,clazz.getClassName(),clazz.getConstantPoolGen());
                  myGen.addAnnotation(ag);
                  Method newMethod = myGen.getMethod();
                  mg.addAnnotation(decaM.getAnnotationX());
                  members.set(memberCounter,new LazyMethodGen(newMethod,clazz));
                 
                  AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decaM.getSourceLocation(),clazz.getName(),mg.getMethod());
                  reportMethodCtorWeavingMessage(clazz, mg.getMemberView(), decaM,mg.getDeclarationLineNumber());
View Full Code Here

    _out.println("    _cg.addField(field.getField());");
  }

  public void visitMethod(Method method) {
    MethodGen mg = new MethodGen(method, _clazz.getClassName(), _cp);

    Type   result_type = mg.getReturnType();
    Type[] arg_types   = mg.getArgumentTypes();

    _out.println("    InstructionList il = new InstructionList();");
    _out.println("    MethodGen method = new MethodGen(" +
     printFlags(method.getAccessFlags()) +
     ", " + printType(result_type) +
     ", " + printArgumentTypes(arg_types) + ", " +
     "new String[] { " +
     Utility.printArray(mg.getArgumentNames(), false, true) +
     " }, \"" + method.getName() + "\", \"" +
     _clazz.getClassName() + "\", il, _cp);\n");
   
    BCELFactory factory = new BCELFactory(mg, _out);
    factory.start();
View Full Code Here

   
    Method[] methods = jc.getMethods(); // Method no "method_no" exists, we ran Pass3a before on it!

    try{

      MethodGen mg = new MethodGen(methods[method_no], myOwner.getClassName(), constantPoolGen);

      icv.setMethodGen(mg);
       
      ////////////// DFA BEGINS HERE ////////////////
      if (! (mg.isAbstract() || mg.isNative()) ){ // IF mg HAS CODE (See pass 2)
       
        ControlFlowGraph cfg = new ControlFlowGraph(mg);

        // Build the initial frame situation for this method.
        Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack());
        if ( !mg.isStatic() ){
          if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){
            Frame._this = new UninitializedObjectType(new ObjectType(jc.getClassName()));
            f.getLocals().set(0, Frame._this);
          }
          else{
            Frame._this = null;
            f.getLocals().set(0, new ObjectType(jc.getClassName()));
          }
        }
        Type[] argtypes = mg.getArgumentTypes();
        int twoslotoffset = 0;
        for (int j=0; j<argtypes.length; j++){
          if (argtypes[j] == Type.SHORT || argtypes[j] == Type.BYTE || argtypes[j] == Type.CHAR || argtypes[j] == Type.BOOLEAN){
            argtypes[j] = Type.INT;
          }
          f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), argtypes[j]);
          if (argtypes[j].getSize() == 2){
            twoslotoffset++;
            f.getLocals().set(twoslotoffset + j + (mg.isStatic()?0:1), Type.UNKNOWN);
          }
        }
        circulationPump(cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
      }
    }
    catch (VerifierConstraintViolatedException ce){
      ce.extendMessage("Constraint violated in method '"+methods[method_no]+"':\n","");
      return new VerificationResult(VerificationResult.VERIFIED_REJECTED, ce.getMessage());
View Full Code Here

    public Method getMethod() {
      if (savedMethod != null) return savedMethod;  //??? this relies on gentle treatment of constant pool
     
      try {
      MethodGen gen = pack();
      return gen.getMethod();
      } catch (ClassGenException e) {
        enclosingClass.getBcelObjectType().getResolvedTypeX().getWorld().showMessage(
          IMessage.ERROR,
        WeaverMessages.format(WeaverMessages.PROBLEM_GENERATING_METHOD,
                          this.getClassName(),
                    this.getName(),
                    e.getMessage()),
          this.getMemberView() == null ? null : this.getMemberView().getSourceLocation(), null);
//        throw e; PR 70201.... let the normal problem reporting infrastructure deal with this rather than crashing.
        body = null;
           MethodGen gen = pack();
           return gen.getMethod();
      }
    }
View Full Code Here

   
    // ---- packing!
   
    public MethodGen pack() {
      //killNops();
        MethodGen gen =
            new MethodGen(
                getAccessFlags(),
                getReturnType(),
                getArgumentTypes(),
                null, //getArgumentNames(),
                getName(),
                getEnclosingClass().getName(),
                new InstructionList(),
                getEnclosingClass().getConstantPoolGen());
        for (int i = 0, len = declaredExceptions.length; i < len; i++) {
            gen.addException(declaredExceptions[i]);
        }
       
        for (int i = 0, len = attributes.length; i < len; i++) {
            gen.addAttribute(attributes[i]);
        }
       
        if (newAnnotations!=null) {
      for (Iterator iter = newAnnotations.iterator(); iter.hasNext();) {
        AnnotationX element = (AnnotationX) iter.next();
        gen.addAnnotation(new AnnotationGen(element.getBcelAnnotation(),gen.getConstantPool(),true));
      }
        }
   
        if (memberView!=null && memberView.getAnnotations()!=null && memberView.getAnnotations().length!=0) {
      AnnotationX[] ans = memberView.getAnnotations();
          for (int i = 0, len = ans.length; i < len; i++) {
      Annotation a= ans[i].getBcelAnnotation();
            gen.addAnnotation(new AnnotationGen(a,gen.getConstantPool(),true));
          }
        }
       
        if (isSynthetic) {
      ConstantPoolGen cpg = gen.getConstantPool();
      int index = cpg.addUtf8("Synthetic");
      gen.addAttribute(new Synthetic(index, 0, new byte[0], cpg.getConstantPool()));
        }
       
        if (hasBody()) {
            packBody(gen);
            gen.setMaxLocals();
            gen.setMaxStack();
        } else {
          gen.setInstructionList(null);
        }
        return gen;
    }
View Full Code Here

    private void initialize() {
      if (returnType != null) return;
     
      //System.err.println("initializing: " + getName() + ", " + enclosingClass.getName() + ", " + returnType + ", " + savedMethod);
     
    MethodGen gen = new MethodGen(savedMethod, enclosingClass.getName(), enclosingClass.getConstantPoolGen());
       
    this.returnType = gen.getReturnType();
    this.argumentTypes = gen.getArgumentTypes();

    this.declaredExceptions = gen.getExceptions();
    this.attributes = gen.getAttributes();
    //this.annotations = gen.getAnnotations();
    this.maxLocals = gen.getMaxLocals();
       
//    this.returnType = BcelWorld.makeBcelType(memberView.getReturnType());
//    this.argumentTypes = BcelWorld.makeBcelTypes(memberView.getParameterTypes());
//
//    this.declaredExceptions = UnresolvedType.getNames(memberView.getExceptions()); //gen.getExceptions();
//    this.attributes = new Attribute[0]; //gen.getAttributes();
//    this.maxLocals = savedMethod.getCode().getMaxLocals();
       
       
        if (gen.isAbstract() || gen.isNative()) {
            body = null;
        } else {
          //body = new InstructionList(savedMethod.getCode().getCode());
            body = gen.getInstructionList();
           
            unpackHandlers(gen);
            unpackLineNumbers(gen);
            unpackLocals(gen);
        }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.MethodGen

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.