SSR: fix matching method parameters in super classes (IDEA-193171)

This commit is contained in:
Bas Leijdekkers
2018-06-04 12:54:55 +02:00
parent 9379250018
commit d327e0de3e
2 changed files with 24 additions and 5 deletions
@@ -957,7 +957,16 @@ public class JavaMatchingVisitor extends JavaElementVisitor {
myMatchingVisitor.setResult(myMatchingVisitor.matchOptionally(initializer, var2Initializer));
}
finally {
myMatchingVisitor.scopeMatch(nameIdentifier, isTypedVar, var2.getNameIdentifier());
final PsiIdentifier identifier = var2.getNameIdentifier();
final String name;
if (identifier == null && (name = var2.getName()) != null) {
// when matching a stub or compiled code
final PsiIdentifier fakeIdentifier = JavaPsiFacade.getElementFactory(var2.getProject()).createIdentifier(name);
myMatchingVisitor.scopeMatch(nameIdentifier, isTypedVar, fakeIdentifier);
}
else {
myMatchingVisitor.scopeMatch(nameIdentifier, isTypedVar, identifier);
}
}
}
@@ -2,11 +2,13 @@
package com.intellij.structuralsearch;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.psi.PsiElement;
import com.intellij.structuralsearch.plugin.ui.Configuration;
import com.intellij.structuralsearch.plugin.ui.SearchConfiguration;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -142,18 +144,26 @@ public class JavaPredefinedConfigurationsTest extends StructuralSearchTestCase {
" <T extends U, V> X(int i) {}" +
"}",
"<T> X(String s) {}", "<T extends U, V> X(int i) {}");
doTest(configurationMap.remove(SSRBundle.message("predefined.configuration.all.methods.of.the.class.within.hierarchy")),
"class X {}",
PsiElement::getText,
"registerNatives", "getClass", "hashCode", "equals", "clone", "toString", "notify", "notifyAll", "wait", "wait", "wait", "finalize");
//assertTrue("untested configurations: " + configurationMap.keySet(), configurationMap.isEmpty());
}
private void doTest(Configuration template, String source, String... results) {
doTest(template, source, e -> StructuralSearchUtil.getPresentableElement(e).getText(), results);
}
private void doTest(Configuration template, String source, Function<? super PsiElement, String> resultConverter, String... expectedResults) {
if (!(template instanceof SearchConfiguration)) fail();
final SearchConfiguration searchConfiguration = (SearchConfiguration)template;
options = searchConfiguration.getMatchOptions();
final List<MatchResult> matches = testMatcher.testFindMatches(source, options, true, StdFileTypes.JAVA, null, false);
assertEquals(template.getName(), results.length, matches.size());
for (int i = 0; i < matches.size(); i++) {
final String matchText = StructuralSearchUtil.getPresentableElement(matches.get(i).getMatch()).getText();
assertEquals(template.getName(), results[i], matchText);
assertEquals(template.getName(), expectedResults.length, matches.size());
String[] actualResults = matches.stream().map(MatchResult::getMatch).map(resultConverter).toArray(String[]::new);
for (int i = 0; i < actualResults.length; i++) {
assertEquals(template.getName(), expectedResults[i], actualResults[i]);
}
}
}