java null argument index: add heuristic to don't process leaves that must not be valid arguments

GitOrigin-RevId: bd8ea6002d48e52b8bd9d91ed8a053198b71e97e
This commit is contained in:
Dmitry Batkovich
2019-06-03 19:51:26 +03:00
committed by intellij-monorepo-bot
parent d730fa522b
commit 199bca8235

View File

@@ -4,7 +4,9 @@ package com.intellij.psi.impl.search;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.lang.LighterAST;
import com.intellij.lang.LighterASTNode;
import com.intellij.lang.ParserDefinition;
import com.intellij.lang.java.JavaParserDefinition;
import com.intellij.lang.java.lexer.JavaLexer;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.vfs.VirtualFile;
@@ -23,6 +25,8 @@ import com.intellij.util.io.EnumeratorStringDescriptor;
import com.intellij.util.io.KeyDescriptor;
import com.intellij.util.text.StringSearcher;
import gnu.trove.THashMap;
import gnu.trove.TIntArrayList;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -39,6 +43,8 @@ public class JavaNullMethodArgumentIndex extends ScalarIndexExtension<JavaNullMe
public static final ID<MethodCallData, Void> INDEX_ID = ID.create("java.null.method.argument");
private interface Lazy {
TokenSet CALL_TYPES = TokenSet.create(METHOD_CALL_EXPRESSION, NEW_EXPRESSION, ANONYMOUS_CLASS);
TIntHashSet WHITE_SPACE_OR_EOL_SYMBOLS = new TIntHashSet(new int[]{' ', '\n', '\r', '\t', '\f'});
TIntHashSet STOP_SYMBOLS = new TIntHashSet(new int[]{'(', ',', ')', '/'}); // stop at slash, bracket, сomma
}
private final boolean myOfflineMode = ApplicationManager.getApplication().isCommandLine() &&
!ApplicationManager.getApplication().isUnitTestMode();
@@ -103,8 +109,14 @@ public class JavaNullMethodArgumentIndex extends ScalarIndexExtension<JavaNullMe
private static Set<LighterASTNode> findCallsWithNulls(@NotNull LighterAST lighterAst,
@NotNull CharSequence text) {
Set<LighterASTNode> calls = new HashSet<>();
int[] occurrences = new StringSearcher(PsiKeyword.NULL, true, true).findAllOccurrences(text);
LightTreeUtil.processLeavesAtOffsets(occurrences, lighterAst, (leaf, offset) -> {
TIntArrayList occurrences = new TIntArrayList();
new StringSearcher(PsiKeyword.NULL, true, true).processOccurrences(text, idx -> {
if (containsStopSymbol(idx, text, true) && containsStopSymbol(idx + 3, text, false)) {
occurrences.add(idx);
}
return true;
});
LightTreeUtil.processLeavesAtOffsets(occurrences.toNativeArray(), lighterAst, (leaf, offset) -> {
LighterASTNode literal = leaf == null ? null : lighterAst.getParent(leaf);
if (isNullLiteral(lighterAst, literal)) {
LighterASTNode exprList = lighterAst.getParent(literal);