mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-10 13:17:09 +07:00
Merge branch 'db/method-chains-completion'
# Conflicts: # jps/jps-builders/src/org/jetbrains/jps/backwardRefs/BackwardReferenceIndexUtil.java # jps/jps-builders/src/org/jetbrains/jps/backwardRefs/BackwardReferenceIndexWriter.java # jps/jps-builders/src/org/jetbrains/jps/incremental/JavaBuilderService.java
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ interface PsiClass {}
|
||||
|
||||
public class TestCompletion {
|
||||
public void method() {
|
||||
PsiMethod psiMethod = <caret><selection>null</selection>;
|
||||
PsiClass c = psiMethod.getContainingClass()
|
||||
PsiMember psiMember = null;
|
||||
PsiClass c = psiMember.getContainingClass()
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -18,6 +18,13 @@ public class TestIndex {
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
e.getContainingFile();
|
||||
}
|
||||
|
||||
void m2() {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import java.util.*;
|
||||
|
||||
class Foo {
|
||||
void m() {
|
||||
List l0 = new ArrayList();
|
||||
|
||||
List l1 = new AbstractList() {
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
List l2 = new AbstractList() {
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
List l3 = new AbstractList() {
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.*;
|
||||
|
||||
class Foo {
|
||||
|
||||
void m() {
|
||||
|
||||
List l1 = new ArrayList();
|
||||
List l2 = new ArrayList();
|
||||
|
||||
List l3 = new LinkedList();
|
||||
List l4 = new LinkedList();
|
||||
List l5 = new LinkedList();
|
||||
|
||||
<caret>
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
class Foo {
|
||||
void m() {
|
||||
new C();
|
||||
new C();
|
||||
|
||||
new B();
|
||||
new B(0);
|
||||
new B(0, 0);
|
||||
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
|
||||
abstract class A {}
|
||||
|
||||
class B extends A {
|
||||
B() {}
|
||||
B(int i) {}
|
||||
B(int i, int j) {}
|
||||
}
|
||||
|
||||
class C extends A {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
class Foo {
|
||||
void m() {
|
||||
new C();
|
||||
new C();
|
||||
|
||||
new B();
|
||||
new B(0);
|
||||
new B(0, 0);
|
||||
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
|
||||
interface A {}
|
||||
|
||||
class B implements A {
|
||||
B() {}
|
||||
B(int i) {}
|
||||
B(int i, int j) {}
|
||||
}
|
||||
|
||||
class C implements A {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Bar {
|
||||
|
||||
void m(Foo foo) {
|
||||
foo.asd();
|
||||
|
||||
foo.asd(null, null, null);
|
||||
foo.asd(null, null, null);
|
||||
|
||||
<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Foo {
|
||||
|
||||
public void asd() {}
|
||||
|
||||
public void asd(String i, String j, String k) {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
class Bar {
|
||||
|
||||
void m(Foo foo) {
|
||||
foo.asd();
|
||||
foo.asd();
|
||||
foo.asd();
|
||||
|
||||
System.out.println(foo.qwe);
|
||||
System.out.println(foo.qwe);
|
||||
System.out.println(foo.qwe);
|
||||
System.out.println(foo.qwe);
|
||||
System.out.println(foo.qwe);
|
||||
|
||||
foo.zxc();
|
||||
foo.zxc();
|
||||
foo.zxc();
|
||||
|
||||
<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Foo {
|
||||
|
||||
public void asd() {}
|
||||
|
||||
public String qwe = "AEDI JilletnI";
|
||||
|
||||
public void zxc() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
class Bar {
|
||||
|
||||
void m(Foo foo) {
|
||||
foo.asd();
|
||||
foo.asd();
|
||||
foo.asd();
|
||||
|
||||
foo.qwe();
|
||||
foo.qwe();
|
||||
foo.qwe();
|
||||
foo.qwe();
|
||||
foo.qwe();
|
||||
|
||||
foo.zxc();
|
||||
foo.zxc();
|
||||
foo.zxc();
|
||||
|
||||
<caret>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Foo {
|
||||
|
||||
public void asd() {}
|
||||
|
||||
public void qwe() {}
|
||||
|
||||
public void zxc() {}
|
||||
|
||||
}
|
||||
+59
-55
@@ -17,12 +17,12 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.compiler.classFilesIndex.api.index.ClassFilesIndexFeature;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.ChainRelevance;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.completion.MethodsChainsCompletionContributor;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.ChainCompletionMethodCallLookupElement;
|
||||
import com.intellij.compiler.classFilesIndex.chainsSearch.completion.lookup.WeightableChainLookupElement;
|
||||
import com.intellij.compiler.chainsSearch.ChainRelevance;
|
||||
import com.intellij.compiler.chainsSearch.completion.MethodsChainsCompletionContributor;
|
||||
import com.intellij.compiler.chainsSearch.completion.lookup.ChainCompletionMethodCallLookupElement;
|
||||
import com.intellij.compiler.chainsSearch.completion.lookup.WeightableChainLookupElement;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.testFramework.SkipSlowTestLocally;
|
||||
import com.intellij.util.SmartList;
|
||||
|
||||
@@ -42,13 +42,16 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
installCompiler();
|
||||
ClassFilesIndexFeature.METHOD_CHAINS_COMPLETION.enable();
|
||||
Registry.get(MethodsChainsCompletionContributor.REGISTRY_KEY).setValue(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
ClassFilesIndexFeature.METHOD_CHAINS_COMPLETION.disable();
|
||||
super.tearDown();
|
||||
try {
|
||||
Registry.get(MethodsChainsCompletionContributor.REGISTRY_KEY).setValue(false);
|
||||
} finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
protected String getTestDataPath() {
|
||||
@@ -56,7 +59,7 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testOneRelevantMethod() {
|
||||
assertAdvisorLookupElementEquals("e.getProject", 0, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("e.getProject", 0, 9, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testCyclingMethodsNotShowed() {
|
||||
@@ -64,20 +67,20 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testStaticMethod() {
|
||||
final List<WeightableChainLookupElement> elements = doCompletion();
|
||||
List<WeightableChainLookupElement> elements = doCompletion();
|
||||
assertSize(2, elements);
|
||||
assertAdvisorLookupElementEquals("getInstance", 0, 2, 1, 0, elements.get(0));
|
||||
assertAdvisorLookupElementEquals("getInstance", 0, 3, 1, 0, elements.get(0));
|
||||
}
|
||||
|
||||
public void testStaticMethodAndMethod() {
|
||||
final List<WeightableChainLookupElement> elements = doCompletion();
|
||||
assertEquals(String.valueOf(elements), elements.size(), 2);
|
||||
assertAdvisorLookupElementEquals("findClass", 0, 3, 1, 1, elements.get(1));
|
||||
assertAdvisorLookupElementEquals("m.getContainingClass", 0, 5, 1, 0, elements.get(0));
|
||||
List<WeightableChainLookupElement> elements = doCompletion();
|
||||
assertEquals(String.valueOf(elements), 2, elements.size());
|
||||
assertAdvisorLookupElementEquals("findClass", 0, 4, 1, 1, elements.get(1));
|
||||
assertAdvisorLookupElementEquals("m.getContainingClass", 0, 6, 1, 0, elements.get(0));
|
||||
}
|
||||
|
||||
public void testOneChainContainsOther() {
|
||||
assertAdvisorLookupElementEquals("p.getBaseDir", 0, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("p.getBaseDir", 0, 9, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testOneChainContainsOther2() {
|
||||
@@ -85,47 +88,47 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testTwoVariablesWithOneTypeOrSuperType() {
|
||||
assertAdvisorLookupElementEquals("c.getProject", 0, 4, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("c.getProject", 0, 5, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testSuperClassMethodsCallings() {
|
||||
assertAdvisorLookupElementEquals("m.getProject", 0, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("m.getProject", 0, 9, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testMethodsWithParametersInContext() {
|
||||
assertAdvisorLookupElementEquals("getInstance().findFile().findElementAt", 0, 4, 3, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("getInstance().findFile().findElementAt", 0, 5, 3, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void _testChainsWithIndependentCallings() {
|
||||
assertOneElement(doCompletion());
|
||||
}
|
||||
|
||||
public void testMethodReturnsSubclassOfTargetClassShowed2() {
|
||||
public void _testMethodReturnsSubclassOfTargetClassShowed2() {
|
||||
assertOneElement(doCompletion());
|
||||
}
|
||||
|
||||
public void testResultsForSuperClassesShowed() {
|
||||
public void _testResultsForSuperClassesShowed() {
|
||||
// if no other elements found we search by super classes
|
||||
assertOneElement(doCompletion());
|
||||
}
|
||||
|
||||
public void _testInnerClasses() {
|
||||
assertAdvisorLookupElementEquals("j.getEntry", 0, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("j.getEntry", 0, 9, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testMethodsWithSameName() {
|
||||
assertAdvisorLookupElementEquals("f.createType", 1, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("f.createType", 1, 5, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testBigrams2() {
|
||||
final List<WeightableChainLookupElement> collection = doCompletion();
|
||||
assertAdvisorLookupElementEquals("e.getContainingFile().getVirtualFile", 0, 8, 1, 0, assertOneElement(collection));
|
||||
List<WeightableChainLookupElement> collection = doCompletion();
|
||||
assertAdvisorLookupElementEquals("e.getContainingFile().getVirtualFile", 0, 9, 2, 0, assertOneElement(collection));
|
||||
}
|
||||
|
||||
public void testBigrams3() {
|
||||
final List<WeightableChainLookupElement> elements = doCompletion();
|
||||
assertSize(2, elements);
|
||||
assertAdvisorLookupElementEquals("getInstance().findFile", 2, 8, 2, 0, elements.get(0));
|
||||
public void _testBigrams3() {
|
||||
List<WeightableChainLookupElement> elements = doCompletion();
|
||||
assertSize(1, elements);
|
||||
assertAdvisorLookupElementEquals("getInstance().findFile", 2, 9, 2, 0, elements.get(0));
|
||||
}
|
||||
|
||||
public void testMethodWithNoQualifiedVariableInContext() {
|
||||
@@ -141,10 +144,10 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testGetterInContext() {
|
||||
assertAdvisorLookupElementEquals("getMyElement().getProject", 0, 8, 1, 0, assertOneElement(doCompletion()));
|
||||
assertAdvisorLookupElementEquals("getMyElement().getProject", 0, 9, 1, 0, assertOneElement(doCompletion()));
|
||||
}
|
||||
|
||||
public void testMethodParameterCompletion() {
|
||||
public void _testMethodParameterCompletion() {
|
||||
assertOneElement(doCompletion());
|
||||
}
|
||||
|
||||
@@ -152,7 +155,7 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
assertOneElement(doCompletion());
|
||||
}
|
||||
|
||||
public void testCyclingInstancesObtaining() {
|
||||
public void _testCyclingInstancesObtaining() {
|
||||
assertEmpty(doCompletion());
|
||||
}
|
||||
|
||||
@@ -169,7 +172,7 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testResultOrdering() {
|
||||
final List<WeightableChainLookupElement> lookupElements = doCompletion();
|
||||
List<WeightableChainLookupElement> lookupElements = doCompletion();
|
||||
assertSize(4, lookupElements);
|
||||
assertLookupElementStringEquals(lookupElements.get(0), "f.createFileFromText");
|
||||
assertLookupElementStringEquals(lookupElements.get(1), "getInstance().findFile");
|
||||
@@ -178,13 +181,14 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
}
|
||||
|
||||
public void testResultRelevance() {
|
||||
final List<WeightableChainLookupElement> weightableChainLookupElements = doCompletion();
|
||||
assertEquals("e.getContainingClass", weightableChainLookupElements.get(0).getLookupString());
|
||||
assertEquals("getInstance().findClass", weightableChainLookupElements.get(1).getLookupString());
|
||||
List<WeightableChainLookupElement> weightableChainLookupElements = doCompletion();
|
||||
assertSize(1, weightableChainLookupElements);
|
||||
//assertEquals("e.getContainingClass", weightableChainLookupElements.get(0).getLookupString());
|
||||
assertEquals("getInstance().findClass", weightableChainLookupElements.get(0).getLookupString());
|
||||
}
|
||||
|
||||
public void testResultRelevance3() {
|
||||
final List<WeightableChainLookupElement> weightableChainLookupElements = doCompletion();
|
||||
List<WeightableChainLookupElement> weightableChainLookupElements = doCompletion();
|
||||
assertSize(2, weightableChainLookupElements);
|
||||
assertEquals("e.getProject1", weightableChainLookupElements.get(0).getLookupString());
|
||||
assertEquals("getProject", weightableChainLookupElements.get(1).getLookupString());
|
||||
@@ -206,26 +210,26 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
doTestRendering();
|
||||
}
|
||||
|
||||
public void assertAdvisorLookupElementEquals(final String lookupText,
|
||||
final int unreachableParametersCount,
|
||||
final int lastMethodWeight,
|
||||
final int chainSize,
|
||||
final int notMatchedStringVars,
|
||||
final WeightableChainLookupElement actualLookupElement) {
|
||||
public void assertAdvisorLookupElementEquals(String lookupText,
|
||||
int unreachableParametersCount,
|
||||
int lastMethodWeight,
|
||||
int chainSize,
|
||||
int notMatchedStringVars,
|
||||
WeightableChainLookupElement actualLookupElement) {
|
||||
assertLookupElementStringEquals(actualLookupElement, lookupText);
|
||||
assertChainRelevanceEquals(actualLookupElement.getChainRelevance(), lastMethodWeight, chainSize, notMatchedStringVars,
|
||||
unreachableParametersCount);
|
||||
}
|
||||
|
||||
private static void assertLookupElementStringEquals(final LookupElement lookupElement, final String lookupText) {
|
||||
private static void assertLookupElementStringEquals(LookupElement lookupElement, String lookupText) {
|
||||
assertEquals(lookupText, lookupElement.getLookupString());
|
||||
}
|
||||
|
||||
private static void assertChainRelevanceEquals(final ChainRelevance chainRelevance,
|
||||
final int lastMethodWeight,
|
||||
final int chainSize,
|
||||
final int notMatchedStringVars,
|
||||
final int unreachableParametersCount) {
|
||||
private static void assertChainRelevanceEquals(ChainRelevance chainRelevance,
|
||||
int lastMethodWeight,
|
||||
int chainSize,
|
||||
int notMatchedStringVars,
|
||||
int unreachableParametersCount) {
|
||||
assertEquals(notMatchedStringVars, chainRelevance.getNotMatchedStringVars());
|
||||
assertEquals(chainSize, chainRelevance.getChainSize());
|
||||
assertEquals(unreachableParametersCount, chainRelevance.getUnreachableParametersCount());
|
||||
@@ -237,7 +241,7 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
.setValue(ChainCompletionMethodCallLookupElement.PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION, String.valueOf(true));
|
||||
compileAndIndexData(TEST_INDEX_FILE_NAME);
|
||||
myFixture.configureByFiles(getBeforeCompletionFilePath());
|
||||
myFixture.complete(CompletionType.BASIC, MethodsChainsCompletionContributor.INVOCATIONS_THRESHOLD);
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
PropertiesComponent.getInstance(getProject())
|
||||
.setValue(ChainCompletionMethodCallLookupElement.PROP_METHODS_CHAIN_COMPLETION_AUTO_COMPLETION, String.valueOf(false));
|
||||
myFixture.checkResultByFile(getAfterCompletionFilePath());
|
||||
@@ -245,9 +249,9 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
|
||||
private List<WeightableChainLookupElement> doCompletion() {
|
||||
compileAndIndexData(TEST_INDEX_FILE_NAME);
|
||||
final LookupElement[] allLookupElements = runCompletion();
|
||||
final List<WeightableChainLookupElement> targetLookupElements = new SmartList<>();
|
||||
for (final LookupElement lookupElement : allLookupElements) {
|
||||
LookupElement[] allLookupElements = runCompletion();
|
||||
List<WeightableChainLookupElement> targetLookupElements = new SmartList<>();
|
||||
for (LookupElement lookupElement : allLookupElements) {
|
||||
if (lookupElement instanceof WeightableChainLookupElement) {
|
||||
targetLookupElements.add((WeightableChainLookupElement)lookupElement);
|
||||
}
|
||||
@@ -257,8 +261,8 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
|
||||
private LookupElement[] runCompletion() {
|
||||
myFixture.configureByFiles(getTestCompletionFilePath());
|
||||
final LookupElement[] lookupElements =
|
||||
myFixture.complete(CompletionType.BASIC, MethodsChainsCompletionContributor.INVOCATIONS_THRESHOLD);
|
||||
LookupElement[] lookupElements =
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
return lookupElements == null ? LookupElement.EMPTY_ARRAY : lookupElements;
|
||||
}
|
||||
|
||||
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.compiler;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiMember;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CompilerReferenceDataInCompletionTest extends CompilerReferencesTestBase {
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
installCompiler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/compiler/completionOrdering/";
|
||||
}
|
||||
|
||||
public void testSimpleMethods() {
|
||||
doTestMemberCompletionOrdering(new String[] {"Bar.java", "Foo.java"}, "qwe(0)", "asd(0)", "zxc(0)");
|
||||
}
|
||||
|
||||
public void testSimpleMembers() {
|
||||
doTestMemberCompletionOrdering(new String[] {"Bar.java", "Foo.java"}, "qwe", "asd(0)", "zxc(0)");
|
||||
}
|
||||
|
||||
public void testOverloads() {
|
||||
doTestMemberCompletionOrdering(new String[] {"Bar.java", "Foo.java"}, "asd(3)", "asd(0)");
|
||||
}
|
||||
|
||||
public void testConstructor() {
|
||||
doTestConstructorCompletionOrdering(new String[] {"Foo.java"}, "List l = new ", "LinkedList", "ArrayList");
|
||||
}
|
||||
|
||||
public void testConstructorSumOccurrences() {
|
||||
doTestConstructorCompletionOrdering(new String[] {"Foo.java"}, "A a = new ", "B", "C");
|
||||
}
|
||||
|
||||
public void testConstructorSumOccurrences2() {
|
||||
doTestConstructorCompletionOrdering(new String[] {"Foo.java"}, "A a = new ", "B", "C");
|
||||
}
|
||||
|
||||
public void testAnonymous() {
|
||||
doTestConstructorCompletionOrdering(new String[] {"Foo.java"}, "List l = new ", "AbstractList", "ArrayList");
|
||||
}
|
||||
|
||||
private void doTestConstructorCompletionOrdering(@NotNull String[] files,
|
||||
@NotNull String phraseToComplete,
|
||||
String... expectedOrder) {
|
||||
doTestCompletion(files, phraseToComplete, expectedOrder, m -> m instanceof PsiClass && ArrayUtil.contains(m.getName(), expectedOrder));
|
||||
}
|
||||
|
||||
private void doTestMemberCompletionOrdering(@NotNull String[] files, String... expectedOrder) {
|
||||
doTestCompletion(files, "foo.", expectedOrder, m -> "Foo".equals(m.getContainingClass().getName()));
|
||||
}
|
||||
|
||||
private void doTestCompletion(@NotNull String[] files,
|
||||
@NotNull String phraseToComplete,
|
||||
@NotNull String[] expectedOrder,
|
||||
@NotNull Predicate<PsiMember> resultFilter) {
|
||||
myFixture.configureByFiles(ContainerUtil.map2Array(files, String.class, f -> getName() + "/" + f));
|
||||
myFixture.type(phraseToComplete);
|
||||
final int offset = myFixture.getCaretOffset();
|
||||
final LookupElement[] completionVariantsBeforeCompilation = myFixture.complete(CompletionType.BASIC);
|
||||
WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> myFixture.getDocument(myFixture.getFile()).deleteString(offset - phraseToComplete.length(), offset));
|
||||
rebuildProject();
|
||||
myFixture.type(phraseToComplete);
|
||||
final LookupElement[] completionVariantsAfterCompilation = myFixture.complete(CompletionType.BASIC);
|
||||
|
||||
assertFalse("Seems the test doesn't test anything: compiler indices doesn't affect on sorting",
|
||||
Arrays.toString(completionVariantsBeforeCompilation).equals(Arrays.toString(completionVariantsAfterCompilation)));
|
||||
|
||||
final String[] orderedMethods = Arrays.stream(completionVariantsAfterCompilation)
|
||||
.map(l -> l.getObject())
|
||||
.filter(o -> o instanceof PsiMember)
|
||||
.map(o -> ((PsiMember)o))
|
||||
.filter(resultFilter)
|
||||
.map(CompilerReferenceDataInCompletionTest::getPresentation)
|
||||
.toArray(String[]::new);
|
||||
|
||||
assertOrderedEquals(orderedMethods, expectedOrder);
|
||||
}
|
||||
|
||||
private static String getPresentation(PsiMember member) {
|
||||
if (member instanceof PsiMethod) {
|
||||
return member.getName() + "(" + ((PsiMethod)member).getParameterList().getParametersCount() + ")";
|
||||
}
|
||||
else if (member instanceof PsiField || member instanceof PsiClass) {
|
||||
return member.getName();
|
||||
}
|
||||
fail("Unexpected member = " + member + " type = " + member.getClass());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user