Merge branch 'master' into upsource-master

This commit is contained in:
Evgeny Pasynkov
2012-07-03 10:28:50 +02:00
700 changed files with 146269 additions and 141471 deletions
@@ -1,3 +0,0 @@
public class OurException extends Throwable{
}
@@ -1,6 +0,0 @@
public class OurNotException {
public static class InnerException extends Throwable{
}
public static class InnerNonException{
}
}
@@ -1,4 +0,0 @@
package pack;
public class AAClass {
}
@@ -1,5 +0,0 @@
package pack;
public class WithInnerAClass{
public static class Inner{}
}
@@ -1,4 +0,0 @@
class Main {
foo.bar.AxBxCxDxEx<caret>
}
@@ -0,0 +1,7 @@
class Util {
void foox() {
int fooy;
foo<caret>
}
}
@@ -1,17 +1,17 @@
class Foo {
int ELEMENT_A = 1;
int ELEMENT_B = 1;
int ELEMENT_C = 1;
int ELEMENT_D = 1;
int ELEMENT_E = 1;
int ELEMENT_F = 1;
int ELEMENT_G = 1;
int ELEMENT_H = 1;
int ELEMENT_I = 1;
{
El<caret>
}
class Foo {
int ELXEMENT_A = 1;
int ELXEMENT_B = 1;
int ELXEMENT_C = 1;
int ELXEMENT_D = 1;
int ELXEMENT_E = 1;
int ELXEMENT_F = 1;
int ELXEMENT_G = 1;
int ELXEMENT_H = 1;
int ELXEMENT_I = 1;
{
Elx<caret>
}
}
@@ -0,0 +1,5 @@
class FooBar {
void foo(FooBar _fooBar) {
fb<caret>
}
}
@@ -1,9 +1,33 @@
class MyClass {
public void foo() {
MyDD<String> d = new MyDD<String>() {
};
}
}
abstract class MyDD<T> {
class MyClass {
public void foo() {
MyDD<String> d = new MyDD<String>() {
@Override
public int hashCode() {
<selection>return super.hashCode(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
@Override
public boolean equals(Object obj) {
return super.equals(obj); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone(); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public String toString() {
return super.toString(); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
protected void finalize() throws Throwable {
super.finalize(); //To change body of overridden methods use File | Settings | File Templates.
}
};
}
}
abstract class MyDD<T> {
}
@@ -1,5 +1,29 @@
interface Function<X, Y> { }
class A {
private static final Function<String, String> a = new Function<String, String>() {
<caret>};
interface Function<X, Y> { }
class A {
private static final Function<String, String> a = new Function<String, String>() {
@Override
public int hashCode() {
<selection>return super.hashCode(); //To change body of overridden methods use File | Settings | File Templates.</selection>
}
@Override
public boolean equals(Object obj) {
return super.equals(obj); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone(); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
public String toString() {
return super.toString(); //To change body of overridden methods use File | Settings | File Templates.
}
@Override
protected void finalize() throws Throwable {
super.finalize(); //To change body of overridden methods use File | Settings | File Templates.
}
};
}
@@ -0,0 +1,7 @@
// "Break string on '\n'" "true"
class A {
String s = "Hello,\n\r" +
"world\n" +
"!\n";
}
@@ -0,0 +1,5 @@
// "Break string on '\n'" "true"
class A {
String s = "Hello,\n\rwor<caret>ld\n!\n";
}
@@ -0,0 +1,5 @@
// "Break string on '\n'" "false"
class A {
String s = "Hello!\n";
}
@@ -0,0 +1,5 @@
// "Break string on '\n'" "false"
class A {
String s = "Hello!\n\r";
}
@@ -0,0 +1,21 @@
// "Convert to 'new Color(0x10101)'" "true"
package java.awt;
class A {
private Color color = new Color(0x10101);
}
class Color {
Color(int r, int g, int b) {
}
Color(int r, int g, int b, int a) {
}
Color(int rgb) {
}
Color(int rgba, boolean hasAlpha) {
}
}
@@ -0,0 +1,21 @@
// "Convert to 'new Color(0x10101)'" "true"
package java.awt;
class A {
private Color color = new Color(257, 257,<caret> 257);
}
class Color {
Color(int r, int g, int b) {
}
Color(int r, int g, int b, int a) {
}
Color(int rgb) {
}
Color(int rgba, boolean hasAlpha) {
}
}
@@ -1,268 +1,270 @@
/*
* Copyright 2000-2012 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.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupManagerImpl;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.JavaModuleType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.TestDataPath;
import java.io.File;
@TestDataPath("$CONTENT_ROOT/testData")
public class ClassNameCompletionTest extends CompletionTestCase {
private static final String BASE_PATH = "/codeInsight/completion/className/";
protected boolean myOldSetting;
@Override
protected void setUp() throws Exception {
super.setUp();
setType(CompletionType.CLASS_NAME);
myOldSetting = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION;
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION = true;
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected void tearDown() throws Exception {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION = myOldSetting;
super.tearDown();
}
public void testImportAfterNew() throws Exception {
String path = BASE_PATH + "/importAfterNew";
configureByFile(path + "/before1.java");
checkResultByFile(path + "/after1.java");
configureByFile(path + "/before2.java");
selectItem(myItems[0]);
checkResultByFile(path + "/after2.java");
}
public void testAfterNewThrowable1() throws Exception {
String path = BASE_PATH + "/afterNewThrowable";
configureByFile(path + "/before1.java");
checkResultByFile(path + "/after1.java");
}
public void testAfterNewThrowable2() throws Exception {
String path = BASE_PATH + "/afterNewThrowable";
configureByFile(path + "/before2.java");
checkResultByFile(path + "/after2.java");
}
public void testExcessParensAfterNew() throws Exception { doTest(); }
public void testReuseParensAfterNew() throws Exception { doTest(); }
public void testBracesAfterNew() throws Exception { doTest(); }
public void testInPlainTextFile() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".txt");
checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt");
}
public void testDoubleStringBuffer() throws Exception {
createClass("package java.lang; public class StringBuffer {}");
doTest();
assertNull(myItems);
}
public void testReplaceReferenceExpressionWithTypeElement() throws Exception {
createClass("package foo.bar; public class ABCDEF {}");
doTest();
}
public void testCamelHumpPrefix() throws Exception {
String path = BASE_PATH + "/java/";
configureByFile(path + getTestName(false) + ".java");
complete();
checkResultByFile(path + getTestName(false) + "_after.java");
assertEquals(2, myItems.length);
}
private void doTest() throws Exception {
String path = BASE_PATH + "/java/";
configureByFile(path + getTestName(false) + ".java");
checkResultByFile(path + getTestName(false) + "_after.java");
}
public void testNameCompletionJava() throws Exception {
String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test1-source.java");
performAction();
checkResultByFile(path + "/test1-result.java");
configureByFile(path + "/test2-source.java");
performAction();
checkResultByFile(path + "/test2-result.java");
}
public void testImplementsFiltering1() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test4-source.java");
performAction();
checkResultByFile(path + "/test4-result.java");
}
public void testImplementsFiltering2() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test3-source.java");
performAction();
checkResultByFile(path + "/test3-result.java");
configureByFile(path + "/implements2-source.java");
performAction();
checkResultByFile(path + "/implements2-result.java");
configureByFile(path + "/implements3-source.java");
performAction();
checkResultByFile(path + "/implements3-result.java");
}
@Override
protected boolean clearModelBeforeConfiguring() {
return "testAnnotationFiltering".equals(getName());
}
public void testAnnotationFiltering() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/test7-source.java");
performAction();
checkResultByFile(path + "/test7-result.java");
configureByFile(path + "/test8-source.java");
performAction();
checkResultByFile(path + "/test8-result.java");
configureByFile(path + "/test9-source.java");
performAction();
checkResultByFile(path + "/test9-result.java");
configureByFile(path + "/test9_2-source.java");
performAction();
checkResultByFile(path + "/test9_2-result.java");
configureByFile(path + "/test9_3-source.java");
performAction();
checkResultByFile(path + "/test9_3-result.java");
configureByFile(path + "/test11-source.java");
performAction();
checkResultByFile(path + "/test11-result.java");
configureByFile(path + "/test10-source.java");
performAction();
checkResultByFile(path + "/test10-result.java");
configureByFile(path + "/test12-source.java");
performAction();
checkResultByFile(path + "/test12-result.java");
configureByFile(path + "/test13-source.java");
performAction();
checkResultByFile(path + "/test13-result.java");
}
public void testInMethodCall() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall-source.java");
performAction();
checkResultByFile(path + "/methodCall-result.java");
}
public void testInMethodCallQualifier() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/methodCall1-source.java");
performAction();
checkResultByFile(path + "/methodCall1-result.java");
}
public void testInVariableDeclarationType() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFile(path + "/varType-source.java");
performAction();
checkResultByFile(path + "/varType-result.java");
}
public void testExtraSpace() throws Exception { doJavaTest(); }
public void testAnnotation() throws Exception { doJavaTest(); }
public void testInStaticImport() throws Exception { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Exception { doJavaTest(); }
public void testQualifyNameOnSecondCompletion() throws Exception {
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Exception {
final JavaModuleType type = new JavaModuleType();
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", type.getId());
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
}
}.execute().throwException();
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false);
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
}
private void doJavaTest() throws Exception {
final String path = BASE_PATH + "/nameCompletion/java";
configureByFileNoCompletion(path + "/" + getTestName(false) + "-source.java");
performAction();
checkResultByFile(path + "/" + getTestName(false) + "-result.java");
}
@Override
protected void configureByFile(String filePath) throws Exception {
final String path = getTestDataPath() + new File(filePath).getParent() + "/source";
if (new File(path).exists()) {
PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete);
}
super.configureByFile(filePath);
}
private void performAction() {
CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.CLASS_NAME);
handler.invokeCompletion(myProject, myEditor);
final LookupManager instance = LookupManager.getInstance(myProject);
if (instance instanceof LookupManagerImpl) {
final LookupManagerImpl testLookupManager = ((LookupManagerImpl)instance);
if (testLookupManager.getActiveLookup() != null) {
testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0);
}
}
}
}
/*
* Copyright 2000-2012 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.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.TestDataPath;
import java.io.IOException;
@TestDataPath("$CONTENT_ROOT/testData")
public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7);
}
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/className/";
}
public void testImportAfterNew() throws Exception {
createClass("package pack; public class AAClass {}");
createClass("package pack; public class WithInnerAClass{\n" +
" public static class Inner{}\n" +
"}");
String path = "/importAfterNew";
configureByFile(path + "/before1.java");
checkResultByFile(path + "/after1.java");
configureByFile(path + "/before2.java");
selectItem(myItems[0]);
checkResultByFile(path + "/after2.java");
}
private void createClass(String text) {
myFixture.addClass(text);
}
public void testAfterNewThrowable1() throws Exception {
addClassesForAfterNewThrowable();
String path = "/afterNewThrowable";
configureByFile(path + "/before1.java");
myFixture.type('\n');
checkResultByFile(path + "/after1.java");
}
private void addClassesForAfterNewThrowable() throws IOException {
createClass("public class OurException extends Throwable{}");
createClass("public class OurNotException {\n" +
" public static class InnerException extends Throwable{}\n" +
" public static class InnerNonException{}\n" +
"}");
}
public void testAfterNewThrowable2() throws Exception {
addClassesForAfterNewThrowable();
String path = "/afterNewThrowable";
configureByFile(path + "/before2.java");
myFixture.type('\n');
checkResultByFile(path + "/after2.java");
}
public void testExcessParensAfterNew() throws Exception { doTest(); }
public void testReuseParensAfterNew() throws Exception { doTest(); }
public void testBracesAfterNew() throws Exception { doTest(); }
public void testInPlainTextFile() throws Exception {
configureByFile(getTestName(false) + ".txt");
checkResultByFile(getTestName(false) + "_after.txt");
}
public void testInPropertiesFile() throws Exception {
myFixture.configureByText("a.properties", "abc = StrinBui<caret>");
complete();
myFixture.checkResult("abc = java.lang.StringBuilder<caret>");
}
public void testDoubleStringBuffer() throws Exception {
createClass("package java.lang; public class StringBuffer {}");
doTest();
assertNull(myItems);
}
public void testReplaceReferenceExpressionWithTypeElement() throws Exception {
createClass("package foo.bar; public class ABCDEF {}");
doTest();
}
public void testCamelHumpPrefix() throws Exception {
String path = "/java/";
configureByFile(path + getTestName(false) + ".java");
complete();
checkResultByFile(path + getTestName(false) + "_after.java");
assertEquals(2, myItems.length);
}
private void doTest() throws Exception {
String path = "/java/";
configureByFile(path + getTestName(false) + ".java");
checkResultByFile(path + getTestName(false) + "_after.java");
}
public void testNameCompletionJava() throws Exception {
String path = "/nameCompletion/java";
configureByFile(path + "/test1-source.java");
performAction();
checkResultByFile(path + "/test1-result.java");
configureByFile(path + "/test2-source.java");
performAction();
checkResultByFile(path + "/test2-result.java");
}
public void testImplementsFiltering1() throws Exception {
final String path = "/nameCompletion/java";
configureByFile(path + "/test4-source.java");
performAction();
checkResultByFile(path + "/test4-result.java");
}
public void testImplementsFiltering2() throws Exception {
final String path = "/nameCompletion/java";
configureByFile(path + "/test3-source.java");
performAction();
checkResultByFile(path + "/test3-result.java");
configureByFile(path + "/implements2-source.java");
performAction();
checkResultByFile(path + "/implements2-result.java");
configureByFile(path + "/implements3-source.java");
performAction();
checkResultByFile(path + "/implements3-result.java");
}
public void testAnnotationFiltering() throws Exception {
createClass("@interface MyObjectType {}");
final String path = "/nameCompletion/java";
configureByFile(path + "/test8-source.java");
performAction();
checkResultByFile(path + "/test8-result.java");
cleanupVfs();
configureByFile(path + "/test9-source.java");
performAction();
checkResultByFile(path + "/test9-result.java");
cleanupVfs();
configureByFile(path + "/test9_2-source.java");
performAction();
checkResultByFile(path + "/test9_2-result.java");
cleanupVfs();
configureByFile(path + "/test9_3-source.java");
performAction();
checkResultByFile(path + "/test9_3-result.java");
cleanupVfs();
configureByFile(path + "/test11-source.java");
performAction();
checkResultByFile(path + "/test11-result.java");
cleanupVfs();
configureByFile(path + "/test10-source.java");
performAction();
checkResultByFile(path + "/test10-result.java");
cleanupVfs();
configureByFile(path + "/test12-source.java");
performAction();
checkResultByFile(path + "/test12-result.java");
cleanupVfs();
configureByFile(path + "/test13-source.java");
performAction();
checkResultByFile(path + "/test13-result.java");
}
private void cleanupVfs() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
for (VirtualFile file : myFixture.getTempDirFixture().getFile("").getChildren()) {
try {
file.delete(this);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
});
}
public void testInMethodCall() throws Exception {
final String path = "/nameCompletion/java";
configureByFile(path + "/methodCall-source.java");
performAction();
checkResultByFile(path + "/methodCall-result.java");
}
public void testInMethodCallQualifier() throws Exception {
final String path = "/nameCompletion/java";
configureByFile(path + "/methodCall1-source.java");
performAction();
checkResultByFile(path + "/methodCall1-result.java");
}
public void testInVariableDeclarationType() throws Exception {
final String path = "/nameCompletion/java";
configureByFile(path + "/varType-source.java");
performAction();
checkResultByFile(path + "/varType-result.java");
}
public void testExtraSpace() throws Exception { doJavaTest(); }
public void testAnnotation() throws Exception { doJavaTest(); }
public void testInStaticImport() throws Exception { doJavaTest(); }
public void testInCommentWithPackagePrefix() throws Exception { doJavaTest(); }
private void doJavaTest() throws Exception {
final String path = "/nameCompletion/java";
myFixture.configureByFile(path + "/" + getTestName(false) + "-source.java");
performAction();
checkResultByFile(path + "/" + getTestName(false) + "-result.java");
}
@Override
protected void complete() {
myItems = myFixture.complete(CompletionType.BASIC, 2);
}
private void performAction() {
complete();
if (LookupManager.getActiveLookup(myFixture.getEditor()) != null) {
myFixture.type('\n');
}
}
}
@@ -1,83 +1,83 @@
/*
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
* Use is subject to license terms.
*/
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.ide.ui.UISettings;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.annotations.NonNls;
/**
* @author peter
*/
@TestDataPath("$CONTENT_ROOT/testData")
public abstract class CompletionSortingTestCase extends LightFixtureCompletionTestCase {
private final CompletionType myType;
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
protected CompletionSortingTestCase(CompletionType type) {
myType = type;
}
@Override
protected void setUp() throws Exception {
super.setUp();
((StatisticsManagerImpl)StatisticsManager.getInstance()).enableStatistics(getTestRootDisposable());
}
@Override
protected void tearDown() throws Exception {
LookupManager.getInstance(getProject()).hideActiveLookup();
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false;
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER;
super.tearDown();
}
@Override
protected abstract String getBasePath();
protected void checkPreferredItems(final int selected, @NonNls final String... expected) {
invokeCompletion(getTestName(false) + ".java");
assertPreferredItems(selected, expected);
}
protected void assertPreferredItems(final int selected, @NonNls final String... expected) {
myFixture.assertPreferredCompletionItems(selected, expected);
}
protected LookupImpl invokeCompletion(final String path) {
configureNoCompletion(path);
myFixture.complete(myType);
return getLookup();
}
protected void configureNoCompletion(String path) {
myFixture.configureFromExistingVirtualFile(
myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/')));
}
protected static void incUseCount(final LookupImpl lookup, final int index) {
imitateItemSelection(lookup, index);
refreshSorting(lookup);
}
protected static void refreshSorting(final LookupImpl lookup) {
lookup.setSelectionTouched(false);
lookup.resort();
}
protected static void imitateItemSelection(final LookupImpl lookup, final int index) {
final LookupElement item = lookup.getItems().get(index);
lookup.setCurrentItem(item);
CompletionLookupArranger.collectStatisticChanges(CompletionServiceImpl.getCompletionService().getCurrentCompletion(), item);
CompletionLookupArranger.applyLastCompletionStatisticsUpdate();
}
}
/*
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
* Use is subject to license terms.
*/
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.ide.ui.UISettings;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.annotations.NonNls;
/**
* @author peter
*/
@TestDataPath("$CONTENT_ROOT/testData")
public abstract class CompletionSortingTestCase extends LightFixtureCompletionTestCase {
private final CompletionType myType;
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
protected CompletionSortingTestCase(CompletionType type) {
myType = type;
}
@Override
protected void setUp() throws Exception {
super.setUp();
((StatisticsManagerImpl)StatisticsManager.getInstance()).enableStatistics(getTestRootDisposable());
}
@Override
protected void tearDown() throws Exception {
LookupManager.getInstance(getProject()).hideActiveLookup();
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = false;
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER;
super.tearDown();
}
@Override
protected abstract String getBasePath();
protected void checkPreferredItems(final int selected, @NonNls final String... expected) {
invokeCompletion(getTestName(false) + ".java");
assertPreferredItems(selected, expected);
}
protected void assertPreferredItems(final int selected, @NonNls final String... expected) {
myFixture.assertPreferredCompletionItems(selected, expected);
}
protected LookupImpl invokeCompletion(final String path) {
configureNoCompletion(path);
myFixture.complete(myType);
return getLookup();
}
protected void configureNoCompletion(String path) {
myFixture.configureFromExistingVirtualFile(
myFixture.copyFileToProject(path, com.intellij.openapi.util.text.StringUtil.getShortName(path, '/')));
}
protected static void incUseCount(final LookupImpl lookup, final int index) {
imitateItemSelection(lookup, index);
refreshSorting(lookup);
}
protected static void refreshSorting(final LookupImpl lookup) {
lookup.setSelectionTouched(false);
lookup.resort(true);
}
protected static void imitateItemSelection(final LookupImpl lookup, final int index) {
final LookupElement item = lookup.getItems().get(index);
lookup.setCurrentItem(item);
CompletionLookupArranger.collectStatisticChanges(CompletionServiceImpl.getCompletionService().getCurrentCompletion(), item);
CompletionLookupArranger.applyLastCompletionStatisticsUpdate();
}
}
@@ -1,201 +1,206 @@
package com.intellij.codeInsight.completion;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.util.ArrayUtil
import com.intellij.codeInsight.lookup.LookupElementPresentation;
/**
* @author peter
*/
public class GlobalMemberNameCompletionTest extends LightCodeInsightFixtureTestCase {
public void testMethodName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcmethod() {}
static void methodThatsNotVisible() {}
}
""")
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod;
class Bar {{ abcmethod()<caret> }}"""
}
public void testFieldName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
doTest "class Bar {{ abcf<caret> }}", true, """import static foo.Foo.abcfield;
class Bar {{ abcfield<caret> }}"""
}
public void testFieldNameQualified() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
doTest "class Bar {{ abcf<caret> }}", false, """import foo.Foo;
class Bar {{ Foo.abcfield<caret> }}"""
}
public void testFieldNamePresentation() {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
myFixture.configureByText "a.java", "class Bar {{ abcf<caret> }}"
def element = myFixture.complete(CompletionType.CLASS_NAME)[0]
def presentation = new LookupElementPresentation()
element.renderElement(presentation)
assert 'Foo.abcfield' == presentation.itemText
assert ' (foo)' == presentation.tailText
assert 'int' == presentation.typeText
}
public void testQualifiedMethodName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcmethod() {}
}
""")
doTest "class Bar {{ abcm<caret> }}", false, """import foo.Foo;
class Bar {{ Foo.abcmethod()<caret> }}"""
}
public void testIfThereAreAlreadyStaticImportsWithThatClass() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int anotherMethod(int a) {}
public static int abcmethod() {}
void methodThatsNotVisible() {}
}
""")
doTest """import static foo.Foo.abcmethod;
class Bar {{ abcmethod(); anoMe<caret> }}""", false,
"""import static foo.Foo.abcmethod;
import static foo.Foo.anotherMethod;
class Bar {{ abcmethod(); anotherMethod(<caret>) }}"""
}
@Override protected void tearDown() {
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ArrayUtil.EMPTY_STRING_ARRAY
super.tearDown()
}
public void testExcludeClassFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod() {}
}
""")
myFixture.addClass("""package foo;
public class Excl {
public static int abcmethod2() {}
}
""")
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Excl"] as String[]
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod;
class Bar {{ abcmethod()<caret> }}"""
}
public void testExcludeMethodFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod1() {}
public static int abcmethodExcluded() {}
}
""")
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Foo.abcmethodExcluded"] as String[]
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod1;
class Bar {{ abcmethod1()<caret> }}"""
}
public void testMergeOverloads() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod(int a) {}
public static int abcmethod(boolean a) {}
public static int abcmethod1(boolean a) {}
}
""")
myFixture.configureByText("a.java", "class Bar {{ abcm<caret> }}")
myFixture.complete(CompletionType.CLASS_NAME)
assertOrderedEquals myFixture.lookupElementStrings, "abcmethod", "abcmethod1"
}
public void testMethodFromTheSameClass() {
myFixture.configureByText("a.java", """
class A {
static void foo() {}
static void goo() {
f<caret>
}
}
""")
def element = myFixture.complete(CompletionType.CLASS_NAME)[0]
def presentation = new LookupElementPresentation()
element.renderElement(presentation)
assert 'foo' == presentation.itemText
myFixture.type '\n'
myFixture.checkResult '''
class A {
static void foo() {}
static void goo() {
foo();<caret>
}
}
'''
}
private void doTest(String input, boolean importStatic, String output) {
myFixture.configureByText("a.java", input)
def item = assertOneElement(myFixture.complete(CompletionType.CLASS_NAME))
if (importStatic) {
item.'as'(StaticallyImportable).shouldBeImported = true
}
myFixture.type('\n')
myFixture.checkResult output
}
}
package com.intellij.codeInsight.completion;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.util.ArrayUtil
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.LookupElement;
/**
* @author peter
*/
public class GlobalMemberNameCompletionTest extends LightCodeInsightFixtureTestCase {
public void testMethodName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcmethod() {}
static void methodThatsNotVisible() {}
}
""")
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod;
class Bar {{ abcmethod()<caret> }}"""
}
public void testFieldName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
doTest "class Bar {{ abcf<caret> }}", true, """import static foo.Foo.abcfield;
class Bar {{ abcfield<caret> }}"""
}
public void testFieldNameQualified() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
doTest "class Bar {{ abcf<caret> }}", false, """import foo.Foo;
class Bar {{ Foo.abcfield<caret> }}"""
}
public void testFieldNamePresentation() {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcfield = 2
static final int fieldThatsNotVisible = 3
}
""")
myFixture.configureByText "a.java", "class Bar {{ abcf<caret> }}"
def element = complete()[0]
def presentation = new LookupElementPresentation()
element.renderElement(presentation)
assert 'Foo.abcfield' == presentation.itemText
assert ' (foo)' == presentation.tailText
assert 'int' == presentation.typeText
}
private LookupElement[] complete() {
myFixture.complete(CompletionType.BASIC, 2)
}
public void testQualifiedMethodName() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int abcmethod() {}
}
""")
doTest "class Bar {{ abcm<caret> }}", false, """import foo.Foo;
class Bar {{ Foo.abcmethod()<caret> }}"""
}
public void testIfThereAreAlreadyStaticImportsWithThatClass() throws Exception {
myFixture.addClass("""
package foo;
public class Foo {
public static int anotherMethod(int a) {}
public static int abcmethod() {}
void methodThatsNotVisible() {}
}
""")
doTest """import static foo.Foo.abcmethod;
class Bar {{ abcmethod(); anoMe<caret> }}""", false,
"""import static foo.Foo.abcmethod;
import static foo.Foo.anotherMethod;
class Bar {{ abcmethod(); anotherMethod(<caret>) }}"""
}
@Override protected void tearDown() {
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ArrayUtil.EMPTY_STRING_ARRAY
super.tearDown()
}
public void testExcludeClassFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod() {}
}
""")
myFixture.addClass("""package foo;
public class Excl {
public static int abcmethod2() {}
}
""")
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Excl"] as String[]
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod;
class Bar {{ abcmethod()<caret> }}"""
}
public void testExcludeMethodFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod1() {}
public static int abcmethodExcluded() {}
}
""")
CodeInsightSettings.instance.EXCLUDED_PACKAGES = ["foo.Foo.abcmethodExcluded"] as String[]
doTest "class Bar {{ abcm<caret> }}", true, """import static foo.Foo.abcmethod1;
class Bar {{ abcmethod1()<caret> }}"""
}
public void testMergeOverloads() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
public static int abcmethod(int a) {}
public static int abcmethod(boolean a) {}
public static int abcmethod1(boolean a) {}
}
""")
myFixture.configureByText("a.java", "class Bar {{ abcm<caret> }}")
complete()
assertOrderedEquals myFixture.lookupElementStrings, "abcmethod", "abcmethod1"
}
public void testMethodFromTheSameClass() {
myFixture.configureByText("a.java", """
class A {
static void foo() {}
static void goo() {
f<caret>
}
}
""")
def element = complete()[0]
def presentation = new LookupElementPresentation()
element.renderElement(presentation)
assert 'foo' == presentation.itemText
myFixture.type '\n'
myFixture.checkResult '''
class A {
static void foo() {}
static void goo() {
foo();<caret>
}
}
'''
}
private void doTest(String input, boolean importStatic, String output) {
myFixture.configureByText("a.java", input)
def item = assertOneElement(complete())
if (importStatic) {
item.'as'(StaticallyImportable).shouldBeImported = true
}
myFixture.type('\n')
myFixture.checkResult output
}
}
@@ -1,102 +1,113 @@
/*
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
* Use is subject to license terms.
*/
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
/**
* @author peter
*/
public class HeavyNormalCompletionTest extends JavaCodeInsightFixtureTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testPackagePrefix() throws Throwable {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final ModifiableRootModel model = ModuleRootManager.getInstance(myFixture.getModule()).getModifiableModel();
model.getContentEntries()[0].getSourceFolders()[0].setPackagePrefix("foo.bar.goo");
model.commit();
}
}.execute().throwException();
myFixture.completeBasic();
myFixture.checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo").isValid());
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo.bar").isValid());
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo.bar.goo").isValid());
}
public void testPreferTestCases() throws Throwable {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final ModifiableRootModel model = ModuleRootManager.getInstance(myFixture.getModule()).getModifiableModel();
ContentEntry contentEntry = model.getContentEntries()[0];
SourceFolder sourceFolder = contentEntry.getSourceFolders()[0];
VirtualFile file = sourceFolder.getFile();
contentEntry.removeSourceFolder(sourceFolder);
contentEntry.addSourceFolder(file, true);
model.commit();
}
}.execute().throwException();
myFixture.addClass("package foo; public class SomeTestCase {}");
myFixture.addClass("package bar; public class SomeTestec {}");
myFixture.addClass("package goo; public class SomeAnchor {}");
myFixture.completeBasic();
myFixture.assertPreferredCompletionItems(0, "SomeTestCase", "SomeAnchor", "SomeTestec");
}
public void testAllClassesWhenNothingIsFound() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}");
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
myFixture.completeBasic();
myFixture.type('\n');
myFixture.checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
}
public void testAllClassesOnSecondBasicCompletion() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}");
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), myFixture.getEditor(), 2, false);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor());
LookupElement[] myItems = lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
assertEquals(2, myItems.length);
assertEquals("AxBxCxDxEx", myItems[1].getLookupString());
assertEquals("AyByCyDyEy", myItems[0].getLookupString());
}
public void testMapsInvalidation() throws Exception {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
assertInstanceOf(myFixture.getFile().getVirtualFile().getFileSystem(), LocalFileSystem.class); // otherwise the completion copy won't be preserved which is critical here
myFixture.completeBasic();
assertOrderedEquals(myFixture.getLookupElementStrings(), "getAaa", "getBbb");
myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getCaretModel().getOffset() + 2);
assertNull(myFixture.completeBasic());
}
}
/*
* Copyright (c) 2000-2005 by JetBrains s.r.o. All Rights Reserved.
* Use is subject to license terms.
*/
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.SourceFolder;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
/**
* @author peter
*/
public class HeavyNormalCompletionTest extends JavaCodeInsightFixtureTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
public void testPackagePrefix() throws Throwable {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final ModifiableRootModel model = ModuleRootManager.getInstance(myFixture.getModule()).getModifiableModel();
model.getContentEntries()[0].getSourceFolders()[0].setPackagePrefix("foo.bar.goo");
model.commit();
}
}.execute().throwException();
myFixture.completeBasic();
myFixture.checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo").isValid());
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo.bar").isValid());
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo.bar.goo").isValid());
}
public void testPreferTestCases() throws Throwable {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
new WriteCommandAction.Simple(getProject()) {
@Override
protected void run() throws Throwable {
final ModifiableRootModel model = ModuleRootManager.getInstance(myFixture.getModule()).getModifiableModel();
ContentEntry contentEntry = model.getContentEntries()[0];
SourceFolder sourceFolder = contentEntry.getSourceFolders()[0];
VirtualFile file = sourceFolder.getFile();
contentEntry.removeSourceFolder(sourceFolder);
contentEntry.addSourceFolder(file, true);
model.commit();
}
}.execute().throwException();
myFixture.addClass("package foo; public class SomeTestCase {}");
myFixture.addClass("package bar; public class SomeTestec {}");
myFixture.addClass("package goo; public class SomeAnchor {}");
myFixture.completeBasic();
myFixture.assertPreferredCompletionItems(0, "SomeTestCase", "SomeAnchor", "SomeTestec");
}
public void testAllClassesWhenNothingIsFound() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}");
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
myFixture.completeBasic();
myFixture.type('\n');
myFixture.checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
}
public void testAllClassesOnSecondBasicCompletion() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}");
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myFixture.getEditor());
LookupElement[] myItems = lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
assertEquals(2, myItems.length);
assertEquals("AxBxCxDxEx", myItems[1].getLookupString());
assertEquals("AyByCyDyEy", myItems[0].getLookupString());
}
public void testMapsInvalidation() throws Exception {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
assertInstanceOf(myFixture.getFile().getVirtualFile().getFileSystem(), LocalFileSystem.class); // otherwise the completion copy won't be preserved which is critical here
myFixture.completeBasic();
assertOrderedEquals(myFixture.getLookupElementStrings(), "getAaa", "getBbb");
myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getCaretModel().getOffset() + 2);
assertNull(myFixture.completeBasic());
}
public void testQualifyInaccessibleClassName() throws Exception {
PsiTestUtil.addModule(getProject(), StdModuleTypes.JAVA, "second", myFixture.getTempDirFixture().findOrCreateDir("second"));
myFixture.addFileToProject("second/foo/bar/AxBxCxDxEx.java", "package foo.bar; class AxBxCxDxEx {}");
myFixture.configureByText("a.java", "class Main { ABCDE<caret> }");
myFixture.complete(CompletionType.BASIC, 3);
myFixture.checkResult("class Main { foo.bar.AxBxCxDxEx<caret> }");
}
}
File diff suppressed because it is too large Load Diff
@@ -1,236 +1,232 @@
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.lang.StdLanguages;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
/**
* @author mike
*/
public class JavadocCompletionTest extends LightFixtureCompletionTestCase {
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/javadoc/";
}
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(new JavaDocLocalInspection());
}
public void testNamesInClass() throws Exception {
configureByFile("ClassTagName.java");
assertStringItems("author", "deprecated", "param", "see", "serial", "since", "version");
}
public void testNamesInField() throws Exception {
configureByFile("FieldTagName.java");
assertStringItems("deprecated", "see", "serial", "serialField", "since");
}
public void testNamesInMethod0() throws Exception {
configureByFile("MethodTagName0.java");
assertStringItems("deprecated", "exception", "param", "return", "see", "serialData", "since", "throws");
}
public void testNamesInMethod1() throws Exception {
configureByFile("MethodTagName1.java");
assertStringItems("see", "serialData", "since");
}
public void testParamValueCompletion() throws Exception {
configureByFile("ParamValue0.java");
assertStringItems("a", "b", "c");
}
public void testParamValueWithPrefixCompletion() throws Exception {
configureByFile("ParamValue1.java");
assertStringItems("a1", "a2", "a3");
}
public void testDescribedParameters() throws Exception {
configureByFile("ParamValue2.java");
assertStringItems("a2", "a3");
}
public void testSee0() throws Exception {
configureByFile("See0.java");
assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives");
}
public void testSee1() throws Exception {
configureByFile("See1.java");
assertStringItems("notify", "notifyAll");
}
public void testSee2() throws Exception {
configureByFile("See2.java");
assertStringItems("notify", "notifyAll");
}
public void testSee3() throws Exception {
configureByFile("See3.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myField")));
}
@NotNull
private List<String> getLookupElementStrings() {
return ObjectUtils.assertNotNull(myFixture.getLookupElementStrings());
}
public void testSee4() throws Exception {
configureByFile("See4.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("A", "B", "C")));
}
public void testSee5() throws Exception {
configureByFile("See5.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName")));
}
public void testIDEADEV10620() throws Exception {
configureByFile("IDEADEV10620.java");
checkResultByFile("IDEADEV10620-after.java");
}
public void testException0() throws Exception {
configureByFile("Exception0.java");
assertStringItems("deprecated", "exception", "param", "see", "serialData", "since", "throws");
}
public void testException1() throws Exception {
configureByFile("Exception1.java");
assertTrue(myItems.length > 18);
}
public void testException2() throws Exception {
myFixture.configureByFile("Exception2.java");
myFixture.complete(CompletionType.SMART);
assertStringItems("IllegalStateException", "IOException");
}
public void testInlineLookup() throws Exception {
configureByFile("InlineTagName.java");
assertStringItems("code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "value");
}
public void testFinishWithSharp() throws Throwable {
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION;
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
try {
checkFinishWithSharp(CompletionType.BASIC);
}
finally {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = old;
}
}
public void testFinishWithSharpClassName() throws Throwable {
checkFinishWithSharp(CompletionType.CLASS_NAME);
}
private void checkFinishWithSharp(CompletionType completionType) throws Exception {
myFixture.configureByFile("FinishWithSharp.java");
myFixture.complete(completionType);
type('#');
checkResultByFile("FinishWithSharp_after.java");
final List<LookupElement> items = getLookup().getItems();
assertEquals("bar", items.get(0).getLookupString());
assertEquals("foo", items.get(1).getLookupString());
}
public void testShortenClassName() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = false;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = true;
}
}
public void testMethodBeforeSharp() throws Throwable {
doTest();
}
public void testFieldReferenceInInnerClassJavadoc() throws Throwable {
doTest();
}
public void testShortenClassReference() throws Throwable { doTest(); }
public void testQualifiedClassReference() throws Throwable {
configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
checkResultByFile(getTestName(false) + "_after.java");
}
public void testThrowsNonImported() throws Throwable {
configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
checkResultByFile(getTestName(false) + "_after.java");
}
private void doTest() throws Exception {
configureByFile(getTestName(false) + ".java");
checkResultByFile(getTestName(false) + "_after.java");
}
public void testInlinePackageReferenceCompletion() throws Exception {
configureByFile("InlineReference.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util")));
}
public void testCustomReferenceProvider() throws Exception {
PsiReferenceRegistrarImpl registrar =
(PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
PsiReferenceProvider provider = new PsiReferenceProvider() {
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) {
@Override
public PsiElement resolve() {
return element;
}
@Override
@NotNull
public Object[] getVariants() {
return new Object[]{"1", "2", "3"};
}
}};
}
};
try {
registrar.registerReferenceProvider(PsiDocTag.class, provider);
configureByFile("ReferenceProvider.java");
assertStringItems("1", "2", "3");
}
finally {
registrar.unregisterReferenceProvider(PsiDocTag.class, provider);
}
}
}
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.lang.StdLanguages;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.psi.javadoc.PsiDocTag;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
/**
* @author mike
*/
public class JavadocCompletionTest extends LightFixtureCompletionTestCase {
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/javadoc/";
}
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.enableInspections(new JavaDocLocalInspection());
}
public void testNamesInClass() throws Exception {
configureByFile("ClassTagName.java");
assertStringItems("author", "deprecated", "param", "see", "serial", "since", "version");
}
public void testNamesInField() throws Exception {
configureByFile("FieldTagName.java");
assertStringItems("deprecated", "see", "serial", "serialField", "since");
}
public void testNamesInMethod0() throws Exception {
configureByFile("MethodTagName0.java");
assertStringItems("deprecated", "exception", "param", "return", "see", "serialData", "since", "throws");
}
public void testNamesInMethod1() throws Exception {
configureByFile("MethodTagName1.java");
assertStringItems("see", "serialData", "since");
}
public void testParamValueCompletion() throws Exception {
configureByFile("ParamValue0.java");
assertStringItems("a", "b", "c");
}
public void testParamValueWithPrefixCompletion() throws Exception {
configureByFile("ParamValue1.java");
assertStringItems("a1", "a2", "a3");
}
public void testDescribedParameters() throws Exception {
configureByFile("ParamValue2.java");
assertStringItems("a2", "a3");
}
public void testSee0() throws Exception {
configureByFile("See0.java");
assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives");
}
public void testSee1() throws Exception {
configureByFile("See1.java");
assertStringItems("notify", "notifyAll");
}
public void testSee2() throws Exception {
configureByFile("See2.java");
assertStringItems("notify", "notifyAll");
}
public void testSee3() throws Exception {
configureByFile("See3.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myField")));
}
@NotNull
private List<String> getLookupElementStrings() {
return ObjectUtils.assertNotNull(myFixture.getLookupElementStrings());
}
public void testSee4() throws Exception {
configureByFile("See4.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("A", "B", "C")));
}
public void testSee5() throws Exception {
configureByFile("See5.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName")));
}
public void testIDEADEV10620() throws Exception {
configureByFile("IDEADEV10620.java");
checkResultByFile("IDEADEV10620-after.java");
}
public void testException0() throws Exception {
configureByFile("Exception0.java");
assertStringItems("deprecated", "exception", "param", "see", "serialData", "since", "throws");
}
public void testException1() throws Exception {
configureByFile("Exception1.java");
assertTrue(myItems.length > 18);
}
public void testException2() throws Exception {
myFixture.configureByFile("Exception2.java");
myFixture.complete(CompletionType.SMART);
assertStringItems("IllegalStateException", "IOException");
}
public void testInlineLookup() throws Exception {
configureByFile("InlineTagName.java");
assertStringItems("code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "value");
}
public void testFinishWithSharp() throws Throwable {
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION;
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false;
try {
checkFinishWithSharp();
}
finally {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = old;
}
}
private void checkFinishWithSharp() throws Exception {
myFixture.configureByFile("FinishWithSharp.java");
myFixture.completeBasic();
type('#');
checkResultByFile("FinishWithSharp_after.java");
final List<LookupElement> items = getLookup().getItems();
assertEquals("bar", items.get(0).getLookupString());
assertEquals("foo", items.get(1).getLookupString());
}
public void testShortenClassName() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = false;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).USE_FQ_CLASS_NAMES_IN_JAVADOC = true;
}
}
public void testMethodBeforeSharp() throws Throwable {
doTest();
}
public void testFieldReferenceInInnerClassJavadoc() throws Throwable {
doTest();
}
public void testShortenClassReference() throws Throwable { doTest(); }
public void testQualifiedClassReference() throws Throwable {
configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
checkResultByFile(getTestName(false) + "_after.java");
}
public void testThrowsNonImported() throws Throwable {
configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
checkResultByFile(getTestName(false) + "_after.java");
}
private void doTest() throws Exception {
configureByFile(getTestName(false) + ".java");
checkResultByFile(getTestName(false) + "_after.java");
}
public void testInlinePackageReferenceCompletion() throws Exception {
configureByFile("InlineReference.java");
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util")));
}
public void testCustomReferenceProvider() throws Exception {
PsiReferenceRegistrarImpl registrar =
(PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
PsiReferenceProvider provider = new PsiReferenceProvider() {
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context) {
return new PsiReference[]{new PsiReferenceBase<PsiElement>(element) {
@Override
public PsiElement resolve() {
return element;
}
@Override
@NotNull
public Object[] getVariants() {
return new Object[]{"1", "2", "3"};
}
}};
}
};
try {
registrar.registerReferenceProvider(PsiDocTag.class, provider);
configureByFile("ReferenceProvider.java");
assertStringItems("1", "2", "3");
}
finally {
registrar.unregisterReferenceProvider(PsiDocTag.class, provider);
}
}
}
@@ -1,373 +1,386 @@
/*
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.ide.ui.UISettings
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiMethod
import com.intellij.openapi.fileEditor.FileDocumentManager
public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
private static final String BASE_PATH = "/codeInsight/completion/normalSorting";
public NormalCompletionOrderingTest() {
super(CompletionType.BASIC);
}
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH;
}
public void testDontPreferRecursiveMethod() throws Throwable {
checkPreferredItems(0, "registrar", "register");
}
public void testDontPreferRecursiveMethod2() throws Throwable {
checkPreferredItems(0, "return", "register");
}
public void testPreferAnnotationMethods() throws Throwable {
checkPreferredItems(0, "name", "value", "Foo", "Anno");
}
public void testPreferSuperMethods() throws Throwable {
checkPreferredItems(0, "foo", "bar");
}
public void testSubstringVsSubSequence() throws Throwable {
checkPreferredItems(0, "substring", "substring", "subSequence");
}
public void testReturnF() throws Throwable {
checkPreferredItems(0, "false", "finalize");
}
public void testPreferDefaultTypeToExpected() throws Throwable {
checkPreferredItems(0, "getName", "getNameIdentifier");
}
public void testShorterPrefixesGoFirst() throws Throwable {
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".html");
assertPreferredItems(0, "p", "param", "pre");
incUseCount(lookup, 2);
assertPreferredItems(0, "p", "pre", "param");
}
public void testUppercaseMatters2() throws Throwable {
final int old = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
try {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.ALL;
checkPreferredItems(0, "classLoader", "classLoader2");
}
finally {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = old;
}
}
public void testShorterShouldBePreselected() throws Throwable {
checkPreferredItems(0, "foo", "fooLongButOfDefaultType");
}
public void testGenericMethodsWithBoundParametersAreStillBetterThanClassLiteral() throws Throwable {
checkPreferredItems(0, "getService", "getService", "class");
}
public void testClassStaticMembersInVoidContext() throws Throwable {
checkPreferredItems(0, "booleanMethod", "voidMethod", "AN_OBJECT", "BOOLEAN", "class");
}
public void testJComponentInstanceMembers() throws Throwable {
checkPreferredItems(0, "getAccessibleContext", "getUI");
}
public void testClassStaticMembersInBooleanContext() throws Throwable {
final String path = getTestName(false) + ".java";
myFixture.configureByFile(path);
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, "BOOLEAN", "booleanMethod", "AN_OBJECT", "voidMethod", "registerNatives");
}
public void testDispreferDeclared() throws Throwable {
checkPreferredItems(0, "aabbb", "aaa");
}
public void testDispreferDeclaredOfExpectedType() throws Throwable {
checkPreferredItems(0, "aabbb", "aaa");
}
public void testDispreferImpls() throws Throwable {
myFixture.addClass("package foo; public class Xxx {}");
configureSecondCompletion();
assertPreferredItems(0, "Xxx", "XxxEx", "XxxImpl", "Xxy");
}
public void testPreferOwnInnerClasses() throws Throwable {
checkPreferredItems(0, "YyyXxx", "YyyZzz");
}
public void testPreferTopLevelClasses() throws Throwable {
configureSecondCompletion();
assertPreferredItems(0, "XxxYyy", "XxzYyy");
}
private void configureSecondCompletion() {
configureNoCompletion(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
}
public void testDontDispreferImplsAfterNew() throws Throwable {
myFixture.addClass("package foo; public interface Xxx {}");
configureSecondCompletion();
assertPreferredItems(0, "Xxx", "XxxImpl");
}
public void testPreferLessHumps() throws Throwable {
myFixture.addClass("package foo; public interface XaYa {}");
myFixture.addClass("package foo; public interface XyYa {}");
configureSecondCompletion();
assertPreferredItems(0, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
}
public void testPreferLessParameters() throws Throwable {
checkPreferredItems(0, "foo", "foo", "foo", "fox");
final List<LookupElement> items = getLookup().getItems();
assertEquals(0, ((PsiMethod)items.get(0).getObject()).getParameterList().getParametersCount());
assertEquals(1, ((PsiMethod)items.get(1).getObject()).getParameterList().getParametersCount());
assertEquals(2, ((PsiMethod)items.get(2).getObject()).getParameterList().getParametersCount());
}
public void testStatsForClassNameInExpression() throws Throwable {
myFixture.addClass("package foo; public interface FooBar {}");
myFixture.addClass("package foo; public interface FooBee {}");
invokeCompletion(getTestName(false) + ".java");
configureSecondCompletion();
incUseCount(getLookup(), 1);
assertPreferredItems(0, "FooBee", "FooBar");
}
public void testSameStatsForDifferentQualifiers() throws Throwable {
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(0, "getComponent");
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
FileDocumentManager.instance.saveAllDocuments()
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(1, "getComponent", "getComponents");
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(1, "getComponent", "getComponents");
}
public void testSameStatsForDifferentQualifiers2() throws Throwable {
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(0, "getComponent");
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
FileDocumentManager.instance.saveAllDocuments()
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(1, "getComponent", "getComponents");
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(1, "getComponent", "getComponents");
}
public void testDispreferFinalize() throws Throwable {
checkPreferredItems(0, "final", "finalize");
}
public void testPreferNewExpectedInner() throws Throwable {
checkPreferredItems(0, "Foooo.Bar", "Foooo");
/*final LookupElementPresentation presentation = new LookupElementPresentation();
getLookup().getItems().get(0).renderElement(presentation);
assertEquals("Foooo.Bar", presentation.getItemText());*/
}
public void testClassInCallOfItsMethod() throws Throwable {
myFixture.addClass("package foo; public interface Foo {}");
myFixture.addClass("package bar; public interface Foo {}");
checkPreferredItems(0, "Foo", "Foo");
assertEquals("foo.Foo", ((JavaPsiClassReferenceElement)getLookup().getCurrentItem()).getQualifiedName());
}
public void testDeclaredMembersGoFirst() throws Exception {
invokeCompletion(getTestName(false) + ".java");
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait",
"wait", "wait");
}
public void testLocalVarsOverMethods() {
checkPreferredItems(0, "value", "valueOf");
}
public void testCurrentClassBest() {
checkPreferredItems(0, "XcodeProjectTemplate", "XcodeConfigurable");
}
public void testFqnStats() {
myFixture.addClass("public interface Baaaaaaar {}");
myFixture.addClass("package zoo; public interface Baaaaaaar {}");
configureSecondCompletion();
final LookupImpl lookup = getLookup();
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(1)).getQualifiedName());
incUseCount(lookup, 1);
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement)lookup.getItems().get(1)).getQualifiedName());
}
public void _testSkipLifted() {
checkPreferredItems(1, "hashCode", "hashCodeMine")
}
public void testDispreferInnerClasses() {
checkPreferredItems(0); //no chosen items
assertFalse(getLookup().getItems().get(0).getObject() instanceof PsiClass);
}
public void testPreferSameNamedMethods() {
checkPreferredItems(0, "foo", "boo", "doo", "hashCode");
}
public void testPreferInterfacesInImplements() {
checkPreferredItems(0, "FooIntf", "FooClass");
}
public void testPreferClassesInExtends() {
checkPreferredItems(0, "FooClass", "Foo_Intf");
}
public void testPreferClassStaticMembers() {
checkPreferredItems(0, "Zoo", "Zoo.A", "Zoo.B", "Zoo.C", "Zoo.D", "Zoo.E", "Zoo.F", "Zoo.G", "Zoo.H");
}
public void testPreferFinallyToFinal() {
checkPreferredItems(1, "final", "finally");
}
public void testPreferReturn() {
checkPreferredItems(0, "return", "rLocal", "rParam", "rMethod");
}
public void testPreferModifiers() {
checkPreferredItems(0, "private", "protected", "public", "paaa", "paab");
}
public void testPreferElse() {
checkPreferredItems(0, "else", "element");
}
public void testPreferMoreMatching() {
checkPreferredItems(0, "FooOCSomething", "FooObjectCollector");
}
public void testPreferSamePackageOverImported() {
myFixture.addClass("package bar; public class Bar1 {}");
myFixture.addClass("package bar; public class Bar2 {}");
myFixture.addClass("package bar; public class Bar3 {}");
myFixture.addClass("package bar; public class Bar4 {}");
myFixture.addClass("class Bar9 {}");
myFixture.addClass("package doo; public class Bar0 {}");
checkPreferredItems(0, "Bar9", "Bar1", "Bar2", "Bar3", "Bar4");
}
public void testPreselectMostRelevantInTheMiddleAlpha() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
myFixture.addClass("package foo; public class Elaaaaaaaaaaaaaaaaaaaa {}");
invokeCompletion(getTestName(false) + ".java");
myFixture.completeBasic();
LookupImpl lookup = getLookup();
assertPreferredItems(lookup.getList().getSelectedIndex());
assertEquals("Elaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
assertEquals("ELEMENT_A", lookup.getCurrentItem().getLookupString());
}
public void testReallyAlphaSorting() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
invokeCompletion(getTestName(false) + ".java");
assert myFixture.lookupElementStrings.sort() == myFixture.lookupElementStrings
}
public void testAlphaSortPackages() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true
def pkgs = ['bar', 'foo', 'goo', 'roo', 'zoo']
for (s in pkgs) {
myFixture.addClass("package $s; public class Foox {}")
}
invokeCompletion(getTestName(false) + ".java")
for (i in 0..<pkgs.size()) {
assert LookupElementPresentation.renderElement(myFixture.lookupElements[i]).tailText?.contains(pkgs[i])
}
}
public void testSortSameNamedVariantsByProximity() {
myFixture.addClass("public class Bar {}");
for (int i = 0; i < 10; i++) {
myFixture.addClass("public class Bar" + i + " {}");
myFixture.addClass("public class Bar" + i + "Colleague {}");
}
myFixture.addClass("package bar; public class Bar {}");
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, "Bar", "Bar");
List<LookupElement> items = getLookup().getItems();
assertEquals(((JavaPsiClassReferenceElement)items.get(0)).getQualifiedName(), "Bar");
assertEquals(((JavaPsiClassReferenceElement)items.get(1)).getQualifiedName(), "bar.Bar");
}
public void testCaseInsensitivePrefixMatch() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
checkPreferredItems(1, "Foo", "foo1", "foo2");
}
public void testExpectedTypeIsMoreImportantThanCase() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
checkPreferredItems(0, "ENABLED", "enable");
}
public void testPreferKeywordsToVoidMethodsInExpectedTypeContext() {
checkPreferredItems 0, 'noo', 'new', 'null', 'noo2', 'notify', 'notifyAll'
}
public void testPreferBetterMatchingConstantToMethods() {
checkPreferredItems 0, 'serial', 'superExpressionInIllegalContext'
}
public void testJComponentAddNewWithStats() throws Throwable {
final LookupImpl lookup = invokeCompletion("/../smartTypeSorting/JComponentAddNew.java");
assertPreferredItems(0, "FooBean3", "JComponent", "Component");
incUseCount(lookup, 2); //Component
assertPreferredItems(0, "Component", "FooBean3", "JComponent");
}
public void testDispreferReturnBeforeStatement() {
checkPreferredItems 0, 'reaction', 'rezet', 'return'
}
public void testDoNotPreferGetClass() {
checkPreferredItems 0, 'get', 'getClass'
incUseCount(lookup, 1)
assertPreferredItems 0, 'get', 'getClass'
}
public void testPreferClassToItsConstants() {
checkPreferredItems 0, 'Calendar', 'Calendar.FIELD_COUNT'
}
}
/*
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.codeInsight.completion;
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.ide.ui.UISettings
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiMethod
import com.intellij.openapi.fileEditor.FileDocumentManager
public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
private static final String BASE_PATH = "/codeInsight/completion/normalSorting";
public NormalCompletionOrderingTest() {
super(CompletionType.BASIC);
}
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + BASE_PATH;
}
public void testDontPreferRecursiveMethod() throws Throwable {
checkPreferredItems(0, "registrar", "register");
}
public void testDontPreferRecursiveMethod2() throws Throwable {
checkPreferredItems(0, "return", "register");
}
public void testPreferAnnotationMethods() throws Throwable {
checkPreferredItems(0, "name", "value", "Foo", "Anno");
}
public void testPreferSuperMethods() throws Throwable {
checkPreferredItems(0, "foo", "bar");
}
public void testSubstringVsSubSequence() throws Throwable {
checkPreferredItems(0, "substring", "substring", "subSequence");
}
public void testReturnF() throws Throwable {
checkPreferredItems(0, "false", "finalize");
}
public void testPreferDefaultTypeToExpected() throws Throwable {
checkPreferredItems(0, "getName", "getNameIdentifier");
}
public void testShorterPrefixesGoFirst() throws Throwable {
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".html");
assertPreferredItems(0, "p", "param", "pre");
incUseCount(lookup, 2);
assertPreferredItems(0, "p", "pre", "param");
}
public void testUppercaseMatters2() throws Throwable {
final int old = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
try {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.ALL;
checkPreferredItems(0, "classLoader", "classLoader2");
}
finally {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = old;
}
}
public void testShorterShouldBePreselected() throws Throwable {
checkPreferredItems(0, "foo", "fooLongButOfDefaultType");
}
public void testGenericMethodsWithBoundParametersAreStillBetterThanClassLiteral() throws Throwable {
checkPreferredItems(0, "getService", "getService", "class");
}
public void testClassStaticMembersInVoidContext() throws Throwable {
checkPreferredItems(0, "booleanMethod", "voidMethod", "AN_OBJECT", "BOOLEAN", "class");
}
public void testJComponentInstanceMembers() throws Throwable {
checkPreferredItems(0, "getAccessibleContext", "getUI");
}
public void testClassStaticMembersInBooleanContext() throws Throwable {
final String path = getTestName(false) + ".java";
myFixture.configureByFile(path);
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, "BOOLEAN", "booleanMethod", "AN_OBJECT", "voidMethod", "registerNatives");
}
public void testDispreferDeclared() throws Throwable {
checkPreferredItems(0, "aabbb", "aaa");
}
public void testDispreferDeclaredOfExpectedType() throws Throwable {
checkPreferredItems(0, "aabbb", "aaa");
}
public void testDispreferImpls() throws Throwable {
myFixture.addClass("package foo; public class Xxx {}");
configureSecondCompletion();
assertPreferredItems(0, "Xxx", "XxxEx", "XxxImpl", "Xxy");
}
public void testPreferOwnInnerClasses() throws Throwable {
checkPreferredItems(0, "YyyXxx", "YyyZzz");
}
public void testPreferTopLevelClasses() throws Throwable {
configureSecondCompletion();
assertPreferredItems(0, "XxxYyy", "XxzYyy");
}
private void configureSecondCompletion() {
configureNoCompletion(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
}
public void testDontDispreferImplsAfterNew() throws Throwable {
myFixture.addClass("package foo; public interface Xxx {}");
configureSecondCompletion();
assertPreferredItems(0, "Xxx", "XxxImpl");
}
public void testPreferLessHumps() throws Throwable {
myFixture.addClass("package foo; public interface XaYa {}");
myFixture.addClass("package foo; public interface XyYa {}");
configureSecondCompletion();
assertPreferredItems(0, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
}
public void testPreferLessParameters() throws Throwable {
checkPreferredItems(0, "foo", "foo", "foo", "fox");
final List<LookupElement> items = getLookup().getItems();
assertEquals(0, ((PsiMethod)items.get(0).getObject()).getParameterList().getParametersCount());
assertEquals(1, ((PsiMethod)items.get(1).getObject()).getParameterList().getParametersCount());
assertEquals(2, ((PsiMethod)items.get(2).getObject()).getParameterList().getParametersCount());
}
public void testStatsForClassNameInExpression() throws Throwable {
myFixture.addClass("package foo; public interface FooBar {}");
myFixture.addClass("package foo; public interface FooBee {}");
invokeCompletion(getTestName(false) + ".java");
configureSecondCompletion();
incUseCount(getLookup(), 1);
assertPreferredItems(0, "FooBee", "FooBar");
}
public void testSameStatsForDifferentQualifiers() throws Throwable {
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(0, "getComponent");
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
FileDocumentManager.instance.saveAllDocuments()
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(1, "getComponent", "getComponents");
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(1, "getComponent", "getComponents");
}
public void testSameStatsForDifferentQualifiers2() throws Throwable {
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(0, "getComponent");
incUseCount(getLookup(), myFixture.lookupElementStrings.indexOf('getComponents'));
FileDocumentManager.instance.saveAllDocuments()
invokeCompletion("SameStatsForDifferentQualifiersJComponent.java");
assertPreferredItems(1, "getComponent", "getComponents");
invokeCompletion("SameStatsForDifferentQualifiersJLabel.java");
assertPreferredItems(1, "getComponent", "getComponents");
}
public void testDispreferFinalize() throws Throwable {
checkPreferredItems(0, "final", "finalize");
}
public void testPreferNewExpectedInner() throws Throwable {
checkPreferredItems(0, "Foooo.Bar", "Foooo");
/*final LookupElementPresentation presentation = new LookupElementPresentation();
getLookup().getItems().get(0).renderElement(presentation);
assertEquals("Foooo.Bar", presentation.getItemText());*/
}
public void testClassInCallOfItsMethod() throws Throwable {
myFixture.addClass("package foo; public interface Foo {}");
myFixture.addClass("package bar; public interface Foo {}");
checkPreferredItems(0, "Foo", "Foo");
assertEquals("foo.Foo", ((JavaPsiClassReferenceElement)getLookup().getCurrentItem()).getQualifiedName());
}
public void testDeclaredMembersGoFirst() throws Exception {
invokeCompletion(getTestName(false) + ".java");
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "getClass", "hashCode", "notify", "notifyAll", "toString", "wait",
"wait", "wait");
}
public void testLocalVarsOverMethods() {
checkPreferredItems(0, "value", "validate", "validateTree", "valueOf");
}
public void testCurrentClassBest() {
checkPreferredItems(0, "XcodeProjectTemplate", "XcodeConfigurable");
}
public void testFqnStats() {
myFixture.addClass("public interface Baaaaaaar {}");
myFixture.addClass("package zoo; public interface Baaaaaaar {}");
configureSecondCompletion();
final LookupImpl lookup = getLookup();
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(1)).getQualifiedName());
incUseCount(lookup, 1);
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement)lookup.getItems().get(1)).getQualifiedName());
}
public void _testSkipLifted() {
checkPreferredItems(1, "hashCode", "hashCodeMine")
}
public void testDispreferInnerClasses() {
checkPreferredItems(0); //no chosen items
assertFalse(getLookup().getItems().get(0).getObject() instanceof PsiClass);
}
public void testPreferSameNamedMethods() {
checkPreferredItems(0, "foo", "boo", "doo", "hashCode");
}
public void testPreferInterfacesInImplements() {
checkPreferredItems(0, "FooIntf", "FooClass");
}
public void testPreferClassesInExtends() {
checkPreferredItems(0, "FooClass", "Foo_Intf");
}
public void testPreferClassStaticMembers() {
checkPreferredItems(0, "Zoo", "Zoo.A", "Zoo.B", "Zoo.C", "Zoo.D", "Zoo.E", "Zoo.F", "Zoo.G", "Zoo.H");
}
public void testPreferFinallyToFinal() {
checkPreferredItems(1, "final", "finally");
}
public void testPreferReturn() {
checkPreferredItems(0, "return", "rLocal", "rParam", "rMethod");
}
public void testPreferModifiers() {
checkPreferredItems(0, "private", "protected", "public", "paaa", "paab");
}
public void testPreferElse() {
checkPreferredItems(0, "else", "element");
}
public void testPreferMoreMatching() {
checkPreferredItems(0, "FooOCSomething", "FooObjectCollector");
}
public void testPreferSamePackageOverImported() {
myFixture.addClass("package bar; public class Bar1 {}");
myFixture.addClass("package bar; public class Bar2 {}");
myFixture.addClass("package bar; public class Bar3 {}");
myFixture.addClass("package bar; public class Bar4 {}");
myFixture.addClass("class Bar9 {}");
myFixture.addClass("package doo; public class Bar0 {}");
checkPreferredItems(0, "Bar9", "Bar1", "Bar2", "Bar3", "Bar4");
}
public void testPreselectMostRelevantInTheMiddleAlpha() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
myFixture.addClass("package foo; public class Elxaaaaaaaaaaaaaaaaaaaa {}");
invokeCompletion(getTestName(false) + ".java");
myFixture.completeBasic();
LookupImpl lookup = getLookup();
assertPreferredItems(lookup.getList().getSelectedIndex());
assertEquals("Elxaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
assertEquals("ELXEMENT_A", lookup.getCurrentItem().getLookupString());
}
public void testReallyAlphaSorting() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
invokeCompletion(getTestName(false) + ".java");
assert myFixture.lookupElementStrings.sort() == myFixture.lookupElementStrings
}
public void testAlphaSortPackages() {
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true
def pkgs = ['bar', 'foo', 'goo', 'roo', 'zoo']
for (s in pkgs) {
myFixture.addClass("package $s; public class Foox {}")
}
invokeCompletion(getTestName(false) + ".java")
for (i in 0..<pkgs.size()) {
assert LookupElementPresentation.renderElement(myFixture.lookupElements[i]).tailText?.contains(pkgs[i])
}
}
public void testSortSameNamedVariantsByProximity() {
myFixture.addClass("public class Bar {}");
for (int i = 0; i < 10; i++) {
myFixture.addClass("public class Bar" + i + " {}");
myFixture.addClass("public class Bar" + i + "Colleague {}");
}
myFixture.addClass("package bar; public class Bar {}");
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, "Bar", "Bar");
List<LookupElement> items = getLookup().getItems();
assertEquals(((JavaPsiClassReferenceElement)items.get(0)).getQualifiedName(), "Bar");
assertEquals(((JavaPsiClassReferenceElement)items.get(1)).getQualifiedName(), "bar.Bar");
}
public void testCaseInsensitivePrefixMatch() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
checkPreferredItems(1, "Foo", "foo1", "foo2");
}
public void testExpectedTypeIsMoreImportantThanCase() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
checkPreferredItems(0, "ENABLED", "enable");
}
public void testPreferKeywordsToVoidMethodsInExpectedTypeContext() {
checkPreferredItems 0, 'noo', 'new', 'null', 'noo2', 'notify', 'notifyAll'
}
public void testPreferBetterMatchingConstantToMethods() {
checkPreferredItems 0, 'serial', 'superExpressionInIllegalContext'
}
public void testJComponentAddNewWithStats() throws Throwable {
final LookupImpl lookup = invokeCompletion("/../smartTypeSorting/JComponentAddNew.java");
assertPreferredItems(0, "FooBean3", "JComponent", "Component");
incUseCount(lookup, 2); //Component
assertPreferredItems(0, "Component", "FooBean3", "JComponent");
}
public void testDispreferReturnBeforeStatement() {
checkPreferredItems 0, 'reaction', 'rezet', 'return'
}
public void testDoNotPreferGetClass() {
checkPreferredItems 0, 'get', 'getClass'
incUseCount(lookup, 1)
assertPreferredItems 0, 'get', 'getClass'
}
public void testPreferClassToItsConstants() {
checkPreferredItems 0, 'Calendar', 'Calendar.FIELD_COUNT'
}
public void testPreferLocalsToStaticsInSecondCompletion() {
myFixture.addClass('public class FooZoo { public static void fooBar() {} }')
myFixture.addClass('public class fooAClass {}')
configureNoCompletion(getTestName(false) + ".java");
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, 'fooy', 'foox', 'fooAClass', 'fooBar');
}
public void testUnderscoresDontMakeMatchMiddle() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE;
checkPreferredItems(0, '_fooBar', 'FooBar')
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2012 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.codeInsight.daemon.quickFix;
/**
* @author Danila Ponomarenko
*/
public class BreakStringOnLineBreaksTest extends LightQuickFixTestCase {
public void test() throws Exception { doAllTests(); }
@Override
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/breakStringOnLineBreaks";
}
}