Skip to content

Commit

Permalink
Solution to NullPointerException at findClassOrMethodInWhichItIsDefin…
Browse files Browse the repository at this point in the history
…ed method #1257
  • Loading branch information
Bhavik3 committed Jun 28, 2015
1 parent ec41464 commit 90178ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Expand Up @@ -257,14 +257,15 @@ private static boolean inLambda(DetailAST paramDef) {
} }


/** /**
* Find the Class or Method in which it is defined. * Find the Class or Constructor or Method in which it is defined.
* @param ast Variable for which we want to find the scope in which it is defined * @param ast Variable for which we want to find the scope in which it is defined
* @return ast The Class or Method in which it is defined. * @return ast The Class or Constructor or Method in which it is defined.
*/ */
private static DetailAST findClassOrMethodInWhichItIsDefined(DetailAST ast) { private static DetailAST findClassOrConstructorOrMethodInWhichItIsDefined(DetailAST ast) {
DetailAST astTraverse = ast; DetailAST astTraverse = ast;
while (!(astTraverse.getType() == TokenTypes.METHOD_DEF while (!(astTraverse.getType() == TokenTypes.METHOD_DEF
|| astTraverse.getType() == TokenTypes.CLASS_DEF)) { || astTraverse.getType() == TokenTypes.CLASS_DEF
|| astTraverse.getType() == TokenTypes.CTOR_DEF)) {
astTraverse = astTraverse.getParent(); astTraverse = astTraverse.getParent();
} }
return astTraverse; return astTraverse;
Expand All @@ -278,9 +279,9 @@ private static DetailAST findClassOrMethodInWhichItIsDefined(DetailAST ast) {
*/ */
private static boolean isSameVariables(DetailAST ast1, DetailAST ast2) { private static boolean isSameVariables(DetailAST ast1, DetailAST ast2) {
final DetailAST classOrMethodOfAst1 = final DetailAST classOrMethodOfAst1 =
findClassOrMethodInWhichItIsDefined(ast1); findClassOrConstructorOrMethodInWhichItIsDefined(ast1);
final DetailAST classOrMethodOfAst2 = final DetailAST classOrMethodOfAst2 =
findClassOrMethodInWhichItIsDefined(ast2); findClassOrConstructorOrMethodInWhichItIsDefined(ast2);


final String identifierOfAst1 = final String identifierOfAst1 =
classOrMethodOfAst1.findFirstToken(TokenTypes.IDENT).getText(); classOrMethodOfAst1.findFirstToken(TokenTypes.IDENT).getText();
Expand Down
Expand Up @@ -24,3 +24,14 @@ void bar () {
} }
} }
} }

enum InputFinalLocalVariableNameShadowingEnum{
test;
final String foo1 = "error";
InputFinalLocalVariableNameShadowingEnum()
{
String foo = foo1;
foo += foo1;
}

}

0 comments on commit 90178ab

Please sign in to comment.