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;
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() });
*/
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);
+
}
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;
+ }
}
--- /dev/null
+/* *******************************************************************
+ * 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;
+ }
+
+}
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;
+ }
+ }
}
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;
* 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;