Smart completion: prefer items matching by name

This commit is contained in:
Valentin Kipyatkov
2014-09-23 23:01:57 +04:00
committed by valentin
parent 56978c4e16
commit 0462d152eb
38 changed files with 414 additions and 48 deletions
@@ -17,10 +17,13 @@
package org.jetbrains.jet.completion;
import com.intellij.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import java.io.File;
import java.util.regex.Pattern;
@@ -21,11 +21,12 @@ import org.jetbrains.jet.InTextDirectivesUtils
import java.io.File
import org.jetbrains.jet.plugin.PluginTestCaseBase
import org.testng.Assert
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jet.test.util.configureWithExtraFile
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor
public abstract class AbstractCompletionWeigherTest() : JetLightCodeInsightFixtureTestCase() {
public abstract class AbstractCompletionWeigherTest(val completionType: CompletionType, val relativeTestDataPath: String) : JetLightCodeInsightFixtureTestCase() {
fun doTest(path: String) {
myFixture.configureWithExtraFile(path)
@@ -34,12 +35,18 @@ public abstract class AbstractCompletionWeigherTest() : JetLightCodeInsightFixtu
val items = InTextDirectivesUtils.findArrayWithPrefixes(text, "// ORDER:")
Assert.assertTrue(!items.isEmpty(), """Some items should be defined with "// ORDER:" directive""")
myFixture.complete(CompletionType.BASIC, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
myFixture.complete(completionType, InTextDirectivesUtils.getPrefixedInt(text, "// INVOCATION_COUNT:") ?: 1)
myFixture.assertPreferredCompletionItems(InTextDirectivesUtils.getPrefixedInt(text, "// SELECTED:") ?: 0, *items)
}
override fun getProjectDescriptor(): LightProjectDescriptor {
return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
protected override fun getTestDataPath() : String? {
return File(PluginTestCaseBase.getTestDataPathBase(), "/completion/weighers").getPath() + File.separator
return File(PluginTestCaseBase.getTestDataPathBase(), relativeTestDataPath).getPath() + File.separator
}
}
public abstract class AbstractBasicCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.BASIC, "/completion/weighers/basic")
public abstract class AbstractSmartCompletionWeigherTest() : AbstractCompletionWeigherTest(CompletionType.SMART, "/completion/weighers/smart")
@@ -30,71 +30,71 @@ import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/completion/weighers")
@TestMetadata("idea/testData/completion/weighers/basic")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public class CompletionWeigherTestGenerated extends AbstractCompletionWeigherTest {
public void testAllFilesPresentInWeighers() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/weighers"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletionWeigherTest {
public void testAllFilesPresentInBasic() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/weighers/basic"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
}
@TestMetadata("DeprecatedFun.kt")
public void testDeprecatedFun() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/DeprecatedFun.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/DeprecatedFun.kt");
doTest(fileName);
}
@TestMetadata("ExactMatchForKeyword.kt")
public void testExactMatchForKeyword() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/ExactMatchForKeyword.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/ExactMatchForKeyword.kt");
doTest(fileName);
}
@TestMetadata("KeywordsLast.kt")
public void testKeywordsLast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/KeywordsLast.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/KeywordsLast.kt");
doTest(fileName);
}
@TestMetadata("LocalFileBeforeImported.kt")
public void testLocalFileBeforeImported() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/LocalFileBeforeImported.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/LocalFileBeforeImported.kt");
doTest(fileName);
}
@TestMetadata("LocalValuesAndParams.kt")
public void testLocalValuesAndParams() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/LocalValuesAndParams.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/LocalValuesAndParams.kt");
doTest(fileName);
}
@TestMetadata("LocalsBeforeKeywords.kt")
public void testLocalsBeforeKeywords() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/LocalsBeforeKeywords.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/LocalsBeforeKeywords.kt");
doTest(fileName);
}
@TestMetadata("LocalsPropertiesKeywords.kt")
public void testLocalsPropertiesKeywords() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/LocalsPropertiesKeywords.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/LocalsPropertiesKeywords.kt");
doTest(fileName);
}
@TestMetadata("NamedParameters.kt")
public void testNamedParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/NamedParameters.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/NamedParameters.kt");
doTest(fileName);
}
@TestMetadata("ParametersBeforeKeywords.kt")
public void testParametersBeforeKeywords() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/ParametersBeforeKeywords.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/ParametersBeforeKeywords.kt");
doTest(fileName);
}
@TestMetadata("PropertiesBeforeKeywords.kt")
public void testPropertiesBeforeKeywords() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/PropertiesBeforeKeywords.kt");
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/basic/PropertiesBeforeKeywords.kt");
doTest(fileName);
}
@@ -0,0 +1,125 @@
/*
* Copyright 2010-2014 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 org.jetbrains.jet.completion.weighers;
import com.intellij.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.junit.runner.RunWith;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.JUnit3RunnerWithInners;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/completion/weighers/smart")
@TestDataPath("$PROJECT_ROOT")
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
public class SmartCompletionWeigherTestGenerated extends AbstractSmartCompletionWeigherTest {
public void testAllFilesPresentInSmart() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/weighers/smart"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
}
@TestMetadata("NameSimilarity1.kt")
public void testNameSimilarity1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarity1.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarity2.kt")
public void testNameSimilarity2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarity2.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarity3.kt")
public void testNameSimilarity3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarity3.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityAndCompiledParameters.kt")
public void testNameSimilarityAndCompiledParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityAndCompiledParameters.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForBlock.kt")
public void testNameSimilarityForBlock() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForBlock.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForElse.kt")
public void testNameSimilarityForElse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForElse.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForElvis.kt")
public void testNameSimilarityForElvis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForElvis.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForEq1.kt")
public void testNameSimilarityForEq1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForEq1.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForEq2.kt")
public void testNameSimilarityForEq2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForEq2.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForEq3.kt")
public void testNameSimilarityForEq3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForEq3.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForEq4.kt")
public void testNameSimilarityForEq4() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForEq4.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityForThen.kt")
public void testNameSimilarityForThen() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityForThen.kt");
doTest(fileName);
}
@TestMetadata("NameSimilarityInImplicitlyTypedVarInitializer.kt")
public void testNameSimilarityInImplicitlyTypedVarInitializer() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilarityInImplicitlyTypedVarInitializer.kt");
doTest(fileName);
}
@TestMetadata("NameSimilaritySorterPlacement.kt")
public void testNameSimilaritySorterPlacement() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/weighers/smart/NameSimilaritySorterPlacement.kt");
doTest(fileName);
}
}