Skip to content

Commit

Permalink
Issue #3106: fixed annotation location check with no modifiers (#3108)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Apr 16, 2016
1 parent 740e1a0 commit e18195d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void visitToken(DetailAST ast) {
* @return Some javadoc.
*/
private static boolean hasAnnotations(DetailAST modifierNode) {
return modifierNode.findFirstToken(TokenTypes.ANNOTATION) != null;
return modifierNode != null && modifierNode.findFirstToken(TokenTypes.ANNOTATION) != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,14 @@ public void testWithMultipleAnnotations() throws Exception {
verify(checkConfig, getPath("InputAnnotationLocation2.java"), expected);
}

@Test
public void testAllTokens() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(AnnotationLocationCheck.class);
checkConfig.addAttribute("tokens", "CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, "
+ "CTOR_DEF, VARIABLE_DEF, PARAMETER_DEF, ANNOTATION_DEF, TYPECAST, "
+ "LITERAL_THROWS, IMPLEMENTS_CLAUSE, TYPE_ARGUMENT, LITERAL_NEW, DOT, "
+ "ANNOTATION_FIELD_DEF");
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputAnnotationLocation3.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.puppycrawl.tools.checkstyle.checks.annotation;

public class InputAnnotationLocation3 {
public static void main(String[] args) {
final Foo foo = new Foo();
foo.bar(new Bar<Foo>() {
public void foo() {
}
});
}

static class Foo {
void bar(Bar<Foo> bar) {
}
}

static abstract class Bar<T> {
abstract void foo();
}
}

0 comments on commit e18195d

Please sign in to comment.