]> source.dussan.org Git - aspectj.git/commitdiff
246125: pull across useful utils from bcel package to 'normal' weaver package
authoraclement <aclement>
Fri, 5 Sep 2008 19:20:30 +0000 (19:20 +0000)
committeraclement <aclement>
Fri, 5 Sep 2008 19:20:30 +0000 (19:20 +0000)
weaver/src/org/aspectj/weaver/Advice.java
weaver/src/org/aspectj/weaver/AnnotationAJ.java
weaver/src/org/aspectj/weaver/StandardAnnotation.java
weaver/src/org/aspectj/weaver/Utils.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/bcel/BcelAnnotation.java
weaver/src/org/aspectj/weaver/bcel/Utility.java

index b63fff6cbad4c62ecbea005a205d2eda4493bd11..60a90a9c67d6b15c4fcdda34450cdc403c84d9ac 100644 (file)
@@ -18,7 +18,6 @@ import java.util.List;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
-import org.aspectj.weaver.bcel.Utility;
 import org.aspectj.weaver.patterns.AndPointcut;
 import org.aspectj.weaver.patterns.PerClause;
 import org.aspectj.weaver.patterns.Pointcut;
@@ -218,7 +217,7 @@ public abstract class Advice extends ShadowMunger {
                        if (shadowReturnType.isParameterizedType() && (shadowReturnType.getRawType() == afterReturningType.getRawType())) {
                                uncheckedMatchWith = shadowReturnType.getSimpleName();
                        }
-                       if (!Utility.isSuppressing(getSignature().getAnnotations(), "uncheckedArgument")) {
+                       if (!Utils.isSuppressing(getSignature().getAnnotations(), "uncheckedArgument")) {
                                world.getLint().uncheckedArgument.signal(new String[] { afterReturningType.getSimpleName(), uncheckedMatchWith,
                                                afterReturningType.getSimpleBaseName(), shadow.toResolvedString(world) }, getSourceLocation(),
                                                new ISourceLocation[] { shadow.getSourceLocation() });
index 5b51dbd25440294865c5d627608505d889c4e97a..c7605c1ee2e5efae45008e6a58de5191eff93d18 100644 (file)
@@ -90,4 +90,13 @@ public interface AnnotationAJ {
         */
        public boolean isRuntimeVisible();
 
+       /**
+        * Determine the string representation of the value of a field.  For example in @SuppressAjWarnings({"adviceDidNotMatch"})
+        * the return value for getStringFormOfValue("value") would be "[adviceDidNotMatch]".
+        * 
+        * @param name the name of the annotation field being looked up
+        * @return string representation of the value of that field, may be null if no such field set
+        */
+       public String getStringFormOfValue(String name);
+
 }
index 64962ecf413e15ff9fe4332f388090eda184d26d..3dd7bfb82aa25c6f0eed5006e3fbff4b7bb04f69 100644 (file)
@@ -136,4 +136,18 @@ public class StandardAnnotation extends AbstractAnnotationAJ {
                nvPairs.add(pair);
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public String getStringFormOfValue(String name) {
+               if (hasNameValuePairs()) {
+                       for (Iterator iterator = nvPairs.iterator(); iterator.hasNext();) {
+                               AnnotationNameValuePair nvPair = (AnnotationNameValuePair) iterator.next();
+                               if (nvPair.getName().equals(name)) {
+                                       return nvPair.getValue().stringify();
+                               }
+                       }
+               }
+               return null;
+       }
 }
diff --git a/weaver/src/org/aspectj/weaver/Utils.java b/weaver/src/org/aspectj/weaver/Utils.java
new file mode 100644 (file)
index 0000000..8053af0
--- /dev/null
@@ -0,0 +1,43 @@
+/* *******************************************************************
+ * Copyright (c) 2008 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * ******************************************************************/
+package org.aspectj.weaver;
+
+/**
+ * 
+ * @author Andy Clement
+ */
+public class Utils {
+
+       /**
+        * Check if the annotations contain a SuppressAjWarnings annotation and if that annotation specifies that the given lint message
+        * (identified by its key) should be ignored.
+        * 
+        */
+       public static boolean isSuppressing(AnnotationAJ[] anns, String lintkey) {
+               if (anns == null) {
+                       return false;
+               }
+               // Go through the annotation types on the advice
+               for (int i = 0; i < anns.length; i++) {
+                       if (UnresolvedType.SUPPRESS_AJ_WARNINGS.getSignature().equals(anns[i].getTypeSignature())) {
+                               // Two possibilities:
+                               // 1. there are no values specified (i.e. @SuppressAjWarnings)
+                               // 2. there are values specified (i.e. @SuppressAjWarnings("A") or @SuppressAjWarnings({"A","B"})
+                               String value = anns[i].getStringFormOfValue("value");
+                               // Slightly lazy, just doing a string indexof
+                               if (value == null || value.indexOf(lintkey) != -1) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
+}
index 9d7e83bca23d7c65ead034f5c8a63bd7610a0d61..9dfaa22c6d888b203242f5f084b3251b25bf5f93 100644 (file)
@@ -104,4 +104,21 @@ public class BcelAnnotation extends AbstractAnnotationAJ {
                return bcelAnnotation;
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public String getStringFormOfValue(String name) {
+               List annotationValues = this.bcelAnnotation.getValues();
+               if (annotationValues == null || annotationValues.size() == 0) {
+                       return null;
+               } else {
+                       for (Iterator iterator = annotationValues.iterator(); iterator.hasNext();) {
+                               ElementNameValuePairGen nvPair = (ElementNameValuePairGen) iterator.next();
+                               if (nvPair.getNameString().equals(name)) {
+                                       return nvPair.getValue().stringifyValue();
+                               }
+                       }
+                       return null;
+               }
+       }
 }
index 52d46b6c057ce4d0e1a91f752226a69e34ba550d..97830a950d3538524b082895a045a6691b7c36a9 100644 (file)
@@ -61,6 +61,7 @@ import org.aspectj.weaver.Lint;
 import org.aspectj.weaver.Member;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.Utils;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
 
@@ -681,53 +682,16 @@ public class Utility {
         * Checks for suppression specified on the member or on the declaring type of that member
         */
        public static boolean isSuppressing(Member member, String lintkey) {
-               boolean isSuppressing = Utility.isSuppressing(member.getAnnotations(), lintkey);
+               boolean isSuppressing = Utils.isSuppressing(member.getAnnotations(), lintkey);
                if (isSuppressing)
                        return true;
                UnresolvedType type = member.getDeclaringType();
                if (type instanceof ResolvedType) {
-                       return Utility.isSuppressing(((ResolvedType) type).getAnnotations(), lintkey);
+                       return Utils.isSuppressing(((ResolvedType) type).getAnnotations(), lintkey);
                }
                return false;
        }
 
-       /**
-        * Check if the annotations contain a SuppressAjWarnings annotation and if that annotation specifies that the given lint message
-        * (identified by its key) should be ignored.
-        * 
-        */
-       public static boolean isSuppressing(AnnotationAJ[] anns, String lintkey) {
-               if (anns == null)
-                       return false;
-               boolean suppressed = false;
-               // Go through the annotation types on the advice
-               for (int i = 0; !suppressed && i < anns.length; i++) {
-                       // Check for the SuppressAjWarnings annotation
-                       if (UnresolvedType.SUPPRESS_AJ_WARNINGS.getSignature().equals(anns[i].getTypeSignature())) {
-                               // Two possibilities:
-                               // 1. there are no values specified (i.e. @SuppressAjWarnings)
-                               // 2. there are values specified (i.e. @SuppressAjWarnings("A")
-                               // or @SuppressAjWarnings({"A","B"})
-                               List vals = ((BcelAnnotation) anns[i]).getBcelAnnotation().getValues();
-                               if (vals == null || vals.isEmpty()) { // (1)
-                                       suppressed = true;
-                               } else { // (2)
-                                       // We know the value is an array value
-                                       ArrayElementValueGen array = (ArrayElementValueGen) ((ElementNameValuePairGen) vals.get(0)).getValue();
-                                       ElementValueGen[] values = array.getElementValuesArray();
-                                       for (int j = 0; j < values.length; j++) {
-                                               // We know values in the array are strings
-                                               SimpleElementValueGen value = (SimpleElementValueGen) values[j];
-                                               if (value.getValueString().equals(lintkey)) {
-                                                       suppressed = true;
-                                               }
-                                       }
-                               }
-                       }
-               }
-               return suppressed;
-       }
-
        public static List/* Lint.Kind */getSuppressedWarnings(AnnotationAJ[] anns, Lint lint) {
                if (anns == null)
                        return Collections.EMPTY_LIST;