mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more tests with middle matching
This commit is contained in:
+21
-4
@@ -111,7 +111,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
|
||||
suggestedNameInfo = codeStyleManager.suggestUniqueVariableName(suggestedNameInfo, var, false);
|
||||
final String[] suggestedNames = suggestedNameInfo.names;
|
||||
addLookupItems(set, suggestedNameInfo, matcher, project, suggestedNames);
|
||||
if (set.isEmpty()) {
|
||||
if (!hasStartMatches(set, matcher)) {
|
||||
if (type.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) && matcher.prefixMatches("object")) {
|
||||
set.add(LookupElementBuilder.create("object"));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
if (set.isEmpty() && includeOverlapped) {
|
||||
if (!hasStartMatches(set, matcher) && includeOverlapped) {
|
||||
addLookupItems(set, null, matcher, project, getOverlappedNameVersions(matcher.getPrefix(), suggestedNames, ""));
|
||||
}
|
||||
PsiElement parent = PsiTreeUtil.getParentOfType(var, PsiCodeBlock.class);
|
||||
@@ -137,6 +137,23 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasStartMatches(PrefixMatcher matcher, Set<String> set) {
|
||||
for (String s : set) {
|
||||
if (matcher.isStartMatch(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static boolean hasStartMatches(Set<LookupElement> set, PrefixMatcher matcher) {
|
||||
for (LookupElement lookupElement : set) {
|
||||
if (hasStartMatches(matcher, lookupElement.getAllLookupStrings())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void addSuggestionsInspiredByFieldNames(Set<LookupElement> set,
|
||||
PrefixMatcher matcher,
|
||||
PsiVariable var,
|
||||
@@ -246,7 +263,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
|
||||
final String[] suggestedNames = suggestedNameInfo.names;
|
||||
addLookupItems(set, suggestedNameInfo, matcher, project, suggestedNames);
|
||||
|
||||
if (set.isEmpty() && includeOverlapped) {
|
||||
if (!hasStartMatches(set, matcher) && includeOverlapped) {
|
||||
// use suggested names as suffixes
|
||||
final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(variableKind);
|
||||
if(variableKind != VariableKind.STATIC_FINAL_FIELD){
|
||||
@@ -295,7 +312,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
if (result.isEmpty() && PsiType.VOID != varType && includeOverlapped) {
|
||||
if (!hasStartMatches(matcher, result) && PsiType.VOID != varType && includeOverlapped) {
|
||||
// use suggested names as suffixes
|
||||
final String requiredSuffix = codeStyleManager.getSuffixByVariableKind(varKind);
|
||||
final String prefix = matcher.getPrefix();
|
||||
|
||||
+22
-24
@@ -1,21 +1,12 @@
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
|
||||
package com.intellij.codeInsight.completion
|
||||
import com.intellij.JavaTestUtil
|
||||
import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher
|
||||
|
||||
public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public static final String FILE_PREFIX = "/codeInsight/completion/variables/";
|
||||
|
||||
@Override
|
||||
protected void setUp() {
|
||||
super.setUp()
|
||||
CamelHumpMatcher.forceStartMatching(getTestRootDisposable());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath();
|
||||
@@ -39,7 +30,7 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testLocals1() throws Exception {
|
||||
doTest("TestSource1.java", "TestResult1.java");
|
||||
doSelectTest("TestSource1.java", "TestResult1.java");
|
||||
}
|
||||
|
||||
public void testInterfaceMethod() throws Exception {
|
||||
@@ -49,24 +40,24 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testLocals2() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "TestSource2.java");
|
||||
assert myFixture.lookupElementStrings == ['abc', 'aaa']
|
||||
myFixture.assertPreferredCompletionItems 0, 'abc', 'aaa'
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "TestResult2.java");
|
||||
}
|
||||
|
||||
public void testLocals3() throws Exception {
|
||||
doTest("TestSource3.java", "TestResult3.java");
|
||||
doSelectTest("TestSource3.java", "TestResult3.java");
|
||||
}
|
||||
|
||||
public void testLocals4() throws Exception {
|
||||
doTest("TestSource4.java", "TestResult4.java");
|
||||
doSelectTest("TestSource4.java", "TestResult4.java");
|
||||
}
|
||||
|
||||
public void testLocals5() throws Exception {
|
||||
doTest("TestSource5.java", "TestResult5.java");
|
||||
doSelectTest("TestSource5.java", "TestResult5.java");
|
||||
}
|
||||
|
||||
public void testLocals6() throws Exception {
|
||||
doTest("TestSource6.java", "TestResult6.java");
|
||||
doSelectTest("TestSource6.java", "TestResult6.java");
|
||||
}
|
||||
|
||||
public void testLocals7() throws Exception {
|
||||
@@ -95,6 +86,12 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after);
|
||||
}
|
||||
|
||||
private void doSelectTest(String before, String after) throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + before);
|
||||
myFixture.type('\n')
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after);
|
||||
}
|
||||
|
||||
public void testLocals8() throws Exception {
|
||||
doTest("TestSource8.java", "TestResult8.java");
|
||||
}
|
||||
@@ -108,9 +105,12 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX;
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion1.java");
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix;
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion1-result.java");
|
||||
try {
|
||||
doSelectTest("FieldNameCompletion1.java", "FieldNameCompletion1-result.java");
|
||||
}
|
||||
finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix;
|
||||
}
|
||||
}
|
||||
|
||||
public void testFieldNameCompletion2() throws Exception {
|
||||
@@ -133,13 +133,11 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testLocals9() throws Exception {
|
||||
doTest("TestSource9.java", "TestResult9.java");
|
||||
doSelectTest("TestSource9.java", "TestResult9.java");
|
||||
}
|
||||
|
||||
public void testFieldOutOfAnonymous() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "TestFieldOutOfAnonymous.java");
|
||||
complete();
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "TestFieldOutOfAnonymousResult.java");
|
||||
doSelectTest("TestFieldOutOfAnonymous.java", "TestFieldOutOfAnonymousResult.java");
|
||||
}
|
||||
|
||||
public void testUnresolvedMethodName() throws Exception {
|
||||
@@ -171,7 +169,7 @@ public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testDuplicateSuggestionsFromUsage() {
|
||||
configure();
|
||||
assertStringItems("preferencePolicy", "policy");
|
||||
assertStringItems("preferencePolicy", "policy", "aPreferencePolicy");
|
||||
}
|
||||
|
||||
public void configure() {
|
||||
|
||||
Reference in New Issue
Block a user