Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.Type$TypeHolder


      frameEnv.put(donorFramePos, targetSlot);
      donorFramePos += 1;
    }
    Type[] argTypes = donor.getArgumentTypes();
    for (int i = 0, len = argTypes.length; i < len; i++) {
      Type argType = argTypes[i];
      int argSlot = recipient.allocateLocal(argType);
      ret.insert(InstructionFactory.createStore(argType, argSlot));
      frameEnv.put(donorFramePos, argSlot);
      donorFramePos += argType.getSize();
    }
    return ret;
  }
View Full Code Here


      if (paramsBroken) {
        return;
      }
    }

    Type returnType = Type.VOID;

    // If around advice we must find the actual delegate method and use its return type
    if (paa.adviceKind == AdviceKind.Around) {
      ResolvedMember[] methods = delegateClass.getDeclaredMethods();
      ResolvedMember found = null;
      for (ResolvedMember candidate : methods) {
        if (candidate.getName().equals(methodName)) {
          UnresolvedType[] cparms = candidate.getParameterTypes();
          if (cparms.length == paramTypes.size()) {
            boolean paramsMatch = true;
            for (int i = 0; i < cparms.length; i++) {
              if (!cparms[i].getSignature().equals(paramTypes.get(i).getSignature())) {
                paramsMatch = false;
                break;
              }
            }
            if (paramsMatch) {
              found = candidate;
              break;
            }
          }
        }
      }
      if (found != null) {
        returnType = Type.getType(found.getReturnType().getSignature());
      } else {
        reportError("Unable to find method to invoke.  In class: " + delegateClass.getName() + " cant find "
            + paa.adviceMethod);
        return;
      }
    }

    // Time to construct the method itself:
    LazyMethodGen advice = new LazyMethodGen(Modifier.PUBLIC, returnType, adviceName, paramTypes.toArray(new Type[paramTypes
        .size()]), EMPTY_STRINGS, cg);

    InstructionList adviceBody = advice.getBody();

    // Generate code to load the parameters
    int pos = 1; // first slot after 'this'
    for (int i = 0; i < paramTypes.size(); i++) {
      adviceBody.append(InstructionFactory.createLoad(paramTypes.get(i), pos));
      pos += paramTypes.get(i).getSize();
    }

    // Generate the delegate call
    adviceBody.append(cg.getFactory().createInvoke(paa.adviceClass, methodName, signature + returnType.getSignature(),
        Constants.INVOKESTATIC));

    // Generate the right return
    if (returnType == Type.VOID) {
      adviceBody.append(InstructionConstants.RETURN);
    } else {
      if (returnType.getSignature().length() < 2) {
        String sig = returnType.getSignature();
        if (sig.equals("F")) {
          adviceBody.append(InstructionConstants.FRETURN);
        } else if (sig.equals("D")) {
          adviceBody.append(InstructionConstants.DRETURN);
        } else if (sig.equals("J")) {
View Full Code Here

    ConstantPool cpg = cg.getConstantPool();
    Member retval = null;

    if (i.opcode == Constants.ANEWARRAY) {
      // ANEWARRAY arrayInstruction = (ANEWARRAY)i;
      Type ot = i.getType(cpg);
      UnresolvedType ut = fromBcel(ot);
      ut = UnresolvedType.makeArray(ut, 1);
      retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", new ResolvedType[] { INT });
    } else if (i instanceof MULTIANEWARRAY) {
      MULTIANEWARRAY arrayInstruction = (MULTIANEWARRAY) i;
      UnresolvedType ut = null;
      short dimensions = arrayInstruction.getDimensions();
      ObjectType ot = arrayInstruction.getLoadClassType(cpg);
      if (ot != null) {
        ut = fromBcel(ot);
        ut = UnresolvedType.makeArray(ut, dimensions);
      } else {
        Type t = arrayInstruction.getType(cpg);
        ut = fromBcel(t);
      }
      ResolvedType[] parms = new ResolvedType[dimensions];
      for (int ii = 0; ii < dimensions; ii++) {
        parms[ii] = INT;
      }
      retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", parms);

    } else if (i.opcode == Constants.NEWARRAY) {
      // NEWARRAY arrayInstruction = (NEWARRAY)i;
      Type ot = i.getType();
      UnresolvedType ut = fromBcel(ot);
      retval = MemberImpl.method(ut, Modifier.PUBLIC, UnresolvedType.VOID, "<init>", new ResolvedType[] { INT });
    } else {
      throw new BCException("Cannot create array construction signature for this non-array instruction:" + i);
    }
View Full Code Here

  private void addFieldSetter(LazyClassGen gen, ResolvedMember field, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    Type fieldType = BcelWorld.makeBcelType(field.getType());

    if (Modifier.isStatic(field.getModifiers())) {
      il.append(InstructionFactory.createLoad(fieldType, 0));
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), fieldType, Constants.PUTSTATIC));
    } else {
View Full Code Here

    if (!Modifier.isStatic(method.getModifiers())) {
      il.append(InstructionConstants.ALOAD_0);
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      il.append(InstructionFactory.createLoad(paramType, pos));
      pos += paramType.getSize();
    }
    il.append(Utility.createInvoke(fact, (BcelWorld) aspectType.getWorld(), method));
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(method.getReturnType())));

    mg.getBody().insert(il);
View Full Code Here

    if (couldMatch(gen.getBcelObjectType(), munger.getTestPointcut())) {
      FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perObjectField(gen.getType(), aspectType));

      gen.addField(fg, getSourceLocation());

      Type fieldType = BcelWorld.makeBcelType(aspectType);
      LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC, fieldType, NameMangler.perObjectInterfaceGet(aspectType),
          new Type[0], new String[0], gen);
      InstructionList il = new InstructionList();
      InstructionFactory fact = gen.getFactory();
      il.append(InstructionConstants.ALOAD_0);
View Full Code Here

    // Add an accessor for this new field, the
    // ajc$<aspectname>$localAspectOf() method
    // e.g.
    // "public com_blah_SecurityAspect ajc$com_blah_SecurityAspect$localAspectOf()"
    Type fieldType = BcelWorld.makeBcelType(aspectType);
    LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC | Modifier.STATIC, fieldType,
        NameMangler.perTypeWithinLocalAspectOf(aspectType), new Type[0], new String[0], gen);
    InstructionList il = new InstructionList();
    // PTWIMPL ?? Should check if it is null and throw
    // NoAspectBoundException
View Full Code Here

          body.append(InstructionFactory.createThis());
          pos++;
        }
        Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
        for (int i = 0, len = paramTypes.length; i < len; i++) {
          Type paramType = paramTypes[i];
          body.append(InstructionFactory.createLoad(paramType, pos));
          pos += paramType.getSize();
        }
        body.append(Utility.createInvoke(fact, classWeaver.getWorld(), interMethodBody));
        body.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(mangledInterMethod.getReturnType())));

        if (classWeaver.getWorld().isInJava5Mode()) { // Don't need bridge
          // methods if not in
          // 1.5 mode.
          createAnyBridgeMethodsForCovariance(classWeaver, munger, unMangledInterMethod, onType, classGen, paramTypes);
        }

      } else {
        // ??? this is okay
        // if (!(mg.getBody() == null)) throw new
        // RuntimeException("bas");
      }

      if (world.isInJava5Mode()) {
        String basicSignature = mangledInterMethod.getSignature();
        String genericSignature = ((ResolvedMemberImpl) mangledInterMethod).getSignatureForAttribute();
        if (!basicSignature.equals(genericSignature)) {
          // Add a signature attribute to it
          newMethod.addAttribute(createSignatureAttribute(classGen.getConstantPool(), genericSignature));
        }
      }
      // XXX make sure to check that we set exceptions properly on this
      // guy.
      classWeaver.addLazyMethodGen(newMethod);
      classWeaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(), getSignature().getSourceLocation());

      addNeededSuperCallMethods(classWeaver, onType, munger.getSuperMethodsCalled());

      return true;

    } else if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) {

      // This means the 'gen' should be the top most implementor
      // - if it is *not* then something went wrong after we worked
      // out that it was the top most implementor (see pr49657)
      if (!classGen.getType().isTopmostImplementor(onType)) {
        ResolvedType rtx = classGen.getType().getTopmostImplementor(onType);
        if (rtx == null) {
          // pr302460
          // null means there is something wrong with what we are looking at
          ResolvedType rt = classGen.getType();
          if (rt.isInterface()) {
            ISourceLocation sloc = munger.getSourceLocation();
            classWeaver
                .getWorld()
                .getMessageHandler()
                .handleMessage(
                    MessageUtil.error(
                        "ITD target "
                            + rt.getName()
                            + " is an interface but has been incorrectly determined to be the topmost implementor of "
                            + onType.getName() + ". ITD is " + this.getSignature(), sloc));
          }
          if (!onType.isAssignableFrom(rt)) {
            ISourceLocation sloc = munger.getSourceLocation();
            classWeaver
                .getWorld()
                .getMessageHandler()
                .handleMessage(
                    MessageUtil.error(
                        "ITD target " + rt.getName() + " doesn't appear to implement " + onType.getName()
                            + " why did we consider it the top most implementor? ITD is "
                            + this.getSignature(), sloc));
          }
        } else if (!rtx.isExposedToWeaver()) {
          ISourceLocation sLoc = munger.getSourceLocation();
          classWeaver
              .getWorld()
              .getMessageHandler()
              .handleMessage(
                  MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR, rtx,
                      getAspectType().getName()), (sLoc == null ? getAspectType().getSourceLocation() : sLoc)));
        } else {
          // XXX what does this state mean?
          // We have incorrectly identified what is the top most
          // implementor and its not because
          // a type wasn't exposed to the weaver
        }
        return false;
      } else {

        ResolvedMember mangledInterMethod = AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false);

        LazyMethodGen mg = makeMethodGen(classGen, mangledInterMethod);

        // From 98901#29 - need to copy annotations across
        if (classWeaver.getWorld().isInJava5Mode()) {
          AnnotationAJ annotationsOnRealMember[] = null;
          ResolvedType toLookOn = aspectType;
          if (aspectType.isRawType()) {
            toLookOn = aspectType.getGenericType();
          }
          ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn, memberHoldingAnyAnnotations, false);
          if (realMember == null) {
            throw new BCException("Couldn't find ITD holder member '" + memberHoldingAnyAnnotations + "' on aspect "
                + aspectType);
          }
          annotationsOnRealMember = realMember.getAnnotations();

          if (annotationsOnRealMember != null) {
            for (AnnotationAJ annotationX : annotationsOnRealMember) {
              AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a, classWeaver.getLazyClassGen().getConstantPool(), true);
              mg.addAnnotation(new BcelAnnotation(ag, classWeaver.getWorld()));
            }
          }

          copyOverParameterAnnotations(mg, realMember);
        }

        if (mungingInterface) {
          // we want the modifiers of the ITD to be used for all
          // *implementors* of the
          // interface, but the method itself we add to the interface
          // must be public abstract
          mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
        }

        Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
        Type returnType = BcelWorld.makeBcelType(mangledInterMethod.getReturnType());

        InstructionList body = mg.getBody();
        InstructionFactory fact = classGen.getFactory();
        int pos = 0;

        if (!Modifier.isStatic(mangledInterMethod.getModifiers())) {
          body.append(InstructionFactory.createThis());
          pos++;
        }
        for (int i = 0, len = paramTypes.length; i < len; i++) {
          Type paramType = paramTypes[i];
          body.append(InstructionFactory.createLoad(paramType, pos));
          pos += paramType.getSize();
        }

        body.append(Utility.createInvoke(fact, classWeaver.getWorld(), interMethodBody));
        Type t = BcelWorld.makeBcelType(interMethodBody.getReturnType());
        if (!t.equals(returnType)) {
          body.append(fact.createCast(t, returnType));
        }
        body.append(InstructionFactory.createReturn(returnType));
        mg.definingType = onType;

View Full Code Here

  }

  private void createBridge(BcelClassWeaver weaver, ResolvedMember unMangledInterMethod, LazyClassGen classGen,
      ResolvedMember toBridgeTo) {
    Type[] paramTypes;
    Type returnType;
    InstructionList body;
    InstructionFactory fact;
    int pos;
    ResolvedMember bridgerMethod = AjcMemberMaker.bridgerToInterMethod(unMangledInterMethod, classGen.getType());
    ResolvedMember bridgingSetter = AjcMemberMaker.interMethodBridger(toBridgeTo, aspectType, false); // pr250493

    LazyMethodGen bridgeMethod = makeMethodGen(classGen, bridgingSetter);
    paramTypes = BcelWorld.makeBcelTypes(bridgingSetter.getParameterTypes());
    Type[] bridgingToParms = BcelWorld.makeBcelTypes(unMangledInterMethod.getParameterTypes());
    returnType = BcelWorld.makeBcelType(bridgingSetter.getReturnType());
    body = bridgeMethod.getBody();
    fact = classGen.getFactory();
    pos = 0;
    if (!Modifier.isStatic(bridgingSetter.getModifiers())) {
      body.append(InstructionFactory.createThis());
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().equals(
          unMangledInterMethod.getParameterTypes()[i].getErasureSignature())) {
        // System.err.println("Putting in cast from "+
        // paramType+" to "+bridgingToParms[i]);
        body.append(fact.createCast(paramType, bridgingToParms[i]));
      }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, weaver.getWorld(), bridgerMethod));
    body.append(InstructionFactory.createReturn(returnType));
    classGen.addMethodGen(bridgeMethod);
View Full Code Here

    bridgeMethod.setAccessFlags(bridgeMethod.getAccessFlags() | 0x00000040 /*
                                         * BRIDGE = 0x00000040
                                         */);
    // UnresolvedType[] newParams =
    // munger.getSignature().getParameterTypes();
    Type returnType = BcelWorld.makeBcelType(theBridgeMethod.getReturnType());
    body = bridgeMethod.getBody();
    fact = clazz.getFactory();

    if (!Modifier.isStatic(unMangledInterMethod.getModifiers())) {
      body.append(InstructionFactory.createThis());
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      // if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().
      // equals
      // (unMangledInterMethod.getParameterTypes()[i].getErasureSignature
      // ())) {
      // System.err.println("Putting in cast from "+paramType+" to "+
      // bridgingToParms[i]);
      // body.append(fact.createCast(paramType,bridgingToParms[i]));
      // }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, world, unMangledInterMethod));
    body.append(InstructionFactory.createReturn(returnType));
    clazz.addMethodGen(bridgeMethod);
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.Type$TypeHolder

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.