SSR: add class keyword to search plan if part of a class object access expression (IDEA-206479)

This commit is contained in:
Bas Leijdekkers
2019-02-06 16:09:30 +01:00
parent a60c5fb932
commit bb64599d5c
2 changed files with 11 additions and 5 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch.impl.matcher.compiler;
import com.intellij.dupLocator.iterators.NodeIterator;
@@ -45,7 +45,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
PsiKeyword.THROWS, PsiKeyword.EXTENDS, PsiKeyword.IMPLEMENTS);
public JavaCompilingVisitor(GlobalCompilingVisitor compilingVisitor) {
this.myCompilingVisitor = compilingVisitor;
myCompilingVisitor = compilingVisitor;
}
public void compile(PsiElement[] topLevelElements) {
@@ -94,6 +94,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
@Override
public void visitCatchSection(PsiCatchSection section) {
// check parameter first and skip catch section if count is zero
final PsiParameter parameter = section.getParameter();
if (parameter != null && !handleWord(parameter.getName(), CODE, myCompilingVisitor.getContext())) return;
super.visitCatchSection(section);
@@ -138,7 +139,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
}
else if (element instanceof PsiKeyword) {
final String keyword = element.getText();
if (!excludedKeywords.contains(keyword)) {
if (!excludedKeywords.contains(keyword) || element.getParent() instanceof PsiExpression) {
GlobalCompilingVisitor.addFilesToSearchForGivenWord(keyword, true, CODE, myCompilingVisitor.getContext());
}
}
@@ -146,7 +147,7 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
@Override
public List<String> getDescendantsOf(String className, boolean includeSelf, Project project) {
SmartList<String> result = new SmartList<>();
final SmartList<String> result = new SmartList<>();
// use project and libraries scope, because super class may be outside the scope of the search
final GlobalSearchScope projectAndLibraries = ProjectScope.getAllScope(project);
@@ -1,4 +1,4 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.structuralsearch;
import com.intellij.openapi.projectRoots.Sdk;
@@ -132,4 +132,9 @@ public class OptimizedSearchScanTest extends StructuralSearchTestCase {
final String plan = findWordsToBeUsedWhenSearchingFor("assert '_exp != null && true: \"'_exp is null\";");
assertEquals("[in literals:null][in literals:is][in code:assert][in code:null][in code:true]", plan);
}
public void testClassObjectAccessExpression() {
final String plan = findWordsToBeUsedWhenSearchingFor("ArrayUtil.toObjectArray($var$, $class$.class)");
assertEquals("[in code:toObjectArray][in code:ArrayUtil][in code:class]", plan);
}
}