diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java index 750e3cbc7..0fcbebe49 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/SignaturePattern.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -103,29 +104,37 @@ public SignaturePattern resolveBindings(IScope scope, Bindings bindings) { private void checkForIncorrectTargetKind(PatternNode patternNode, IScope scope, boolean targetsOtherThanTypeAllowed) { checkForIncorrectTargetKind(patternNode, scope, targetsOtherThanTypeAllowed, false); - } // bug 115252 - adding an xlint warning if the annnotation target type is // wrong. This logic, or similar, may have to be applied elsewhere in the case // of pointcuts which don't go through SignaturePattern.resolveBindings(..) - private void checkForIncorrectTargetKind(PatternNode patternNode, IScope scope, boolean targetsOtherThanTypeAllowed, - boolean parameterTargettingAnnotationsAllowed) { + private void checkForIncorrectTargetKind( + PatternNode patternNode, + IScope scope, + boolean targetsOtherThanTypeAllowed, + boolean parameterTargettingAnnotationsAllowed + ) + { + final World world = scope.getWorld(); // return if we're not in java5 mode, if the unmatchedTargetKind Xlint // warning has been turned off, or if the patternNode is * - if (!scope.getWorld().isInJava5Mode() || scope.getWorld().getLint().unmatchedTargetKind == null - || (patternNode instanceof AnyTypePattern)) { + if ( + !world.isInJava5Mode() || + !world.getLint().unmatchedTargetKind.isEnabled() || + patternNode instanceof AnyTypePattern + ) { return; } if (patternNode instanceof ExactAnnotationTypePattern) { - ResolvedType resolvedType = ((ExactAnnotationTypePattern) patternNode).getAnnotationType().resolve(scope.getWorld()); + ResolvedType resolvedType = ((ExactAnnotationTypePattern) patternNode).getAnnotationType().resolve(world); if (targetsOtherThanTypeAllowed) { AnnotationTargetKind[] targetKinds = resolvedType.getAnnotationTargetKinds(); if (targetKinds == null) { return; } reportUnmatchedTargetKindMessage(targetKinds, patternNode, scope, true); - } else if (!targetsOtherThanTypeAllowed && !resolvedType.canAnnotationTargetType()) { + } else if (!resolvedType.canAnnotationTargetType()) { // everything is incorrect since we've already checked whether we have the TYPE target annotation AnnotationTargetKind[] targetKinds = resolvedType.getAnnotationTargetKinds(); if (targetKinds == null) { @@ -134,12 +143,11 @@ private void checkForIncorrectTargetKind(PatternNode patternNode, IScope scope, reportUnmatchedTargetKindMessage(targetKinds, patternNode, scope, false); } } else { - TypePatternVisitor visitor = new TypePatternVisitor(scope, targetsOtherThanTypeAllowed, - parameterTargettingAnnotationsAllowed); + TypePatternVisitor visitor = new TypePatternVisitor(scope, targetsOtherThanTypeAllowed, parameterTargettingAnnotationsAllowed); patternNode.traverse(visitor, null); if (visitor.containedIncorrectTargetKind()) { Set keys = visitor.getIncorrectTargetKinds().keySet(); - for (PatternNode node : keys) { + for (ExactAnnotationTypePattern node : keys) { AnnotationTargetKind[] targetKinds = visitor.getIncorrectTargetKinds().get(node); reportUnmatchedTargetKindMessage(targetKinds, node, scope, false); } @@ -156,13 +164,16 @@ private void reportUnmatchedTargetKindMessage(AnnotationTargetKind[] annotationT return; } if (i < (annotationTargetKinds.length - 1)) { - targetNames.append("ElementType." + targetKind.getName() + ","); + targetNames.append("ElementType.").append(targetKind.getName()).append(","); } else { - targetNames.append("ElementType." + targetKind.getName() + "}"); + targetNames.append("ElementType.").append(targetKind.getName()).append("}"); } } - scope.getWorld().getLint().unmatchedTargetKind.signal(new String[] { node.toString(), targetNames.toString() }, - getSourceLocation(), new ISourceLocation[0]); + scope.getWorld().getLint().unmatchedTargetKind.signal( + new String[] { node.toString(), targetNames.toString() }, + getSourceLocation(), + new ISourceLocation[0] + ); } /**