mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
de-duplicate choose by name @hack
This commit is contained in:
@@ -21,20 +21,33 @@ class ChooseByNameTest extends LightCodeInsightFixtureTestCase {
|
||||
def wordSkipMatch = myFixture.addClass("class UiAbstractUtil {}")
|
||||
def camelMatch = myFixture.addClass("class UberInstructionUxTopicInterface {}")
|
||||
def middleMatch = myFixture.addClass("class BaseUiUtil {}")
|
||||
def elements = createPopup(new GotoClassModel2(project), "uiuti")
|
||||
def elements = getPopupElements(new GotoClassModel2(project), "uiuti")
|
||||
assert elements == [startMatch, wordSkipMatch, camelMatch, ChooseByNameBase.NON_PREFIX_SEPARATOR, middleMatch]
|
||||
}
|
||||
|
||||
public void "test annotation syntax"() {
|
||||
def match = myFixture.addClass("@interface Anno1 {}")
|
||||
myFixture.addClass("class Anno2 {}")
|
||||
def elements = createPopup(new GotoClassModel2(project), "@Anno")
|
||||
def elements = getPopupElements(new GotoClassModel2(project), "@Anno")
|
||||
assert elements == [match]
|
||||
}
|
||||
|
||||
private List<Object> createPopup(ChooseByNameModel model, String text) {
|
||||
def popup = ChooseByNamePopup.createPopup(project, model, (PsiElement)null, "")
|
||||
Disposer.register(testRootDisposable, { popup.close(false) } as Disposable)
|
||||
public void "test no result for empty patterns"() {
|
||||
myFixture.addClass("@interface Anno1 {}")
|
||||
myFixture.addClass("class Anno2 {}")
|
||||
|
||||
def popup = createPopup(new GotoClassModel2(project))
|
||||
assert getPopupElements(popup, "") == []
|
||||
popup.close(false)
|
||||
|
||||
assert getPopupElements(new GotoClassModel2(project), "@") == []
|
||||
}
|
||||
|
||||
private List<Object> getPopupElements(ChooseByNameModel model, String text) {
|
||||
return getPopupElements(createPopup(model), text)
|
||||
}
|
||||
|
||||
private static ArrayList<String> getPopupElements(ChooseByNamePopup popup, String text) {
|
||||
List<Object> elements = ['empty']
|
||||
def semaphore = new Semaphore()
|
||||
semaphore.down()
|
||||
@@ -46,6 +59,12 @@ class ChooseByNameTest extends LightCodeInsightFixtureTestCase {
|
||||
return elements
|
||||
}
|
||||
|
||||
private ChooseByNamePopup createPopup(ChooseByNameModel model) {
|
||||
def popup = ChooseByNamePopup.createPopup(project, model, (PsiElement)null, "")
|
||||
Disposer.register(testRootDisposable, { popup.close(false) } as Disposable)
|
||||
popup
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean runInDispatchThread() {
|
||||
return false
|
||||
|
||||
+10
-8
@@ -57,10 +57,7 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
String namePattern = getNamePattern(base, pattern);
|
||||
String qualifierPattern = getQualifierPattern(base, pattern);
|
||||
|
||||
ChooseByNameModel model = base.getModel();
|
||||
boolean empty = namePattern.isEmpty() ||
|
||||
namePattern.equals("@") && model instanceof GotoClassModel2; // TODO[yole]: remove implicit dependency
|
||||
if (empty && !base.canShowListForEmptyPattern()) return true;
|
||||
if (removeModelSpecificMarkup(base, pattern).isEmpty() && !base.canShowListForEmptyPattern()) return true;
|
||||
|
||||
Set<String> names = new THashSet<String>(Arrays.asList(base.getNames(everywhere)));
|
||||
|
||||
@@ -277,20 +274,25 @@ public class DefaultChooseByNameItemProvider implements ChooseByNameItemProvider
|
||||
}
|
||||
|
||||
private static String convertToMatchingPattern(ChooseByNameBase base, String pattern) {
|
||||
pattern = removeModelSpecificMarkup(base, pattern);
|
||||
|
||||
if (!base.canShowListForEmptyPattern()) {
|
||||
LOG.assertTrue(!pattern.isEmpty(), base);
|
||||
}
|
||||
|
||||
if (base.getModel() instanceof GotoClassModel2 && (pattern.startsWith("@"))) {
|
||||
pattern = pattern.substring(1);
|
||||
}
|
||||
|
||||
if (base.isSearchInAnyPlace() && !pattern.trim().isEmpty()) {
|
||||
pattern = "*" + pattern;
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private static String removeModelSpecificMarkup(ChooseByNameBase base, String pattern) {
|
||||
if (base.getModel() instanceof GotoClassModel2 && pattern.startsWith("@")) {
|
||||
pattern = pattern.substring(1);
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private static boolean matches(@NotNull ChooseByNameBase base,
|
||||
@NotNull String pattern,
|
||||
@NotNull Matcher matcher,
|
||||
|
||||
Reference in New Issue
Block a user