IDEA-130071 (SSR incorrectly says pattern does not match anything in selected scope)

This commit is contained in:
Bas Leijdekkers
2014-12-18 20:27:09 +01:00
parent 2562fcf408
commit cabfec01e9
3 changed files with 38 additions and 10 deletions
@@ -436,7 +436,31 @@ public class JavaCompilingVisitor extends JavaRecursiveElementWalkingVisitor {
private void handleReference(PsiJavaCodeReferenceElement reference) {
handleReferenceText(reference.getReferenceName(), myCompilingVisitor.getContext());
if (shouldOccur(reference)) {
handleReferenceText(reference.getReferenceName(), myCompilingVisitor.getContext());
}
}
private boolean shouldOccur(PsiJavaCodeReferenceElement reference) {
final CompileContext compileContext = myCompilingVisitor.getContext();
final PsiElement parent = reference.getParent();
if (!(parent instanceof PsiReferenceList)) {
return true;
}
final PsiElement grandParent = parent.getParent();
if (!(grandParent instanceof PsiMethod)) {
return true;
}
final PsiMethod method = (PsiMethod)grandParent;
if (method.getThrowsList() != parent) {
return true;
}
final String name = method.getName();
if (!compileContext.getPattern().isTypedVar(name)) {
return true;
}
final SubstitutionHandler handler = (SubstitutionHandler)compileContext.getPattern().getHandler(name);
return !(handler != null && handler.getMinOccurs() == 0);
}
private static void handleReferenceText(String refname, CompileContext compileContext) {
@@ -28,7 +28,7 @@ public class TestModeOptimizingSearchHelper extends OptimizingSearchHelperBase {
}
protected void doAddSearchWordInCode(final String refname) {
append(refname, "reserved in code:");
append(refname, "in code:");
}
@Override
@@ -1,18 +1,22 @@
package com.intellij.structuralsearch;
import com.intellij.structuralsearch.impl.matcher.compiler.PatternCompiler;
import com.intellij.idea.Bombed;
import java.util.Calendar;
/**
* @author Maxim.Mossienko
*/
@Bombed(day = 28, description = "support it", month = Calendar.JULY, user = "maxim.mossienko")
public abstract class OptimizedSearchScanTest extends StructuralSearchTestCase {
public void _testClassByQName() throws Exception {
String plan = findWordsToBeUsedWhenSearchingFor("A.f");
assertEquals("[in code:f]", plan);
public class OptimizedSearchScanTest extends StructuralSearchTestCase {
public void testClassByQName() throws Exception {
final String plan = findWordsToBeUsedWhenSearchingFor("A.f");
assertEquals("[in code:f][in code:A]", plan);
}
public void testOptionalMethodWithThrowsClause() {
final String plan = findWordsToBeUsedWhenSearchingFor("class C {" +
" void 'm{0,1} () throws OMGWTFBBQException {}" +
"}");
assertEquals("exception should not be in plan", "[in code:C]", plan);
}
private String findWordsToBeUsedWhenSearchingFor(final String s) {