Package org.aspectj.apache.bcel.classfile

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


  public String getDeclaredGenericSignature() {
    if (!haveLookedForDeclaredSignature) {
      haveLookedForDeclaredSignature = true;
      Attribute[] as = javaClass.getAttributes();
      for (int i = 0; i < as.length && declaredSignature==null; i++) {
        Attribute attribute = as[i];
        if (attribute instanceof Signature) declaredSignature = ((Signature)attribute).getSignature();
      }
      if (declaredSignature!=null) isGenericType= (declaredSignature.charAt(0)=='<');
    }
    return declaredSignature;
View Full Code Here


    List l = new ArrayList();
   
    // first pass, look for version
    List forSecondPass = new ArrayList();
    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.startsWith(AjAttribute.AttributePrefix)) {
          if (name.endsWith(WeaverVersionInfo.AttributeName)) {
            version = (AjAttribute.WeaverVersionInfo)AjAttribute.read(version,name,u.getBytes(),context,msgHandler);
            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());
            }
                    }
          forSecondPass.add(a);
        }
      }
    }
       
    for (int i = forSecondPass.size()-1; i >= 0; i--) {
      Unknown a = (Unknown)forSecondPass.get(i);
      String name = a.getName();
      AjAttribute attr = AjAttribute.read(version,name,a.getBytes(),context,msgHandler);
      if (attr!=null) l.add(attr);
    }
    return l;
  }
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)) {
                RuntimeAnnotations rvs = (RuntimeAnnotations) attribute;
                // we don't need to look for several attribute occurence 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 EMPTY_LIST;
        }

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


        //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 = new AjAttributeMethodStruct(method, null, type, context, msgHandler);//FIXME AVASM
            Attribute[] mattributes = method.getAttributes();

            for (int j = 0; j < mattributes.length; j++) {
                Attribute mattribute = mattributes[j];
                if (acceptAttribute(mattribute)) {
                    RuntimeAnnotations mrvs = (RuntimeAnnotations) mattribute;
                    handlePointcutAnnotation(mrvs, mstruct);
                    // there can only be one RuntimeVisible bytecode attribute
                    break;
                }
            }
            // 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
        for (int i = 0; i < javaClass.getFields().length; i++) {
            Field field = javaClass.getFields()[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)) {
                    RuntimeAnnotations frvs = (RuntimeAnnotations) fattribute;
                    if (handleDeclareErrorOrWarningAnnotation(frvs, fstruct)
                            || handleDeclareParentsAnnotation(frvs, fstruct)) {
                        // semantic check - must be in an @Aspect [remove if previous block bypassed in advance]
View Full Code Here

        // but then we would not see any warning. We do bypass for pointcut but 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)) {
                    RuntimeAnnotations rvs = (RuntimeAnnotations) attribute;
                    hasAtAspectJAnnotationMustReturnVoid = hasAtAspectJAnnotationMustReturnVoid || handleBeforeAnnotation(
                            rvs, struct, preResolvedPointcut
View Full Code Here

   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 c = (Code)a;
  setMaxStack(c.getMaxStack());
  setMaxLocals(c.getMaxLocals());
View Full Code Here

    if((il != null) && !isAbstract()) {
      // Remove any stale code attribute
      Attribute[] attributes = getAttributes();
      for(int i=0; i < attributes.length; i++) {
      Attribute a = attributes[i];
      if(a instanceof Code)
        removeAttribute(a);
      }

      code = new Code(cp.addUtf8("Code"),
View Full Code Here

    Attribute[] attrs = getAttributes();
    RuntimeParameterAnnotations paramAnnVisAttr = null;
    RuntimeParameterAnnotations paramAnnInvisAttr=null;
    List accumulatedAnnotations = new ArrayList();
    for (int i = 0; i < attrs.length; i++) {
    Attribute attribute = attrs[i];
    if (attribute instanceof RuntimeParameterAnnotations) { 
     
      // Initialize param_annotations
      if (!hasParameterAnnotations) {
        param_annotations = new List[arg_types.length];
View Full Code Here

   * Look for attributes representing annotations and unpack them.
   */
  private AnnotationGen[] unpackAnnotations(Attribute[] attrs) {
    List /*AnnotationGen*/ annotationGenObjs = new ArrayList();
    for (int i = 0; i < attrs.length; i++) {
    Attribute attr = attrs[i];
    if (attr instanceof RuntimeVisibleAnnotations) {
      RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations)attr;
      List annos = rva.getAnnotations();
      for (Iterator iter = annos.iterator(); iter.hasNext();) {
        Annotation a = (Annotation) iter.next();
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.