Package org.aspectj.apache.bcel.generic

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


    // if (couldMatch(gen.getBcelObjectType(), munger.getTestPointcut())) {

    // Add (to the target type) the field that will hold the aspect instance
    // e.g ajc$com_blah_SecurityAspect$ptwAspectInstance
    FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType));
    gen.addField(fg, getSourceLocation());

    // 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
    InstructionFactory fact = gen.getFactory();
    il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETSTATIC));
    il.append(InstructionFactory.createReturn(fieldType));
    mg.getBody().insert(il);
    gen.addMethodGen(mg);
    return true;
    // } else {
View Full Code Here


    munger.matches(weaver.getLazyClassGen().getType(), aspectType); // why
    // do
    // this?
    ResolvedMember host = AjcMemberMaker.itdAtDeclareParentsField(weaver.getLazyClassGen().getType(), munger.getSignature()
        .getType(), aspectType);
    FieldGen field = makeFieldGen(weaver.getLazyClassGen(), host);
    field.setModifiers(field.getModifiers() | BcelField.AccSynthetic);
    weaver.getLazyClassGen().addField(field, null);
    return true;
  }
View Full Code Here

        gen.addMethodGen(mg1);
      } else {
        weaver.addInitializer(this);
        ResolvedMember newField = AjcMemberMaker.interFieldClassField(field, aspectType,
            munger.version == NewFieldTypeMunger.VersionTwo);
        FieldGen fg = makeFieldGen(gen, newField);

        if (annotationsOnRealMember != null) {
          for (int i = 0; i < annotationsOnRealMember.length; i++) {
            AnnotationAJ annotationX = annotationsOnRealMember[i];
            AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
            fg.addAnnotation(ag);
          }
        }

        if (weaver.getWorld().isInJava5Mode()) {
          String basicSignature = field.getSignature();
          String genericSignature = field.getReturnType().resolve(weaver.getWorld()).getSignatureForAttribute();
          // String genericSignature =
          // ((ResolvedMemberImpl)field).getSignatureForAttribute();
          if (!basicSignature.equals(genericSignature)) {
            // Add a signature attribute to it
            fg.addAttribute(createSignatureAttribute(gen.getConstantPool(), genericSignature));
          }
        }
        gen.addField(fg, getSourceLocation());

      }
      return true;
    } else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
      // wew know that we can't be static since we don't allow statics on
      // interfaces
      if (Modifier.isStatic(field.getModifiers())) {
        throw new RuntimeException("unimplemented");
      }
      weaver.addInitializer(this);
      // System.err.println("impl body on " + gen.getType() + " for " +
      // munger);

      Type fieldType = BcelWorld.makeBcelType(field.getType());

      FieldGen fg = makeFieldGen(gen, AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));

      if (annotationsOnRealMember != null) {
        for (int i = 0; i < annotationsOnRealMember.length; i++) {
          AnnotationAJ annotationX = annotationsOnRealMember[i];
          AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
          AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
          fg.addAnnotation(ag);
        }
      }

      gen.addField(fg, getSourceLocation());
      // this uses a shadow munger to add init method to constructors
      // weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod)
      // );

      ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType()/* onType */, aspectType);
      LazyMethodGen mg = makeMethodGen(gen, itdfieldGetter);
      InstructionList il = new InstructionList();
      InstructionFactory fact = gen.getFactory();
      if (Modifier.isStatic(field.getModifiers())) {
        il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETSTATIC));
      } else {
        il.append(InstructionConstants.ALOAD_0);
        il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETFIELD));
      }
      il.append(InstructionFactory.createReturn(fieldType));
      mg.getBody().insert(il);

      gen.addMethodGen(mg);

      // Check if we need bridge methods for the field getter and setter
      if (munger.getDeclaredSignature() != null) { // is this munger a
        // parameterized
        // form of some
        // original munger?
        ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,
            munger.getSignature().getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
        boolean needsbridging = false;
        if (!toBridgeTo.getReturnType().getErasureSignature().equals(
            munger.getSignature().getReturnType().getErasureSignature())) {
          needsbridging = true;
        }
        if (needsbridging) {
          ResolvedMember bridgingGetter = AjcMemberMaker.interFieldInterfaceGetter(toBridgeTo, gen.getType(), aspectType);
          createBridgeMethodForITDF(weaver, gen, itdfieldGetter, bridgingGetter);
        }
      }

      ResolvedMember itdfieldSetter = AjcMemberMaker.interFieldInterfaceSetter(field, gen.getType(), aspectType);
      LazyMethodGen mg1 = makeMethodGen(gen, itdfieldSetter);
      InstructionList il1 = new InstructionList();
      if (Modifier.isStatic(field.getModifiers())) {
        il1.append(InstructionFactory.createLoad(fieldType, 0));
        il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTSTATIC));
      } else {
        il1.append(InstructionConstants.ALOAD_0);
        il1.append(InstructionFactory.createLoad(fieldType, 1));
        il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTFIELD));
      }
      il1.append(InstructionFactory.createReturn(Type.VOID));
      mg1.getBody().insert(il1);

      gen.addMethodGen(mg1);
View Full Code Here

    if (world.isTargettingAspectJRuntime12()) { // TAG:SUPPORTING12: We didn't have different staticjp types in 1.2
      jpType = staticTjpType;
    } else {
      jpType = isEnclosingJp?enclosingStaticTjpType:staticTjpType;
    }
    ret = new FieldGen(modifiers,jpType,"ajc$tjp_" + tjpFields.size(),getConstantPoolGen()).getField();
      addField(ret);
      tjpFields.put(shadow, ret);
      return ret;
    }
View Full Code Here

            if(decaF.getAnnotationX().isRuntimeVisible()){ // isAnnotationWithRuntimeRetention(clazz.getJavaClass(world))){
            //if(decaF.getAnnotationTypeX().isAnnotationWithRuntimeRetention(world)){           
              // it should be runtime visible, so put it on the Field
              Annotation a = decaF.getAnnotationX().getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
              FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
              myGen.addAnnotation(ag);
              Field newField = myGen.getField();
             
              aBcelField.addAnnotation(decaF.getAnnotationX());
              clazz.replaceField(fields[fieldCounter],newField);
              fields[fieldCounter]=newField;
             
View Full Code Here

    return ret;
  }


  protected FieldGen makeFieldGen(LazyClassGen gen, ResolvedMember member) {
    return new FieldGen(
      member.getModifiers(),
      BcelWorld.makeBcelType(member.getReturnType()),
      member.getName(),
      gen.getConstantPoolGen());
  }
View Full Code Here

  {
    //System.err.println("Munging perobject ["+munger+"] onto "+weaver.getLazyClassGen().getClassName());
    LazyClassGen gen = weaver.getLazyClassGen();
   
    if (couldMatch(gen.getBcelObjectType(), munger.getTestPointcut())) {
      FieldGen fg = makeFieldGen(gen,
        AjcMemberMaker.perObjectField(gen.getType(), aspectType));

        gen.addField(fg.getField(),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);
      il.append(fact.createFieldAccess(
        gen.getClassName(),
        fg.getName(),
        fieldType, Constants.GETFIELD));
      il.append(InstructionFactory.createReturn(fieldType));
      mg.getBody().insert(il);
       
      gen.addMethodGen(mg);
     
      LazyMethodGen mg1 = new LazyMethodGen(
        Modifier.PUBLIC,
        Type.VOID,
        NameMangler.perObjectInterfaceSet(aspectType),
       
        new Type[]{fieldType,}, new String[0],
        gen);
      InstructionList il1 = new InstructionList();
      il1.append(InstructionConstants.ALOAD_0);
      il1.append(InstructionFactory.createLoad(fieldType, 1));
      il1.append(fact.createFieldAccess(
        gen.getClassName(),
        fg.getName(),
        fieldType, Constants.PUTFIELD));
      il1.append(InstructionFactory.createReturn(Type.VOID));
      mg1.getBody().insert(il1);
       
      gen.addMethodGen(mg1);
View Full Code Here

     
    // if (couldMatch(gen.getBcelObjectType(), munger.getTestPointcut())) {
     
      // Add (to the target type) the field that will hold the aspect instance
      // e.g ajc$com_blah_SecurityAspect$ptwAspectInstance
      FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType));
        gen.addField(fg.getField(),getSourceLocation());
         
        // 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
      InstructionFactory fact = gen.getFactory();
      il.append(fact.createFieldAccess(
        gen.getClassName(),
        fg.getName(),
        fieldType, Constants.GETSTATIC));
      il.append(InstructionFactory.createReturn(fieldType));
      mg.getBody().insert(il);   
      gen.addMethodGen(mg);
      return true;
View Full Code Here

        LazyMethodGen mg1 = makeMethodGen(gen,
          AjcMemberMaker.interFieldInterfaceSetter(field, onType, aspectType));
        gen.addMethodGen(mg1);
      } else {
        weaver.addInitializer(this);
        FieldGen fg = makeFieldGen(gen,
          AjcMemberMaker.interFieldClassField(field, aspectType));
       
        if (annotationsOnRealMember!=null) {
          for (int i = 0; i < annotationsOnRealMember.length; i++) {
            AnnotationX annotationX = annotationsOnRealMember[i];
            Annotation a = annotationX.getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true)
            fg.addAnnotation(ag);
          }
        }
       
        gen.addField(fg.getField(),getSourceLocation());
         
      }
        return true;
    } else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
      // wew know that we can't be static since we don't allow statics on interfaces
      if (field.isStatic()) throw new RuntimeException("unimplemented");
      weaver.addInitializer(this);
      //System.err.println("impl body on " + gen.getType() + " for " + munger);
     
     
      Type fieldType =   BcelWorld.makeBcelType(field.getType());
       
      FieldGen fg = makeFieldGen(gen,AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));
         
        if (annotationsOnRealMember!=null) {
          for (int i = 0; i < annotationsOnRealMember.length; i++) {
            AnnotationX annotationX = annotationsOnRealMember[i];
            Annotation a = annotationX.getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a,weaver.getLazyClassGen().getConstantPoolGen(),true)
            fg.addAnnotation(ag);
          }
        }
       
          gen.addField(fg.getField(),getSourceLocation());
        //this uses a shadow munger to add init method to constructors
        //weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod));
       
        ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType()/*onType*/, aspectType);
      LazyMethodGen mg = makeMethodGen(gen, itdfieldGetter);
      InstructionList il = new InstructionList();
      InstructionFactory fact = gen.getFactory();
      if (field.isStatic()) {
        il.append(fact.createFieldAccess(
          gen.getClassName(),
          fg.getName(),
          fieldType, Constants.GETSTATIC));
      } else {
        il.append(InstructionConstants.ALOAD_0);
        il.append(fact.createFieldAccess(
          gen.getClassName(),
          fg.getName(),
          fieldType, Constants.GETFIELD));
      }
      il.append(InstructionFactory.createReturn(fieldType));
      mg.getBody().insert(il);
       
      gen.addMethodGen(mg);
           
      // Check if we need bridge methods for the field getter and setter
      if (munger.getDeclaredSignature()!=null) { // is this munger a parameterized form of some original munger?
        ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,munger.getSignature().getDeclaringType().resolve(getWorld()),false,munger.getTypeVariableAliases());
        boolean needsbridging = false;
        if (!toBridgeTo.getReturnType().getErasureSignature().equals(munger.getSignature().getReturnType().getErasureSignature())) needsbridging = true;
        if (toBridgeTo!=null && needsbridging) {
          ResolvedMember bridgingGetter = AjcMemberMaker.interFieldInterfaceGetter(toBridgeTo, gen.getType(), aspectType);         
          createBridgeMethodForITDF(weaver,gen,itdfieldGetter,bridgingGetter);
        }
      }   
     
      ResolvedMember itdfieldSetter = AjcMemberMaker.interFieldInterfaceSetter(field, gen.getType(), aspectType);
      LazyMethodGen mg1 = makeMethodGen(gen, itdfieldSetter);
      InstructionList il1 = new InstructionList();
      if (field.isStatic()) {
        il1.append(InstructionFactory.createLoad(fieldType, 0));
        il1.append(fact.createFieldAccess(
          gen.getClassName(),
          fg.getName(),
          fieldType, Constants.PUTSTATIC));
      } else {
        il1.append(InstructionConstants.ALOAD_0);
        il1.append(InstructionFactory.createLoad(fieldType, 1));
        il1.append(fact.createFieldAccess(
          gen.getClassName(),
          fg.getName(),
          fieldType, Constants.PUTFIELD));
      }
      il1.append(InstructionFactory.createReturn(Type.VOID));
      mg1.getBody().insert(il1);
       
View Full Code Here

  public boolean munge(BcelClassWeaver weaver) {
    LazyClassGen gen = weaver.getLazyClassGen();
    if (!gen.getType().equals(cflowStackField.getDeclaringType())) return false;

    Field f = new FieldGen(cflowStackField.getModifiers(),
        BcelWorld.makeBcelType(cflowStackField.getReturnType()),
        cflowStackField.getName(),
        gen.getConstantPoolGen()).getField();
      gen.addField(f,getSourceLocation());
View Full Code Here

TOP

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

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.