Package org.aspectj.apache.bcel.generic

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


   */

  private LazyMethodGen makeClosureClassAndReturnConstructor(String closureClassName, LazyMethodGen callbackMethod,
      IntMap proceedMap) {
    String superClassName = "org.aspectj.runtime.internal.AroundClosure";
    Type objectArrayType = new ArrayType(Type.OBJECT, 1);

    LazyClassGen closureClass = new LazyClassGen(closureClassName, superClassName, getEnclosingClass().getFileName(),
        Modifier.PUBLIC, new String[] {}, getWorld());
    InstructionFactory fact = new InstructionFactory(closureClass.getConstantPool());

    // constructor
    LazyMethodGen constructor = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, "<init>", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList cbody = constructor.getBody();
    cbody.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    cbody.append(InstructionFactory.createLoad(objectArrayType, 1));
    cbody.append(fact
        .createInvoke(superClassName, "<init>", Type.VOID, new Type[] { objectArrayType }, Constants.INVOKESPECIAL));
    cbody.append(InstructionFactory.createReturn(Type.VOID));

    closureClass.addMethodGen(constructor);

    // method
    LazyMethodGen runMethod = new LazyMethodGen(Modifier.PUBLIC, Type.OBJECT, "run", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList mbody = runMethod.getBody();
    BcelVar proceedVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), 1);
    // int proceedVarIndex = 1;
    BcelVar stateVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), runMethod.allocateLocal(1));
    // int stateVarIndex = runMethod.allocateLocal(1);
    mbody.append(InstructionFactory.createThis());
    mbody.append(fact.createGetField(superClassName, "state", objectArrayType));
    mbody.append(stateVar.createStore(fact));
    // mbody.append(fact.createStore(objectArrayType, stateVarIndex));

    Type[] stateTypes = callbackMethod.getArgumentTypes();

    for (int i = 0, len = stateTypes.length; i < len; i++) {
      Type stateType = stateTypes[i];
      ResolvedType stateTypeX = BcelWorld.fromBcel(stateType).resolve(world);
      if (proceedMap.hasKey(i)) {
        mbody.append(proceedVar.createConvertableArrayLoad(fact, proceedMap.get(i), stateTypeX));
      } else {
        mbody.append(stateVar.createConvertableArrayLoad(fact, i, stateTypeX));
View Full Code Here


  private InstructionList createLoadInstructions(ResolvedType toType, InstructionFactory fact) {

    InstructionList il = new InstructionList();

    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JL_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, isWithin);

        // 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);
View Full Code Here

   * At a FieldGet or FieldSet shadow, generate the bytecode to access the annotation for that field. The annotation is cached so
   * the code checks that cached value before proceeding.
   */
  private void generateBytecodeToAccessAnnotationAtFieldGetSetShadow(ResolvedType toType, InstructionFactory fact,
      InstructionList il, Instruction pushConstantAnnotationType) {
    Type jlClass = BcelWorld.makeBcelType(UnresolvedType.JL_CLASS);
    Type jlString = BcelWorld.makeBcelType(UnresolvedType.JL_STRING);
    Type jlaAnnotation = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_ANNOTATION);
    Type jlrField = BcelWorld.makeBcelType(UnresolvedType.JAVA_LANG_REFLECT_FIELD);

    LazyClassGen shadowEnclosingClass = shadow.getEnclosingClass();

    // The annotation for the field of interest is cached, check cached value before fetching it
    Field annotationCachingField = shadowEnclosingClass.getAnnotationCachingField(shadow, toType, isWithin);
View Full Code Here

    } else if (fromType.equals(UnresolvedType.VOID)) {
      // assert toType.equals(UnresolvedType.OBJECT)
      il.append(InstructionFactory.createNull(Type.OBJECT));
      return;
    } else if (fromType.equals(UnresolvedType.OBJECT)) {
      Type to = BcelWorld.makeBcelType(toType);
      if (toType.isPrimitiveType()) {
        String name = toType.toString() + "Value";
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, to, new Type[] { Type.OBJECT },
            Constants.INVOKESTATIC));
      } else {
        il.append(fact.createCheckCast((ReferenceType) to));
      }
    } else if (toType.equals(UnresolvedType.OBJECT)) {
      // assert fromType.isPrimitive()
      Type from = BcelWorld.makeBcelType(fromType);
      String name = fromType.toString() + "Object";
      il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, Type.OBJECT, new Type[] { from },
          Constants.INVOKESTATIC));
    } else if (toType.getWorld().isInJava5Mode() && validBoxing.get(toType.getSignature() + fromType.getSignature()) != null) {
      // XXX could optimize by using any java boxing code that may be just
      // before the call...
      Type from = BcelWorld.makeBcelType(fromType);
      Type to = BcelWorld.makeBcelType(toType);
      String name = validBoxing.get(toType.getSignature() + fromType.getSignature());
      if (toType.isPrimitiveType()) {
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, to, new Type[] { Type.OBJECT },
            Constants.INVOKESTATIC));
      } else {
        il.append(fact.createInvoke("org.aspectj.runtime.internal.Conversions", name, Type.OBJECT, new Type[] { from },
            Constants.INVOKESTATIC));
        il.append(fact.createCheckCast((ReferenceType) to));
      }
    } else if (fromType.isPrimitiveType()) {
      // assert toType.isPrimitive()
      Type from = BcelWorld.makeBcelType(fromType);
      Type to = BcelWorld.makeBcelType(toType);
      try {
        Instruction i = fact.createCast(from, to);
        if (i != null) {
          il.append(i);
        } else {
          il.append(fact.createCast(from, Type.INT));
          il.append(fact.createCast(Type.INT, to));
        }
      } catch (RuntimeException e) {
        il.append(fact.createCast(from, Type.INT));
        il.append(fact.createCast(Type.INT, to));
      }
    } else {
      Type to = BcelWorld.makeBcelType(toType);
      // assert ! fromType.isPrimitive() && ! toType.isPrimitive()
      il.append(fact.createCheckCast((ReferenceType) to));
    }
  }
View Full Code Here

    int len = proceedParamTypes.length;
    BcelVar[] ret = new BcelVar[len];

    for (int i = len - 1; i >= 0; i--) {
      ResolvedType typeX = proceedParamTypes[i];
      Type type = BcelWorld.makeBcelType(typeX);
      int local = enclosingMethod.allocateLocal(type);

      il.append(InstructionFactory.createStore(type, local));
      ret[i] = new BcelVar(typeX, local);
    }
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.JL_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

    // assert method.isStatic()
    Expr[] args = call.getArgs();
    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

      if (!isStatic()) {
        String cname = this.enclosingClass.getClassName();
        if (cname == null) {
          return; // give up for now
        }
        Type enclosingType = BcelWorld.makeBcelType(UnresolvedType.forName(cname));
        gen.addLocalVariable("this", enclosingType, slot++, start, end);
      }
      // Add entries for the method arguments
      String[] paramNames = (memberView == null ? null : memberView.getParameterNames());
      if (paramNames != null) {
View Full Code Here

      } 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, end);
    }
View Full Code Here

      if (!isStatic()) {
        String cname = this.enclosingClass.getClassName();
        if (cname == null) {
          return; // give up for now
        }
        Type enclosingType = BcelWorld.makeBcelType(UnresolvedType.forName(cname));
        gen.addLocalVariable("this", enclosingType, slot++, start, end);
      }
      // Add entries for the method arguments
      String[] paramNames = (memberView == null ? null : memberView.getParameterNames());
      if (paramNames != null) {
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.