Fix NullPointerException in ClassScope.resolveGenericType()

This commit is contained in:
Björn Kautler
2015-04-14 11:12:57 +02:00
parent f310138f9d
commit d8961a903a
2 changed files with 19 additions and 2 deletions

View File

@ -502,8 +502,11 @@ public class ClassScope extends AbstractJavaScope {
private Class<?> resolveGenericType(Node argument, String typeImage) {
List<ASTTypeParameter> types = new ArrayList<ASTTypeParameter>();
// first search only within the same method
types.addAll(argument.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class).findDescendantsOfType(
ASTTypeParameter.class));
ASTClassOrInterfaceBodyDeclaration firstParentOfType =
argument.getFirstParentOfType(ASTClassOrInterfaceBodyDeclaration.class);
if (firstParentOfType != null) {
types.addAll(firstParentOfType.findDescendantsOfType(ASTTypeParameter.class));
}
// then search class level types
ASTClassOrInterfaceDeclaration enclosingClassOrEnum = argument

View File

@ -34,6 +34,11 @@ public class ClassScopeTest extends STBBaseTst {
parseCode15(ENUM_SCOPE);
}
@Test
public void testEnumTypeParameter() {
parseCode15(ENUM_TYPE_PARAMETER);
}
@Test
public void testVarArgsEmpty() {
parseCode15(
@ -387,6 +392,15 @@ public class ClassScopeTest extends STBBaseTst {
" public abstract String getFilterableString(TreeNode node);" + PMD.EOL +
"}";
private static final String ENUM_TYPE_PARAMETER =
"public enum Foo {" + PMD.EOL +
" BAR(isCustomer(BazEnum.FOO_BAR));" + PMD.EOL +
" Foo(boolean isCustomer) { }" + PMD.EOL +
" private static boolean isCustomer(BazEnum baz) {" + PMD.EOL +
" return false;" + PMD.EOL +
" }" + PMD.EOL +
"}";
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(ClassScopeTest.class);
}