mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
choose by name: restore navigation to anonymous classes, add tests
This commit is contained in:
+11
-2
@@ -36,6 +36,8 @@ import com.intellij.util.indexing.IdFilter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class DefaultClassNavigationContributor implements ChooseByNameContributorEx, GotoClassContributor {
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -91,8 +93,15 @@ public class DefaultClassNavigationContributor implements ChooseByNameContributo
|
||||
@NotNull final Processor<NavigationItem> processor,
|
||||
@NotNull final FindSymbolParameters parameters) {
|
||||
String namePattern = StringUtil.getShortName(parameters.getCompletePattern());
|
||||
boolean innerClass = namePattern.contains("$");
|
||||
final MinusculeMatcher innerMatcher = innerClass ? new MinusculeMatcher("*" + namePattern, NameUtil.MatchingCaseSensitivity.NONE) : null;
|
||||
boolean hasDollar = namePattern.contains("$");
|
||||
if (hasDollar) {
|
||||
Matcher matcher = ChooseByNamePopup.patternToDetectAnonymousClasses.matcher(namePattern);
|
||||
if (matcher.matches()) {
|
||||
namePattern = matcher.group(1);
|
||||
hasDollar = namePattern.contains("$");
|
||||
}
|
||||
}
|
||||
final MinusculeMatcher innerMatcher = hasDollar ? new MinusculeMatcher("*" + namePattern, NameUtil.MatchingCaseSensitivity.NONE) : null;
|
||||
PsiShortNamesCache.getInstance(parameters.getProject()).processClassesWithName(name, new Processor<PsiClass>() {
|
||||
final boolean isAnnotation = parameters.getLocalPatternName().startsWith("@");
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.Consumer
|
||||
import com.intellij.util.concurrency.Semaphore
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -210,6 +209,20 @@ class Intf {
|
||||
assert !getPopupElements(new GotoClassModel2(project), 'foo$Goo')
|
||||
}
|
||||
|
||||
public void "test anonymous classes"() {
|
||||
def goo = myFixture.addClass("package goo; class Goo { Runnable r = new Runnable() {}; }")
|
||||
assert getPopupElements(new GotoClassModel2(project), 'Goo$1') == [goo]
|
||||
}
|
||||
|
||||
public void "test qualified name matching"() {
|
||||
def bar = myFixture.addClass("package foo.bar; class Bar { }")
|
||||
def bar2 = myFixture.addClass("package goo.baz; class Bar { }")
|
||||
assert getPopupElements(new GotoClassModel2(project), 'foo.Bar') == [bar]
|
||||
assert getPopupElements(new GotoClassModel2(project), 'foo.bar.Bar') == [bar]
|
||||
assert getPopupElements(new GotoClassModel2(project), 'goo.Bar') == [bar2]
|
||||
assert getPopupElements(new GotoClassModel2(project), 'goo.baz.Bar') == [bar2]
|
||||
}
|
||||
|
||||
public void "test super method in jdk"() {
|
||||
def ourRun = myFixture.addClass("package foo.bar; class Goo implements Runnable { public void run() {} }").methods[0]
|
||||
def sdkRun
|
||||
|
||||
@@ -339,7 +339,7 @@ public class ChooseByNamePopup extends ChooseByNameBase implements ChooseByNameP
|
||||
}
|
||||
|
||||
private static final Pattern patternToDetectLinesAndColumns = Pattern.compile("([^:]+)(?::|@|,|)\\[?(\\d+)?(?:(?:\\D)(\\d+)?)?\\]?");
|
||||
private static final Pattern patternToDetectAnonymousClasses = Pattern.compile("([\\.\\w]+)((\\$[\\d]+)*(\\$)?)");
|
||||
public static final Pattern patternToDetectAnonymousClasses = Pattern.compile("([\\.\\w]+)((\\$[\\d]+)*(\\$)?)");
|
||||
private static final Pattern patternToDetectMembers = Pattern.compile("(.+)(#)(.*)");
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -189,6 +189,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
|
||||
@NotNull
|
||||
private static String getQualifierPattern(@NotNull ChooseByNameBase base, @NotNull String pattern) {
|
||||
pattern = base.transformPattern(pattern);
|
||||
final String[] separators = base.getModel().getSeparators();
|
||||
int lastSeparatorOccurrence = 0;
|
||||
for (String separator : separators) {
|
||||
|
||||
Reference in New Issue
Block a user