Package org.aspectj.apache.bcel.generic

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


        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


  public boolean munge(BcelClassWeaver weaver) {
    LazyClassGen gen = weaver.getLazyClassGen();
    if (!gen.getType().equals(cflowStackField.getDeclaringType())) {
      return false;
    }
    FieldGen f = new FieldGen(cflowStackField.getModifiers(), BcelWorld.makeBcelType(cflowStackField.getReturnType()),
        cflowStackField.getName(), gen.getConstantPool());
    gen.addField(f, getSourceLocation());

    LazyMethodGen clinit = gen.getAjcPreClinit(); // StaticInitializer();
    InstructionList setup = new InstructionList();
View Full Code Here

  public Field getField(ConstantPool cpool) {
    if (!annotationsOnFieldObjectAreOutOfDate) {
      return field;
    }
    FieldGen newFieldGen = new FieldGen(field, cpool);
    newFieldGen.removeAnnotations();
    // List<AnnotationGen> alreadyHas = fg.getAnnotations();
    // if (annotations != null) {
    // fg.removeAnnotations();
    for (AnnotationAJ annotation : annotations) {
      newFieldGen.addAnnotation(new AnnotationGen(((BcelAnnotation) annotation).getBcelAnnotation(), cpool, true));
    }
    // for (int i = 0; i < annotations.length; i++) {
    // AnnotationAJ array_element = annotations[i];
    // boolean alreadyHasIt = false;
    // for (AnnotationGen gen : alreadyHas) {
    // if (gen.getTypeName().equals(array_element.getTypeName())) {
    // alreadyHasIt = true;
    // break;
    // }
    // }
    // if (!alreadyHasIt) {
    // fg.addAnnotation(new AnnotationGen(((BcelAnnotation) array_element).getBcelAnnotation(), cpg, true));
    // // }
    // // }
    // }
    field = newFieldGen.getField();
    annotationsOnFieldObjectAreOutOfDate = false; // we are now correct again
    return field;
  }
View Full Code Here

  // FIXME asc badly performing code ftw !
  public Field getField(ConstantPool cpg) {
    if (!annotationsAdded) {
      return field;
    }
    FieldGen fg = new FieldGen(field, cpg);
    List<AnnotationGen> alreadyHas = fg.getAnnotations();
    if (annotations != null) {
      for (int i = 0; i < annotations.length; i++) {
        AnnotationAJ array_element = annotations[i];
        boolean alreadyHasIt = false;
        for (AnnotationGen gen : alreadyHas) {
          if (gen.getTypeName().equals(array_element.getTypeName())) {
            alreadyHasIt = true;
            break;
          }
        }
        if (!alreadyHasIt) {
          fg.addAnnotation(new AnnotationGen(((BcelAnnotation) array_element).getBcelAnnotation(), cpg, true));
        }
      }
    }
    field = fg.getField();
    annotationsAdded = false; // we are now correct again
    return field;
  }
View Full Code Here

        parttwo.append(InstructionFactory.createStore(clazzType, slotForThis)); // ? should be the real type ? String or
        // something?
        parttwo.append(InstructionFactory.MONITORENTER);

        String fieldname = synchronizedMethod.getEnclosingClass().allocateField("class$");
        FieldGen f = new FieldGen(Modifier.STATIC | Modifier.PRIVATE, Type.getType(Class.class), fieldname,
            synchronizedMethod.getEnclosingClass().getConstantPool());
        synchronizedMethod.getEnclosingClass().addField(f, null);

        // 10: invokestatic #44; //Method
        // java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
View Full Code Here

      }

      // Do we need to calculate an SUID and add it?
      if (!getType().isInterface() && !hasSerialVersionUIDField && world.isAddSerialVerUID()) {
        calculatedSerialVersionUID = myGen.getSUID();
        FieldGen fg = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_FINAL | Constants.ACC_STATIC, BasicType.LONG,
            "serialVersionUID", getConstantPool());
        addField(fg);
        hasSerialVersionUIDField = true;
        serialVersionUIDRequiresInitialization = true;
        // warn about what we've done?
View Full Code Here

            // System.out.println("tjp counter starting at " + tjpFieldsCounter);
          }
        }
      }
    }
    FieldGen fGen = new FieldGen(modifiers, jpType, "ajc$tjp_" + tjpFieldsCounter++, getConstantPool());
    addField(fGen);
    tjpField = fGen.getField();
    tjpFields.put(shadow, tjpField);
    return tjpField;
  }
View Full Code Here

    if (field == null) {
      // private static Annotation ajc$anno$<nnn>
      StringBuilder sb = new StringBuilder();
      sb.append(NameMangler.ANNOTATION_CACHE_FIELD_NAME);
      sb.append(annoFieldsCounter++);
      FieldGen annotationCacheField = new FieldGen(Modifier.PRIVATE | Modifier.STATIC, typeForAnnotation, sb.toString(), cp);
      addField(annotationCacheField);
      field = annotationCacheField.getField();
      annotationCachingFieldCache.put(cacheKey, field);
    }
    return field;
  }
View Full Code Here

    // ret.makeSynthetic();
    return ret;
  }

  protected FieldGen makeFieldGen(LazyClassGen gen, ResolvedMember member) {
    return new FieldGen(member.getModifiers(), BcelWorld.makeBcelType(member.getReturnType()), member.getName(), gen
        .getConstantPool());
  }
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, 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

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.