Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.Method


    // in order to be able to resolve the pointcut references later on
    // we don't need to look in super class, the pointcut reference in the
    // grammar will do it

    for (int i = 0; i < javaClass.getMethods().length; i++) {
      Method method = javaClass.getMethods()[i];
      if (method.getName().startsWith(NameMangler.PREFIX)) {
        continue; // already dealt with by ajc...
      }
      // FIXME alex optimize, this method struct will gets recreated for
      // advice extraction
      AjAttributeMethodStruct mstruct = null;
      boolean processedPointcut = false;
      Attribute[] mattributes = method.getAttributes();
      for (int j = 0; j < mattributes.length; j++) {
        Attribute mattribute = mattributes[j];
        if (acceptAttribute(mattribute)) {
          // TODO speed all this nonsense up rather than looking
          // through all the annotations every time
View Full Code Here


    if (declareMixinAnnotation == null) {
      // No annotation found
      return false;
    }

    Method annotatedMethod = struct.method;
    World world = struct.enclosingType.getWorld();
    NameValuePair declareMixinPatternNameValuePair = getAnnotationElement(declareMixinAnnotation, VALUE);

    // declareMixinPattern could be of the form "Bar*" or "A || B" or "Foo+"
    String declareMixinPattern = declareMixinPatternNameValuePair.getValue().stringifyValue();
    TypePattern targetTypePattern = parseTypePattern(declareMixinPattern, struct);

    // Return value of the annotated method is the interface or class that the mixin delegate should have
    ResolvedType methodReturnType = UnresolvedType.forSignature(annotatedMethod.getReturnType().getSignature()).resolve(world);

    if (methodReturnType.isPrimitiveType()) {
      reportError(getMethodForMessage(struct) + ":  factory methods for a mixin cannot return void or a primitive type",
          struct);
      return false;
    }

    if (annotatedMethod.getArgumentTypes().length > 1) {
      reportError(getMethodForMessage(struct) + ": factory methods for a mixin can take a maximum of one parameter", struct);
      return false;
    }

    // The set of interfaces to be mixed in is either:
View Full Code Here

   *
   * @param struct
   * @return null if no debug info is available
   */
  private static FormalBinding[] extractBindings(AjAttributeMethodStruct struct) throws UnreadableDebugInfoException {
    Method method = struct.method;
    String[] argumentNames = struct.getArgumentNames();

    // assert debug info was here
    if (argumentNames.length != method.getArgumentTypes().length) {
      reportError(
          "Cannot read debug info for @Aspect to handle formal binding in pointcuts (please compile with 'javac -g' or '<javac debug='true'.../>' in Ant)",
          struct);
      throw new UnreadableDebugInfoException();
    }

    List<FormalBinding> bindings = new ArrayList<FormalBinding>();
    for (int i = 0; i < argumentNames.length; i++) {
      String argumentName = argumentNames[i];
      UnresolvedType argumentType = UnresolvedType.forSignature(method.getArgumentTypes()[i].getSignature());

      // do not bind JoinPoint / StaticJoinPoint /
      // EnclosingStaticJoinPoint
      // TODO solve me : this means that the JP/SJP/ESJP cannot appear as
      // binding
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

                    continue; // skip this one...
                  }
                 
                  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

      String name = ((ConstantUtf8) cp.getConstant(obj.getNameIndex())).getBytes();
      if (! name.equals("Code")){
        throw new ClassConstraintException("The Code attribute '"+tostring(obj)+"' is not correctly named 'Code' but '"+name+"'.");
      }

      Method m = null; // satisfy compiler
      if (!(carrier.predecessor() instanceof Method)){
        addMessage("Code attribute '"+tostring(obj)+"' is not declared in a method_info structure but in '"+carrier.predecessor()+"'. Ignored.");
        return;
      }
      else{
View Full Code Here

      JavaClass jc = Repository.lookupClass(myOwner.getClassName());
      Method[] methods = jc.getMethods();
      if (method_no >= methods.length){
        throw new InvalidMethodException("METHOD DOES NOT EXIST!");
      }
      Method method = methods[method_no];
      code = method.getCode();
     
      // No Code? Nothing to verify!
      if ( method.isAbstract() || method.isNative() ){ // IF mg HAS NO CODE (static constraint of Pass 2)
        return VerificationResult.VR_OK;
      }

      // TODO:
      // We want a very sophisticated code examination here with good explanations
      // on where to look for an illegal instruction or such.
      // Only after that we should try to build an InstructionList and throw an
      // AssertionViolatedException if after our examination InstructionList building
      // still fails.
      // That examination should be implemented in a byte-oriented way, i.e. look for
      // an instruction, make sure its validity, count its length, find the next
      // instruction and so on.
      try{
        instructionList = new InstructionList(method.getCode().getCode());
      }
      catch(RuntimeException re){
        return new VerificationResult(VerificationResult.VERIFIED_REJECTED, "Bad bytecode in the code array of the Code attribute of method '"+method+"'.");
      }
     
View Full Code Here

      // INVOKEINTERFACE is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
View Full Code Here

      // INVOKESPECIAL is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verfier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
     
      JavaClass current = Repository.lookupClass(myOwner.getClassName());
      if (current.isSuper()){
     
        if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){
         
          if (! (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME) )){
            // Special lookup procedure for ACC_SUPER classes.
           
            int supidx = -1;
           
            Method meth = null;
            while (supidx != 0){
              supidx = current.getSuperclassNameIndex();
              current = Repository.lookupClass(current.getSuperclassName());
             
              Method[] meths = current.getMethods();
View Full Code Here

      // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
     
      if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2.
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset.");
      }
   
    }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.Method

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.