1414
1515import java .io .IOException ;
1616import java .util .ArrayList ;
17+ import java .util .Arrays ;
1718import java .util .Collection ;
1819import java .util .Collections ;
1920import java .util .HashMap ;
4243import org .aspectj .weaver .World ;
4344
4445public class SignaturePattern extends PatternNode implements ISignaturePattern {
45- private MemberKind kind ;
46- private ModifiersPattern modifiers ;
46+ private final MemberKind kind ;
47+ private final ModifiersPattern modifiers ;
4748 private TypePattern returnType ;
4849 private TypePattern declaringType ;
49- private NamePattern name ;
50+ private final NamePattern name ;
5051 private TypePatternList parameterTypes ;
5152 private int bits = 0x0000 ;
5253 private static final int PARAMETER_ANNOTATION_MATCHING = 0x0001 ;
@@ -103,29 +104,37 @@ public SignaturePattern resolveBindings(IScope scope, Bindings bindings) {
103104
104105 private void checkForIncorrectTargetKind (PatternNode patternNode , IScope scope , boolean targetsOtherThanTypeAllowed ) {
105106 checkForIncorrectTargetKind (patternNode , scope , targetsOtherThanTypeAllowed , false );
106-
107107 }
108108
109109 // bug 115252 - adding an xlint warning if the annnotation target type is
110110 // wrong. This logic, or similar, may have to be applied elsewhere in the case
111111 // of pointcuts which don't go through SignaturePattern.resolveBindings(..)
112- private void checkForIncorrectTargetKind (PatternNode patternNode , IScope scope , boolean targetsOtherThanTypeAllowed ,
113- boolean parameterTargettingAnnotationsAllowed ) {
112+ private void checkForIncorrectTargetKind (
113+ PatternNode patternNode ,
114+ IScope scope ,
115+ boolean targetsOtherThanTypeAllowed ,
116+ boolean parameterTargettingAnnotationsAllowed
117+ )
118+ {
119+ final World world = scope .getWorld ();
114120 // return if we're not in java5 mode, if the unmatchedTargetKind Xlint
115121 // warning has been turned off, or if the patternNode is *
116- if (!scope .getWorld ().isInJava5Mode () || scope .getWorld ().getLint ().unmatchedTargetKind == null
117- || (patternNode instanceof AnyTypePattern )) {
122+ if (
123+ !world .isInJava5Mode () ||
124+ !world .getLint ().unmatchedTargetKind .isEnabled () ||
125+ patternNode instanceof AnyTypePattern
126+ ) {
118127 return ;
119128 }
120129 if (patternNode instanceof ExactAnnotationTypePattern ) {
121- ResolvedType resolvedType = ((ExactAnnotationTypePattern ) patternNode ).getAnnotationType ().resolve (scope . getWorld () );
130+ ResolvedType resolvedType = ((ExactAnnotationTypePattern ) patternNode ).getAnnotationType ().resolve (world );
122131 if (targetsOtherThanTypeAllowed ) {
123132 AnnotationTargetKind [] targetKinds = resolvedType .getAnnotationTargetKinds ();
124133 if (targetKinds == null ) {
125134 return ;
126135 }
127136 reportUnmatchedTargetKindMessage (targetKinds , patternNode , scope , true );
128- } else if (!targetsOtherThanTypeAllowed && ! resolvedType .canAnnotationTargetType ()) {
137+ } else if (!resolvedType .canAnnotationTargetType ()) {
129138 // everything is incorrect since we've already checked whether we have the TYPE target annotation
130139 AnnotationTargetKind [] targetKinds = resolvedType .getAnnotationTargetKinds ();
131140 if (targetKinds == null ) {
@@ -134,12 +143,11 @@ private void checkForIncorrectTargetKind(PatternNode patternNode, IScope scope,
134143 reportUnmatchedTargetKindMessage (targetKinds , patternNode , scope , false );
135144 }
136145 } else {
137- TypePatternVisitor visitor = new TypePatternVisitor (scope , targetsOtherThanTypeAllowed ,
138- parameterTargettingAnnotationsAllowed );
146+ TypePatternVisitor visitor = new TypePatternVisitor (scope , targetsOtherThanTypeAllowed , parameterTargettingAnnotationsAllowed );
139147 patternNode .traverse (visitor , null );
140148 if (visitor .containedIncorrectTargetKind ()) {
141149 Set <ExactAnnotationTypePattern > keys = visitor .getIncorrectTargetKinds ().keySet ();
142- for (PatternNode node : keys ) {
150+ for (ExactAnnotationTypePattern node : keys ) {
143151 AnnotationTargetKind [] targetKinds = visitor .getIncorrectTargetKinds ().get (node );
144152 reportUnmatchedTargetKindMessage (targetKinds , node , scope , false );
145153 }
@@ -156,13 +164,16 @@ private void reportUnmatchedTargetKindMessage(AnnotationTargetKind[] annotationT
156164 return ;
157165 }
158166 if (i < (annotationTargetKinds .length - 1 )) {
159- targetNames .append ("ElementType." + targetKind .getName () + "," );
167+ targetNames .append ("ElementType." ). append ( targetKind .getName ()). append ( "," );
160168 } else {
161- targetNames .append ("ElementType." + targetKind .getName () + "}" );
169+ targetNames .append ("ElementType." ). append ( targetKind .getName ()). append ( "}" );
162170 }
163171 }
164- scope .getWorld ().getLint ().unmatchedTargetKind .signal (new String [] { node .toString (), targetNames .toString () },
165- getSourceLocation (), new ISourceLocation [0 ]);
172+ scope .getWorld ().getLint ().unmatchedTargetKind .signal (
173+ new String [] { node .toString (), targetNames .toString () },
174+ getSourceLocation (),
175+ new ISourceLocation [0 ]
176+ );
166177 }
167178
168179 /**
@@ -172,16 +183,11 @@ private void reportUnmatchedTargetKindMessage(AnnotationTargetKind[] annotationT
172183 */
173184 private class TypePatternVisitor extends AbstractPatternNodeVisitor {
174185
175- private IScope scope ;
176- private Map <ExactAnnotationTypePattern , AnnotationTargetKind []> incorrectTargetKinds = new HashMap <>();
177- private boolean targetsOtherThanTypeAllowed ;
178- private boolean parameterTargettingAnnotationsAllowed ;
186+ private final IScope scope ;
187+ private final Map <ExactAnnotationTypePattern , AnnotationTargetKind []> incorrectTargetKinds = new HashMap <>();
188+ private final boolean targetsOtherThanTypeAllowed ;
189+ private final boolean parameterTargettingAnnotationsAllowed ;
179190
180- /**
181- * @param requiredTarget - the signature pattern Kind
182- * @param scope
183- * @param parameterTargettingAnnotationsAllowed
184- */
185191 public TypePatternVisitor (IScope scope , boolean targetsOtherThanTypeAllowed , boolean parameterTargettingAnnotationsAllowed ) {
186192 this .scope = scope ;
187193 this .targetsOtherThanTypeAllowed = targetsOtherThanTypeAllowed ;
@@ -264,7 +270,7 @@ public Object visit(AnyWithAnnotationTypePattern node, Object data) {
264270 }
265271
266272 public boolean containedIncorrectTargetKind () {
267- return (incorrectTargetKinds .size () != 0 );
273+ return (! incorrectTargetKinds .isEmpty () );
268274 }
269275
270276 public Map <ExactAnnotationTypePattern , AnnotationTargetKind []> getIncorrectTargetKinds () {
@@ -450,12 +456,8 @@ private boolean parametersCannotMatch(JoinPointSignature methodJoinpoint) {
450456
451457 // Quick rule: pattern doesn't specify ellipsis and there are a different number of parameters on the
452458 // method join point as compared with the pattern
453- if (parameterTypes .ellipsisCount == 0 && !equalCount ) {
454- if (patternParameterCount > 0 && parameterTypes .get (patternParameterCount - 1 ).isVarArgs ()) {
455- return false ;
456- }
457- return true ;
458- }
459+ if (parameterTypes .ellipsisCount == 0 && !equalCount )
460+ return patternParameterCount <= 0 || !parameterTypes .get (patternParameterCount - 1 ).isVarArgs ();
459461 }
460462
461463 return false ;
@@ -674,9 +676,7 @@ private boolean matchesVarArgs(JoinPointSignature aMethodOrConstructor, World in
674676 }
675677 } else {
676678 // the method ends with an array type, check that we don't *require* a varargs
677- if (lastPattern .isVarArgs ()) {
678- return false ;
679- }
679+ return !lastPattern .isVarArgs ();
680680 }
681681
682682 return true ;
@@ -723,7 +723,7 @@ private FuzzyBoolean matchesAnnotations(ResolvedMember member, World world) {
723723 }
724724
725725 private ResolvedMember findMethod (ResolvedType aspectType , ResolvedMember ajcMethod ) {
726- ResolvedMember decMethods [] = aspectType .getDeclaredMethods ();
726+ ResolvedMember [] decMethods = aspectType .getDeclaredMethods ();
727727 for (ResolvedMember member : decMethods ) {
728728 if (member .equals (ajcMethod )) {
729729 return member ;
0 commit comments