diff options
author | aclement <aclement> | 2011-09-07 22:00:30 +0000 |
---|---|---|
committer | aclement <aclement> | 2011-09-07 22:00:30 +0000 |
commit | 668a0fbd632c4d4862f06d10fa01f2d10fa4689f (patch) | |
tree | ecf1e5fc418acfcd19b37a7e49fcae1394dc6e8d /org.aspectj.matcher/src | |
parent | e5ed164a438cc11f4ec55a68f28f62fc14ade0ac (diff) | |
download | aspectj-668a0fbd632c4d4862f06d10fa01f2d10fa4689f.tar.gz aspectj-668a0fbd632c4d4862f06d10fa01f2d10fa4689f.zip |
357012/357013
Diffstat (limited to 'org.aspectj.matcher/src')
3 files changed, 86 insertions, 34 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java index f332f1c1b..772e8f6ca 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/ExactAnnotationTypePattern.java @@ -110,9 +110,11 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { if (annotationType instanceof ReferenceType) { ReferenceType rt = (ReferenceType) annotationType; if (rt.getRetentionPolicy() != null && rt.getRetentionPolicy().equals("SOURCE")) { - rt.getWorld().getMessageHandler().handleMessage( - MessageUtil.warn(WeaverMessages.format(WeaverMessages.NO_MATCH_BECAUSE_SOURCE_RETENTION, - annotationType, annotated), getSourceLocation())); + rt.getWorld() + .getMessageHandler() + .handleMessage( + MessageUtil.warn(WeaverMessages.format(WeaverMessages.NO_MATCH_BECAUSE_SOURCE_RETENTION, + annotationType, annotated), getSourceLocation())); return FuzzyBoolean.NO; } } @@ -124,12 +126,25 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { // Check each one Set<String> keys = annotationValues.keySet(); for (String k : keys) { + boolean notEqual = false; String v = annotationValues.get(k); + // if the key has a trailing '!' then it means the source expressed k!=v - so we are looking for + // something other than the value specified + if (k.endsWith("!")) { + notEqual = true; + k = k.substring(0, k.length() - 1); + } if (theAnnotation.hasNamedValue(k)) { // Simple case, value is 'name=value' and the // annotation specified the same thing - if (!theAnnotation.hasNameValuePair(k, v)) { - return FuzzyBoolean.NO; + if (notEqual) { + if (theAnnotation.hasNameValuePair(k, v)) { + return FuzzyBoolean.NO; + } + } else { + if (!theAnnotation.hasNameValuePair(k, v)) { + return FuzzyBoolean.NO; + } } } else { // Complex case, look at the default value @@ -144,8 +159,14 @@ public class ExactAnnotationTypePattern extends AnnotationTypePattern { } } } - if (!foundMatch) { - return FuzzyBoolean.NO; + if (notEqual) { + if (foundMatch) { + return FuzzyBoolean.NO; + } + } else { + if (!foundMatch) { + return FuzzyBoolean.NO; + } } } } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java index b0ed830c3..321f1e759 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java @@ -900,7 +900,7 @@ public class PatternParser { // Parse annotation values. In an expression in @A(a=b,c=d) this method will be // parsing the a=b,c=d.) - public Map/* String,String */<String, String> parseAnnotationValues() { + public Map<String, String> parseAnnotationValues() { Map<String, String> values = new HashMap<String, String>(); boolean seenDefaultValue = false; do { @@ -916,6 +916,14 @@ public class PatternParser { throw new ParserException("expecting simple literal ", tokenSource.peek(-1)); } values.put(possibleKeyString, valueString); + } else if (maybeEat("!=")) { + // it was a key, with a != + String valueString = parseAnnotationNameValuePattern(); + if (valueString == null) { + throw new ParserException("expecting simple literal ", tokenSource.peek(-1)); + } + // negation is captured by adding a trailing ! to the key name + values.put(possibleKeyString + "!", valueString); } else { if (seenDefaultValue) { throw new ParserException("cannot specify two default values", tokenSource.peek(-1)); @@ -1315,6 +1323,9 @@ public class PatternParser { if (tok.getString() == ")" && depth == 0) { break; } + if (tok.getString() == "!=" && depth == 0) { + break; + } if (tok.getString() == "=" && depth == 0) { break; } diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java index 56492c3f2..2acd01690 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java @@ -86,19 +86,24 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { ResolvedMember[] ms = annotationType.getDeclaredMethods(); for (Iterator<String> kIter = keys.iterator(); kIter.hasNext();) { String k = kIter.next(); + String key = k; + // a trailing ! indicates the the user expressed key!=value rather than key=value as a match constraint + if (k.endsWith("!")) { + key = key.substring(0, k.length() - 1); + } String v = annotationValues.get(k); boolean validKey = false; for (int i = 0; i < ms.length; i++) { ResolvedMember resolvedMember = ms[i]; - if (resolvedMember.getName().equals(k) && resolvedMember.isAbstract()) { + if (resolvedMember.getName().equals(key) && resolvedMember.isAbstract()) { validKey = true; ResolvedType t = resolvedMember.getReturnType().resolve(scope.getWorld()); if (t.isEnum()) { // value must be an enum reference X.Y int pos = v.lastIndexOf("."); if (pos == -1) { - IMessage m = MessageUtil.error(WeaverMessages - .format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "enum"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "enum"), getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } else { String typename = v.substring(0, pos); @@ -112,8 +117,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { int value = Integer.parseInt(v); annotationValues.put(k, Integer.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "int"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "int"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "F") { @@ -121,8 +127,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { float value = Float.parseFloat(v); annotationValues.put(k, Float.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "float"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "float"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } @@ -130,8 +137,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { if (v.equalsIgnoreCase("true") || v.equalsIgnoreCase("false")) { // is it ok ! } else { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "boolean"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "boolean"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "S") { @@ -139,8 +147,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { short value = Short.parseShort(v); annotationValues.put(k, Short.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "short"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "short"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "J") { @@ -148,8 +157,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { long value = Long.parseLong(v); annotationValues.put(k, Long.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "long"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "long"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "D") { @@ -157,8 +167,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { double value = Double.parseDouble(v); annotationValues.put(k, Double.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "double"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "double"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "B") { @@ -166,14 +177,16 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { byte value = Byte.parseByte(v); annotationValues.put(k, Byte.toString(value)); } catch (NumberFormatException nfe) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "byte"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "byte"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } } else if (t.getSignature() == "C") { if (v.length() != 3) { // '?' - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, - "char"), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.INVALID_ANNOTATION_VALUE, v, "char"), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); } else { annotationValues.put(k, v.substring(1, 2)); @@ -183,6 +196,15 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { } } else if (t.equals(ResolvedType.JL_STRING)) { // nothing to do, it will be OK + } else if (t.equals(ResolvedType.JL_CLASS)) { + String typename = v.substring(0, v.lastIndexOf('.')); // strip off '.class' + ResolvedType rt = scope.lookupType(typename, this).resolve(scope.getWorld()); + if (rt.isMissing()) { + IMessage m = MessageUtil.error("Unable to resolve type '" + v + "' specified for value '" + k + "'", + getSourceLocation()); + scope.getWorld().getMessageHandler().handleMessage(m); + } + annotationValues.put(k, rt.getSignature()); } else { throw new RuntimeException("Compiler limitation: annotation value support not implemented for type " + t); } @@ -192,6 +214,8 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.UNKNOWN_ANNOTATION_VALUE, annotationType, k), getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); + } else { + break; } } } @@ -268,8 +292,9 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { if (typePattern instanceof ExactTypePattern) { ExactTypePattern et = (ExactTypePattern) typePattern; if (!et.getExactType().resolve(scope.getWorld()).isAnnotation()) { - IMessage m = MessageUtil.error(WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE, et - .getExactType().getName()), getSourceLocation()); + IMessage m = MessageUtil.error( + WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE, et.getExactType().getName()), + getSourceLocation()); scope.getWorld().getMessageHandler().handleMessage(m); resolved = false; } @@ -296,11 +321,6 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { private static final byte VERSION = 1; // rev if ser. form changes - /* - * (non-Javadoc) - * - * @see org.aspectj.weaver.patterns.PatternNode#write(java.io.DataOutputStream) - */ @Override public void write(CompressingDataOutputStream s) throws IOException { s.writeByte(AnnotationTypePattern.WILD); |