Package org.aspectj.apache.bcel.generic

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


      } else if (slots.contains(new Integer(tag.getSlot()))) {
        // we already have a var starting at this tag with this slot
        continue;
      }
      slots.add(Integer.valueOf(tag.getSlot()));
      Type t = tag.getRealType();
      if (t == null) {
        t = BcelWorld.makeBcelType(UnresolvedType.forSignature(tag.getType()));
      }
      gen.addLocalVariable(tag.getName(), t, tag.getSlot(), start, lvpos.end);
    }
View Full Code Here


    il.append(createLoadInstructions(getType(), fact));
  }

  public InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {
    InstructionList il = new InstructionList();
    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS);
    Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.ANNOTATION);
    il.append(target.createLoad(fact));
    il.append(fact.createInvoke("java/lang/Object", "getClass", jlClass, new Type[] {}, Constants.INVOKEVIRTUAL));
    il.append(fact.createConstant(new ObjectType(toType.getName())));
    il.append(fact.createInvoke("java/lang/Class", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
        Constants.INVOKEVIRTUAL));
View Full Code Here

    Expr[] args = call.getArgs();
    // System.out.println("args: " + Arrays.asList(args));
    InstructionList callIl = new InstructionList();
    for (int i = 0, len = args.length; i < len; i++) {
      // XXX only correct for static method calls
      Type desiredType = BcelWorld.makeBcelType(method.getParameterTypes()[i]);
      Expr arg = args[i];
      // if arg is null it is because we couldn't bind it properly, for example see 162135
      if (arg == null) {
        InstructionList iList = new InstructionList();
        iList.append(InstructionFactory.createNull(desiredType));
View Full Code Here

  private InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {

    InstructionList il = new InstructionList();

    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_STRING);
    Type jlClassArray = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_CLASS_ARRAY);
    Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_ANNOTATION);

    Instruction pushConstant = fact.createConstant(new ObjectType(toType.getName()));

    if (kind == Shadow.MethodCall || kind == Shadow.MethodExecution || kind == Shadow.PreInitialization
        || kind == Shadow.Initialization || kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution
        || kind == Shadow.AdviceExecution ||
        // annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
        ((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)) {

      Type jlrMethod = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/reflect/Method;"));
      Type jlAnnotation = BcelWorld.makeBcelType(UnresolvedType.forSignature("Ljava/lang/annotation/Annotation;"));
      Type[] paramTypes = BcelWorld.makeBcelTypes(member.getParameterTypes());

      // il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));

      if (kind == Shadow.MethodCall
          || kind == Shadow.MethodExecution
          || kind == Shadow.AdviceExecution
          ||
          // annotations for fieldset/fieldget when an ITD is involved are stored against a METHOD
          ((kind == Shadow.FieldGet || kind == Shadow.FieldSet) && member.getKind() == Member.METHOD)
          || ((kind == Shadow.ConstructorCall || kind == Shadow.ConstructorExecution) && member.getKind() == Member.METHOD)) {

        // Need to look at the cached annotation before going to fetch it again
        Field annotationCachingField = shadow.getEnclosingClass().getAnnotationCachingField(shadow, toType);

        // Basic idea here is to check if the cached field is null, if it is then initialize it, otherwise use it
        il.append(fact
            .createGetStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
        il.append(InstructionConstants.DUP);
        InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
        il.append(ifNonNull);
        il.append(InstructionConstants.POP);
        il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));

        il.append(fact.createConstant(member.getName()));
        buildArray(il, fact, jlClass, paramTypes, 1);
        // OPTIMIZE cache result of getDeclaredMethod?
        il.append(fact.createInvoke("java/lang/Class", "getDeclaredMethod", jlrMethod,
            new Type[] { jlString, jlClassArray }, Constants.INVOKEVIRTUAL));
        il.append(pushConstant);// fact.createConstant(new ObjectType(toType.getName())));
        il.append(fact.createInvoke("java/lang/reflect/Method", "getAnnotation", jlaAnnotation, new Type[] { jlClass },
            Constants.INVOKEVIRTUAL));
        il.append(InstructionConstants.DUP);
        il.append(fact
            .createPutStatic(shadow.getEnclosingClass().getName(), annotationCachingField.getName(), jlAnnotation));
        InstructionHandle ifNullElse = il.append(InstructionConstants.NOP);
        ifNonNull.setTarget(ifNullElse);

      } else { // init/preinit/ctor-call/ctor-exec
        il.append(fact.createConstant(BcelWorld.makeBcelType(containingType)));
        buildArray(il, fact, jlClass, paramTypes, 1);
        Type jlrCtor = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_CONSTRUCTOR);
        // OPTIMIZE cache result of getDeclaredConstructor and getAnnotation? Might be able to use it again if someone else
        // needs the same annotations?
        il.append(fact.createInvoke("java/lang/Class", "getDeclaredConstructor", jlrCtor, new Type[] { jlClassArray },
            Constants.INVOKEVIRTUAL));
        il.append(pushConstant);
        il.append(fact.createInvoke("java/lang/reflect/Constructor", "getAnnotation", jlaAnnotation,
            new Type[] { jlClass }, Constants.INVOKEVIRTUAL));
      }
    } else if (kind == Shadow.FieldSet || kind == Shadow.FieldGet) {
      Type jlrField = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_FIELD);
      il.append(fact.createConstant(BcelWorld.makeBcelType(containingType))); // Stick the target on the stack
      il.append(fact.createConstant(member.getName())); // Stick what we are after on the stack
      il.append(fact.createInvoke("java/lang/Class", "getDeclaredField", jlrField, new Type[] { jlString },
          Constants.INVOKEVIRTUAL));
      il.append(pushConstant);
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, ResolvedType.VOID, "<init>", new ResolvedType[] { 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] = ResolvedType.INT;
      }
      retval = MemberImpl.method(ut, Modifier.PUBLIC, ResolvedType.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, ResolvedType.VOID, "<init>", new ResolvedType[] { ResolvedType.INT });
    } else {
      throw new BCException("Cannot create array construction signature for this non-array instruction:" + i);
    }
View Full Code Here

      InstructionList il = method.getBody();
      int register = 0;
      for (int i = 0; i < inlineAccessor.getParameterTypes().length; i++) {
        UnresolvedType typeX = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(typeX);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Modifier.isStatic(resolvedMember.getModifiers()) ? Constants.INVOKESTATIC
          : Constants.INVOKEVIRTUAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));
View Full Code Here

      InstructionList il = method.getBody();
      il.append(InstructionConstants.ALOAD_0);
      int register = 1;
      for (int i = 0; i < inlineAccessor.getParameterTypes().length; i++) {
        UnresolvedType typeX = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(typeX);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Constants.INVOKESPECIAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));

      m_inlineAccessorBcelMethods.put(accessor, new BcelMethod(m_aspectGen.getBcelObjectType(), method.getMethod()));
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

TOP

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

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.