Merge branch 'issue-185'

Closes #196 (rebased onto pmd/5.5.x)
This commit is contained in:
Andreas Dangel
2017-01-27 11:42:38 +01:00
3 changed files with 32 additions and 1 deletions

View File

@ -255,7 +255,16 @@ public class JavaTokenizer implements Tokenizer {
break;
default:
// other tokens are not relevant to process
/*
* Did we find a "class" token not followed by an identifier? i.e:
* expectThrows(IllegalStateException.class, () -> {
* newSearcher(r).search(parentQuery.build(), c);
* });
*/
if (storeNextIdentifier) {
classMembersIndentations.pop();
storeNextIdentifier = false;
}
break;
}
}

View File

@ -202,4 +202,25 @@ public class JavaTokensTokenizerTest {
// Enum constructor
assertEquals("Foo", tokenList.get(13).toString());
}
@Test
public void testIgnoreIdentifiersWithClassKeyword() throws IOException {
JavaTokenizer t = new JavaTokenizer();
t.setIgnoreAnnotations(false);
t.setIgnoreIdentifiers(true);
SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(
"package foo.bar.baz;" + PMD.EOL + "public class Foo {" + PMD.EOL + "Foo() {" + PMD.EOL
+ "}" + PMD.EOL + "public void bar() {" + PMD.EOL + "Bar.baz(Foo.class, () -> {});"
+ PMD.EOL + "}" + PMD.EOL + "}" + PMD.EOL
));
Tokens tokens = new Tokens();
t.tokenize(sourceCode, tokens);
TokenEntry.getEOF();
List<TokenEntry> tokenList = tokens.getTokens();
// Class constructor
assertEquals("Foo", tokenList.get(4).toString());
assertEquals(String.valueOf(JavaParserConstants.IDENTIFIER), tokenList.get(11).toString());
}
}