Package org.aspectj.apache.bcel.classfile.annotation

Examples of org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair


     * @return true if found
     */
    private static boolean handleAroundAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct, ResolvedPointcutDefinition preResolvedPointcut) {
        Annotation around = getAnnotation(runtimeAnnotations, AjcMemberMaker.AROUND_ANNOTATION);
        if (around != null) {
            ElementNameValuePair aroundAdvice = getAnnotationElement(around, VALUE);
            if (aroundAdvice != null) {
                // this/target/args binding
                FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
                try {
                    bindings = extractBindings(struct);
                } catch (UnreadableDebugInfoException unreadableDebugInfoException) {
                    return false;
                }
                IScope binding = new BindingScope(
                        struct.enclosingType,
                        struct.context,
                        bindings
                );

                // joinpoint, staticJoinpoint binding
                int extraArgument = extractExtraArgument(struct.method);

                Pointcut pc = null;
                if (preResolvedPointcut != null) {
                    pc = preResolvedPointcut.getPointcut();
                } else {
                    pc = parsePointcut(aroundAdvice.getValue().stringifyValue(), struct, false);
                    if (pc == null) return false;//parse error
                    pc.resolve(binding);
                }
                setIgnoreUnboundBindingNames(pc, bindings);

View Full Code Here


     * @param struct
     */
    private static void handlePointcutAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeMethodStruct struct) {
        Annotation pointcut = getAnnotation(runtimeAnnotations, AjcMemberMaker.POINTCUT_ANNOTATION);
        if (pointcut != null) {
            ElementNameValuePair pointcutExpr = getAnnotationElement(pointcut, VALUE);

            // semantic check: the method must return void, or be "public static boolean" for if() support
            if (!(Type.VOID.equals(struct.method.getReturnType())
                  || (Type.BOOLEAN.equals(struct.method.getReturnType()) && struct.method.isStatic() && struct.method.isPublic()))) {
                reportWarning("Found @Pointcut on a method not returning 'void' or not 'public static boolean'", struct);
                ;//no need to stop
            }

            // semantic check: the method must not throw anything
            if (struct.method.getExceptionTable() != null) {
                reportWarning("Found @Pointcut on a method throwing exception", struct);
                ;// no need to stop
            }

            // this/target/args binding
            final IScope binding;
            try {
                binding = new BindingScope(
                        struct.enclosingType,
                        struct.context,
                        extractBindings(struct)
                );
            } catch (UnreadableDebugInfoException e) {
                return;
            }

            UnresolvedType[] argumentTypes = new UnresolvedType[struct.method.getArgumentTypes().length];
            for (int i = 0; i < argumentTypes.length; i++) {
                argumentTypes[i] = UnresolvedType.forSignature(struct.method.getArgumentTypes()[i].getSignature());
            }

            Pointcut pc = null;
            if (struct.method.isAbstract()) {
                if ((pointcutExpr != null && isNullOrEmpty(pointcutExpr.getValue().stringifyValue()))
                    || pointcutExpr == null) {
                    // abstract pointcut
                    // leave pc = null
                } else {
                    reportError("Found defined @Pointcut on an abstract method", struct);
                    return;//stop
                }
            } else {
                if (pointcutExpr != null) {
                    // use a LazyResolvedPointcutDefinition so that the pointcut is resolved lazily
                    // since for it to be resolved, we will need other pointcuts to be registered as well
                    pc = parsePointcut(pointcutExpr.getValue().stringifyValue(), struct, true);
                    if (pc == null) return;//parse error
                    pc.setLocation(struct.context, -1, -1);//FIXME AVASM !! bMethod is null here..
                } else {
                    reportError("Found undefined @Pointcut on a non-abstract method", struct);
                    return;
View Full Code Here

     */
    private static boolean handleDeclareErrorOrWarningAnnotation(RuntimeAnnotations runtimeAnnotations, AjAttributeFieldStruct struct) {
        Annotation error = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREERROR_ANNOTATION);
        boolean hasError = false;
        if (error != null) {
            ElementNameValuePair declareError = getAnnotationElement(error, VALUE);
            if (declareError != null) {
                if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
                    reportError("@DeclareError used on a non String constant field", struct);
                    return false;
                }
                FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
                IScope binding = new BindingScope(
                        struct.enclosingType,
                        struct.context,
                        bindings
                );
                Pointcut pc = parsePointcut(declareError.getValue().stringifyValue(), struct, false);
                if (pc == null) {
                    hasError = false;//cannot parse pointcut
                } else {
                    pc .resolve(binding);
                    DeclareErrorOrWarning deow = new DeclareErrorOrWarning(true, pc, struct.field.getConstantValue().toString());
                    deow.setLocation(struct.context, -1, -1);
                    struct.ajAttributes.add(new AjAttribute.DeclareAttribute(deow));
                    hasError = true;
                }
            }
        }
        Annotation warning = getAnnotation(runtimeAnnotations, AjcMemberMaker.DECLAREWARNING_ANNOTATION);
        boolean hasWarning = false;
        if (warning != null) {
            ElementNameValuePair declareWarning = getAnnotationElement(warning, VALUE);
            if (declareWarning != null) {
                if (!STRING_DESC.equals(struct.field.getSignature()) || struct.field.getConstantValue() == null) {
                    reportError("@DeclareWarning used on a non String constant field", struct);
                    return false;
                }
                FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
                IScope binding = new BindingScope(
                        struct.enclosingType,
                        struct.context,
                        bindings
                );
                Pointcut pc = parsePointcut(declareWarning.getValue().stringifyValue(), struct, false);
                if (pc == null) {
                    hasWarning = false;//cannot parse pointcut
                } else {
                    pc.resolve(binding);
                    DeclareErrorOrWarning deow = new DeclareErrorOrWarning(false, pc, struct.field.getConstantValue().toString());
View Full Code Here

     * @param elementName
     * @return annotation NVP
     */
    private static ElementNameValuePair getAnnotationElement(Annotation annotation, String elementName) {
        for (Iterator iterator1 = annotation.getValues().iterator(); iterator1.hasNext();) {
            ElementNameValuePair element = (ElementNameValuePair) iterator1.next();
            if (elementName.equals(element.getNameString())) {
                return element;
            }
        }
        return null;
    }
View Full Code Here

  public static List getListOfAnnotationNames(Annotation a) {
    List l = a.getValues();
    List names = new ArrayList();
    for (Iterator i = l.iterator(); i.hasNext();) {
    ElementNameValuePair element = (ElementNameValuePair) i.next();
    names.add(element.getNameString());
  }
    return names;
  }
View Full Code Here

  }
 
  private List copyValues(List in,ConstantPoolGen cpool,boolean copyPoolEntries) {
    List out = new ArrayList();
    for (Iterator iter = in.iterator(); iter.hasNext();) {
      ElementNameValuePair nvp = (ElementNameValuePair) iter.next();
      out.add(new ElementNameValuePairGen(nvp,cpool,copyPoolEntries));
    }
    return out;
  }
View Full Code Here

  /**
   * Retrieve an immutable version of this ElementNameValuePairGen
   */
  public ElementNameValuePair getElementNameValuePair() {
    ElementValue immutableValue = value.getElementValue();
    return new ElementNameValuePair(nameIdx,immutableValue,cpool.getConstantPool());
  }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair

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.