Skip to content

Commit

Permalink
Check ASTHelpers.getSymbol for nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
cernat-catalin committed Jan 6, 2023
1 parent 2b75e96 commit 56a6741
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState

@Override
public Description matchIdentifier(IdentifierTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(tree);
if (isMatch(symbol)) {
return getDescription(tree, state, symbol);
if (isMatch(tree)) {
return getDescription(tree, state);
}

return Description.NO_MATCH;
}

private Description getDescription(IdentifierTree tree, VisitorState state, Symbol symbol) {
private Description getDescription(IdentifierTree tree, VisitorState state) {
Symbol symbol = ASTHelpers.getSymbol(tree);
SuggestedFix.Builder builder =
SuggestedFix.builder().removeStaticImport(getImportToRemove(symbol));
String replacement =
Expand All @@ -142,7 +142,12 @@ private static String getImportToRemove(Symbol symbol) {
".", symbol.getEnclosingElement().getQualifiedName(), symbol.getSimpleName());
}

private static boolean isMatch(Symbol symbol) {
private static boolean isMatch(IdentifierTree tree) {
Symbol symbol = ASTHelpers.getSymbol(tree);
if (symbol == null) {
return false;
}

Symbol enclosingSymbol = symbol.getEnclosingElement();
if (enclosingSymbol == null) {
return false;
Expand Down

0 comments on commit 56a6741

Please sign in to comment.