Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.Attribute


            .getModifiers() & (Constants.ACC_ABSTRACT | Constants.ACC_NATIVE)) == 0) ? new InstructionList(m.getCode()
            .getCode()) : null, cp);

    Attribute[] attributes = m.getAttributes();
    for (int i = 0; i < attributes.length; i++) {
      Attribute a = attributes[i];

      if (a instanceof Code) {
        Code code = (Code) a;
        setMaxStack(code.getMaxStack());
        setMaxLocals(code.getMaxLocals());
View Full Code Here


    if ((il != null) && !isAbstract()) {
      // Remove any stale code attribute
      List<Attribute> attributes = getAttributes();
      for (int i = 0; i < attributes.size(); i++) {
        Attribute a = attributes.get(i);
        if (a instanceof Code) {
          removeAttribute(a);
        }
      }
View Full Code Here

          // +
          // onMember.getName()+"' in class '"+jc.getClassName()+"'");
        } else {
          Attribute[] attrs = bcelMethod.getAttributes();
          for (int i = 0; i < attrs.length; i++) {
            Attribute attribute = attrs[i];
            if (attribute.getName().equals("AnnotationDefault")) {
              AnnotationDefault def = (AnnotationDefault) attribute;
              return def.getElementValue().stringifyValue();
            }
          }
          return null;
View Full Code Here

    List<AjAttribute> attributes = new ArrayList<AjAttribute>();

    // first pass, look for version
    List<Unknown> forSecondPass = new ArrayList<Unknown>();
    for (int i = as.length - 1; i >= 0; i--) {
      Attribute a = as[i];
      if (a instanceof Unknown) {
        Unknown u = (Unknown) a;
        String name = u.getName();
        if (name.charAt(0) == 'o') { // 'o'rg.aspectj
          if (name.startsWith(AjAttribute.AttributePrefix)) {
            if (name.endsWith(WeaverVersionInfo.AttributeName)) {
              version = (AjAttribute.WeaverVersionInfo) AjAttribute.read(version, name, u.getBytes(), context, w,
                  dataDecompressor);
              if (version.getMajorVersion() > WeaverVersionInfo.getCurrentWeaverMajorVersion()) {
                throw new BCException(
                    "Unable to continue, this version of AspectJ supports classes built with weaver version "
                        + WeaverVersionInfo.toCurrentVersionString() + " but the class " + classname
                        + " is version " + version.toString() + ".  Please update your AspectJ.");
              }
            }
            forSecondPass.add(u);
          }
        }
      }
    }

    // FIXASC why going backwards? is it important
    for (int i = forSecondPass.size() - 1; i >= 0; i--) {
      Unknown a = forSecondPass.get(i);
      String name = a.getName();
      AjAttribute attr = AjAttribute.read(version, name, a.getBytes(), context, w, dataDecompressor);
      if (attr != null) {
        attributes.add(attr);
      }
    }
    return attributes;
View Full Code Here

    Attribute[] attributes = javaClass.getAttributes();
    boolean hasAtAspectAnnotation = false;
    boolean hasAtPrecedenceAnnotation = false;

    for (int i = 0; i < attributes.length; i++) {
      Attribute attribute = attributes[i];
      if (acceptAttribute(attribute)) {
        RuntimeAnnos rvs = (RuntimeAnnos) attribute;
        // we don't need to look for several attribute occurrences since
        // it cannot happen as per JSR175
        if (!isCodeStyleAspect && !javaClass.isInterface()) {
          hasAtAspectAnnotation = handleAspectAnnotation(rvs, struct);
          // TODO AV - if put outside the if isCodeStyleAspect then we
          // would enable mix style
          hasAtPrecedenceAnnotation = handlePrecedenceAnnotation(rvs, struct);
        }
        // there can only be one RuntimeVisible bytecode attribute
        break;
      }
    }

    // basic semantic check
    if (hasAtPrecedenceAnnotation && !hasAtAspectAnnotation) {
      msgHandler.handleMessage(new Message("Found @DeclarePrecedence on a non @Aspect type '" + type.getName() + "'",
          IMessage.WARNING, null, type.getSourceLocation()));
      // bypass what we have read
      return NO_ATTRIBUTES;
    }

    // the following block will not detect @Pointcut in non @Aspect types
    // for optimization purpose
    if (!(hasAtAspectAnnotation || isCodeStyleAspect) && !containsPointcut) {
      return NO_ATTRIBUTES;
    }

    // FIXME AV - turn on when ajcMightHaveAspect
    // if (hasAtAspectAnnotation && type.isInterface()) {
    // msgHandler.handleMessage(
    // new Message(
    // "Found @Aspect on an interface type '" + type.getName() + "'",
    // IMessage.WARNING,
    // null,
    // type.getSourceLocation()
    // )
    // );
    // // bypass what we have read
    // return EMPTY_LIST;
    // }

    // semantic check: @Aspect must be public
    // FIXME AV - do we really want to enforce that?
    // if (hasAtAspectAnnotation && !javaClass.isPublic()) {
    // msgHandler.handleMessage(
    // new Message(
    // "Found @Aspect annotation on a non public class '" +
    // javaClass.getClassName() + "'",
    // IMessage.ERROR,
    // null,
    // type.getSourceLocation()
    // )
    // );
    // return EMPTY_LIST;
    // }

    // code style pointcuts are class attributes
    // we need to gather the @AJ pointcut right now and not at method level
    // annotation extraction time
    // in order to be able to resolve the pointcut references later on
    // we don't need to look in super class, the pointcut reference in the
    // grammar will do it

    for (int i = 0; i < javaClass.getMethods().length; i++) {
      Method method = javaClass.getMethods()[i];
      if (method.getName().startsWith(NameMangler.PREFIX)) {
        continue; // already dealt with by ajc...
      }
      // FIXME alex optimize, this method struct will gets recreated for
      // advice extraction
      AjAttributeMethodStruct mstruct = null;
      boolean processedPointcut = false;
      Attribute[] mattributes = method.getAttributes();
      for (int j = 0; j < mattributes.length; j++) {
        Attribute mattribute = mattributes[j];
        if (acceptAttribute(mattribute)) {
          // TODO speed all this nonsense up rather than looking
          // through all the annotations every time
          // same for fields
          mstruct = new AjAttributeMethodStruct(method, null, type, context, msgHandler);
          processedPointcut = handlePointcutAnnotation((RuntimeAnnos) mattribute, mstruct);
          if (!processedPointcut) {
            processedPointcut = handleDeclareMixinAnnotation((RuntimeAnnos) mattribute, mstruct);
          }
          // there can only be one RuntimeVisible bytecode attribute
          break;
        }
      }
      if (processedPointcut) {
        // FIXME asc should check we aren't adding multiple versions...
        // will do once I get the tests passing again...
        struct.ajAttributes.add(new AjAttribute.WeaverVersionInfo());
        struct.ajAttributes.addAll(mstruct.ajAttributes);
      }
    }

    // code style declare error / warning / implements / parents are field
    // attributes
    Field[] fs = javaClass.getFields();
    for (int i = 0; i < fs.length; i++) {
      Field field = fs[i];
      if (field.getName().startsWith(NameMangler.PREFIX)) {
        continue; // already dealt with by ajc...
      }
      // FIXME alex optimize, this method struct will gets recreated for
      // advice extraction
      AjAttributeFieldStruct fstruct = new AjAttributeFieldStruct(field, null, type, context, msgHandler);
      Attribute[] fattributes = field.getAttributes();

      for (int j = 0; j < fattributes.length; j++) {
        Attribute fattribute = fattributes[j];
        if (acceptAttribute(fattribute)) {
          RuntimeAnnos frvs = (RuntimeAnnos) fattribute;
          if (handleDeclareErrorOrWarningAnnotation(model, frvs, fstruct)
              || handleDeclareParentsAnnotation(frvs, fstruct)) {
            // semantic check - must be in an @Aspect [remove if
View Full Code Here

    // not for advice since it would
    // be too silent.
    boolean hasAtAspectJAnnotation = false;
    boolean hasAtAspectJAnnotationMustReturnVoid = false;
    for (int i = 0; i < attributes.length; i++) {
      Attribute attribute = attributes[i];
      try {
        if (acceptAttribute(attribute)) {
          RuntimeAnnos rvs = (RuntimeAnnos) attribute;
          hasAtAspectJAnnotationMustReturnVoid = hasAtAspectJAnnotationMustReturnVoid
              || handleBeforeAnnotation(rvs, struct, preResolvedPointcut);
View Full Code Here

  @Override
  public String getAnnotationDefaultValue() {
    Attribute[] attrs = method.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
      Attribute attribute = attrs[i];
      if (attribute.getName().equals("AnnotationDefault")) {
        AnnotationDefault def = (AnnotationDefault) attribute;
        return def.getElementValue().stringifyValue();
      }
    }
    return null;
View Full Code Here

        // Attribute[] oldAttrs = field.getAttributes();
        // Attribute[] newAttrs = new Attribute[oldAttrs.length + 1];
        // System.arraycopy(oldAttrs, 0, newAttrs, 0, oldAttrs.length);
        ConstantPool cpg = myGen.getConstantPool();
        int index = cpg.addUtf8("Synthetic");
        Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg);
        field.addAttribute(synthetic);
        // newAttrs[newAttrs.length - 1] = synthetic;
        // field.setAttributes(newAttrs);
      }
    }
View Full Code Here

       
        // Add a weaver version attribute to the file being produced (if necessary...)
        boolean hasVersionAttribute = false;       
        Attribute[] attrs = myGen.getAttributes();
        for (int i = 0; i < attrs.length && !hasVersionAttribute; i++) {
      Attribute attribute = attrs[i];
      if (attribute.getName().equals("org.aspectj.weaver.WeaverVersion")) hasVersionAttribute=true;
    }       
        if (!hasVersionAttribute)
          myGen.addAttribute(BcelAttributes.bcelAttribute(new AjAttribute.WeaverVersionInfo(),getConstantPoolGen()));

        if (myType != null && myType.getWeaverState() != null) {
View Full Code Here

    // 2. Find the old attribute
    Signature sigAttr = null;
    if (myType!=null) { // if null, this is a type built from scratch, it won't already have a sig attribute
      Attribute[] as = myGen.getAttributes();
      for (int i = 0; i < as.length; i++) {
        Attribute attribute = as[i];
        if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute;
      }
    }
   
    // 3. Do we need an attribute?
    boolean needAttribute = false;
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.Attribute

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.