IDEA-241607 Show all available completion elements during indexing for Java

GitOrigin-RevId: fc8cb0f5a1f5bcc3fac479ae7fc463445702e56c
This commit is contained in:
Elena Shaverdova
2020-06-16 02:05:57 +03:00
committed by intellij-monorepo-bot
parent 327f9cbffd
commit 00772f73e1
64 changed files with 1687 additions and 83 deletions
@@ -1251,6 +1251,7 @@
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.SkipAutopopupInComments" id="javaComments"/>
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.SkipAutopopupInStrings" id="javaSkipAutopopupInStrings"/>
<completion.plainTextSymbol language="JAVA" implementationClass="com.intellij.codeInsight.completion.JvmPlainTextSymbolCompletionContributor"/>
<completion.ignoringDumbnessAllowed language="JAVA"/>
<lookup.actionProvider implementation="com.intellij.codeInsight.completion.ExcludeFromCompletionLookupActionProvider" id="excludeFromCompletion" order="last"/>
<lookup.actionProvider implementation="com.intellij.codeInsight.completion.ImportStaticLookupActionProvider" id="importStatic"/>
<fileType extensions="java" hashBangs="java" name="JAVA" language="JAVA" fieldName="INSTANCE" implementationClass="com.intellij.ide.highlighter.JavaFileType"/>
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.generation.OverrideImplementExploreUtil;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.project.DumbService;
import com.intellij.psi.*;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.util.PsiTreeUtil;
@@ -46,6 +47,7 @@ public class AbstractExpectedTypeSkipper extends CompletionPreselectSkipper {
private static Result getSkippingStatus(final LookupElement item, final CompletionLocation location) {
if (location.getCompletionType() != CompletionType.SMART && !hasEmptyPrefix(location)) return Result.ACCEPT;
if (DumbService.getInstance(location.getProject()).isDumb()) return Result.ACCEPT;
CompletionParameters parameters = location.getCompletionParameters();
PsiExpression expression = PsiTreeUtil.getParentOfType(parameters.getPosition(), PsiExpression.class);
@@ -27,6 +27,7 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleManager;
@@ -309,6 +310,7 @@ public class ConstructorInsertHandler implements InsertHandler<LookupElementDeco
private static Runnable createOverrideRunnable(final Editor editor, final PsiFile file, final Project project) {
return () -> {
TemplateManager.getInstance(project).finishTemplate(editor);
if (DumbService.getInstance(project).isDumb()) return;
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
final PsiAnonymousClass
@@ -9,6 +9,7 @@ import com.intellij.codeInspection.ex.GlobalInspectionContextBase;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
@@ -45,8 +46,11 @@ public class JavaGenerateMemberCompletionContributor {
if (parameters.getCompletionType() != CompletionType.BASIC && parameters.getCompletionType() != CompletionType.SMART) {
return;
}
PsiElement position = parameters.getPosition();
if (DumbService.getInstance(position.getProject()).isDumb()) {
return;
}
if (psiElement(PsiIdentifier.class).withParents(PsiJavaCodeReferenceElement.class, PsiTypeElement.class, PsiClass.class).
andNot(JavaKeywordCompletion.AFTER_DOT).accepts(position)) {
PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf(position);
@@ -640,9 +640,13 @@ public class JavaKeywordCompletion {
}
if (position instanceof PsiIdentifier && position.getParent() instanceof PsiLocalVariable) {
PsiType type = ((PsiLocalVariable)position.getParent()).getType();
if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == null) {
return true;
PsiType type = ((PsiLocalVariable) position.getParent()).getType();
if (type instanceof PsiClassType && ((PsiClassType) type).resolve() == null) {
PsiElement grandParent = position.getParent().getParent();
if (!(grandParent instanceof PsiDeclarationStatement) || !(grandParent.getParent() instanceof PsiForStatement) ||
((PsiForStatement) grandParent.getParent()).getInitialization() != grandParent) {
return true;
}
}
}
@@ -842,8 +842,14 @@ public class TypeConversionUtil {
}
final PsiClassType.ClassResolveResult leftResult = PsiUtil.resolveGenericsClassInType(left);
final PsiClassType.ClassResolveResult rightResult = PsiUtil.resolveGenericsClassInType(right);
if (leftResult.getElement() == null || rightResult.getElement() == null) {
if (leftResult.getElement() != rightResult.getElement()) return false;
PsiClass leftResultElement = leftResult.getElement();
PsiClass rightResultElement = rightResult.getElement();
if (leftResultElement == null || rightResultElement == null) {
if (leftResultElement == null && rightResultElement != null &&
left instanceof PsiClassType && left.equalsToText(JAVA_LANG_OBJECT)) {
return true;
}
if (leftResultElement != rightResultElement) return false;
// let's suppose 2 unknown classes, which could be the same to be the same
String lText = left.getPresentableText();
String rText = right.getPresentableText();
@@ -3,7 +3,7 @@ package com.intellij.psi.impl;
import com.intellij.openapi.application.ReadActionProcessor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.DumbUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.FileIndexFacade;
import com.intellij.openapi.roots.PackageIndex;
@@ -43,7 +43,7 @@ public final class PsiElementFinderImpl extends PsiElementFinder implements Dumb
@Override
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
if (DumbService.getInstance(myProject).isDumb()) {
if (!DumbUtil.getInstance(myProject).mayUseIndices()) {
return null;
}
return myFileManager.findClass(qualifiedName, scope);
@@ -51,7 +51,7 @@ public final class PsiElementFinderImpl extends PsiElementFinder implements Dumb
@Override
public PsiClass @NotNull [] findClasses(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
if (DumbService.getInstance(myProject).isDumb()) {
if (!DumbUtil.getInstance(myProject).mayUseIndices()) {
return PsiClass.EMPTY_ARRAY;
}
return myFileManager.findClasses(qualifiedName, scope);
@@ -4,8 +4,10 @@ package com.intellij.psi.impl.compiled;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProviders;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.roots.FileIndexFacade;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.AtomicNotNullLazyValue;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.VolatileNullableLazyValue;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.ElementPresentationUtil;
@@ -20,7 +22,10 @@ import com.intellij.psi.impl.source.tree.TreeElement;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.scope.util.PsiScopesUtil;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.util.*;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
import com.intellij.psi.util.MethodSignatureUtil;
import com.intellij.ui.IconManager;
import com.intellij.ui.icons.RowIcon;
import com.intellij.util.PlatformIcons;
@@ -260,11 +265,7 @@ public class ClsMethodImpl extends ClsMemberImpl<PsiMethodStub> implements PsiAn
@Nullable
public PsiMethod getSourceMirrorMethod() {
return CachedValuesManager.getCachedValue(this, () -> {
PsiFile file = getContainingFile();
ModificationTracker tracker = FileIndexFacade.getInstance(getProject()).getRootModificationTracker();
return CachedValueProvider.Result.create(calcSourceMirrorMethod(), file, file.getNavigationElement(), tracker);
});
return CachedValuesManager.getProjectPsiDependentCache(this, __ -> calcSourceMirrorMethod());
}
@Nullable
@@ -169,8 +169,8 @@ public class PsiPackageImpl extends PsiPackageBase implements PsiPackage, Querya
private PsiClass @NotNull [] getCachedClassesByName(@NotNull String name, GlobalSearchScope scope) {
DumbService dumbService = DumbService.getInstance(getProject());
if (dumbService.isDumb()) {
return dumbService.isAlternativeResolveEnabled() ? getCachedClassesInDumbMode(name, scope) : PsiClass.EMPTY_ARRAY;
if (dumbService.isDumb() && dumbService.isAlternativeResolveEnabled()) {
return getCachedClassesInDumbMode(name, scope);
}
if (ModelBranchImpl.hasBranchedFilesInScope(scope)) {
@@ -0,0 +1,6 @@
class Foo {
Object test() {
return !new <caret>
}
}
@@ -2,7 +2,9 @@
package com.intellij.java.codeInsight.completion
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.testFramework.NeedsIndicesState
@NeedsIndicesState.FullIndices
class AtomicFieldUpdaterCompletionTest : LightFixtureCompletionTestCase() {
override fun setUp() {
super.setUp()
@@ -14,6 +14,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiClass;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.TestDataPath;
import java.io.IOException;
@@ -32,6 +33,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/className/";
}
@NeedsIndicesState.FullIndices
public void testImportAfterNew() {
createClass("package pack; public class AAClass {}");
createClass("package pack; public class WithInnerAClass{\n" +
@@ -60,11 +62,12 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset())
);
assertEquals(doc,
"<html>Candidates for new <b>Time</b>() are:<br>&nbsp;&nbsp;<a href=\"psi_element://Time#Time()\">Time()</a><br>&nbsp;" +
"&nbsp;<a href=\"psi_element://Time#Time(long)\">Time(long time)</a><br></html>");
assertEquals("<html>Candidates for new <b>Time</b>() are:<br>&nbsp;&nbsp;<a href=\"psi_element://Time#Time()\">Time()</a>" +
"<br>&nbsp;&nbsp;<a href=\"psi_element://Time#Time(long)\">Time(long time)</a><br></html>",
doc);
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testTypeParametersTemplate() {
createClass("package pack; public interface Foo<T> {void foo(T t};");
@@ -91,6 +94,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
}
private void createClass(String text) {
//noinspection LanguageMismatch
myFixture.addClass(text);
}
@@ -111,6 +115,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
"}");
}
@NeedsIndicesState.FullIndices
public void testAfterNewThrowable2() {
addClassesForAfterNewThrowable();
String path = "/afterNewThrowable";
@@ -126,6 +131,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
public void testBracesAfterNew() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode not supported for property files")
public void testInPropertiesFile() {
myFixture.configureByText("a.properties", "abc = StrinBui<caret>");
complete();
@@ -144,6 +150,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
assertNull(myItems);
}
@NeedsIndicesState.FullIndices
public void testReplaceReferenceExpressionWithTypeElement() {
createClass("package foo.bar; public class ABCDEF {}");
doTest();
@@ -194,6 +201,7 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/implements3-result.java");
}
@NeedsIndicesState.FullIndices
public void testAnnotationFiltering() {
createClass("@interface MyObjectType {}");
@@ -276,16 +284,20 @@ public class ClassNameCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/varType-result.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testExtraSpace() { doJavaTest('\n'); }
public void testAnnotation() { doJavaTest('\n'); }
@NeedsIndicesState.StandardLibraryIndices
public void testInStaticImport() { doJavaTest('\n'); }
@NeedsIndicesState.StandardLibraryIndices
public void testInCommentWithPackagePrefix() { doJavaTest('\n'); }
public void testNestedAnonymousTab() { doJavaTest('\t');}
@NeedsIndicesState.FullIndices
public void testClassStartsWithUnderscore() {
myFixture.addClass("package foo; public class _SomeClass {}");
doJavaTest('\n');
@@ -14,6 +14,7 @@ import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.LightJavaCodeInsightTestCase;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.annotations.NotNull;
@@ -32,6 +33,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@NeedsIndicesState.FullIndices
public void testGenericParametersReplace() {
final String path = BASE_PATH;
@@ -91,6 +93,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after3.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodsParametersStyle2() {
final String path = BASE_PATH;
@@ -108,6 +111,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after6.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testLocalVariablePreselect() {
configureByFile(BASE_PATH + "/before5.java");
@@ -115,6 +119,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
assertEquals("xxxx", getSelected().getLookupString());
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodCompletionInsideInlineTags() {
final String path = BASE_PATH;
@@ -151,6 +156,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after10.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testCaretPositionAfterCompletion1() {
final String path = BASE_PATH;
@@ -160,6 +166,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after11.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testCaretPositionAfterCompletion2() {
final String path = BASE_PATH;
@@ -169,6 +176,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after12.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testParensReuse() {
final String path = BASE_PATH;
@@ -188,6 +196,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after22.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodReplacementReuseParens1() {
final String path = BASE_PATH;
@@ -197,6 +206,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after15.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodReplacementReuseParens2() {
final String path = BASE_PATH;
@@ -206,6 +216,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after16.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodReplacementReuseParens3() {
final String path = BASE_PATH;
@@ -233,6 +244,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
checkResultByFile(path + "/after31.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodParensStyle2() {
final String path = BASE_PATH;
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
@@ -249,6 +261,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodParensStyle3() {
final String path = BASE_PATH;
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
@@ -336,6 +349,7 @@ public class CompletionStyleTest extends LightJavaCodeInsightTestCase {
return LookupManager.getInstance(getProject()).getActiveLookup().getCurrentItem();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testAfterNew15() {
final LanguageLevelProjectExtension ll = LanguageLevelProjectExtension.getInstance(getProject());
final LanguageLevel old = ll.getLanguageLevel();
@@ -3,6 +3,7 @@ package com.intellij.java.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.completion.LightCompletionTestCase;
import com.intellij.testFramework.NeedsIndicesState;
import org.jetbrains.annotations.NotNull;
public class DotCompletionTest extends LightCompletionTestCase {
@@ -42,6 +43,7 @@ public class DotCompletionTest extends LightCompletionTestCase {
assertContainsItems("util", "lang");
}
@NeedsIndicesState.StandardLibraryIndices
public void testArrayElement() {
configureByFile("Dot6.java");
assertContainsItems("toString", "substring");
@@ -79,6 +81,7 @@ public class DotCompletionTest extends LightCompletionTestCase {
assertNotContainItems("foo1");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMultiCatch() {
configureByFile("MultiCatch.java");
assertContainsItems("i", "addSuppressed", "getMessage", "printStackTrace");
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.completion.JavaCompletionUtil
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.lang.java.JavaLanguage
import com.intellij.psi.*
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.util.PairFunction
import groovy.transform.CompileStatic
@@ -90,6 +91,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
assert myFixture.lookupElementStrings[0..1] == ['boolean', 'byte']
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifierCastingInExpressionCodeFragment() throws Throwable {
final ctxText = "class Bar {{ Object o; o=null }}"
final ctxFile = createLightFile(JavaFileType.INSTANCE, ctxText)
@@ -102,6 +104,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
myFixture.checkResult("o instanceof String && ((String) o).substring(<caret>)")
}
@NeedsIndicesState.StandardLibraryIndices
void testNoGenericQualifierCastingWithRuntimeType() throws Throwable {
final ctxText = "import java.util.*; class Bar {{ Map<Integer,Integer> map = new HashMap<Integer,Integer>(); map=null; }}"
final ctxFile = createLightFile(JavaFileType.INSTANCE, ctxText)
@@ -142,6 +145,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
assert !myFixture.lookupElementStrings.contains('class')
}
@NeedsIndicesState.StandardLibraryIndices
void "test annotation context"() {
def ctxFile = myFixture.addClass("class Class { void foo(int context) { @Anno int a; } }").containingFile
def context = ctxFile.findElementAt(ctxFile.text.indexOf('Anno'))
@@ -151,6 +155,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
assert myFixture.lookupElementStrings.contains('context')
}
@NeedsIndicesState.FullIndices
void "test proximity ordering in scratch-like file"() {
def barField = myFixture.addClass('package bar; public class Field {}')
def fooField = myFixture.addClass('package foo; public class Field {}')
@@ -163,6 +168,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
assert barField == items[1].object
}
@NeedsIndicesState.StandardLibraryIndices
void "test package default class in code fragment"() {
myFixture.addClass "class ABCD {}"
PsiJavaCodeReferenceCodeFragment fragment =
@@ -173,6 +179,7 @@ class FragmentCompletionTest extends LightJavaCodeInsightFixtureTestCase {
assert myFixture.lookupElements.find { (it.lookupString == "ABCD") } != null
}
@NeedsIndicesState.FullIndices
void "test qualified class in code fragment"() {
myFixture.addClass "package foo; public class Foo1 {}"
PsiJavaCodeReferenceCodeFragment fragment =
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.util.ClassConditionKey
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import groovy.transform.CompileStatic
@@ -32,6 +33,7 @@ import groovy.transform.CompileStatic
@CompileStatic
class GlobalMemberNameCompletionTest extends LightJavaCodeInsightFixtureTestCase {
@NeedsIndicesState.FullIndices
void testMethodName() throws Exception {
myFixture.addClass("""
package foo;
@@ -47,6 +49,7 @@ public class Foo {
class Bar {{ abcmethod()<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testFieldName() throws Exception {
myFixture.addClass("""
package foo;
@@ -62,6 +65,7 @@ public class Foo {
class Bar {{ abcfield<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testFieldNameQualified() throws Exception {
myFixture.addClass("""
package foo;
@@ -77,6 +81,7 @@ public class Foo {
class Bar {{ Foo.abcfield<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testFieldNamePresentation() {
myFixture.addClass("""
package foo;
@@ -98,6 +103,7 @@ public class Foo {
myFixture.complete(CompletionType.BASIC, 2)
}
@NeedsIndicesState.FullIndices
void testQualifiedMethodName() throws Exception {
myFixture.addClass("""
package foo;
@@ -112,6 +118,7 @@ public class Foo {
class Bar {{ Foo.abcmethod()<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testIfThereAreAlreadyStaticImportsWithThatClass() throws Exception {
myFixture.addClass("""
package foo;
@@ -132,7 +139,7 @@ import static foo.Foo.anotherMethod;
class Bar {{ abcmethod(); anotherMethod(<caret>) }}"""
}
@NeedsIndicesState.FullIndices
void testExcludeClassFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -152,6 +159,7 @@ class Bar {{ abcmethod(); anotherMethod(<caret>) }}"""
class Bar {{ abcmethod()<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testExcludeMethodFromCompletion() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -167,6 +175,7 @@ class Bar {{ abcmethod()<caret> }}"""
class Bar {{ abcmethod1()<caret> }}"""
}
@NeedsIndicesState.FullIndices
void testMergeOverloads() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -213,6 +222,7 @@ class A {
'''
}
@NeedsIndicesState.FullIndices
void "test static import before an identifier"() {
myFixture.addClass '''
package test.t1;
@@ -279,6 +289,7 @@ class Foo {
myFixture.checkResult text
}
@NeedsIndicesState.FullIndices
void "test no global reformatting"() {
CodeStyleSettingsManager.getSettings(project).getCommonSettings(JavaLanguage.INSTANCE).ALIGN_MULTILINE_BINARY_OPERATION = true
@@ -25,9 +25,12 @@ import com.intellij.psi.statistics.StatisticsManager
import com.intellij.psi.statistics.impl.StatisticsManagerImpl
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
import com.intellij.ui.JBColor
import com.intellij.util.indexing.DumbModeAccessType
import com.intellij.util.indexing.FileBasedIndex
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
/**
@@ -56,6 +59,7 @@ class HeavyCompletionTest extends JavaCodeInsightFixtureTestCase {
assertTrue(JavaPsiFacade.getInstance(getProject()).findPackage("foo.bar.goo").isValid())
}
@NeedsIndicesState.FullIndices
void testPreferTestCases() throws Throwable {
myFixture.configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java")
ApplicationManager.application.runWriteAction {
@@ -76,6 +80,7 @@ class HeavyCompletionTest extends JavaCodeInsightFixtureTestCase {
myFixture.assertPreferredCompletionItems(0, "SomeTestCase", "SomeAnchor", "SomeTestec")
}
@NeedsIndicesState.FullIndices
void testAllClassesWhenNothingIsFound() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}")
@@ -85,6 +90,7 @@ class HeavyCompletionTest extends JavaCodeInsightFixtureTestCase {
myFixture.checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java")
}
@NeedsIndicesState.FullIndices
void testAllClassesOnSecondBasicCompletion() throws Throwable {
myFixture.addClass("package foo.bar; public class AxBxCxDxEx {}")
@@ -116,6 +122,7 @@ class HeavyCompletionTest extends JavaCodeInsightFixtureTestCase {
assert myFixture.completeBasic() == null
}
@NeedsIndicesState.FullIndices
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 {}")
@@ -125,11 +132,15 @@ class HeavyCompletionTest extends JavaCodeInsightFixtureTestCase {
myFixture.checkResult("class Main { foo.bar.AxBxCxDxEx<caret> }")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferOwnMethods() {
def nanoUrls = IntelliJProjectConfiguration.getProjectLibraryClassesRootUrls("NanoXML")
ModuleRootModificationUtil.addModuleLibrary(module, 'nano1', nanoUrls, [])
assert JavaPsiFacade.getInstance(project).findClass('net.n3.nanoxml.StdXMLParser', GlobalSearchScope.allScope(project))
def finalProject = project
FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, { ->
assert JavaPsiFacade.getInstance(finalProject).findClass('net.n3.nanoxml.StdXMLParser', GlobalSearchScope.allScope(finalProject))
})
myFixture.configureByText "a.java", """
public class Test {
@@ -168,6 +179,7 @@ public class Test {
assert oldCount == tracker.modificationCount
}
@NeedsIndicesState.FullIndices
void testForbiddenApiVariants() {
IdeaTestUtil.setModuleLanguageLevel(module, LanguageLevel.JDK_1_4)
myFixture.addClass("""\
@@ -197,6 +209,7 @@ public class SocketChannel {
assert p.itemTextForeground == JBColor.foreground()
}
@NeedsIndicesState.StandardLibraryIndices
void "test seemingly scrambled subclass"() {
PsiTestUtil.addLibrary(module, JavaTestUtil.getJavaTestDataPath() + "/codeInsight/completion/normal/seemsScrambled.jar")
myFixture.configureByText 'a.java', '''import test.Books;
@@ -211,6 +224,7 @@ class Foo {{ Books.Test.v1<caret> }}
}
@NeedsIndicesState.FullIndices
void "test different jdks in different modules"() {
(StatisticsManager.instance as StatisticsManagerImpl).enableStatistics(myFixture.testRootDisposable)
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.completion.CompletionType
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.StdModuleTypes
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase
import groovy.transform.CompileStatic
@@ -19,6 +20,7 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
return JavaTestUtil.getJavaTestDataPath()
}
@NeedsIndicesState.FullIndices(reason = "ClassLiteralGetter provides option, but it's filtered out in TypeConversionUtil.isAssignable(com.intellij.psi.PsiType, com.intellij.psi.PsiType)")
void testGetInstance() throws Throwable {
myFixture.configureFromExistingVirtualFile(
myFixture.copyFileToProject(BASE_PATH + "/foo/" + getTestName(false) + ".java", "foo/" + getTestName(false) + ".java"))
@@ -27,6 +29,7 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
myFixture.checkResultByFile(BASE_PATH + "/foo/" + getTestName(false) + "-out.java")
}
@NeedsIndicesState.FullIndices
void testProtectedAnonymousConstructor() throws Throwable {
myFixture.addClass("package pkg;" +
"public class Foo {" +
@@ -39,6 +42,7 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
doTest()
}
@NeedsIndicesState.FullIndices
void testProtectedAnonymousConstructor2() throws Throwable {
myFixture.addClass("package pkg;" +
"public class Foo {" +
@@ -51,6 +55,7 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
doTest()
}
@NeedsIndicesState.FullIndices
void testUnlockDocument() throws Throwable {
myFixture.addClass("package pkg; public class Bar {}")
myFixture.addClass("package pkg; public class Foo {" +
@@ -74,6 +79,7 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
myFixture.complete(CompletionType.SMART)
}
@NeedsIndicesState.FullIndices
void testClassLiteralShouldInsertImport() throws Throwable {
myFixture.addClass("package bar; public class Intf {}")
myFixture.addClass("package foo; public class Bar extends bar.Intf {}")
@@ -94,7 +100,12 @@ class HeavySmartTypeCompletion15Test extends JavaCodeInsightFixtureTestCase {
myFixture.addFileToProject('b/bar/Bar.java', 'package bar; public class Bar { public static void accept(foo.Foo i) {} }')
configure()
if (indexingMode == IndexingMode.DUMB_EMPTY_INDEX || indexingMode == IndexingMode.DUMB_RUNTIME_ONLY_INDEX) {
assertNull(myFixture.getLookup())
return
}
myFixture.type('\n')
checkResult()
}
}
@@ -0,0 +1,117 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.completion;
import com.intellij.TestAll;
import com.intellij.TestCaseLoader;
import com.intellij.codeInsight.completion.JavaCompletionAutoPopupTestCase;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.SkipSlowTestLocally;
import com.intellij.testFramework.TestIndexingModeSupporter;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
@SkipSlowTestLocally
public class JavaCompletionTestSuite extends TestSuite {
private static final TestIndexingModeSupporter.IndexingModeTestHandler FULL_INDEX_TRANSFORMATION = new FullIndexSuite();
private static class FullIndexSuite extends TestIndexingModeSupporter.IndexingModeTestHandler {
private FullIndexSuite() {
super("Full index", "Full index: ");
}
@Override
public boolean shouldIgnore(@NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return JavaCompletionAutoPopupTestCase.class.isAssignableFrom(aClass) ||
CompletionHintsTest.class == aClass ||
aClass.isAnnotationPresent(NeedsIndicesState.SmartMode.class);
}
@Override
public boolean shouldIgnore(@NotNull Method method,
@NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return method.isAnnotationPresent(NeedsIndicesState.SmartMode.class);
}
@Override
public TestIndexingModeSupporter.@NotNull IndexingMode getIndexingMode() {
return TestIndexingModeSupporter.IndexingMode.DUMB_FULL_INDEX;
}
}
private static final TestIndexingModeSupporter.IndexingModeTestHandler RUNTIME_ONLY_INDEX_TRANSFORMATION = new RuntimeOnlyIndexSuite();
private static class RuntimeOnlyIndexSuite extends TestIndexingModeSupporter.IndexingModeTestHandler {
private RuntimeOnlyIndexSuite() {
super("RuntimeOnlyIndex", "Runtime only index: ");
}
@Override
public boolean shouldIgnore(@NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return FULL_INDEX_TRANSFORMATION.shouldIgnore(aClass) || aClass.isAnnotationPresent(NeedsIndicesState.FullIndices.class);
}
@Override
public boolean shouldIgnore(@NotNull Method method,
@NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return FULL_INDEX_TRANSFORMATION.shouldIgnore(method, aClass) || method.isAnnotationPresent(NeedsIndicesState.FullIndices.class);
}
@Override
public TestIndexingModeSupporter.@NotNull IndexingMode getIndexingMode() {
return TestIndexingModeSupporter.IndexingMode.DUMB_RUNTIME_ONLY_INDEX;
}
}
private static final TestIndexingModeSupporter.IndexingModeTestHandler EMPTY_INDEX_TRANSFORMATION = new EmptyIndexSuite();
private static class EmptyIndexSuite extends TestIndexingModeSupporter.IndexingModeTestHandler {
private EmptyIndexSuite() {
super("EmptyIndex", "Empty index: ");
}
@Override
public boolean shouldIgnore(@NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return RUNTIME_ONLY_INDEX_TRANSFORMATION.shouldIgnore(aClass) || aClass.isAnnotationPresent(NeedsIndicesState.StandardLibraryIndices.class);
}
@Override
public boolean shouldIgnore(@NotNull Method method, @NotNull Class<? extends TestIndexingModeSupporter> aClass) {
return RUNTIME_ONLY_INDEX_TRANSFORMATION.shouldIgnore(method, aClass) || method.isAnnotationPresent(NeedsIndicesState.StandardLibraryIndices.class);
}
@Override
public TestIndexingModeSupporter.@NotNull IndexingMode getIndexingMode() {
return TestIndexingModeSupporter.IndexingMode.DUMB_EMPTY_INDEX;
}
}
public static Test suite() {
JavaCompletionTestSuite suite = new JavaCompletionTestSuite();
if (!"Java Dumb Completion Tests".equals(System.getProperty("teamcity.buildConfName"))) {
return suite;
}
suite.setName("Java completion tests suite");
System.setProperty("intellij.build.test.groups", "JAVA_TESTS");
TestCaseLoader myTestCaseLoader = new TestCaseLoader("tests/testGroups.properties");
myTestCaseLoader.fillTestCases("", TestAll.getClassRoots());
for (Class<?> aClass : myTestCaseLoader.getClasses()) {
if (!aClass.getSimpleName().contains("Completion")) continue;
if (TestIndexingModeSupporter.class.isAssignableFrom(aClass)) {
//noinspection unchecked
Class<? extends TestIndexingModeSupporter> testCaseClass = (Class<? extends TestIndexingModeSupporter>)aClass;
TestIndexingModeSupporter.addTest(testCaseClass, FULL_INDEX_TRANSFORMATION, suite);
TestIndexingModeSupporter.addTest(testCaseClass, RUNTIME_ONLY_INDEX_TRANSFORMATION, suite);
TestIndexingModeSupporter.addTest(testCaseClass, EMPTY_INDEX_TRANSFORMATION, suite);
} else if (!JavaCompletionTestSuite.class.equals(aClass)) {
suite.addTest(warning("Unexpected class " + aClass + " in " + suite.getClass()));
}
}
return suite;
}
}
@@ -19,11 +19,13 @@ import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
/**
* @author Pavel Dolgov
*/
@NeedsIndicesState.FullIndices
class JavaLangInvokeHandleCompletionTest : LightFixtureCompletionTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor = LightJavaCodeInsightFixtureTestCase.JAVA_9
@@ -17,10 +17,12 @@ package com.intellij.java.codeInsight.completion
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.testFramework.NeedsIndicesState
/**
* @author Pavel.Dolgov
*/
@NeedsIndicesState.StandardLibraryIndices
class JavaReflectionCompletionOverloadTest : LightFixtureCompletionTestCase() {
override fun getBasePath() = JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/reflectionOverload/"
@@ -66,7 +68,7 @@ class JavaReflectionCompletionOverloadTest : LightFixtureCompletionTestCase() {
configureByFile(getTestName(false) + ".java")
val lookupItems = lookup.items
val texts = com.intellij.java.codeInsight.completion.lookupFirstItemsTexts(lookupItems, expected.size)
val texts = lookupFirstItemsTexts(lookupItems, expected.size)
assertOrderedEquals(texts, *expected)
if (index >= 0) selectItem(lookupItems[index])
myFixture.checkResultByFile(getTestName(false) + "_after.java")
@@ -19,11 +19,13 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.util.ArrayUtil;
/**
* @author Konstantin Bulenkov
*/
@NeedsIndicesState.StandardLibraryIndices
public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase {
@Override
@@ -51,22 +53,27 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTestFirst(1, "method", "method2", "method3");
}
@NeedsIndicesState.FullIndices
public void testForNameDeclaredMethod() {
doTest(2, "method", "method1", "method2");
}
@NeedsIndicesState.FullIndices
public void testForNameMethod() {
doTestFirst(1, "method", "method2", "method3");
}
@NeedsIndicesState.FullIndices
public void testForNameField() {
doTest(1, "num", "num2", "num3");
}
@NeedsIndicesState.FullIndices
public void testForNameDeclaredField() {
doTest(1, "num", "num1", "num2");
}
@NeedsIndicesState.FullIndices
public void testVarargMethod() {
doTest(0, "vararg", "vararg2");
}
@@ -108,10 +115,12 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTestFirst(1, "method", "method2");
}
@NeedsIndicesState.FullIndices
public void testInitChain() {
doTest(1, "num", "num2");
}
@NeedsIndicesState.FullIndices
public void testAssignChain() {
doTest(1, "num", "num2");
}
@@ -165,6 +174,7 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTest(-1);
}
@NeedsIndicesState.FullIndices
public void testClassForNamePackages() {
myFixture.addClass("package foo.bar.one; public class FirstClass {}");
myFixture.addClass("package foo.bar.two; public class SecondClass {}");
@@ -175,11 +185,13 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTest(0, "StringBuffer", "StringBuilder");
}
@NeedsIndicesState.FullIndices
public void testClassForNameNestedAutocomplete() {
myFixture.addClass("package foo.bar; public class PublicClass { public static class NestedClass {} }");
doTest(-1, () -> assertNull("Auto-completed", myFixture.getLookupElementStrings()));
}
@NeedsIndicesState.FullIndices
public void testClassForNameNested() {
myFixture.addClass("package foo.bar; public class PublicClass {" +
" public static class NestedClass {}" +
@@ -21,13 +21,18 @@ import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.psi.PsiMethod
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.util.indexing.DumbModeAccessType
import com.intellij.util.indexing.FileBasedIndex
/**
* @author Pavel.Dolgov
*/
@NeedsIndicesState.FullIndices
class JavaReflectionParametersCompletionTest : LightFixtureCompletionTestCase() {
override fun getBasePath(): String = JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/reflectionParameters/"
@@ -99,18 +104,23 @@ public class Construct {
}
}
fun lookupFirstItemsTexts(lookupItems: List<LookupElement?>, maxSize: Int): List<String> =
lookupItems.subList(0, Math.min(lookupItems.size, maxSize)).map {
val obj = it?.`object`
when (obj) {
is PsiMethod -> {
obj.name + obj.parameterList.parameters.map { it.type.canonicalText + " " + it.name }
.joinToString(",", prefix = "(", postfix = ")")
}
else -> {
val presentation = LookupElementPresentation()
it?.renderElement(presentation)
(presentation.itemText ?: "") + (presentation.tailText ?: "")
// PsiJavaCodeReferenceElementImpl.getCanonicalText needs resolve()
// see JavaReflectionParametersCompletionTest.testConstructor and JavaReflectionParametersCompletionTest.testDeclaredConstructor
FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, ThrowableComputable<List<String>, RuntimeException> {
lookupItems.subList(0, Math.min(lookupItems.size, maxSize)).map {
val obj = it?.`object`
when (obj) {
is PsiMethod -> {
obj.name + obj.parameterList.parameters.map { it.type.canonicalText + " " + it.name }
.joinToString(",", prefix = "(", postfix = ")")
}
else -> {
val presentation = LookupElementPresentation()
it?.renderElement(presentation)
(presentation.itemText ?: "") + (presentation.tailText ?: "")
}
}
}
}
})
@@ -18,6 +18,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleSettings
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.testFramework.NeedsIndicesState
import com.intellij.util.ProcessingContext
import com.intellij.util.SystemProperties
import org.jetbrains.annotations.NotNull
@@ -82,16 +83,19 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("a2", "a3")
}
@NeedsIndicesState.StandardLibraryIndices
void testSee0() {
configureByFile("See0.java")
myFixture.assertPreferredCompletionItems(0, "foo", "clone", "equals", "hashCode")
}
@NeedsIndicesState.StandardLibraryIndices
void testSee1() {
configureByFile("See1.java")
assertStringItems("notify", "notifyAll")
}
@NeedsIndicesState.StandardLibraryIndices
void testSee2() {
configureByFile("See2.java")
assertStringItems("notify", "notifyAll")
@@ -120,6 +124,7 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("foo", "myName")))
}
@NeedsIndicesState.StandardLibraryIndices
void testIDEADEV10620() {
configureByFile("IDEADEV10620.java")
@@ -136,6 +141,7 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
assertTrue(myItems.length > 18)
}
@NeedsIndicesState.StandardLibraryIndices
void testException2() {
myFixture.configureByFile("Exception2.java")
myFixture.complete(CompletionType.SMART)
@@ -181,19 +187,23 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testShortenClassReference() throws Throwable {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifiedClassReference() throws Throwable {
configureByFile(getTestName(false) + ".java")
myFixture.complete(CompletionType.BASIC, 2)
checkResultByFile(getTestName(false) + "_after.java")
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifiedImportedClassReference() throws Throwable { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testThrowsNonImported() throws Throwable {
configureByFile(getTestName(false) + ".java")
myFixture.complete(CompletionType.BASIC, 2)
@@ -210,6 +220,7 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
assertTrue(getLookupElementStrings().containsAll(Arrays.asList("io", "lang", "util")))
}
@NeedsIndicesState.FullIndices
void testQualifyClassReferenceInPackageStatement() {
configureByFile(getTestName(false) + ".java")
myFixture.type('\n')
@@ -247,6 +258,7 @@ class Foo<T,V>{}
myFixture.assertPreferredCompletionItems 0, 'param', 'param <V>'
}
@NeedsIndicesState.StandardLibraryIndices
void "test fqns in package info"() {
myFixture.configureByText "package-info.java", '''
/**
@@ -314,6 +326,7 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'some integer param'
}
@NeedsIndicesState.FullIndices
void "test see super class"() {
myFixture.addClass("package foo; public interface Foo {}")
myFixture.addClass("package bar; public class Bar {} ")
@@ -359,6 +372,7 @@ class Goo { void goo(Foo foo, Bar bar) {} }
myFixture.checkResult(text)
}
@NeedsIndicesState.StandardLibraryIndices
void testShortNameInJavadocIfWasImported() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED
def text = '''
@@ -384,6 +398,7 @@ class Test {
'''
}
@NeedsIndicesState.StandardLibraryIndices
void testFqnInJavadocIfWasNotImported() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED
def text = '''
@@ -409,7 +424,7 @@ class Test {
'''
}
@NeedsIndicesState.StandardLibraryIndices
void testFqnNameInJavadocIfWasImported() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_ALWAYS
def text = '''
@@ -435,6 +450,7 @@ class Test {
'''
}
@NeedsIndicesState.StandardLibraryIndices
void testShortNameInJavadoc() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT
def text = '''
@@ -460,6 +476,7 @@ class Test {
'''
}
@NeedsIndicesState.StandardLibraryIndices
void testShortNameInJavadocIfWasImportOnDemand() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED
def text = '''
@@ -522,6 +539,7 @@ public class Test {
}
@NeedsIndicesState.StandardLibraryIndices
void testShortNameIfImplicitlyImported() {
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED
def text = '''
@@ -620,12 +638,14 @@ class Foo {
myFixture.checkResult "/** @author $userName<caret> */"
}
@NeedsIndicesState.StandardLibraryIndices
void "test insert link to class"() {
myFixture.configureByText 'a.java', "/** FileNotFoEx<caret> */"
myFixture.completeBasic()
myFixture.checkResult "/** {@link java.io.FileNotFoundException<caret>} */"
}
@NeedsIndicesState.FullIndices
void "test insert link to inner class"() {
myFixture.addClass('package zoo; public class Outer { public static class FooBarGoo{}}')
myFixture.configureByText 'a.java', "/** FooBarGo<caret> */"
@@ -633,6 +653,7 @@ class Foo {
myFixture.checkResult "/** {@link zoo.Outer.FooBarGoo<caret>} */"
}
@NeedsIndicesState.StandardLibraryIndices
void "test insert link to imported class"() {
myFixture.configureByText 'a.java', "import java.io.*; /** FileNotFoEx<caret> */ class A{}"
myFixture.completeBasic()
@@ -653,6 +674,7 @@ class Foo {
assert !TemplateManagerImpl.getTemplateState(myFixture.editor)
}
@NeedsIndicesState.StandardLibraryIndices
void "test insert link to method in a q-named class"() {
myFixture.configureByText 'a.java', "/** a. java.io.File#liFi<caret> */ interface Foo {}"
myFixture.completeBasic()
@@ -693,6 +715,7 @@ class Foo {
myFixture.checkResult "/** @see java.io.IOException<caret> */"
}
@NeedsIndicesState.StandardLibraryIndices
void "test no hierarchical generic method duplicates"() {
myFixture.configureByText 'a.java', """
interface Foo<T> {
@@ -9,6 +9,7 @@ import com.intellij.lang.java.JavaLanguage;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.testFramework.NeedsIndicesState;
import org.jetbrains.annotations.NotNull;
public class KeywordCompletionTest extends LightCompletionTestCase {
@@ -96,6 +97,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testNullInMethodCall() { doTest(); }
public void testNullInMethodCall2() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNewInMethodRefs() {
doTest(1, "new", "null", "true", "false");
assertEquals("new", LookupElementPresentation.renderElement(myItems[0]).getItemText());
@@ -103,6 +105,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
checkResultByTestName();
}
@NeedsIndicesState.StandardLibraryIndices
public void testNewInMethodRefsArray() {
doTest(1, "new", "null", "true", "false");
assertEquals("Object", assertInstanceOf(myItems[0].getPsiElement(), PsiMethod.class).getName());
@@ -111,7 +114,16 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
}
public void testNewInCast() { doTest(2, "new", "null", "true", "false"); }
public void testNewInNegation() { doTest(1, "new", "null", "true", "false"); }
public void testNewInNegation() {
if (getIndexingMode() == IndexingMode.DUMB_EMPTY_INDEX) {
// Object's methods are not found in empty indices, so the only element is inserted
doTest();
} else {
doTest(1, "new", "null", "true", "false");
}
}
public void testSpaceAfterInstanceof() { doTest(); }
public void testInstanceofAfterUnresolved() { doTest(1, "instanceof"); }
public void testInstanceofAfterStatementStart() { doTest(1, "instanceof"); }
@@ -127,7 +139,9 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testNoPrimitivesInBooleanAnnotationAttribute() { doTest(1, "true", "int", "boolean"); }
public void testNoPrimitivesInIntAnnotationValueAttribute() { doTest(0, "true", "int", "boolean"); }
public void testNoPrimitivesInEnumAnnotationAttribute() { doTest(0, "true", "int", "boolean"); }
@NeedsIndicesState.StandardLibraryIndices
public void testPrimitivesInClassAnnotationValueAttribute() { doTest(2, "true", "int", "boolean"); }
@NeedsIndicesState.StandardLibraryIndices
public void testPrimitivesInClassAnnotationAttribute() { doTest(3, "true", "int", "boolean"); }
public void testPrimitivesInMethodReturningArray() { doTest(2, "true", "byte", "boolean"); }
public void testPrimitivesInMethodReturningClass() { doTest(3, "byte", "boolean", "void"); }
@@ -181,6 +195,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testFinalAfterAnnotationAttributes() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testTryInExpression() {
configureByTestName();
assertEquals("toString", myItems[0].getLookupString());
@@ -19,9 +19,12 @@ import com.intellij.openapi.projectRoots.Sdk
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.testFramework.IdeaTestUtil
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.intellij.util.indexing.DumbModeAccessType
import com.intellij.util.indexing.FileBasedIndex
import groovy.transform.CompileStatic
import org.intellij.lang.annotations.MagicConstant
@@ -37,8 +40,11 @@ class MagicConstantCompletion4Test extends LightJavaCodeInsightFixtureTestCase {
}
}
@NeedsIndicesState.StandardLibraryIndices
void "test suppress class constants in MagicConstant presence"() {
assert !myFixture.javaFacade.findClass(MagicConstant.name, GlobalSearchScope.allScope(myFixture.project))
FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, { ->
assert !myFixture.javaFacade.findClass(MagicConstant.name, GlobalSearchScope.allScope(myFixture.project))
})
myFixture.configureByText "a.java", """import java.util.*;
class Bar {
@@ -18,6 +18,7 @@ package com.intellij.java.codeInsight.completion
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.psi.PsiClass
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import groovy.transform.CompileStatic
import org.intellij.lang.annotations.Language
@@ -28,6 +29,7 @@ import org.intellij.lang.annotations.Language
@CompileStatic
class MagicConstantCompletionTest extends LightJavaCodeInsightFixtureTestCase {
@NeedsIndicesState.FullIndices
void "test in method argument"() {
addModifierList()
myFixture.configureByText "a.java", """
@@ -13,12 +13,14 @@ import com.intellij.compiler.chainsSearch.completion.lookup.JavaRelevantChainLoo
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.SkipSlowTestLocally;
import com.intellij.util.SmartList;
import java.util.List;
@SkipSlowTestLocally
@NeedsIndicesState.StandardLibraryIndices
public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
private final static String TEST_INDEX_FILE_NAME = "TestIndex.java";
private final static String TEST_COMPLETION_FILE_NAME = "TestCompletion.java";
@@ -4,6 +4,7 @@ package com.intellij.java.codeInsight.completion
import com.intellij.java.testFramework.fixtures.LightJava9ModulesCodeInsightFixtureTestCase
import com.intellij.java.testFramework.fixtures.MultiModuleJava9ProjectDescriptor.ModuleDescriptor.M2
import com.intellij.java.testFramework.fixtures.MultiModuleJava9ProjectDescriptor.ModuleDescriptor.M4
import com.intellij.testFramework.NeedsIndicesState
import org.assertj.core.api.Assertions.assertThat
import java.util.jar.JarFile
@@ -34,12 +35,15 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
fun testStatementsAfterStatement() = variants("module M { requires X; <caret> }", "requires", "exports", "opens", "uses", "provides")
fun testStatementsUnambiguous() = complete("module M { requires X; ex<caret> }", "module M { requires X; exports <caret> }")
@NeedsIndicesState.FullIndices
fun testRequiresBare() =
variants("module M { requires <caret>",
"transitive", "static", "M2", "java.base", "java.non.root", "java.se", "java.xml.bind", "java.xml.ws",
"lib.multi.release", "lib.named", "lib.auto", "lib.claimed", "all.fours")
fun testRequiresTransitive() = complete("module M { requires tr<caret> }", "module M { requires transitive <caret> }")
@NeedsIndicesState.FullIndices
fun testRequiresSimpleName() = complete("module M { requires M<caret> }", "module M { requires M2;<caret> }")
@NeedsIndicesState.StandardLibraryIndices
fun testRequiresQualifiedName() = complete("module M { requires lib.m<caret> }", "module M { requires lib.multi.release;<caret> }")
fun testExportsBare() = variants("module M { exports <caret> }", "pkg")
@@ -47,9 +51,11 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
fun testExportsQualified() = variants("module M { exports pkg.<caret> }", "main", "other", "empty")
fun testExportsQualifiedUnambiguous() = complete("module M { exports pkg.o<caret> }", "module M { exports pkg.other.<caret> }")
fun testExportsTo() = complete("module M { exports pkg.other <caret> }", "module M { exports pkg.other to <caret> }")
@NeedsIndicesState.FullIndices
fun testExportsToList() =
variants("module M { exports pkg.other to <caret> }",
"M2", "java.base", "java.non.root", "java.se", "java.xml.bind", "java.xml.ws", "lib.multi.release", "lib.named")
@NeedsIndicesState.FullIndices
fun testExportsToUnambiguous() = complete("module M { exports pkg.other to M<caret> }", "module M { exports pkg.other to M2<caret> }")
fun testUsesPrefixed() = complete("module M { uses p<caret> }", "module M { uses pkg.<caret> }")
@@ -69,6 +75,7 @@ class ModuleCompletionTest : LightJava9ModulesCodeInsightFixtureTestCase() {
fun testProvidesWithUnambiguous() =
complete("module M { provides pkg.main.MySvc with pkg.other.M<caret> }", "module M { provides pkg.main.MySvc with pkg.other.MySvcImpl<caret> }")
@NeedsIndicesState.FullIndices
fun testImports() {
addFile("module-info.java", "module M { requires M2; }")
addFile("module-info.java", "module M2 { exports pkg.m2; }", M2)
@@ -3,6 +3,7 @@ package com.intellij.java.codeInsight.completion
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
@CompileStatic
@@ -57,6 +58,7 @@ class Normal11CompletionTest extends NormalCompletionTestCase {
return var
}
@NeedsIndicesState.StandardLibraryIndices
void testToUnmodifiable() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'collect(Collectors.toUnmodifiableList())', 'collect(Collectors.toUnmodifiableSet())'
@@ -2,6 +2,7 @@
package com.intellij.java.codeInsight.completion
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
@@ -24,7 +25,8 @@ class Normal14CompletionTest extends NormalCompletionTestCase {
myFixture.completeBasic()
myFixture.checkResult("record X() cla")
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters generation)")
void testRecordAccessorDeclaration() {
doTest()
}
@@ -2,6 +2,7 @@
package com.intellij.java.codeInsight.completion
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
/**
@@ -21,12 +22,16 @@ class Normal6CompletionTest extends NormalCompletionTestCase {
void testOverwriteGenericsAfterNew() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testExplicitTypeArgumentsWhenParameterTypesDoNotDependOnTypeParameters() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testClassNameWithGenericsTab2() { doTest('\t') }
@NeedsIndicesState.StandardLibraryIndices
void testClassNameGenerics() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testDoubleExpectedTypeFactoryMethod() throws Throwable {
configure()
assertStringItems('Key', 'create', 'create')
@@ -20,6 +20,8 @@ import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.psi.PsiClass
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
/**
* @author anna
*/
@@ -67,6 +69,7 @@ class Test {
assert LookupElementPresentation.renderElement(items[0]).itemText == 'x1 -> {}'
}
@NeedsIndicesState.StandardLibraryIndices
void "test lambda signature duplicate parameter name"() {
myFixture.configureByText "a.java", """
import java.util.function.Function;
@@ -135,6 +138,7 @@ class MethodRef {
assert items.find {LookupElementPresentation.renderElement(it).itemText.contains('MethodRef::boo')}
}
@NeedsIndicesState.StandardLibraryIndices
void "test suggest receiver method reference for generic methods"() {
myFixture.configureByText "a.java", """
import java.util.*;
@@ -186,6 +190,7 @@ class Test88 {
"""
}
@NeedsIndicesState.StandardLibraryIndices
void testInheritorConstructorRef() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'ArrayList::new', 'ArrayList', 'CopyOnWriteArrayList::new'
@@ -218,6 +223,7 @@ class Test88 {
assert items.find {LookupElementPresentation.renderElement(it).itemText.contains('Bar::new')}
}
@NeedsIndicesState.StandardLibraryIndices
void "test new array ref"() {
myFixture.configureByText "a.java", """
interface Foo9<T> {
@@ -234,18 +240,21 @@ class Test88 {
assert items.find {LookupElementPresentation.renderElement(it).itemText.contains('String[]::new')}
}
@NeedsIndicesState.StandardLibraryIndices
void testCollectorsToList() {
configureByTestName()
selectItem(myItems.find { it.lookupString.contains('toList') })
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testStaticallyImportedCollectorsToList() {
configureByTestName()
selectItem(myItems.find { it.lookupString.contains('collect(toList())') })
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testAllCollectors() {
configureByTestName()
assert myFixture.lookupElementStrings == ['collect', 'collect', 'collect(Collectors.toCollection())', 'collect(Collectors.toList())', 'collect(Collectors.toSet())']
@@ -253,14 +262,17 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testCollectorsJoining() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCollectorsToSet() {
configureByTestName()
selectItem(myItems.find { it.lookupString.contains('toSet') })
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testCollectorsInsideCollect() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'toCollection', 'toList', 'toSet'
@@ -268,30 +280,36 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testCollectorsJoiningInsideCollect() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNoExplicitTypeArgsInTernary() {
configureByTestName()
selectItem(myItems.find { it.lookupString.contains('empty') })
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testCallBeforeLambda() {
configureByTestName()
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testLambdaInAmbiguousCall() {
configureByTestName()
myFixture.assertPreferredCompletionItems(0, 'toString', 'wait')
}
@NeedsIndicesState.StandardLibraryIndices
void testLambdaInAmbiguousConstructorCall() {
configureByTestName()
selectItem(myItems.find { it.lookupString.contains('Empty') })
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testLambdaWithSuperWildcardInAmbiguousCall() {
configureByTestName()
myFixture.assertPreferredCompletionItems(0, 'substring', 'substring', 'subSequence')
@@ -303,6 +321,7 @@ class Test88 {
void testNoContinueInsideLambdaInLoop() { doAntiTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNoSemicolonAfterVoidMethodInLambda() {
configureByTestName()
myFixture.type('l\t')
@@ -315,12 +334,14 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLocalsOverMethodRefs() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
configureByTestName()
myFixture.assertPreferredCompletionItems 0, "psiElement1 -> ", "psiElement", "getParent", "PsiElement"
}
@NeedsIndicesState.FullIndices
void testStaticallyImportedFromInterface() {
myFixture.addClass("package pkg;\n" +
"public interface Point {\n" +
@@ -331,6 +352,7 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for overriding method completion)")
void testOverrideMethodAsDefault() {
configureByTestName()
assert LookupElementPresentation.renderElement(myFixture.lookupElements[0]).itemText == 'default void run'
@@ -338,11 +360,13 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testChainedMethodReference() {
configureByTestName()
checkResultByFileName()
}
@NeedsIndicesState.FullIndices
void testChainedMethodReferenceWithNoPrefix() {
myFixture.addClass("package bar; public class Strings {}")
myFixture.addClass("package foo; public class Strings { public static void goo() {} }")
@@ -350,6 +374,7 @@ class Test88 {
myFixture.assertPreferredCompletionItems 0, 'Strings::goo'
}
@NeedsIndicesState.StandardLibraryIndices
void testOnlyAccessibleClassesInChainedMethodReference() {
configureByTestName()
def p = LookupElementPresentation.renderElement(assertOneElement(myFixture.lookupElements))
@@ -363,16 +388,19 @@ class Test88 {
myFixture.assertPreferredCompletionItems 0, 'output', 'out -> '
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLambdaToConstructorReference() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, '() -> ', 'Exception::new'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLambdaToTooGenericLocalVariables() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, '(foo, foo2) -> '
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLambdaToRecentSelections() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'String'
@@ -401,7 +429,7 @@ class Test88 {
}
void "test only importable suggestions in import"() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
myFixture.addClass("package com.foo; public class Comments { public static final int B = 2; }")
myFixture.configureByText("a.java", "import com.<caret>x.y;\n" +
"import static java.util.stream.Collectors.joining;")
@@ -409,12 +437,14 @@ class Test88 {
assert myFixture.lookupElementStrings == ['foo']
}
@NeedsIndicesState.StandardLibraryIndices
void "test no overloaded method reference duplicates"() {
myFixture.configureByText 'a.java', 'class C { { Runnable r = this::wa<caret>x; } }'
myFixture.completeBasic()
assert myFixture.lookupElementStrings == ['wait']
}
@NeedsIndicesState.StandardLibraryIndices
void testStreamMethodsOnCollection() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'filter'
@@ -428,6 +458,7 @@ class Test88 {
checkResultByFileName()
}
@NeedsIndicesState.StandardLibraryIndices
void testStreamMethodsOnArray() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'length', 'clone'
@@ -18,6 +18,7 @@ package com.intellij.java.codeInsight.completion
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
/**
@@ -31,8 +32,11 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
return JAVA_8
}
@NeedsIndicesState.StandardLibraryIndices
void testCastInstanceofedQualifier() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastInstanceofedQualifierInForeach() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastComplexInstanceofedQualifier() { doTest() }
void _testCastIncompleteInstanceofedQualifier() { doTest() }
@@ -40,40 +44,68 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
void testCastInstanceofedThisQualifier() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testDontCastInstanceofedQualifier() { doTest() }
void testDontCastPartiallyInstanceofedQualifier() { doAntiTest() }
@NeedsIndicesState.StandardLibraryIndices
void testQualifierCastingWithUnknownAssignments() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testQualifierCastingBeforeLt() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastQualifierForPrivateFieldReference() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testOrAssignmentDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testAssignmentPreciseTypeDfa() { doTestSecond() }
@NeedsIndicesState.StandardLibraryIndices
void testAssignmentTwicePreciseTypeDfa() { doTestSecond() }
void testAssignmentParameterDfa() { doTest() }
void testAssignmentNoPreciseTypeDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testAssignmentPrimitiveLiteral() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testDeclarationPreciseTypeDfa() { doTestSecond() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfAssignmentDfa() { doTestSecond() }
@NeedsIndicesState.StandardLibraryIndices
void testStreamDfa() { doTest() }
@NeedsIndicesState.FullIndices
void testStreamIncompleteDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testOptionalDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testFieldWithCastingCaret() { doTest() }
void testCastWhenMethodComesFromDfaSuperType() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testGenericTypeDfa() { doTestSecond() }
void testNarrowingReturnType() { doTest() }
void testNarrowingReturnTypeInVoidContext() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNoUnnecessaryCastDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNoUnnecessaryCastRawDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInconsistentHierarchyDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testAfterAssertTrueDfa() { doTest() }
void testNoUnnecessaryCastDeepHierarchy() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfAfterFunction() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfDisjunction() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfDisjunction2() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfDisjunctionDeep() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInstanceOfDisjunctionCircular() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testAfterGetClass() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNoCastForCompatibleCapture() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testBooleanFlagDfa() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testComplexInstanceOfDfa() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'methodFromX', 'methodFromX2', 'methodFromY', 'methodFromY2'
@@ -81,11 +113,13 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
assert LookupElementPresentation.renderElement(myItems[0]).tailText == '() on X'
}
@NeedsIndicesState.StandardLibraryIndices
void testCastTwice() {
configureByTestName()
myFixture.assertPreferredCompletionItems 0, 'b', 'a'
}
@NeedsIndicesState.FullIndices
void testPublicMethodExtendsProtected() {
myFixture.addClass '''
package foo;
@@ -103,10 +137,13 @@ public class FooImpl extends Foo {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testCastInstanceofedQualifierInLambda() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastInstanceofedQualifierInLambda2() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastInstanceofedQualifierInExpressionLambda() { doTest() }
void testCastQualifierInstanceofedTwice() {
@@ -117,6 +154,7 @@ public class FooImpl extends Foo {
checkResultByFile(getTestName(false) + "_after.java")
}
@NeedsIndicesState.FullIndices
void testPreferCastExpressionSuperTypes() {
myFixture.addClass('package nonImported; public interface SzNameInTheEnd {}')
configureByTestName()
@@ -18,6 +18,7 @@ import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiField
import com.intellij.psi.PsiMethod
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.ui.JBColor
class NormalCompletionOrderingTest extends CompletionSortingTestCase {
@@ -43,6 +44,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems 0, 'element'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferAnnotationMethods() throws Throwable {
checkPreferredItems(0, "name", "value", "String", "Foo", "Anno")
}
@@ -51,10 +53,12 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "foo", "bar")
}
@NeedsIndicesState.StandardLibraryIndices
void testSubstringVsSubSequence() throws Throwable {
checkPreferredItems(0, "substring", "substring", "subSequence")
}
@NeedsIndicesState.StandardLibraryIndices
void testReturnF() throws Throwable {
checkPreferredItems(0, "false", "float", "finalize")
}
@@ -63,6 +67,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "getName", "getNameIdentifier")
}
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for html")
void testShorterPrefixesGoFirst() throws Throwable {
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".html")
assertPreferredItems(0, "p", "param", "pre")
@@ -71,7 +76,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
}
void testUppercaseMatters2() throws Throwable {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.ALL
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.ALL)
checkPreferredItems(0, "classLoader", "classLoader2")
}
@@ -83,6 +88,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "getService", "getService", "class")
}
@NeedsIndicesState.StandardLibraryIndices
void testGenericityDoesNotMatterWhenNoTypeIsExpected() {
checkPreferredItems 0, "generic", "nonGeneric", "clone", "equals"
}
@@ -91,10 +97,12 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "booleanMethod", "voidMethod", "AN_OBJECT", "BOOLEAN", "class")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferClassLiteralWhenClassIsExpected() {
checkPreferredItems(0, "class")
}
@NeedsIndicesState.StandardLibraryIndices
void testJComponentInstanceMembers() throws Throwable {
checkPreferredItems(0, "getAccessibleContext", "getUI", "getUIClassID")
}
@@ -110,6 +118,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "aabbb", "aaa")
}
@NeedsIndicesState.FullIndices
void testDispreferImpls() throws Throwable {
myFixture.addClass("package foo; public class Xxx {}")
configureSecondCompletion()
@@ -120,6 +129,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "YyyXxx", "YyyZzz")
}
@NeedsIndicesState.FullIndices
void testPreferTopLevelClasses() throws Throwable {
configureSecondCompletion()
assertPreferredItems(0, "XxxYyy", "XxzYyy")
@@ -130,16 +140,19 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
myFixture.complete(CompletionType.BASIC, 2)
}
@NeedsIndicesState.FullIndices
void testImplsAfterNew() {
myFixture.addClass("package foo; public interface Xxx {}")
configureSecondCompletion()
assertPreferredItems(0, "XxxImpl", "Xxx")
}
@NeedsIndicesState.StandardLibraryIndices
void testAfterThrowNew() {
checkPreferredItems(0, "Exception", "RuntimeException")
}
@NeedsIndicesState.FullIndices
void testPreferLessHumps() throws Throwable {
myFixture.addClass("package foo; public interface XaYa {}")
myFixture.addClass("package foo; public interface XyYa {}")
@@ -155,6 +168,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals(2, ((PsiMethod)items.get(2).getObject()).getParameterList().getParametersCount())
}
@NeedsIndicesState.FullIndices
void testStatsForClassNameInExpression() throws Throwable {
myFixture.addClass("package foo; public interface FooBar {}")
myFixture.addClass("package foo; public interface FooBee {}")
@@ -165,6 +179,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "FooBee", "FooBar")
}
@NeedsIndicesState.StandardLibraryIndices
void testDispreferFinalize() throws Throwable {
checkPreferredItems(0, "final", "finalize")
}
@@ -177,12 +192,14 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals("Foooo.Bar", presentation.getItemText());*/
}
@NeedsIndicesState.StandardLibraryIndices
void testDeclaredMembersGoFirst() throws Exception {
invokeCompletion(getTestName(false) + ".java")
assertStringItems("fromThis", "overridden", "fromSuper", "equals", "hashCode", "toString", "getClass", "notify", "notifyAll", "wait",
"wait", "wait")
}
@NeedsIndicesState.StandardLibraryIndices
void testLocalVarsOverMethods() {
checkPreferredItems(0, "value", "validate", "validateTree")
}
@@ -191,6 +208,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "XcodeProjectTemplate", "XcodeConfigurable")
}
@NeedsIndicesState.FullIndices
void testFqnStats() {
myFixture.addClass("public interface Baaaaaaar {}")
myFixture.addClass("package boo; public interface Baaaaaaar {}")
@@ -209,15 +227,18 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals("boo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.items[2]).qualifiedName)
}
@NeedsIndicesState.StandardLibraryIndices
void testSkipLifted() {
checkPreferredItems(0, "hashCodeMine", "hashCode")
}
@NeedsIndicesState.StandardLibraryIndices
void testDispreferInnerClasses() {
checkPreferredItems(0) //no chosen items
assertFalse(getLookup().getItems().get(0).getObject() instanceof PsiClass)
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferSameNamedMethods() {
checkPreferredItems(0, "foo", "boo", "doo", "hashCode")
}
@@ -253,10 +274,12 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "return", "retainAll")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferReturnInSingleStatementPlace() {
checkPreferredItems 0, "return", "registerKeyboardAction"
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferContinueInsideLoops() {
checkPreferredItems 0, "continue", "color", "computeVisibleRect"
}
@@ -269,6 +292,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "MyEnum.bar", "MyEnum", "MyEnum.foo")
}
@NeedsIndicesState.FullIndices
void testPreferExpectedEnumConstantsDespiteStats() {
checkPreferredItems 0, "const1", "const2", "constx1", "constx2"
myFixture.lookup.currentItem = myFixture.lookupElements[2]
@@ -303,6 +327,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "Bar9", "Bar1", "Bar2", "Bar3", "Bar4")
}
@NeedsIndicesState.FullIndices
void testPreselectMostRelevantInTheMiddleAlpha() {
UISettings.getInstance().setSortLookupElementsLexicographically(true)
@@ -322,6 +347,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
assert myFixture.lookupElementStrings.sort() == myFixture.lookupElementStrings
}
@NeedsIndicesState.FullIndices
void testAlphaSortPackages() {
UISettings.getInstance().setSortLookupElementsLexicographically(true)
@@ -340,6 +366,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems 0, 'xxbar', 'xxfoo', 'xxgoo', 'barxx', 'fooxx', 'gooxx'
}
@NeedsIndicesState.FullIndices
void testSortSameNamedVariantsByProximity() {
myFixture.addClass("public class Bar {}")
for (int i = 0; i < 10; i++) {
@@ -356,10 +383,11 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
}
void testCaseInsensitivePrefixMatch() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
checkPreferredItems(1, "Foo", "foo1", "foo2")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferKeywordsToVoidMethodsInExpectedTypeContext() {
checkPreferredItems 0, 'noo', 'new', 'null', 'noo2', 'notify', 'notifyAll'
}
@@ -368,6 +396,7 @@ class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems 0, 'serial', 'superExpressionInIllegalContext'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferApplicableAnnotations() throws Throwable {
myFixture.addClass '''
import java.lang.annotation.ElementType;
@@ -381,6 +410,7 @@ import java.lang.annotation.Target;
checkPreferredItems 0, 'TMetaAnno', 'Target', 'TabLayoutPolicy', 'TabPlacement'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferApplicableAnnotationsMethod() throws Throwable {
myFixture.addClass '''
import java.lang.annotation.ElementType;
@@ -397,6 +427,7 @@ interface TxANotAnno {}
assert !('TxANotAnno' in myFixture.lookupElementStrings)
}
@NeedsIndicesState.StandardLibraryIndices
void testJComponentAddNewWithStats() throws Throwable {
final LookupImpl lookup = invokeCompletion("/../smartTypeSorting/JComponentAddNew.java")
assertPreferredItems(0, "FooBean3", "JComponent", "Component")
@@ -420,10 +451,12 @@ interface TxANotAnno {}
checkPreferredItems 0, 'returnMethod', 'return'
}
@NeedsIndicesState.StandardLibraryIndices
void testDispreferReturnInVoidLambda() {
checkPreferredItems 0, 'reaction', 'rezet', 'return'
}
@NeedsIndicesState.StandardLibraryIndices
void testDoNotPreferGetClass() {
checkPreferredItems 0, 'get', 'getClass'
incUseCount(lookup, 1)
@@ -432,6 +465,7 @@ interface TxANotAnno {}
assertPreferredItems 0, 'get', 'getClass'
}
@NeedsIndicesState.StandardLibraryIndices
void testEqualsStats() {
checkPreferredItems 0, 'equals', 'equalsIgnoreCase'
incUseCount(lookup, 1)
@@ -444,6 +478,7 @@ interface TxANotAnno {}
checkPreferredItems 0, 'MyCalendar.FIELD_COUNT', 'MyCalendar', 'MyCalendar.AM'
}
@NeedsIndicesState.FullIndices
void testPreferLocalsToStaticsInSecondCompletion() {
myFixture.addClass('public class FooZoo { public static void fooBar() {} }')
myFixture.addClass('public class fooAClass {}')
@@ -461,7 +496,7 @@ interface TxANotAnno {}
}
void testUnderscoresDontMakeMatchMiddle() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
checkPreferredItems(0, 'fooBar', '_fooBar', 'FooBar')
}
@@ -486,6 +521,7 @@ interface TxANotAnno {}
assert lookup.items[1].object instanceof PsiMethod
}
@NeedsIndicesState.StandardLibraryIndices
void testPreselectLastChosen() {
checkPreferredItems(0, 'add', 'addAll')
for (i in 0..10) {
@@ -542,7 +578,7 @@ interface TxANotAnno {}
}
void testCommonPrefixMoreImportantThanKind() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
checkPreferredItems(0, 'PsiElement', 'psiElement')
}
@@ -551,7 +587,7 @@ interface TxANotAnno {}
}
void testLocalVarsOverStats() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
checkPreferredItems 0, 'psiElement', 'PsiElement'
incUseCount lookup, 1
assertPreferredItems 0, 'psiElement', 'PsiElement'
@@ -582,6 +618,7 @@ interface TxANotAnno {}
checkPreferredItems 0, 'MyEnum.BAR', 'MyEnum', 'MyEnum.FOO'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferClassesOfExpectedClassType() {
myFixture.addClass "class XException extends Exception {}"
checkPreferredItems 0, 'XException', 'XClass', 'XIntf'
@@ -595,19 +632,22 @@ interface TxANotAnno {}
checkPreferredItems 0, 'fact'
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for 'Override/Implement methods...')")
void testPreferAnnotationsToInterfaceKeyword() {
checkPreferredItems 0, 'Override/Implement methods...', 'Override', 'Deprecated'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferThrownExceptionsInCatch() {
checkPreferredItems 0, 'final', 'FileNotFoundException', 'File'
}
void testHonorFirstLetterCase() {
CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.getInstance().setCompletionCaseSensitive(CodeInsightSettings.NONE)
checkPreferredItems 0, 'posIdMap', 'PImageDecoder', 'PNGImageDecoder'
}
@NeedsIndicesState.FullIndices
void testGlobalStaticMemberStats() {
configureNoCompletion(getTestName(false) + ".java")
myFixture.complete(CompletionType.BASIC, 2)
@@ -616,10 +656,12 @@ interface TxANotAnno {}
assertPreferredItems 0, 'newLinkedSet1', 'newLinkedSet0', 'newLinkedSet2'
}
@NeedsIndicesState.StandardLibraryIndices
void testStaticMemberTypes() {
checkPreferredItems 0, 'newMap', 'newList'
}
@NeedsIndicesState.StandardLibraryIndices
void testNoStatsInSuperInvocation() {
checkPreferredItems 0, 'put', 'putAll'
@@ -638,6 +680,7 @@ interface TxANotAnno {}
assert lookup.items.find { it.lookupString == 'ritar'} != null
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLocalToExpectedTypedMethod() {
checkPreferredItems 0, 'event', 'equals'
}
@@ -653,12 +696,14 @@ interface TxANotAnno {}
assert LookupElementPresentation.renderElement(items.find { it.lookupString == 'BAR' }).itemTextForeground == JBColor.RED
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferValueTypesReturnedFromMethod() {
checkPreferredItems 0, 'StringBuffer', 'String', 'Serializable', 'SomeInterface', 'SomeInterface', 'SomeOtherClass'
assert 'SomeInterface<String>' == LookupElementPresentation.renderElement(myFixture.lookupElements[3]).itemText
assert 'SomeInterface' == LookupElementPresentation.renderElement(myFixture.lookupElements[4]).itemText
}
@NeedsIndicesState.FullIndices
void testPreferCastTypesHavingSpecifiedMethod() {
checkPreferredItems 0, 'MainClass1', 'MainClass2', 'Maa'
}
@@ -667,14 +712,17 @@ interface TxANotAnno {}
checkPreferredItems 0, 'fun1', 'fun2', 'fun10'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferVarsHavingReferencedMember() {
checkPreferredItems 0, 'xzMap', 'xaString'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferCollectionsStaticOfExpectedType() {
checkPreferredItems 0, 'unmodifiableList', 'unmodifiableCollection'
}
@NeedsIndicesState.FullIndices
void testDispreferDeprecatedMethodWithUnresolvedQualifier() {
myFixture.addClass("package foo; public class Assert { public static void assertTrue() {} }")
myFixture.addClass("package bar; @Deprecated public class Assert { public static void assertTrue() {}; public static void assertTrue2() {} }")
@@ -701,6 +749,7 @@ interface TxANotAnno {}
checkPreferredItems 0, 'false', 'factory'
}
@NeedsIndicesState.FullIndices
void testPreferExplicitlyImportedStaticMembers() {
myFixture.addClass("""
class ContainerUtilRt {
@@ -720,6 +769,7 @@ class ContainerUtil extends ContainerUtilRt {
checkPreferredItems 0, 'catch', 'finally'
}
@NeedsIndicesState.FullIndices
void testPreselectClosestExactPrefixItem() {
UISettings.instance.setSortLookupElementsLexicographically(true)
myFixture.addClass 'package pack1; public class SameNamed {}'
@@ -729,6 +779,7 @@ class ContainerUtil extends ContainerUtilRt {
assert LookupElementPresentation.renderElement(myFixture.lookupElements[1]).tailText.contains('pack2')
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferExpectedMethodTypeArg() {
checkPreferredItems 0, 'String', 'Usage'
@@ -750,6 +801,7 @@ class ContainerUtil extends ContainerUtilRt {
myFixture.assertPreferredCompletionItems 0, 'String', "Usage"
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodStatisticsPerQualifierType() {
checkPreferredItems 0, 'charAt'
myFixture.type('eq\n);\n')
@@ -760,6 +812,7 @@ class ContainerUtil extends ContainerUtilRt {
assertPreferredItems 0, 'someMethod'
}
@NeedsIndicesState.FullIndices
void testPreferImportedClassesAmongstSameNamed() {
myFixture.addClass('package foo; public class String {}')
@@ -786,12 +839,14 @@ class ContainerUtil extends ContainerUtilRt {
assertPreferredItems 0, 'ContainerUtil', 'ConflictsUtil'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferListAddWithoutIndex() {
checkPreferredItems 0, 'add', 'add', 'addAll', 'addAll'
assert LookupElementPresentation.renderElement(myFixture.lookupElements[1]).tailText.contains('int index')
assert LookupElementPresentation.renderElement(myFixture.lookupElements[3]).tailText.contains('int index')
}
@NeedsIndicesState.FullIndices
void testPreferExpectedTypeConstantOverSameNamedClass() {
myFixture.addClass("package another; public class JSON {}")
checkPreferredItems 0, 'Point.JSON', 'JSON'
@@ -835,6 +890,7 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'a', 'b', 'a, b'
}
@NeedsIndicesState.StandardLibraryIndices
void "test selecting static field after static method"() {
myFixture.configureByText 'a.java', 'class Foo { { System.<caret> } }'
myFixture.completeBasic()
@@ -850,14 +906,17 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'out', 'exit'
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters)")
void testPreferTypeToGeneratedMethod() {
checkPreferredItems 0, 'SomeClass', 'public SomeClass getZoo'
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters and equals())")
void testPreferPrimitiveTypeToGeneratedMethod() {
checkPreferredItems 0, 'boolean', 'public boolean isZoo', 'public boolean equals'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferExceptionsInCatch() {
myFixture.configureByText 'a.java', 'class Foo { { Enu<caret> } }'
myFixture.completeBasic()
@@ -867,14 +926,17 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'Exception', 'Error'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferExceptionsInThrowsList() {
checkPreferredItems 0, 'IllegalStateException', 'IllegalAccessException', 'IllegalArgumentException'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferExceptionsInJavadocThrows() {
checkPreferredItems 0, 'IllegalArgumentException', 'IllegalAccessException', 'IllegalStateException'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferExpectedTypeArguments() {
checkPreferredItems 0, 'BlaOperation'
}
@@ -883,6 +945,7 @@ class Foo {
checkPreferredItems 0, 'final', 'find1'
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testDispreferMultiMethodInterfaceAfterNew() {
checkPreferredItems 1, 'Intf', 'IntfImpl'
}
@@ -895,6 +958,7 @@ class Foo {
checkPreferredItems 0, 'AbstractListener', 'Listener'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferPrintln() {
myFixture.configureByText 'a.java', 'class Foo { { System.out.pri<caret>x } }'
myFixture.completeBasic()
@@ -20,6 +20,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.NeedsIndicesState
import com.intellij.util.ui.UIUtil
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection
import groovy.transform.CompileStatic
@@ -84,6 +85,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
doTest 'a\n'
}
@NeedsIndicesState.StandardLibraryIndices
void testSimpleVariable() throws Exception { doTest('\n') }
void testTypeParameterItemPresentation() {
@@ -114,6 +116,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert presentation.tailText == ' default "unknown"'
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodItemPresentation() {
configure()
LookupElementPresentation presentation = renderElement(myItems[0])
@@ -137,6 +140,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert "String" == presentation.typeText
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodItemPresentationGenerics() {
configure()
LookupElementPresentation presentation = renderElement(myItems[1])
@@ -175,18 +179,21 @@ class NormalCompletionTest extends NormalCompletionTestCase {
configureByFile("SCR7208.java")
}
@NeedsIndicesState.StandardLibraryIndices
void testProtectedFromSuper() throws Exception {
configureByFile("ProtectedFromSuper.java")
Arrays.sort(myItems)
assertTrue("Exception not found", Arrays.binarySearch(myItems, "xxx") > 0)
}
@NeedsIndicesState.StandardLibraryIndices
void testBeforeInitialization() throws Exception {
configureByFile("BeforeInitialization.java")
assertNotNull(myItems)
assertTrue(myItems.length > 0)
}
@NeedsIndicesState.StandardLibraryIndices
void testProtectedFromSuper2() throws Exception {
configureByFile("ProtectedFromSuper.java")
@@ -207,7 +214,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
@Override
protected void tearDown() throws Exception {
CodeInsightSettings.instance.AUTOCOMPLETE_ON_CODE_COMPLETION = true
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.FIRST_LETTER
CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.FIRST_LETTER)
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = true
super.tearDown()
}
@@ -224,6 +231,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert 'ABCDE' in myFixture.lookupElementStrings
}
@NeedsIndicesState.StandardLibraryIndices
void testObjectsInThrowsBlock() throws Exception {
configureByFile("InThrowsCompletion.java")
assert "C" == myFixture.lookupElementStrings[0]
@@ -286,6 +294,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
void testSecondSwitchCaseWithEnumConstant() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testInsideSwitchCaseWithEnumConstant() {
configure()
myFixture.assertPreferredCompletionItems 0, 'compareTo', 'equals'
@@ -387,10 +396,12 @@ class NormalCompletionTest extends NormalCompletionTestCase {
void testAnonymousTypeParameter() throws Throwable { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testClassLiteralInAnnoParam() throws Throwable {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testNoForceBraces() {
codeStyleSettings.IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_ALWAYS
doTest('\n')
@@ -402,6 +413,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert !('StringBuffer' in myFixture.lookupElementStrings)
}
@NeedsIndicesState.FullIndices
void testExcludeInstanceInnerClasses() throws Throwable {
JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
@@ -411,6 +423,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert myFixture.lookupElementStrings == ['Inner']
}
@NeedsIndicesState.FullIndices
void testExcludedInstanceInnerClassCreation() throws Throwable {
JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
@@ -420,6 +433,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert myFixture.lookupElementStrings == ['Inner']
}
@NeedsIndicesState.FullIndices
void testExcludedInstanceInnerClassQualifiedReference() throws Throwable {
JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
myFixture.addClass 'package foo; public class Outer { public class Inner {} }'
@@ -429,6 +443,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert myFixture.lookupElementStrings == ['Inner']
}
@NeedsIndicesState.FullIndices
void testStaticMethodOfExcludedClass() {
JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo")
myFixture.addClass 'package foo; public class Outer { public static void method() {} }'
@@ -436,6 +451,7 @@ class NormalCompletionTest extends NormalCompletionTestCase {
assert myFixture.lookupElementStrings == ['method']
}
@NeedsIndicesState.FullIndices
void testExcludeWildcards() {
JavaProjectCodeInsightSettings.setExcludedNames(project, myFixture.testRootDisposable, "foo.Outer.*1*")
myFixture.addClass '''
@@ -451,6 +467,7 @@ public class Outer {
assert myFixture.lookupElementStrings == ['method2', 'method42']
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for int hashCode lookup preventing autocompletion and additional \n)")
void testAtUnderClass() throws Throwable {
doTest('\n')
}
@@ -469,16 +486,19 @@ public class Outer {
assert 'K' in myFixture.lookupElementStrings
}
@NeedsIndicesState.StandardLibraryIndices
void testLocalClassTwice() throws Throwable {
configure()
assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo', 'ZipOutputStream'
}
@NeedsIndicesState.StandardLibraryIndices
void testLocalTopLevelConflict() throws Throwable {
configure()
assertOrderedEquals myFixture.lookupElementStrings, 'Zoooz', 'Zooooo', 'ZipOutputStream'
}
@NeedsIndicesState.StandardLibraryIndices
void testFinalBeforeMethodCall() throws Throwable {
configure()
assertStringItems 'final', 'finalize'
@@ -574,6 +594,7 @@ public class Outer {
}}""".stripIndent())
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
void testAnonymousProcess() {
myFixture.addClass 'package java.lang; public class Process {}'
myFixture.addClass '''
@@ -604,6 +625,7 @@ public class ListUtils {
assertStringItems("case", "default")
}
@NeedsIndicesState.StandardLibraryIndices
void testBooleanLiterals() throws Throwable {
doTest('\n')
}
@@ -622,6 +644,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testChainedCallOnNextLine() throws Throwable {
configureByFile(getTestName(false) + ".java")
selectItem(myItems[0])
@@ -636,6 +659,7 @@ public class ListUtils {
void testEnclosingThis() throws Throwable { doTest() }
@NeedsIndicesState.FullIndices
void testSeamlessConstant() throws Throwable {
configureByFile(getTestName(false) + ".java")
selectItem(myItems[0])
@@ -651,6 +675,7 @@ public class ListUtils {
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testNoSpaceInParensWithoutParams() throws Throwable {
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
try {
@@ -661,25 +686,30 @@ public class ListUtils {
}
}
@NeedsIndicesState.StandardLibraryIndices
void testTwoSpacesInParensWithParams() throws Throwable {
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifierAsPackage() throws Throwable {
configureByFile(getTestName(false) + ".java")
selectItem(myItems[0])
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifierAsPackage2() throws Throwable {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testQualifierAsPackage3() throws Throwable {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testPreselectEditorSelection() {
configure()
assert lookup.currentItem != myFixture.lookupElements[0]
@@ -691,8 +721,10 @@ public class ListUtils {
assertStringItems("*")
}
@NeedsIndicesState.StandardLibraryIndices
void testMembersInStaticImports() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testPackageNamedVariableBeforeAssignment() throws Throwable {
doTest()
}
@@ -718,6 +750,7 @@ public class ListUtils {
assert myFixture.lookupElementStrings == ['MyParam']
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodReturnType() { doTest('\n') }
void testMethodReturnTypeNoSpace() throws Throwable {
@@ -730,6 +763,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testDoWhileMethodCall() throws Throwable {
doTest()
}
@@ -738,6 +772,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testGetterWithExistingNonEmptyParameterList() throws Throwable {
doTest()
}
@@ -762,6 +797,7 @@ public class ListUtils {
doTest('.')
}
@NeedsIndicesState.StandardLibraryIndices
void testFinishClassNameWithLParen() throws Throwable {
doTest('(')
}
@@ -774,6 +810,7 @@ public class ListUtils {
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testCompletionInsideClassLiteral() throws Throwable {
configureByFile(getTestName(false) + ".java")
type('\n')
@@ -790,6 +827,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testSuperInConstructorWithParams() throws Throwable {
doTest()
}
@@ -845,16 +883,19 @@ public class ListUtils {
assertStringItems("fofoo", "fofoo")
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodMergingMinimalTail() { doTest() }
void testAnnotationQualifiedName() throws Throwable {
doTest()
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
void testClassNameAnonymous() throws Throwable {
doTest('\n')
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
void testClassNameWithInner() throws Throwable {
configure()
assertStringItems 'Zzoo', 'Zzoo.Impl'
@@ -866,6 +907,7 @@ public class ListUtils {
void testClassNameWithInstanceInner() throws Throwable { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testDoubleFalse() throws Throwable {
configureByFile(getTestName(false) + ".java")
assertFirstStringItems("false", "fefefef", "float", "finalize")
@@ -882,6 +924,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testNoSemicolonAfterExistingParenthesesEspeciallyIfItsACast() throws Throwable { doTest() }
void testReturningTypeVariable() throws Throwable { doTest() }
@@ -890,6 +933,7 @@ public class ListUtils {
void testReturningTypeVariable3() throws Throwable { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testImportInGenericType() throws Throwable {
configure()
myFixture.complete(CompletionType.BASIC, 2)
@@ -910,6 +954,7 @@ public class ListUtils {
assertStringItems 'final'
}
@NeedsIndicesState.StandardLibraryIndices
void testFinalInForLoop2() throws Throwable {
configure()
myFixture.assertPreferredCompletionItems 0, 'finalize', 'final'
@@ -960,6 +1005,7 @@ public class ListUtils {
assertStringItems("fai1", "fai2")
}
@NeedsIndicesState.FullIndices
void testProtectedInaccessibleOnSecondInvocation() throws Throwable {
myFixture.configureByFile(getTestName(false) + ".java")
myFixture.complete(CompletionType.BASIC, 2)
@@ -972,6 +1018,7 @@ public class ListUtils {
doAntiTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testSecondAnonymousClassParameter() { doTest() }
void testSpaceAfterReturn() throws Throwable {
@@ -1000,6 +1047,7 @@ public class ListUtils {
void testSmartEnterWithNewLine() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
@NeedsIndicesState.SmartMode(reason = "MethodCallFixer.apply needs smart mode to count number of parameters")
void testSmartEnterGuessArgumentCount() throws Throwable { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
void testSmartEnterInsideArrayBrackets() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
@@ -1008,6 +1056,7 @@ public class ListUtils {
void testMethodParameterAnnotationClass() throws Throwable { doTest() }
@NeedsIndicesState.FullIndices
void testInnerAnnotation() {
configure()
assert myFixture.lookupElementStrings == ['Dependency']
@@ -1022,7 +1071,7 @@ public class ListUtils {
void testClassReferenceInFor2() throws Throwable { doTest ' ' }
void testClassReferenceInFor3() throws Throwable {
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
doTest ' '
}
@@ -1049,17 +1098,20 @@ public class ListUtils {
void testExpectedTypesDotSelectsItem() throws Throwable { doTest('.') }
@NeedsIndicesState.FullIndices
void testExpectedTypeMembersVersusStaticImports() throws Throwable {
configure()
assertStringItems('XFOO', 'XFOX')
}
@NeedsIndicesState.FullIndices
void testSuggestExpectedTypeMembersNonImported() throws Throwable {
myFixture.addClass("package foo; public class Super { public static final Super FOO = null; }")
myFixture.addClass("package foo; public class Usage { public static void foo(Super s) {} }")
doTest('\n')
}
@NeedsIndicesState.FullIndices
void testStaticallyImportedInner() throws Throwable {
configure()
assertStringItems('AIOInner', 'ArrayIndexOutOfBoundsException')
@@ -1078,6 +1130,7 @@ public class ListUtils {
void testOnlyAnnotationsAfterAt() throws Throwable { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyAnnotationsAfterAt2() throws Throwable { doTest('\n') }
void testAnnotationBeforeIdentifier() { doTest('\n') }
@@ -1086,12 +1139,16 @@ public class ListUtils {
void testAnnotationBeforeIdentifierFinishWithSpace() { doTest(' ') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInCatch1() throws Exception { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInCatch2() throws Exception { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInCatch3() throws Exception { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInCatch4() throws Exception { doTest('\n') }
void testCommaAfterVariable() throws Throwable { doTest(',') }
@@ -1110,6 +1167,7 @@ public class ListUtils {
void testMethodParameterTypeDot() throws Throwable { doAntiTest() }
@NeedsIndicesState.StandardLibraryIndices
void testNewGenericClass() throws Throwable { doTest('\n') }
void testNewGenericInterface() throws Throwable { doTest() }
@@ -1132,6 +1190,7 @@ public class ListUtils {
assertStringItems("MyParameter", "MySecondParameter")
}
@NeedsIndicesState.FullIndices
void testSuperProtectedMethod() throws Throwable {
myFixture.addClass """package foo;
public class Bar {
@@ -1140,6 +1199,7 @@ public class ListUtils {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testOuterSuperMethodCall() {
configure()
assert 'Class2.super.put' == LookupElementPresentation.renderElement(myItems[0]).itemText
@@ -1160,6 +1220,7 @@ public class ListUtils {
assertStringItems("myField1", "myField2")
}
@NeedsIndicesState.StandardLibraryIndices
void testAfterCommonPrefix() throws Throwable {
configure()
type 'eq'
@@ -1170,6 +1231,7 @@ public class ListUtils {
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testClassNameInsideIdentifierInIf() throws Throwable {
configure()
myFixture.complete(CompletionType.BASIC, 2)
@@ -1185,6 +1247,7 @@ public class ListUtils {
}
void testSynchronizedArgumentSmartEnter() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR as String) }
@NeedsIndicesState.FullIndices
void testImportStringValue() throws Throwable {
myFixture.addClass("package foo; public class StringValue {}")
myFixture.addClass("package java.lang; class StringValue {}")
@@ -1196,6 +1259,7 @@ public class ListUtils {
void testPrimitiveArrayWithRBrace() throws Throwable { doTest '[' }
@NeedsIndicesState.FullIndices
void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -1206,6 +1270,7 @@ public class ListUtils {
doTest('\n')
}
@NeedsIndicesState.FullIndices
void testSuggestMembersOfStaticallyImportedClassesUnqualifiedOnly() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -1220,6 +1285,7 @@ public class ListUtils {
checkResult()
}
@NeedsIndicesState.FullIndices
void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalMethod() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -1235,6 +1301,7 @@ public class ListUtils {
checkResult()
}
@NeedsIndicesState.FullIndices
void testSuggestMembersOfStaticallyImportedClassesConflictWithLocalField() throws Exception {
myFixture.addClass("""package foo;
public class Foo {
@@ -1282,6 +1349,7 @@ public class ListUtils {
assertFirstStringItems "final", "float"
}
@NeedsIndicesState.FullIndices
void testNonImportedClassInAnnotation() {
myFixture.addClass("package foo; public class XInternalTimerServiceController {}")
myFixture.configureByText "a.java", """
@@ -1295,6 +1363,7 @@ class XInternalError {}
assertFirstStringItems "XInternalError", "XInternalTimerServiceController"
}
@NeedsIndicesState.FullIndices
void testNonImportedAnnotationClass() {
myFixture.addClass("package foo; public @interface XAnotherAnno {}")
configure()
@@ -1302,6 +1371,7 @@ class XInternalError {}
assertFirstStringItems "XAnno", "XAnotherAnno"
}
@NeedsIndicesState.StandardLibraryIndices
void testMetaAnnotation() {
myFixture.configureByText "a.java", "@<caret> @interface Anno {}"
myFixture.complete(CompletionType.BASIC)
@@ -1310,6 +1380,7 @@ class XInternalError {}
void testAnnotationClassFromWithinAnnotation() { doTest() }
@NeedsIndicesState.FullIndices
void testStaticallyImportedFieldsTwice() {
myFixture.addClass("""
class Foo {
@@ -1364,7 +1435,7 @@ class XInternalError {}
}
void testDontPreselectCaseInsensitivePrefixMatch() {
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
myFixture.configureByText "a.java", "import java.io.*; class Foo {{ int fileSize; fil<caret>x }}"
myFixture.completeBasic()
assert lookup.currentItem.lookupString == 'fileSize'
@@ -1375,21 +1446,26 @@ class XInternalError {}
assert lookup.currentItem == lookup.items[1]
}
@NeedsIndicesState.StandardLibraryIndices
void testNoGenericsWhenChoosingWithParen() { doTest('Ma(') }
@NeedsIndicesState.StandardLibraryIndices
void testNoClosingWhenChoosingWithParenBeforeIdentifier() { doTest '(' }
void testPackageInMemberType() { doTest() }
void testPackageInMemberTypeGeneric() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testConstantInAnno() { doTest('\n') }
@NeedsIndicesState.SmartMode(reason = "Smart mode needed for EncodingReferenceInjector to provide EncodingReference with variants")
void testCharsetName() {
myFixture.addClass("package java.nio.charset; public class Charset { public static Charset forName(String s) {} }")
configureByTestName()
assert myFixture.lookupElementStrings.contains('UTF-8')
}
@NeedsIndicesState.FullIndices
void testInnerClassInExtendsGenerics() {
def text = "package bar; class Foo extends List<Inne<caret>> { public static class Inner {} }"
myFixture.configureFromExistingVirtualFile(myFixture.addClass(text).containingFile.virtualFile)
@@ -1398,8 +1474,10 @@ class XInternalError {}
myFixture.checkResult(text.replace('Inne<caret>', 'Foo.Inner<caret>'))
}
@NeedsIndicesState.StandardLibraryIndices
void testClassNameDot() { doTest('.') }
@NeedsIndicesState.FullIndices
void testClassNameDotBeforeCall() {
myFixture.addClass("package foo; public class FileInputStreamSmth {}")
myFixture.configureByFile(getTestName(false) + ".java")
@@ -1417,6 +1495,7 @@ class XInternalError {}
assert !('return' in myFixture.lookupElementStrings)
}
@NeedsIndicesState.StandardLibraryIndices
void testDuplicateExpectedTypeInTypeArgumentList() {
configure()
def items = myFixture.lookupElements.findAll { it.lookupString == 'String' }
@@ -1438,8 +1517,10 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testNoParenthesesAroundCallQualifier() { doTest() }
@NeedsIndicesState.FullIndices
void testAllAssertClassesMethods() {
myFixture.addClass 'package foo; public class Assert { public static boolean foo() {} }'
myFixture.addClass 'package bar; public class Assert { public static boolean bar() {} }'
@@ -1449,6 +1530,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.FullIndices
void testCastVisually() {
configure()
def p = LookupElementPresentation.renderElement(myFixture.lookupElements[0])
@@ -1457,6 +1539,7 @@ class XInternalError {}
assert p.typeText == 'Foo'
}
@NeedsIndicesState.StandardLibraryIndices
void testSuggestEmptySet() {
configure()
assert 'emptySet' == myFixture.lookupElementStrings[0]
@@ -1464,6 +1547,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testSuggestAllTypeArguments() {
configure()
assert 'String, List<String>' == lookup.items[0].lookupString
@@ -1474,12 +1558,15 @@ class XInternalError {}
void testNoFinalInAnonymousConstructor() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testListArrayListCast() { doTest('\n') }
void testInterfaceImplementationNoCast() { doTest() }
@NeedsIndicesState.FullIndices
void testStaticallyImportedMethodsBeforeExpression() { doTest() }
@NeedsIndicesState.FullIndices
void testInnerChainedReturnType() { doTest() }
private CommonCodeStyleSettings getCodeStyleSettings() {
@@ -1497,6 +1584,7 @@ class XInternalError {}
assert lookup.items.size() == 1
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for method implementations)")
void testImplementViaCompletion() {
configure()
myFixture.assertPreferredCompletionItems 0, 'private', 'protected', 'public', 'public void run'
@@ -1512,6 +1600,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for implementing methods)")
void testImplementViaCompletionWithGenerics() {
configure()
myFixture.assertPreferredCompletionItems 0, 'public void methodWithGenerics', 'public void methodWithTypeParam'
@@ -1519,6 +1608,7 @@ class XInternalError {}
assert LookupElementPresentation.renderElement(lookup.items[1]).tailText == '(K k) {...}'
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
void testImplementViaOverrideCompletion() {
configure()
myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override', 'public void run'
@@ -1527,6 +1617,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
void testSuggestToOverrideMethodsWhenTypingOverrideAnnotation() {
configure()
myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override'
@@ -1534,6 +1625,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants provides dialog option in smart mode only")
void testSuggestToOverrideMethodsWhenTypingOverrideAnnotationBeforeMethod() {
configure()
myFixture.assertPreferredCompletionItems 0, 'Override/Implement methods...', 'Override'
@@ -1541,6 +1633,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for implementing methods)")
void testStrikeOutDeprecatedSuperMethods() {
configure()
myFixture.assertPreferredCompletionItems 0, 'void foo1', 'void foo2'
@@ -1548,9 +1641,12 @@ class XInternalError {}
assert LookupElementPresentation.renderElement(lookup.items[1]).strikeout
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for equals() and hashCode())")
void testInvokeGenerateEqualsHashCodeOnOverrideCompletion() { doTest() }
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for 'toString()')")
void testInvokeGenerateToStringOnOverrideCompletion() { doTest() }
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters and setters)")
void testAccessorViaCompletion() {
configure()
@@ -1574,6 +1670,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters and setters)")
void testNoSetterForFinalField() {
configure()
myFixture.assertPreferredCompletionItems 0, 'public', 'public int getFinalField'
@@ -1595,10 +1692,12 @@ class XInternalError {}
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testMulticaretMethodWithParen() {
doTest()
}
@NeedsIndicesState.StandardLibraryIndices
void testMulticaretTyping() {
configure()
assert lookup
@@ -1608,6 +1707,7 @@ class XInternalError {}
checkResult()
}
@NeedsIndicesState.StandardLibraryIndices
void testMulticaretCompletionFromNonPrimaryCaret() {
configure()
myFixture.assertPreferredCompletionItems(0, "arraycopy")
@@ -1617,6 +1717,7 @@ class XInternalError {}
doTest '\t'
}
@NeedsIndicesState.FullIndices
void "test complete lowercase class name"() {
myFixture.addClass("package foo; public class myClass {}")
myFixture.configureByText "a.java", """
@@ -1629,6 +1730,7 @@ class Foo extends myClass
'''
}
@NeedsIndicesState.StandardLibraryIndices
void "test don't show static inner class after instance qualifier"() {
myFixture.configureByText "a.java", """
class Foo {
@@ -1644,6 +1746,7 @@ class Bar {
assert !('Inner' in myFixture.lookupElementStrings)
}
@NeedsIndicesState.StandardLibraryIndices
void "test show static member after instance qualifier when nothing matches"() {
myFixture.configureByText "a.java", "class Foo{{ \"\".<caret> }}"
myFixture.completeBasic()
@@ -1656,6 +1759,7 @@ class Bar {
void testNoMathTargetMethods() { doAntiTest() }
@NeedsIndicesState.FullIndices
void testNoLowercaseClasses() {
myFixture.addClass("package foo; public class abcdefgXxx {}")
doAntiTest()
@@ -1663,11 +1767,13 @@ class Bar {
assertStringItems('abcdefgXxx')
}
@NeedsIndicesState.FullIndices
void testProtectedFieldInAnotherPackage() {
myFixture.addClass("package foo; public class Super { protected String myString; }")
doTest()
}
@NeedsIndicesState.FullIndices
void testUnimportedStaticInnerClass() {
myFixture.addClass("package foo; public class Super { public static class Inner {} }")
doTest()
@@ -1675,6 +1781,7 @@ class Bar {
void testNoJavaLangPackagesInImport() { doAntiTest() }
@NeedsIndicesState.FullIndices
void testNoStaticDuplicatesFromExpectedMemberFactories() {
configure()
myFixture.complete(CompletionType.BASIC, 2)
@@ -1689,6 +1796,7 @@ class Bar {
assertNull(getLookup())
}
@NeedsIndicesState.SmartMode(reason = "JavaGenerateMemberCompletionContributor.fillCompletionVariants works in smart mode only (for getters)")
void "test code cleanup during completion generation"() {
myFixture.configureByText "a.java", "class Foo {int i; ge<caret>}"
myFixture.enableInspections(new UnqualifiedFieldAccessInspection())
@@ -1709,6 +1817,7 @@ class Bar {
assert 'B' == LookupElementPresentation.renderElement(myFixture.lookup.items[0]).typeText
}
@NeedsIndicesState.StandardLibraryIndices
void testShowMostSpecificOverrideOnlyFromClass() {
configure()
assert 'Door' == LookupElementPresentation.renderElement(myFixture.lookup.items[0]).typeText
@@ -1727,6 +1836,7 @@ class Bar {
assert LookupElementPresentation.renderElement(items[3]).tailFragments[0].italic
}
@NeedsIndicesState.FullIndices
void testShowNonImportedVarInitializers() {
configure()
myFixture.assertPreferredCompletionItems 1, 'Field', 'FIELD1', 'FIELD2', 'FIELD3', 'FIELD4'
@@ -1736,12 +1846,14 @@ class Bar {
assert !LookupElementPresentation.renderElement(fieldItems[3]).tailFragments[1].italic
}
@NeedsIndicesState.StandardLibraryIndices
void testSuggestInterfaceArrayWhenObjectIsExpected() {
configure()
assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
assert LookupElementPresentation.renderElement(myFixture.lookup.items[1]).tailText.contains('[]')
}
@NeedsIndicesState.StandardLibraryIndices
void testSuggestInterfaceArrayWhenObjectArrayIsExpected() {
configure()
assert LookupElementPresentation.renderElement(myFixture.lookup.items[0]).tailText.contains('{...}')
@@ -1749,18 +1861,21 @@ class Bar {
}
void testDispreferPrimitiveTypesInCallArgs() throws Throwable {
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
configure()
myFixture.assertPreferredCompletionItems 0, "dx", "doo", "Doo", "double"
}
@NeedsIndicesState.StandardLibraryIndices
void testCopyConstructor() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testGetClassType() {
configure()
assert 'Class<? extends Number>' == LookupElementPresentation.renderElement(myFixture.lookupElements[0]).typeText
}
@NeedsIndicesState.FullIndices
void testNonImportedClassAfterNew() {
def uClass = myFixture.addClass('package foo; public class U {}')
myFixture.configureByText('a.java', 'class X {{ new U<caret>x }}')
@@ -1771,7 +1886,7 @@ class Bar {
void testSuggestClassNamesForLambdaParameterTypes() { doTest('\n') }
void testOnlyExtendsSuperInWildcard() {
CodeInsightSettings.instance.COMPLETION_CASE_SENSITIVE = CodeInsightSettings.NONE
CodeInsightSettings.instance.setCompletionCaseSensitive(CodeInsightSettings.NONE)
configure()
assert myFixture.lookupElementStrings == ['extends', 'super']
@@ -1783,12 +1898,14 @@ class Bar {
checkResultByFile(getTestName(false) + ".java")
}
@NeedsIndicesState.FullIndices
void testChainInLambdaBinary() {
codeStyleSettings.ALIGN_MULTILINE_BINARY_OPERATION = true
myFixture.addClass("package pkg; public class PathUtil { public static String toSystemDependentName() {} }")
doTest('\n')
}
@NeedsIndicesState.StandardLibraryIndices
void testPairAngleBracketDisabled() {
CodeInsightSettings.instance.AUTOINSERT_PAIR_BRACKET = false
doTest('<')
@@ -1799,6 +1916,7 @@ class Bar {
assert myFixture.lookupElementStrings == ['indexOf']
}
@NeedsIndicesState.StandardLibraryIndices
void testDuplicateEnumValueOf() {
configure()
assert myFixture.lookupElements.collect { LookupElementPresentation.renderElement((LookupElement)it).itemText } == ['Bar.valueOf', 'Foo.valueOf', 'Enum.valueOf']
@@ -1811,6 +1929,7 @@ class Bar {
void testNoCallsInPackageStatement() { doAntiTest() }
@NeedsIndicesState.FullIndices
void testTypeParameterShadowingClass() {
configure()
myFixture.assertPreferredCompletionItems 0, 'Tttt', 'Tttt'
@@ -1843,21 +1962,28 @@ class Bar {{
void testNoNonAnnotationMethods() { doAntiTest() }
@NeedsIndicesState.StandardLibraryIndices
void testPreferBigDecimalToJavaUtilInner() {
configure()
myFixture.assertPreferredCompletionItems 0, 'BigDecimal', 'BigDecimalLayoutForm'
}
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInMultiCatch1() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyExceptionsInMultiCatch2() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyResourcesInResourceList1() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyResourcesInResourceList2() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyResourcesInResourceList3() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testOnlyResourcesInResourceList4() { doTest('\n') }
void testOnlyResourcesInResourceList5() { doTest('\n') }
@@ -1866,8 +1992,10 @@ class Bar {{
void testMethodReferenceCallContext() { doTest('\n') }
@NeedsIndicesState.FullIndices
void testDestroyingCompletedClassDeclaration() { doTest('\n') }
@NeedsIndicesState.StandardLibraryIndices
void testResourceParentInResourceList() {
configureByTestName()
assert 'MyOuterResource' == myFixture.lookupElementStrings[0]
@@ -1888,6 +2016,7 @@ class Bar {{
checkResultByFile(getTestName(false) + "_after.java")
}
@NeedsIndicesState.FullIndices
void testCompletingClassWithSameNameAsPackage() {
myFixture.addClass("package Apple; public class Apple {}")
doTest('\n')
@@ -1902,6 +2031,7 @@ class Bar {{
checkResult()
}
@NeedsIndicesState.FullIndices
void testRemoveUnusedImportOfSameName() {
myFixture.addClass("package foo; public class List {}")
configureByTestName()
@@ -1941,6 +2071,7 @@ class Abc {
void testSuggestCurrentClassInSecondSuperGenericParameter() { doTest('\n') }
@NeedsIndicesState.FullIndices
void "test after new editing prefix back and forth when sometimes there are expected type suggestions and sometimes not"() {
myFixture.addClass("class Super {}")
myFixture.addClass("class Sub extends Super {}")
@@ -1974,6 +2105,7 @@ class Abc {
myFixture.checkResult("enum X ex")
}
@NeedsIndicesState.FullIndices
void testAddImportWhenCompletingInnerAfterNew() {
myFixture.addClass("package p; public class Outer { public static class Inner {} }")
configureByTestName()
@@ -1989,6 +2121,7 @@ class Abc {
myFixture.checkResult("class C implements java.util.List<caret>")
}
@NeedsIndicesState.StandardLibraryIndices
void "test suggest Object methods when super is unresolved"() {
def checkGetClassPresent = { String text ->
myFixture.configureByText("a.java", text)
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.util.ThrowableRunnable;
import com.intellij.util.containers.ContainerUtil;
@@ -57,11 +58,15 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
assertStringItems("getBar().getGoo", "getBar().getGoo2");
}
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestArraysAsList() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestArraysAsListWildcard() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestToArrayWithNewEmptyArray() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestToArrayWithExistingEmptyArray() throws Throwable {
configure();
assertStringItems("foos().toArray(EMPTY_ARRAY)", "foos().toArray(EMPTY_ARRAY2)");
@@ -71,11 +76,15 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
public void testToArrayGenericArrayCreation() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testToArrayFieldsQualifier() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testToArrayMethodQualifier() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testToListWithQualifier() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestToArrayWithExistingEmptyArrayFromAnotherClass() throws Throwable {
configure();
assertStringItems("foos().toArray(Bar.EMPTY_ARRAY)", "foos().toArray(Bar.EMPTY_ARRAY2)");
@@ -86,12 +95,14 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
public void testNonInitializedField() throws Throwable { doTest(); }
public void testIgnoreToString() throws Throwable { doTest(); }
public void testDontIgnoreToStringInsideIt() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testDontIgnoreToStringInStringBuilders() throws Throwable {
configure();
myFixture.assertPreferredCompletionItems(0, "bar.substring", "bar.substring", "bar.toString");
}
public void testNoObjectMethodsAsFirstPart() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testGetClassLoader() throws Throwable {
configure();
selectItem(myItems[0]);
@@ -125,6 +136,7 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
configureByFile(getTestName(false) + ".java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoArraysAsListCommonPrefix() throws Throwable {
configure();
checkResultByFile(getTestName(false) + ".java");
@@ -144,6 +156,7 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
}
public void testDontChainStringMethodsOnString() throws Throwable { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testStringMethodsWhenNothingFound() throws Throwable { doTest(); }
public void testDontSuggestTooGenericMethods() throws Throwable {
@@ -164,6 +177,7 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
assertStringItems("o.gggg", "false", "true");
}
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListInMethodCall() throws Throwable {
configure();
selectItem(myItems[0]);
@@ -174,12 +188,14 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
checkResultByFile(getTestName(false) + "-out.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testSingletonMap() throws Throwable {
configure();
selectItem(myItems[0]);
checkResult();
}
@NeedsIndicesState.StandardLibraryIndices
public void testChainDuplicationAfterInstanceof() {
configure();
assertStringItems("test.test", "toString");
@@ -202,11 +218,13 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
checkResult();
}
@NeedsIndicesState.FullIndices
public void testGlobalFactoryMethods() {
configure();
assertStringItems("createExpected", "Constants.SUBSTRING", "createSubGeneric", "createSubRaw", "createSubString");
}
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyMapPresentation() {
configure();
LookupElementPresentation presentation = new LookupElementPresentation();
@@ -214,6 +232,7 @@ public class SecondSmartTypeCompletionTest extends LightFixtureCompletionTestCas
assertEquals("Collections.<String, S...>emptyMap", presentation.getItemText());
}
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyMapPresentation2() {
configure();
LookupElementPresentation presentation = new LookupElementPresentation();
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.registry.Registry
import com.intellij.psi.PsiMethod
import com.intellij.psi.statistics.StatisticsManager
import com.intellij.psi.statistics.impl.StatisticsManagerImpl
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
/**
@@ -51,6 +52,7 @@ class SignatureCompletionTest extends LightFixtureCompletionTestCase {
void testNonDefaultConstructor() { doFirstItemTest() }
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
void testAnonymousNonDefaultConstructor() {
configureByTestName()
myFixture.type('\n')
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.NeedsIndicesState;
import org.jetbrains.annotations.NotNull;
public class SmartType14CompletionTest extends LightFixtureCompletionTestCase {
@@ -39,6 +40,7 @@ public class SmartType14CompletionTest extends LightFixtureCompletionTestCase {
return JAVA_1_4;
}
@NeedsIndicesState.StandardLibraryIndices
public void testLogger14() {
doTest();
}
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElementPresentation;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.NeedsIndicesState;
import org.jetbrains.annotations.NotNull;
public class SmartType17CompletionTest extends LightFixtureCompletionTestCase {
@@ -44,6 +45,7 @@ public class SmartType17CompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testDiamondCollapsedWithMethodTypeParameter() {
doTest();
}
@@ -56,20 +58,24 @@ public class SmartType17CompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testDiamondNotCollapsedNotApplicable() {
doTest();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testDiamondNotCollapsedInCaseOfAnonymousClasses() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testDiamondNotCollapsedInCaseOfInapplicableInference() {
doTest();
}
public void testTryWithResourcesNoSemicolon() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testTryWithResourcesThrowsException() {
configureByFile("/" + getTestName(false) + ".java");
myFixture.type('\n');
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CompletionType;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.NeedsIndicesState;
import org.jetbrains.annotations.NotNull;
public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
@@ -40,6 +41,7 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
}
@NeedsIndicesState.StandardLibraryIndices
public void testExpectedReturnType() {
doTest();
}
@@ -48,26 +50,32 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testExpectedReturnType1() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testSemicolonInExpressionBodyInLocalVariable() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testSemicolonInCodeBlocBodyInLocalVariable() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testSemicolonInExpressionBodyInExpressionList() {
doTest();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testIgnoreDefaultMethods() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testInLambdaPosition() {
doTest();
}
@@ -76,34 +84,42 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testInLambdaPositionNameSubstitution() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testInLambdaPositionSameNames() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testInCollectionForEach() { doTest();}
public void testConstructorRef() {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testInnerArrayConstructorRef() { doTest(true); }
@NeedsIndicesState.StandardLibraryIndices
public void testAbstractArrayConstructorRef() { doTest(true); }
public void testNoConstraintsWildcard() {
doTest();
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
public void testDiamondCollapsedInsideAnonymous() {
doTest();
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
public void testDiamondCollapsedInFieldInitializerInsideAnonymous() {
doTest();
}
@NeedsIndicesState.FullIndices
public void testInheritorConstructorRef() {
myFixture.addClass("package intf; public interface Intf<T> {}");
myFixture.addClass("package foo; public class ImplBar implements intf.Intf<String> {}");
@@ -123,14 +139,17 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testFilteredStaticMethods() {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testFilterWrongParamsMethods() {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoQualifier() {
doTest();
}
@@ -138,38 +157,44 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
public void testFilterAmbiguity() {
configureByFile("/" + getTestName(false) + ".java");
assertNotNull(myItems);
assertTrue(myItems.length == 0);
assertEquals(0, myItems.length);
}
public void testNotAvailableInLambdaPositionAfterQualifier() {
configureByFile("/" + getTestName(false) + ".java");
assertNotNull(myItems);
assertTrue(myItems.length == 0);
assertEquals(0, myItems.length);
}
public void testInferFromRawType() {
configureByFile("/" + getTestName(false) + ".java");
assertNotNull(myItems);
assertTrue(myItems.length == 0);
assertEquals(0, myItems.length);
}
public void testDiamondsInsideMethodCall() {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testSimpleMethodReference() {
doTest(true);
}
@NeedsIndicesState.StandardLibraryIndices
public void testStaticMethodReference() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testStaticMethodReferenceInContextWithTypeArgs() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testOuterMethodReference() { doTest(true); }
public void testNoAnonymousOuterMethodReference() { doAntiTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testMethodReferenceOnAncestor() { doTest(true); }
@NeedsIndicesState.StandardLibraryIndices
public void testObjectsNonNull() { doTest(true); }
public void testNoLambdaSuggestionForGenericsFunctionalInterfaceMethod() {
@@ -177,13 +202,15 @@ public class SmartType18CompletionTest extends LightFixtureCompletionTestCase {
assertEmpty(myItems);
}
public void testConvertToObjectStream() {
@NeedsIndicesState.StandardLibraryIndices
public void testConvertToObjectStream() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 2);
myFixture.type('\n');
myFixture.type('\n');
checkResultByFile("/" + getTestName(false) + "-out.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testConvertToDoubleStream() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 2);
@@ -191,12 +218,14 @@ public void testConvertToObjectStream() {
checkResultByFile("/" + getTestName(false) + "-out.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoUnrelatedMethodSuggestion() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 1);
assertOrderedEquals(myFixture.getLookupElementStrings(), "this");
}
@NeedsIndicesState.StandardLibraryIndices
public void testInferFromReturnTypeWhenCompleteInsideArgList() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 1);
@@ -210,6 +239,7 @@ public void testConvertToObjectStream() {
checkResultByFile("/" + getTestName(false) + "-out.java");
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testInsideNewExpressionWithDiamondAndOverloadConstructors() {
configureByTestName();
myFixture.complete(CompletionType.SMART, 1);
@@ -217,11 +247,14 @@ public void testConvertToObjectStream() {
checkResultByFile("/" + getTestName(false) + "-out.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testCollectorsToList() {
doTest(false);
}
@NeedsIndicesState.StandardLibraryIndices
public void testCollectionsEmptyMap() { doTest(true); }
@NeedsIndicesState.StandardLibraryIndices
public void testExpectedSuperOfLowerBound() {
doTest(false);
}
@@ -246,55 +279,68 @@ public void testConvertToObjectStream() {
checkResultByFile("/" + getTestName(false) + "-out.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testOnlyCompatibleTypes() {
configureByTestName();
assertOrderedEquals(myFixture.getLookupElementStrings(), "get2");
}
@NeedsIndicesState.StandardLibraryIndices
public void testInferredObjects() {
configureByTestName();
assertOrderedEquals(myFixture.getLookupElementStrings(), "M", "HM");
}
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestMapInheritors() { doTest(); }
public void testUnboundTypeArgs() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCallBeforeLambda() { doTest(false); }
@NeedsIndicesState.StandardLibraryIndices
public void testMapGetOrDefault() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "TimeUnit.DAYS");
}
@NeedsIndicesState.StandardLibraryIndices
public void testFreeGenericsAfterClassLiteral() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "String.class", "tryCast");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNewHashMapTypeArguments() { doTest(false); }
@NeedsIndicesState.StandardLibraryIndices
public void testNewMapTypeArguments() { doTest(false); }
@NeedsIndicesState.StandardLibraryIndices
public void testPreferLambdaOverGenericGetter() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "s -> ", "isEmpty", "isNull", "nonNull", "getSomeGenericValue");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoInaccessibleConstructorRef() {
configureByTestName();
assertOrderedEquals(myFixture.getLookupElementStrings(), "() -> ");
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
public void testPreselectTreeMapWhenSortedMapExpected() {
configureByTestName();
myFixture.assertPreferredCompletionItems(2, "SortedMap", "NavigableMap", "TreeMap", "ConcurrentNavigableMap", "ConcurrentSkipListMap");
}
@NeedsIndicesState.StandardLibraryIndices
public void testConsiderClassProximityForClassLiterals() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "String.class");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNestedCollectorsCounting() { doTest(false); }
public void testFilterInaccessibleConstructors() { doAntiTest(); }
@@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.completion
import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
/**
@@ -43,8 +44,10 @@ class SmartTypeCompletionDfaTest extends LightFixtureCompletionTestCase {
checkResultByFile("/" + getTestName(false) + "-out.java")
}
@NeedsIndicesState.FullIndices
void testCastGenericQualifier() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testDontAutoCastWhenAlreadyCasted() {
configureByTestName()
myFixture.assertPreferredCompletionItems(0, "s", "toString")
@@ -52,22 +55,28 @@ class SmartTypeCompletionDfaTest extends LightFixtureCompletionTestCase {
checkResultByTestName()
}
@NeedsIndicesState.StandardLibraryIndices
void testAutoCastWhenAlreadyCasted() {
configureByTestName()
myFixture.type('\n')
checkResultByTestName()
}
@NeedsIndicesState.StandardLibraryIndices
void testSuggestCastedValueAfterCast() { doTest() }
@NeedsIndicesState.FullIndices
void testSuggestInstanceofedValue() { doTest() }
void testSuggestInstanceofedValueInTernary() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testSuggestInstanceofedValueInComplexIf() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testSuggestInstanceofedValueInElseNegated() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testSuggestInstanceofedValueAfterReturn() { doTest() }
void testNoInstanceofedValueWhenBasicSuits() { doTest() }
@@ -80,6 +89,7 @@ class SmartTypeCompletionDfaTest extends LightFixtureCompletionTestCase {
void testInstanceofedInsideAnonymous() { doTest() }
@NeedsIndicesState.StandardLibraryIndices
void testCastToTypeWithWildcard() { doTest() }
}
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.psi.PsiClass
import com.intellij.psi.statistics.StatisticsManager
import com.intellij.testFramework.NeedsIndicesState
class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
private static final String BASE_PATH = "/codeInsight/completion/smartTypeSorting"
@@ -33,15 +34,18 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
super(CompletionType.SMART)
}
@NeedsIndicesState.StandardLibraryIndices
void testJComponentAdd() throws Throwable {
checkPreferredItems(0, "name", "b", "fooBean239", "foo")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testJComponentAddNew() throws Throwable {
//there's no PopupMenu in mock jdk
checkPreferredItems(2, "Component", "String", "FooBean3", "JComponent", "Container")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testJComponentAddNewWithStats() throws Throwable {
//there's no PopupMenu in mock jdk
final LookupImpl lookup = invokeCompletion("/JComponentAddNew.java")
@@ -56,6 +60,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(2, "Component", "String", "Container", "FooBean3", "JComponent")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testNewListAlwaysFirst() {
def lookup = invokeCompletion(getTestName(false) + ".java")
assertPreferredItems 1, 'List', 'ArrayList', 'AbstractList', 'AbstractSequentialList'
@@ -66,6 +71,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems 1, 'List', 'AbstractSequentialList', 'ArrayList', 'AbstractList'
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testNoStatsOnUnsuccessfulAttempt() {
final LookupImpl lookup = invokeCompletion("/JComponentAddNew.java")
assertPreferredItems(2, "Component", "String", "FooBean3", "JComponent", "Container")
@@ -84,26 +90,32 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "goo", "bar", "foo")
}
@NeedsIndicesState.FullIndices
void testNewRunnable() throws Throwable {
checkPreferredItems(0, "Runnable", "MyAnotherRunnable", "MyRunnable", "Thread")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testNewComponent() throws Throwable {
checkPreferredItems(1, "Component", "Foo", "JComponent", "Container")
}
@NeedsIndicesState.StandardLibraryIndices
void testClassLiteral() throws Throwable {
checkPreferredItems(0, "String.class")
}
@NeedsIndicesState.StandardLibraryIndices
void testMethodsWithSubstitutableReturnType() throws Throwable {
checkPreferredItems(0, "foo", "toString", "bar")
}
@NeedsIndicesState.StandardLibraryIndices
void testDontPreferKeywords() throws Throwable {
checkPreferredItems(0, "o1", "foo", "name", "this")
}
@NeedsIndicesState.StandardLibraryIndices
void testEnumValueOf() throws Throwable {
checkPreferredItems(0, "e", "MyEnum.BAR", "MyEnum.FOO", "valueOf", "valueOf")
}
@@ -116,48 +128,59 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "getVersionString", "getTitle")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testPreferImportedClasses() throws Throwable {
//there's no PopupMenu in mock jdk
checkPreferredItems(2, "Component", "String", "FooBean3", "JPanel", "JComponent")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testPreferNestedClasses() throws Throwable {
//there's no PopupMenu in mock jdk
checkPreferredItems(2, "Component", "String", "FooBean3", "NestedClass", "JComponent")
}
@NeedsIndicesState.StandardLibraryIndices
void testSmartCollections() throws Throwable {
checkPreferredItems(0, "s")
}
@NeedsIndicesState.StandardLibraryIndices
void testSmartEquals() throws Throwable {
checkPreferredItems(0, "s")
}
@NeedsIndicesState.StandardLibraryIndices
void testSmartEquals2() throws Throwable {
checkPreferredItems(0, "foo", "this", "o", "s")
}
@NeedsIndicesState.StandardLibraryIndices
void testSmartEquals3() throws Throwable {
checkPreferredItems(0, "b", "this", "a", "z")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testSmartCollectionsNew() throws Throwable {
checkPreferredItems(1, "Foo", "Bar")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testSmartEqualsNew() throws Throwable {
checkPreferredItems(1, "Foo", "Bar")
}
@NeedsIndicesState.StandardLibraryIndices
void testSmartEqualsNew2() throws Throwable {
checkPreferredItems(0, "Foo")
}
@NeedsIndicesState.StandardLibraryIndices
void testBooleanValueOf() throws Throwable {
checkPreferredItems(0, "b", "Boolean.FALSE", "Boolean.TRUE", "equals", "false", "true", "valueOf", "valueOf")
}
@NeedsIndicesState.StandardLibraryIndices
void testXmlTagGetAttribute() throws Throwable {
checkPreferredItems(0, "getAttributeValue", "getNamespace", "toString")
}
@@ -178,6 +201,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "MyProcessor", "Proc1")
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
void testStatisticsAffectsNonPreferableExpectedItems() throws Throwable {
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java")
assertPreferredItems(1, "List", "ArrayList", "AbstractList", "AbstractSequentialList")
@@ -187,6 +211,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "List", "ArrayList", "AbstractList", "AbstractSequentialList")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferNonRecursiveMethodParams() throws Throwable {
checkPreferredItems(0, "b", "s", "a", "hashCode")
}
@@ -223,18 +248,22 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "Foo", "Bar", "Goo")
}
@NeedsIndicesState.StandardLibraryIndices
void testLiteralInReturn() throws Throwable {
checkPreferredItems(0, "false", "true", "equals")
}
@NeedsIndicesState.StandardLibraryIndices
void testLiteralInIf() throws Throwable {
checkPreferredItems(0, "equals", "false", "true")
}
@NeedsIndicesState.StandardLibraryIndices
void testFactoryMethodForDefaultType() throws Throwable {
checkPreferredItems(0, "create", "this")
}
@NeedsIndicesState.StandardLibraryIndices
void testLocalVarsBeforeClassLiterals() throws Throwable {
checkPreferredItems(0, "local", "Foo.class", "Bar.class")
}
@@ -243,6 +272,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "_o", "b")
}
@NeedsIndicesState.FullIndices
void testInnerClassesProximity() throws Throwable {
checkPreferredItems(0, "Goo", "InnerGoo", "Bar", "AGoo")
}
@@ -259,6 +289,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "foo", "param", "this", "goo", "bar")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferredByNameDontChangeStatistics() throws Throwable {
invokeCompletion(getTestName(false) + ".java")
assertPreferredItems(0, "foo", "false")
@@ -274,10 +305,12 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "myBar", "myFoo")
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferSameNamedMethods() {
checkPreferredItems(0, "foo", "boo", "doo", "hashCode")
}
@NeedsIndicesState.FullIndices
void testErasureNotAffectingProximity() {
myFixture.addClass("package foo; public interface Foo<T> {}")
myFixture.addClass("package bar; public class Bar implements foo.Foo {}")
@@ -298,11 +331,13 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertEquals("Bar", presentation.getItemText())
}
@NeedsIndicesState.FullIndices
void testAssertEquals() throws Throwable {
myFixture.addClass("package junit.framework; public class Assert { public static void assertEquals(Object a, Object b) {} }")
checkPreferredItems(0, "boo", "bar")
}
@NeedsIndicesState.FullIndices
void testPreferCollectionsEmptyList() throws Throwable {
myFixture.addClass("package foo; public class FList<T> implements java.util.List<T> { public static <T> FList<T> emptyList() {} }")
configureNoCompletion(getTestName(false) + ".java")
@@ -311,10 +346,12 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems(0, "local", "local.subList", "locMethod")
}
@NeedsIndicesState.StandardLibraryIndices
void testDispreferGetterInSetterCall() {
checkPreferredItems 0, 'color', 'getZooColor', 'getColor', 'hashCode'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferOtherGetterInSetterCall() {
checkPreferredItems 0, 'color', 'getColor', 'getZooColor', 'hashCode'
}
@@ -323,30 +360,37 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems 0, 'e', 'createEvent'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLocalOverThis() {
checkPreferredItems 0, 'value', 'this', 'hashCode'
}
@NeedsIndicesState.StandardLibraryIndices
void testGetLogger() {
checkPreferredItems 0, 'Foo.class', 'forName'
}
@NeedsIndicesState.StandardLibraryIndices
void testGetWildcardLogger() {
checkPreferredItems 0, 'Foo.class', 'forName'
}
@NeedsIndicesState.StandardLibraryIndices
void testGetWildcardFactoryLogger() {
checkPreferredItems 0, 'Foo.class', 'forName'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferLocalWildcardClassOverObject() {
checkPreferredItems 0, 'type', 'Object.class', 'forName', 'forName'
}
@NeedsIndicesState.StandardLibraryIndices
void testPreferStringsInStringConcatenation() {
checkPreferredItems 0, 'toString'
}
@NeedsIndicesState.FullIndices
void testGlobalStaticMemberStats() {
configureNoCompletion(getTestName(false) + ".java")
myFixture.complete(CompletionType.SMART, 2)
@@ -355,6 +399,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assertPreferredItems 0, 'newLinkedSet1', 'newLinkedSet0', 'newLinkedSet2'
}
@NeedsIndicesState.FullIndices
void testPreferExpectedTypeMembers() {
configureNoCompletion(getTestName(false) + ".java")
myFixture.complete(CompletionType.SMART, 2)
@@ -362,6 +407,7 @@ class SmartTypeCompletionOrderingTest extends CompletionSortingTestCase {
assert lookup.items.size() == 2
}
@NeedsIndicesState.FullIndices
void testPreferGlobalMembersReturningExpectedType() {
configureNoCompletion(getTestName(false) + ".java")
def items = myFixture.complete(CompletionType.SMART, 2)
@@ -22,6 +22,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
import com.intellij.psi.util.PsiUtil;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -47,6 +48,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
@NeedsIndicesState.StandardLibraryIndices
public void testParenAfterCast3() {
String path = "/parenAfterCast";
@@ -150,6 +152,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after3.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew4() {
String path = "/afterNew";
@@ -158,6 +161,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after4.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew5() {
String path = "/afterNew";
@@ -166,6 +170,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after5.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew6() {
String path = "/afterNew";
@@ -174,6 +179,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after6.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew7() {
String path = "/afterNew";
@@ -182,6 +188,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after7.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew8() {
String path = "/afterNew";
@@ -190,6 +197,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after8.java");
}
@NeedsIndicesState.FullIndices
public void testAfterNew9() {
String path = "/afterNew";
@@ -214,6 +222,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after13.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testAfterThrowNew1() {
String path = "/afterNew";
@@ -222,6 +231,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after14.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testAfterThrowNew2() {
String path = "/afterNew";
@@ -230,6 +240,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after15.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testAfterThrowNew3() {
String path = "/afterNew";
@@ -239,6 +250,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
public void testCastInThrow() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNonExistentGenericAfterNew() { doTest('\n'); }
public void testParenAfterNewWithinInnerExpr() {
@@ -313,6 +325,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after5.java");
}
@NeedsIndicesState.FullIndices
public void testAfterInstanceOf1() {
String path = "/afterInstanceOf";
@@ -320,6 +333,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after1.java");
}
@NeedsIndicesState.FullIndices
public void testAfterInstanceOf2() {
String path = "/afterInstanceOf";
@@ -327,8 +341,11 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(path + "/after2.java");
}
@NeedsIndicesState.StandardLibraryIndices
public void testInsideCatch() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testInsideCatchFinal() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testInsideCatchWithoutThrow() { doTest(); }
public void testGenerics6() {
@@ -388,28 +405,36 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertEquals(2, myItems.length);
}
@NeedsIndicesState.StandardLibraryIndices
public void testCollectionsEmptySetInMethodCall() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCollectionsEmptySetInTernary() { doTest(); }
public void testStringConstantInAnno() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCollectionsEmptySetInTernary2() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testConstructorOnSeparateLineInMethodCall() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testConstructorWithExistingParens() { doTest(); }
public void testMethodAnnotationNamedParameter() { doTest(); }
public void testInheritedClass() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteralInAnno1() { doTest(); }
public void testMeaninglessExplicitWildcardParam() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExplicitWildcardArrayParam() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCatchInAnonymous() { doTest(); }
public void testThrowRuntimeException() { doTest(); }
@@ -422,8 +447,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testQualifiedThisInAnonymousConstructor() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExceptionTwice() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExceptionTwice2() { doTest(); }
public void testNewInnerRunnable() { doTest(); }
@@ -434,6 +461,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testJavadocThrows() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testMethodThrows() { doTest(); }
public void testDoNotExcludeAssignedVariable() { doTest(); }
@@ -443,25 +471,32 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testPrivateOverloads() { doTest(); }
public void testInaccessibleMethodArgument() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testPolyadicExpression() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCastAutoboxing() {
doItemTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testCastAutoboxing2() {
doItemTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testCastAutoboxing3() {
doItemTest();
}
public void testCastWildcards() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNoSecondMethodTypeArguments() { doTest(Lookup.REPLACE_SELECT_CHAR); }
public void testNoFieldsInSuperConstructorCall() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testChainMethodsInSuperConstructorCall() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNoUninitializedFieldsInConstructor() {
configureByTestName();
assertStringItems("aac", "aab", "hashCode");
@@ -488,6 +523,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByTestName();
}
@NeedsIndicesState.StandardLibraryIndices
public void testVoidExpectedType() {
configureByTestName();
assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "equals", "hashCode", "toString", "getClass");
@@ -523,10 +559,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testSameNamedFieldAndLocal() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNoTailWhenNoPairBracket() { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
public void testNoTailWhenNoPairBracket2() { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testAnonymousNoPairBracket() { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
private void doTestNoPairBracket(final char c) {
@@ -540,8 +578,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoConstructorTailWhenNoPairBracket() { doTestNoPairBracket(Lookup.NORMAL_SELECT_CHAR); }
@NeedsIndicesState.StandardLibraryIndices
public void testConstructorNoPairBracketSemicolon() { doTestNoPairBracket(';'); }
public void testMethodNoPairBracketComma() { doTestNoPairBracket(','); }
@@ -553,6 +593,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testConstantTwice() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testConstantTwice2() {
configureByTestName();
assertEquals(2, myItems.length);
@@ -576,6 +617,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testExclamationMethodFinish() { doTest('!'); }
public void testExclamationVariableFinish() { doTest('!'); }
@NeedsIndicesState.StandardLibraryIndices
public void testExclamationStaticFieldFinish() { doTest('!'); }
public void testExclamationFinishNonBoolean() { doTest('!'); }
@@ -589,6 +631,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testBeforeBinaryExpressionInMethodCall() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testAssignableToAfterCast() { doTest(); }
public void testInstanceMethodParametersFromStaticContext() { doTest(); }
@@ -601,6 +644,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testVoidCast() { doAntiTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNoGenericMethodAutoInsertion() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "valueOf");
@@ -610,8 +654,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testIntPlusLongNotDouble() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNestedAssignments() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
public void testAfterNewInTernary() { doTest(); }
public void testSuggestAnythingWhenWildcardExpected() {
@@ -627,6 +673,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertEquals("[]{...} (default package)", LookupElementPresentation.renderElement(myItems[2]).getTailText());
}
@NeedsIndicesState.StandardLibraryIndices
public void testNewVararg2() {
configureByTestName();
assertStringItems("String", "String", "String");
@@ -652,8 +699,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testDefaultAnnoParam() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNewWithTypeParameterErasure() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEverythingDoubles() {
configureByTestName();
assertStringItems("hashCode", "indexOf", "lastIndexOf", "size");
@@ -692,8 +741,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testDefaultAnnoMethodValue() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNewAnonymousFunction() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNewRunnableInsideMethod() {
CommonCodeStyleSettings settings = getCodeStyleSettings();
boolean lParenOnNextLine = settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE;
@@ -705,6 +756,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNewRunnableInsideMethodMultiParams() {
CommonCodeStyleSettings settings = getCodeStyleSettings();
boolean lParenOnNextLine = settings.CALL_PARAMETERS_LPAREN_ON_NEXT_LINE;
@@ -720,6 +772,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
public void testUseIntConstantsFromTargetClass() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testUseObjectConstantsFromTargetClass() { doTest(); }
public void testUseIntConstantsFromTargetClassReturnValue() { doTest(); }
public void testUseIntConstantsFromConstructedClass() { doTest(); }
@@ -731,6 +784,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoSemicolonInsideParentheses() { doTest(); }
public void testAssignFromTheSameFieldOfAnotherObject() {
@@ -759,6 +813,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testCastToArray() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testCommaDoublePenetration() {
doFirstItemTest(',');
}
@@ -818,11 +873,13 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByTestName();
}
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestTypeParametersInTypeArgumentList() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "T", "String");
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testWrongAnonymous() {
configureByTestName();
select();
@@ -833,6 +890,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doActionTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteral() {
doActionTest();
assertStringItems("String.class");
@@ -846,39 +904,49 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertInstanceOf(item.getPsiElement(), PsiClass.class);
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoClassLiteral() {
doActionTest();
assertStringItems("Object.class", "getClass", "forName", "forName");
}
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteralInAnno2() {
doItemTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteralInheritors() {
doItemTest();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testInsertOverride() {
JavaCodeStyleSettings styleSettings = JavaCodeStyleSettings.getInstance(getProject());
styleSettings.INSERT_OVERRIDE_ANNOTATION = true;
doItemTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testForeach() {
doActionTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testIDEADEV2626() {
doItemTest();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testDontSuggestWildcardGenerics() { doItemTest(); }
public void testCastWith2TypeParameters() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteralInArrayAnnoInitializer() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testClassLiteralInArrayAnnoInitializer2() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testAnnotation() {
configureByTestName();
assertStringItems("ElementType.ANNOTATION_TYPE", "ElementType.CONSTRUCTOR",
@@ -887,10 +955,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
"ElementType.TYPE" /*, "ElementType.TYPE_PARAMETER", "ElementType.TYPE_USE"*/);
}
@NeedsIndicesState.StandardLibraryIndices
public void testAnnotation2() {
configureByTestName();
assertStringItems("RetentionPolicy.CLASS", "RetentionPolicy.RUNTIME", "RetentionPolicy.SOURCE");
}
@NeedsIndicesState.StandardLibraryIndices
public void testAnnotation2_2() {
configureByTestName();
assertSameElements(myFixture.getLookupElementStrings(), "RetentionPolicy.CLASS", "RetentionPolicy.SOURCE", "RetentionPolicy.RUNTIME");
@@ -918,6 +988,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("CONNECTION", "NO_CONNECTION");
}
@NeedsIndicesState.StandardLibraryIndices
public void testAnnotation6() {
configureByTestName();
@@ -931,6 +1002,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testIDEADEV5150() {
doTest('\n');
}
@@ -943,11 +1015,14 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testTypeArgs2() {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testTypeArgsOverwrite() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testIfConditionExpectedType() { doTest(); }
public void testUnboundTypeArgs() { doTest(); }
@@ -959,6 +1034,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
public void testExcessiveTail() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testSeveralTypeArguments() { doTest(); }
public void testSeveralTypeArgumentsSomeUnknown() { doTest(); }
@@ -970,8 +1046,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doFirstItemTest(Lookup.REPLACE_SELECT_CHAR);
}
@NeedsIndicesState.StandardLibraryIndices
public void testConstructorArgsSmartEnter() { doTest(Lookup.COMPLETE_STATEMENT_SELECT_CHAR); }
@NeedsIndicesState.StandardLibraryIndices
public void testIDEADEV13148() {
configureByFile("/IDEADEV13148.java");
assertStringItems("false", "true"); //todo don't suggest boolean literals in synchronized
@@ -986,32 +1064,41 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoCommaBeforeVarargs() { doTest(); }
public void testEnumField() {
doItemTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testEnumField1() {
configureByTestName();
checkResultByTestName();
assertEquals(4, myItems.length);
}
@NeedsIndicesState.StandardLibraryIndices
public void testInsertTypeParametersOnImporting() { doTest('\n'); }
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListInReturn() { doItemTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListInReturn2() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListInReturnTernary() { doItemTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListBeforeSemicolon() { doItemTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEmptyListWithCollectionsPrefix() { doItemTest(); }
public void testForeachLoopVariableInIterableExpression() { doAntiTest(); }
@NeedsIndicesState.FullIndices
public void testStaticallyImportedMagicMethod() {
configureByTestName();
assertStringItems("foo");
@@ -1021,21 +1108,29 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void _testCallVarargArgument() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testTabToReplaceClassKeyword() {
configureByTestName();
selectItem(myItems[0], Lookup.REPLACE_SELECT_CHAR);
checkResultByTestName();
}
@NeedsIndicesState.StandardLibraryIndices
public void testNoTypeParametersForToArray() {
doTest();
}
@NeedsIndicesState.FullIndices
public void testStaticallyImportedField() { doTest('\n'); }
@NeedsIndicesState.FullIndices
public void testSiblingOfAStaticallyImportedField() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testPrimitiveArrayClassInMethod() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testPrimitiveClassInAnno() { doTest(); }
@NeedsIndicesState.FullIndices
public void testNewInnerClassOfSuper() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testAssertThatMatcher() { doTest(); }
public void testInferFromCall() {
@@ -1080,12 +1175,15 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
"}}");
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNewAbstractInsideAnonymous() { doTest(); }
public void testFilterPrivateConstructors() { doAntiTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExplicitMethodTypeParametersQualify() { doTest(); }
public void testExplicitMethodTypeParametersOverZealous() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExplicitMethodTypeParametersFromSuperClass() { doTest(); }
public void testWildcardedInstanceof() { doTest(); }
@@ -1106,6 +1204,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("Bar", "Goo");
}
@NeedsIndicesState.SmartMode(reason = "AbstractExpectedTypeSkipper works in smart mode only")
public void testAutoImportExpectedType() {
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
@@ -1119,25 +1218,32 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNoWrongSubstitutorFromStats() {
doTest();
FileDocumentManager.getInstance().saveDocument(myFixture.getEditor().getDocument());
doTest(); // stats are changed now
}
@NeedsIndicesState.StandardLibraryIndices
public void testCommonPrefixWithSelection() {
doItemTest();
}
@NeedsIndicesState.SmartMode(reason = "For now ConstructorInsertHandler.createOverrideRunnable doesn't work in dumb mode")
public void testNewAbstractClassWithConstructorArgs() {
doItemTest();
}
public void testArrayInitializerBeforeVarargs() { doTest(); }
@NeedsIndicesState.FullIndices
public void testDuplicateMembersFromSuperClass() { doTest(); }
public void testInnerAfterNew() { doTest(); }
@NeedsIndicesState.FullIndices
public void testOuterAfterNew() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testEverythingInStringConcatenation() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testGetClassWhenClassExpected() { doTest(); }
public void testMemberImportStatically() {
@@ -1156,11 +1262,13 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertStringItems("Foo");
}
@NeedsIndicesState.FullIndices
public void testDuplicateMembersFromSuperClassInAnotherFile() {
myFixture.addClass("class Super { public static final Super FOO = null; }");
doTest();
}
@NeedsIndicesState.StandardLibraryIndices
public void testInsideGenericClassLiteral() {
configureByTestName();
assertStringItems("String.class", "StringBuffer.class", "StringBuilder.class");
@@ -1170,6 +1278,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doActionTest();
}
@NeedsIndicesState.FullIndices
public void testInnerClassImports() {
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
settings.INSERT_INNER_CLASS_IMPORTS = true;
@@ -1189,20 +1298,24 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByTestName();
}
@NeedsIndicesState.FullIndices
public void testQualifiedAfterNew() {
myFixture.addClass("package foo; public interface Foo<T> {}");
myFixture.addClass("package bar; public class Bar implements foo.Foo {}");
doTest();
}
@NeedsIndicesState.FullIndices
public void testAfterQualifiedNew() {
myFixture.addClass("class Aa { public class B { } }");
doTest();
}
@NeedsIndicesState.FullIndices
public void testTabAfterNew() {
doFirstItemTest('\t');
}
@NeedsIndicesState.StandardLibraryIndices
public void testSuggestMethodReturnType() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "Serializable", "CharSequence", "Object");
@@ -1213,12 +1326,14 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
assertOrderedEquals(myFixture.getLookupElementStrings(), "Object");
}
@NeedsIndicesState.FullIndices
public void testSuggestCastReturnTypeByCalledMethod() { doTest(); }
public void testOnlyInterfacesInImplements() { doTest(); }
public void testNonStaticField() { doAntiTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testLocalClassInExpectedTypeArguments() { doTest(); }
private void doActionTest() {
@@ -1288,6 +1403,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
@NeedsIndicesState.StandardLibraryIndices(reason = "On empty indices 'get2' is filtered out by unmatching type in ReferenceExpressionCompletionContributor.addSmartReferenceSuggestions")
public void testOnlyCompatibleTypes() {
configureByTestName();
assertOrderedEquals(myFixture.getLookupElementStrings(), "get2");
@@ -1295,6 +1411,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testQualifyOuterClassCall() { doActionTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testExpressionSubtypesInCast() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "String", "StringBuffer", "StringBuilder");
@@ -1302,6 +1419,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testStaticBuilder() { doTest(); }
public void testStaticBuilderWithArguments() { doTest(); }
@NeedsIndicesState.FullIndices
public void testStaticBuilderWithInterfaceAndGenerics() { doTest(); }
public void testStaticBuilderWithGenerics() {
@@ -1311,20 +1429,26 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
checkResultByTestName();
}
@NeedsIndicesState.StandardLibraryIndices
public void testFreeGenericsAfterClassLiteral() {
configureByTestName();
myFixture.assertPreferredCompletionItems(0, "String.class", "tryCast");
}
@NeedsIndicesState.StandardLibraryIndices
public void testNewHashMapTypeArguments() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNewMapTypeArguments() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNewMapObjectTypeArguments() { doTest(); }
@NeedsIndicesState.StandardLibraryIndices
public void testNoUnrelatedMethodSuggestion() {
configureByTestName();
assertOrderedEquals(myFixture.getLookupElementStrings(), "this");
}
@NeedsIndicesState.FullIndices
public void testLog4jLevel() {
myFixture.addClass("package org.apache.log4j; " +
"public class Category { " +
@@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.completion;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
import com.intellij.testFramework.NeedsIndicesState;
public class TabCompletionTest extends LightFixtureCompletionTestCase {
@Override
@@ -34,16 +35,19 @@ public class TabCompletionTest extends LightFixtureCompletionTestCase {
checkResultJava();
}
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for txt, properties and xml")
public void testTabInXml() {
configureByFile("TabInXml.xml");
checkResultByFile("TabInXml_After.xml");
}
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for txt, properties and xml")
public void testTabInXml2() {
configureByFile("TabInXml2.xml");
checkResultByFile("TabInXml2_After.xml");
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodCallBeforeAnnotation() {
myFixture.configureByFile("MethodCallBeforeAnnotation.java");
myFixture.completeBasic();
@@ -51,6 +55,7 @@ public class TabCompletionTest extends LightFixtureCompletionTestCase {
checkResultJava();
}
@NeedsIndicesState.StandardLibraryIndices
public void testMethodCallBeforeAnnotation2() {
myFixture.configureByFile("MethodCallBeforeAnnotation2.java");
myFixture.completeBasic();
@@ -58,6 +63,7 @@ public class TabCompletionTest extends LightFixtureCompletionTestCase {
checkResultJava();
}
@NeedsIndicesState.StandardLibraryIndices
public void testReplaceStringLiteral() {
configureByTestName();
checkResultJava();
@@ -19,6 +19,7 @@ import com.intellij.JavaTestUtil
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
import com.intellij.testFramework.NeedsIndicesState
import groovy.transform.CompileStatic
@CompileStatic
@@ -40,6 +41,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java")
}
@NeedsIndicesState.FullIndices
void testInputMethodEventVariable() throws Exception {
myFixture.addClass("package java.awt.event; public interface InputMethodEvent {}")
@@ -47,6 +49,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java")
}
@NeedsIndicesState.StandardLibraryIndices
void testLocals1() throws Exception {
doSelectTest("TestSource1.java", "TestResult1.java")
}
@@ -66,6 +69,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
doTest("TestSource3.java", "TestResult3.java")
}
@NeedsIndicesState.StandardLibraryIndices
void testLocals4() throws Exception {
doSelectTest("TestSource4.java", "TestResult4.java")
}
@@ -115,6 +119,7 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
doTest("TestSource8.java", "TestResult8.java")
}
@NeedsIndicesState.StandardLibraryIndices(reason = "With empty indices 'Object' may be considered variable name, and instanceof is ok here; Object is not resolved thus not replaced with 'o'")
void testUnresolvedReference() throws Exception {
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java")
assertStringItems("o", "psiClass")
@@ -203,6 +208,7 @@ class Foo {
myFixture.assertPreferredCompletionItems 0, 'total'
}
@NeedsIndicesState.StandardLibraryIndices(reason = "On empty indices String is not resolved and replaced with name 's', filtered out in JavaMemberNameCompletionContributor.getOverlappedNameVersions for being short")
void testInitializerMatters() throws Exception {
myFixture.configureByText(JavaFileType.INSTANCE, "class Foo {{ String f<caret>x = getFoo(); }; String getFoo() {}; }")
complete()
@@ -244,11 +250,13 @@ class Foo {
checkResultByFile(FILE_PREFIX + getTestName(false) + "_after.java")
}
@NeedsIndicesState.StandardLibraryIndices(reason = "On empty indices String is not resolved and replaced with name 's', filtered out in JavaMemberNameCompletionContributor.getOverlappedNameVersions for being short")
void testConstructorParameterName() {
configure()
assertStringItems("color")
}
@NeedsIndicesState.StandardLibraryIndices(reason = "On empty indices String is not resolved and replaced with name 's', filtered out in JavaMemberNameCompletionContributor.getOverlappedNameVersions for being short; P is from PARAMETER_NAME_PREFIX")
void testConstructorParameterNameWithPrefix() {
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
settings.FIELD_NAME_PREFIX = "my"
@@ -298,6 +306,7 @@ class Rectangle2D {
myFixture.assertPreferredCompletionItems 0, 'aDouble', 'rectangle2D'
}
@NeedsIndicesState.StandardLibraryIndices
void "test suggest field-shadowing parameter name"() {
myFixture.configureByText 'a.java', '''
class FooFoo {
@@ -21,6 +21,7 @@ import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl;
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
@@ -34,6 +35,7 @@ public class WordCompletionTest extends NormalCompletionTestCase {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/word/";
}
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for txt, properties and xml")
public void testKeyWordCompletion() {
configureByFile("1.txt");
checkResultByFile("1_after.txt");
@@ -107,6 +109,7 @@ public class WordCompletionTest extends NormalCompletionTestCase {
public void testTextInComment() { doTest(); }
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for txt, properties and xml")
public void testDollarsInPrefix() {
configureByFile(getTestName(false) + ".txt");
checkResultByFile(getTestName(false) + "_after.txt");
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.NeedsIndicesState;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import java.io.IOException;
@@ -28,6 +29,7 @@ import java.io.IOException;
*/
public class SPICompletionTest extends LightJavaCodeInsightFixtureTestCase {
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for SPI")
public void testQualifiedReference() {
myFixture.addClass("package com.foo; public class Interface {}");
myFixture.addClass("package com.foo; public class Implementation extends Interface {}");
@@ -37,6 +39,7 @@ public class SPICompletionTest extends LightJavaCodeInsightFixtureTestCase {
myFixture.checkResult("com.foo.Implementation");
}
@NeedsIndicesState.SmartMode(reason = "Smart completion in dumb mode is not supported for SPI")
public void testCompletionAfterRenaming() throws IOException {
VirtualFile file = myFixture.addFileToProject("META-INF/services/aaa", "<caret>").getVirtualFile();
myFixture.configureFromExistingVirtualFile(file);
@@ -10,6 +10,7 @@ import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.testFramework.TestIndexingModeSupporter;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
import org.jetbrains.annotations.NonNls;
@@ -20,8 +21,9 @@ import java.io.File;
/**
* @author peter
*/
public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase {
public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase implements TestIndexingModeSupporter {
protected JavaCodeInsightTestFixture myFixture;
private @NotNull IndexingMode myIndexingMode = IndexingMode.SMART;
@NotNull
@Override
@@ -35,6 +37,7 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase {
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
myFixture = JavaIndexingModeCodeInsightTestFixture.Companion.wrapFixture(myFixture, myIndexingMode);
JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
if (toAddSourceRoot()) {
moduleFixtureBuilder.addSourceContentRoot(myFixture.getTempDirPath());
@@ -106,4 +109,14 @@ public abstract class JavaCodeInsightFixtureTestCase extends UsefulTestCase {
protected Module getModule() {
return myFixture.getModule();
}
@Override
public void setIndexingMode(@NotNull IndexingMode mode) {
myIndexingMode = mode;
}
@Override
public @NotNull IndexingMode getIndexingMode() {
return myIndexingMode;
}
}
@@ -0,0 +1,122 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testFramework.fixtures
import com.intellij.openapi.Disposable
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiFile
import com.intellij.testFramework.TestIndexingModeSupporter
open class JavaIndexingModeCodeInsightTestFixture private constructor(private val delegate: JavaCodeInsightTestFixture,
private val indexingMode: TestIndexingModeSupporter.IndexingMode) :
JavaCodeInsightTestFixture by delegate {
companion object {
fun wrapFixture(delegate: JavaCodeInsightTestFixture,
indexingMode: TestIndexingModeSupporter.IndexingMode): JavaCodeInsightTestFixture {
return if (indexingMode === TestIndexingModeSupporter.IndexingMode.SMART) {
delegate
}
else JavaIndexingModeCodeInsightTestFixture(delegate, indexingMode)
}
}
@Throws(Exception::class)
override fun setUp() {
delegate.setUp()
indexingMode.setUpTest(project, testRootDisposable)
}
@Throws(Exception::class)
override fun tearDown() {
delegate.tearDown()
}
private fun ensureIndexingStatus() {
indexingMode.ensureIndexingStatus(project)
}
override fun copyFileToProject(sourceFilePath: String): VirtualFile {
val file = delegate.copyFileToProject(sourceFilePath)
ensureIndexingStatus()
return file
}
override fun copyFileToProject(sourceFilePath: String, targetPath: String): VirtualFile {
val file = delegate.copyFileToProject(sourceFilePath, targetPath)
ensureIndexingStatus()
return file
}
override fun copyDirectoryToProject(sourceFilePath: String, targetPath: String): VirtualFile {
val file = delegate.copyDirectoryToProject(sourceFilePath, targetPath)
ensureIndexingStatus()
return file
}
override fun configureByFile(filePath: String): PsiFile? {
val file = delegate.configureByFile(filePath)
ensureIndexingStatus()
return file
}
override fun configureByFiles(vararg filePaths: String): Array<PsiFile?> {
val files = delegate.configureByFiles(*filePaths)
ensureIndexingStatus()
return files
}
override fun configureByText(fileType: FileType, text: String): PsiFile? {
val file = delegate.configureByText(fileType, text)
ensureIndexingStatus()
return file
}
override fun configureByText(fileName: String, text: String): PsiFile? {
val file = delegate.configureByText(fileName, text)
ensureIndexingStatus()
return file
}
override fun configureFromTempProjectFile(filePath: String): PsiFile? {
val file = delegate.configureFromTempProjectFile(filePath)
ensureIndexingStatus()
return file
}
override fun configureFromExistingVirtualFile(virtualFile: VirtualFile) {
delegate.configureFromExistingVirtualFile(virtualFile)
ensureIndexingStatus()
}
override fun addFileToProject(relativePath: String, fileText: String): PsiFile? {
val file = delegate.addFileToProject(relativePath, fileText)
ensureIndexingStatus()
return file
}
override fun openFileInEditor(file: VirtualFile) {
delegate.openFileInEditor(file)
ensureIndexingStatus()
}
override fun saveText(file: VirtualFile, text: String) {
delegate.saveText(file, text)
ensureIndexingStatus()
}
override fun addClass(classText: String): PsiClass? {
val aClass = delegate.addClass(classText)
ensureIndexingStatus()
return aClass
}
override fun getProjectDisposable(): Disposable {
return delegate.projectDisposable //default method of interface is not delegated by default
}
override fun getTestRootDisposable(): Disposable {
return delegate.testRootDisposable //default method of interface is not delegated by default
}
}
@@ -23,7 +23,7 @@ import java.io.File;
/**
* @author peter
*/
public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase {
public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase implements TestIndexingModeSupporter {
protected static class ProjectDescriptor extends DefaultLightProjectDescriptor {
protected final LanguageLevel myLanguageLevel;
private final boolean myWithAnnotations;
@@ -85,6 +85,8 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
protected JavaCodeInsightTestFixture myFixture;
private @NotNull IndexingMode myIndexingMode = IndexingMode.SMART;
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -93,6 +95,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(getProjectDescriptor());
IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(fixture, getTempDirFixture());
myFixture = JavaIndexingModeCodeInsightTestFixture.Companion.wrapFixture(myFixture, myIndexingMode);
myFixture.setTestDataPath(getTestDataPath());
myFixture.setUp();
@@ -172,4 +175,14 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
public PsiFile createLightFile(String fileName, Language language, String text) {
return PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, language, text, false, true);
}
@Override
public void setIndexingMode(@NotNull IndexingMode mode) {
myIndexingMode = mode;
}
@Override
public @NotNull IndexingMode getIndexingMode() {
return myIndexingMode;
}
}
@@ -26,4 +26,10 @@ public interface DumbUtil {
@ApiStatus.Internal
@ApiStatus.Experimental
@NotNull <T> List<T> filterByDumbAwarenessHonoringIgnoring(@NotNull Collection<? extends T> collection);
/**
* @return true iff one may use file based indices, i.e. project is not in dumb mode, or
* {@link com.intellij.util.indexing.FileBasedIndex#ignoreDumbMode(Runnable, com.intellij.util.indexing.DumbModeAccessType)} was used
*/
boolean mayUseIndices();
}
@@ -16,9 +16,8 @@ import org.jetbrains.annotations.NotNull;
* to check if PSI has changed since they accessed it last time. This can be used to flush and rebuild various internal caches.
* See {@link #getModificationCount()}
*
* <li/> Make a {@link CachedValue} instance dependent on a specific PSI modification tracker.
* To achieve that, one should can one of the constants in this interface as {@link CachedValueProvider.Result}
* dependencies.
* <li/> Make a {@link CachedValue} instance outdated on every physical PSI change.
* To achieve that, one should use {@link #MODIFICATION_COUNT} as {@link CachedValueProvider.Result} dependency.
*
* <li/> Subscribe to any PSI change (for example, to drop caches in the listener manually).
* See {@link PsiModificationTracker.Listener}
@@ -19,6 +19,7 @@ import com.intellij.openapi.progress.impl.CoreProgressManager;
import com.intellij.openapi.progress.util.ProgressWrapper;
import com.intellij.openapi.progress.util.TooManyUsagesStatus;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.DumbUtil;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
@@ -516,7 +517,7 @@ public class PsiSearchHelperImpl implements PsiSearchHelper {
ApplicationUtil.tryRunReadAction(() -> {
Project project = myManager.getProject();
if (project.isDisposed()) throw new ProcessCanceledException();
if (DumbService.isDumb(project) && FileBasedIndex.getInstance().getCurrentDumbModeAccessType() == null) {
if (!DumbUtil.getInstance(project).mayUseIndices()) {
throw ApplicationUtil.CannotRunReadActionException.create();
}
@@ -386,7 +386,10 @@ public final class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesU
@Override
public void filePropertiesChanged(@NotNull final VirtualFile file) {
ApplicationManager.getApplication().assertReadAccessAllowed();
((FileBasedIndexImpl)FileBasedIndex.getInstance()).requestReindex(file, false);
FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
if (fileBasedIndex instanceof FileBasedIndexImpl) {
((FileBasedIndexImpl) fileBasedIndex).requestReindex(file, false);
}
for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
reloadPsi(file, project);
}
@@ -301,7 +301,7 @@ public final class StubIndexImpl extends StubIndexEx implements PersistentStateC
IdIterator ids = getContainingIds(indexKey, key, project, idFilter, scope);
PersistentFS fs = PersistentFS.getInstance();
IntPredicate accessibleFileFilter = ((FileBasedIndexImpl)FileBasedIndex.getInstance()).getAccessibleFileIdFilter(project);
IntPredicate accessibleFileFilter = ((FileBasedIndexEx)FileBasedIndex.getInstance()).getAccessibleFileIdFilter(project);
// already ensured up-to-date in getContainingIds() method
try {
while (ids.hasNext()) {
@@ -450,13 +450,13 @@ public final class StubIndexImpl extends StubIndexEx implements PersistentStateC
final @NotNull Project project,
@Nullable IdFilter idFilter,
final @Nullable GlobalSearchScope scope) {
final FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
final FileBasedIndexEx fileBasedIndex = (FileBasedIndexEx)FileBasedIndex.getInstance();
ID<Integer, SerializedStubTree> stubUpdatingIndexId = StubUpdatingIndex.INDEX_ID;
final UpdatableIndex<Key, Void, FileContent> index = getIndex(indexKey); // wait for initialization to finish
if (index == null || !fileBasedIndex.ensureUpToDate(stubUpdatingIndexId, project, scope, null)) return IdIterator.EMPTY;
if (idFilter == null) {
idFilter = ((FileBasedIndexImpl)FileBasedIndex.getInstance()).projectIndexableFiles(project);
idFilter = ((FileBasedIndexEx)FileBasedIndex.getInstance()).projectIndexableFiles(project);
}
UpdatableIndex<Integer, SerializedStubTree, FileContent> stubUpdatingIndex = fileBasedIndex.getIndex(stubUpdatingIndexId);
@@ -717,7 +717,7 @@ public final class StubIndexImpl extends StubIndexEx implements PersistentStateC
}
static UpdatableIndex<Integer, SerializedStubTree, FileContent> getStubUpdatingIndex() {
return ((FileBasedIndexImpl)FileBasedIndex.getInstance()).getIndex(StubUpdatingIndex.INDEX_ID);
return ((FileBasedIndexEx)FileBasedIndex.getInstance()).getIndex(StubUpdatingIndex.INDEX_ID);
}
private static final class CompositeKey<K> {
@@ -51,7 +51,7 @@ public abstract class FileBasedIndexEx extends FileBasedIndex {
public abstract ProjectIndexableFilesFilter projectIndexableFiles(@Nullable Project project);
@ApiStatus.Internal
abstract <K, V> UpdatableIndex<K, V, FileContent> getIndex(ID<K, V> indexId);
public abstract <K, V> UpdatableIndex<K, V, FileContent> getIndex(ID<K, V> indexId);
@ApiStatus.Internal
public abstract void waitUntilIndicesAreInitialized();
@@ -276,7 +276,10 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
static class MyShutDownTask implements Runnable {
@Override
public void run() {
((FileBasedIndexImpl)FileBasedIndex.getInstance()).performShutdown(false);
FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
if (fileBasedIndex instanceof FileBasedIndexImpl) {
((FileBasedIndexImpl)fileBasedIndex).performShutdown(false);
}
}
}
@@ -19,15 +19,19 @@ public class DumbUtilImpl implements DumbUtil {
@Override
@Contract(pure = true)
public @NotNull <T> List<T> filterByDumbAwarenessHonoringIgnoring(@NotNull Collection<? extends T> collection) {
DumbService service = DumbService.getInstance(myProject);
if (!service.isDumb() || FileBasedIndex.getInstance().getCurrentDumbModeAccessType() == null) {
return service.filterByDumbAwareness(collection);
if (!mayUseIndices()) {
return DumbService.getInstance(myProject).filterByDumbAwareness(collection);
}
if (collection instanceof List) {
return (List<T>)collection;
return (List<T>) collection;
}
return new ArrayList<>(collection);
}
@Override
public boolean mayUseIndices() {
return !DumbService.getInstance(myProject).isDumb() || FileBasedIndex.getInstance().getCurrentDumbModeAccessType() != null;
}
}
@@ -0,0 +1,362 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testFramework;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Processor;
import com.intellij.util.indexing.*;
import com.intellij.util.indexing.impl.AbstractUpdateData;
import com.intellij.util.indexing.roots.IndexableFilesProvider;
import com.intellij.util.indexing.snapshot.SnapshotSingleValueIndexStorage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.IntPredicate;
public class EmptyFileBasedIndex extends FileBasedIndexEx {
private static final ThreadLocal<DumbModeAccessType> ourDumbModeAccessType = new ThreadLocal<>();
@Override
public void iterateIndexableFiles(@NotNull ContentIterator processor, @NotNull Project project, @Nullable ProgressIndicator indicator) {
}
@Override
public @Nullable VirtualFile getFileBeingCurrentlyIndexed() {
return null;
}
@Override
public DumbModeAccessType getCurrentDumbModeAccessType() {
return ourDumbModeAccessType.get();
}
@Override
public void registerIndexableSet(@NotNull IndexableFileSet set, @Nullable Project project) {
}
@Override
public void removeIndexableSet(@NotNull IndexableFileSet set) {
}
@Override
public VirtualFile findFileById(Project project, int id) {
return null;
}
@Override
public void requestRebuild(@NotNull ID<?, ?> indexId) {
super.requestRebuild(indexId);
}
@Override
public @NotNull <K, V> List<V> getValues(@NotNull ID<K, V> indexId, @NotNull K dataKey, @NotNull GlobalSearchScope filter) {
return Collections.emptyList();
}
@Override
public @NotNull <K, V> Collection<VirtualFile> getContainingFiles(@NotNull ID<K, V> indexId,
@NotNull K dataKey,
@NotNull GlobalSearchScope filter) {
return Collections.emptyList();
}
@Override
public <K, V> boolean processValues(@NotNull ID<K, V> indexId,
@NotNull K dataKey,
@Nullable VirtualFile inFile,
@NotNull ValueProcessor<? super V> processor,
@NotNull GlobalSearchScope filter) {
return true;
}
@Override
public <K, V> boolean processValues(@NotNull ID<K, V> indexId,
@NotNull K dataKey,
@Nullable VirtualFile inFile,
@NotNull ValueProcessor<? super V> processor,
@NotNull GlobalSearchScope filter,
@Nullable IdFilter idFilter) {
return super.processValues(indexId, dataKey, inFile, processor, filter, idFilter);
}
@Override
public <K, V> long getIndexModificationStamp(@NotNull ID<K, V> indexId, @NotNull Project project) {
return 0;
}
@Override
public <K, V> boolean processFilesContainingAllKeys(@NotNull ID<K, V> indexId,
@NotNull Collection<? extends K> dataKeys,
@NotNull GlobalSearchScope filter,
@Nullable Condition<? super V> valueChecker,
@NotNull Processor<? super VirtualFile> processor) {
return true;
}
@Override
public @NotNull <K> Collection<K> getAllKeys(@NotNull ID<K, ?> indexId, @NotNull Project project) {
return Collections.emptyList();
}
@Override
public <K> void ensureUpToDate(@NotNull ID<K, ?> indexId, @Nullable Project project, @Nullable GlobalSearchScope filter) {
}
@Override
public void requestRebuild(@NotNull ID<?, ?> indexId, @NotNull Throwable throwable) {
}
@Override
public <K> void scheduleRebuild(@NotNull ID<K, ?> indexId, @NotNull Throwable e) {
}
@Override
public void requestReindex(@NotNull VirtualFile file) {
}
@Override
public <K, V> boolean getFilesWithKey(@NotNull ID<K, V> indexId,
@NotNull Set<? extends K> dataKeys,
@NotNull Processor<? super VirtualFile> processor,
@NotNull GlobalSearchScope filter) {
return true;
}
@Override
public void ignoreDumbMode(@NotNull Runnable command, @NotNull DumbModeAccessType dumbModeAccessType) {
ignoreDumbMode(dumbModeAccessType, () -> {
command.run();
return null;
});
}
@Override
public <T, E extends Throwable> T ignoreDumbMode(@NotNull DumbModeAccessType dumbModeAccessType,
@NotNull ThrowableComputable<T, E> computable) throws E {
boolean setAccessType = true;
DumbModeAccessType currentAccessType = ourDumbModeAccessType.get();
if (currentAccessType != null) {
if (currentAccessType == dumbModeAccessType) {
setAccessType = false;
}
else {
throw new AssertionError(
"Reentrant dumb mode ignorance. Current mode: " + currentAccessType + ", Requested mode: " + dumbModeAccessType);
}
}
if (setAccessType) ourDumbModeAccessType.set(dumbModeAccessType);
try {
return computable.compute();
}
finally {
if (setAccessType) ourDumbModeAccessType.set(null);
}
}
@Override
public <K> boolean processAllKeys(@NotNull ID<K, ?> indexId, @NotNull Processor<? super K> processor, @Nullable Project project) {
return true;
}
@Override
public <K> boolean processAllKeys(@NotNull ID<K, ?> indexId,
@NotNull Processor<? super K> processor,
@NotNull GlobalSearchScope scope,
@Nullable IdFilter idFilter) {
return super.processAllKeys(indexId, processor, scope, idFilter);
}
@Override
public @NotNull <K, V> Map<K, V> getFileData(@NotNull ID<K, V> id, @NotNull VirtualFile virtualFile, @NotNull Project project) {
return Collections.emptyMap();
}
@Override
public void invalidateCaches() {
}
@Override
public @NotNull IntPredicate getAccessibleFileIdFilter(@Nullable Project project) {
return value -> false;
}
@Override
public ProjectIndexableFilesFilter projectIndexableFiles(@Nullable Project project) {
return null;
}
@Override
public void waitUntilIndicesAreInitialized() {
}
@Override
public <K> boolean ensureUpToDate(@NotNull ID<K, ?> indexId,
@Nullable Project project,
@Nullable GlobalSearchScope filter,
@Nullable VirtualFile restrictedFile) {
return true;
}
@Override
public @NotNull List<IndexableFilesProvider> getOrderedIndexableFilesProviders(@NotNull Project project) {
return super.getOrderedIndexableFilesProviders(project);
}
@Override
public <K, V> UpdatableIndex<K, V, FileContent> getIndex(ID<K, V> indexId) {
return EmptyIndex.getInstance();
}
private static class EmptyIndex<Key, Value> implements UpdatableIndex<Key, Value, FileContent> {
@SuppressWarnings("rawtypes")
private static final EmptyIndex INSTANCE = new EmptyIndex();
private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock();
@SuppressWarnings("unchecked")
static <Key, Value> EmptyIndex<Key, Value> getInstance() {
return INSTANCE;
}
@Override
public boolean processAllKeys(@NotNull Processor<? super Key> processor,
@NotNull GlobalSearchScope scope,
@Nullable IdFilter idFilter) {
return true;
}
@Override
public @NotNull ReadWriteLock getLock() {
return myLock;
}
@Override
public @NotNull Map<Key, Value> getIndexedFileData(int fileId) {
return Collections.emptyMap();
}
@Override
public void setIndexedStateForFile(int fileId, @NotNull IndexedFile file) {
throw new UnsupportedOperationException();
}
@Override
public void resetIndexedStateForFile(int fileId) {
throw new UnsupportedOperationException();
}
@Override
public @NotNull FileIndexingState getIndexingStateForFile(int fileId, @NotNull IndexedFile file) {
throw new UnsupportedOperationException();
}
@Override
public long getModificationStamp() {
return 0;
}
@Override
public void removeTransientDataForFile(int inputId) {
}
@Override
public void removeTransientDataForKeys(int inputId, @NotNull Collection<? extends Key> keys) {
}
@Override
public @NotNull IndexExtension<Key, Value, FileContent> getExtension() {
throw new UnsupportedOperationException();
}
@Override
public void updateWithMap(@NotNull AbstractUpdateData<Key, Value> updateData) {
throw new UnsupportedOperationException();
}
@Override
public void setBufferingEnabled(boolean enabled) {
}
@Override
public void cleanupMemoryStorage() {
}
@Override
public void cleanupForNextTest() {
}
@Override
public void dumpStatistics() {
}
@Override
public @NotNull ValueContainer<Value> getData(@NotNull Key key) {
return SnapshotSingleValueIndexStorage.empty();
}
@Override
public @NotNull Computable<Boolean> mapInputAndPrepareUpdate(int inputId, @Nullable FileContent content) {
throw new UnsupportedOperationException();
}
@Override
public void flush() {
}
@Override
public void clear() {
}
@Override
public void dispose() {
}
private static final Lock NO_LOCK = new Lock() {
@Override
public void lock() {
}
@Override
public void lockInterruptibly() {
}
@Override
public boolean tryLock() {
return false;
}
@Override
public boolean tryLock(long time, @NotNull TimeUnit unit) {
return false;
}
@Override
public void unlock() {
}
@NotNull
@Override
public java.util.concurrent.locks.Condition newCondition() {
throw new UnsupportedOperationException();
}
};
}
}
@@ -54,10 +54,11 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTestCase {
public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTestCase implements TestIndexingModeSupporter {
private Editor myEditor;
private PsiFile myFile;
private VirtualFile myVFile;
private TestIndexingModeSupporter.IndexingMode myIndexingMode = IndexingMode.SMART;
@Override
protected void runTest() throws Throwable {
@@ -176,6 +177,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
}
EditorTestUtil.setCaretsAndSelection(getEditor(), caretsState);
setupEditorForInjectedLanguage();
myIndexingMode.ensureIndexingStatus(getProject());
return document;
});
}
@@ -192,6 +194,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
((EditorImpl)editor).setCaretActive();
EditorTestUtil.setCaretsAndSelection(editor, caretsState);
myIndexingMode.ensureIndexingStatus(getProject());
return editor;
});
}
@@ -203,6 +206,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
DaemonCodeAnalyzer.getInstance(getProject()).restart();
assertNotNull(editor);
((EditorImpl)editor).setCaretActive();
myIndexingMode.ensureIndexingStatus(getProject());
return editor;
}
@@ -215,7 +219,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
myEditor = createSaveAndOpenFile(relativePath, fileText);
myVFile = FileDocumentManager.getInstance().getFile(getEditor().getDocument());
myFile = getPsiManager().findFile(myVFile);
myIndexingMode.ensureIndexingStatus(getProject());
return getEditor().getDocument();
}
@@ -223,6 +227,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
protected Editor createSaveAndOpenFile(@NotNull String relativePath, @NotNull String fileText) {
Editor editor = createEditor(VfsTestUtil.createFile(getSourceRoot(), relativePath, fileText));
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
myIndexingMode.ensureIndexingStatus(getProject());
return editor;
}
@@ -259,9 +264,16 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
FileEditorManager.getInstance(getProject()).closeFile(myVFile);
myVFile.delete(getProject());
});
myIndexingMode.ensureIndexingStatus(getProject());
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
myIndexingMode.setUpTest(getProject(), getTestRootDisposable());
}
@Override
protected void tearDown() throws Exception {
try {
@@ -657,7 +669,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
* @see FileBasedTestCaseHelperEx
* @Parameterized.Parameter fields are injected on parameterized test creation.
*/
@Parameterized.Parameter()
@Parameterized.Parameter
public String myFileSuffix;
/**
@@ -748,6 +760,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
invokeTestRunnable(() -> {
try {
setUp();
myIndexingMode.ensureIndexingStatus(getProject());
}
catch (Throwable e) {
throwables[0] = e;
@@ -804,4 +817,14 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
protected void setVFile(VirtualFile virtualFile) {
myVFile = virtualFile;
}
@Override
public void setIndexingMode(@NotNull IndexingMode mode) {
myIndexingMode = mode;
}
@Override
public @NotNull IndexingMode getIndexingMode() {
return myIndexingMode;
}
}
@@ -0,0 +1,49 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testFramework;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public interface NeedsIndicesState {
/**
* Used to mark those completion tests that are not expected to work in dumb mode even with full indices.
* Please also provide reason the test fails when you use this annotation.
*
* @see com.intellij.java.codeInsight.completion.JavaCompletionTestSuite
* @see com.jetbrains.php.slowTests.PhpDumbCompletionTestSuite
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface SmartMode {
String reason();
}
/**
* Used to mark those completion tests that are not expected to work in dumb mode
* with runtime-only indices (of JDK, php standard libraries, etc.), but work with full indices
*
* @see com.intellij.java.codeInsight.completion.JavaCompletionTestSuite
* @see com.jetbrains.php.slowTests.PhpDumbCompletionTestSuite
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@interface FullIndices {
String reason() default "";
}
/**
* Used to mark those completion tests that are not expected to work in dumb mode with empty indices,
* but works with indices of standard library only (of JDK, php standard libraries, etc.)
*
* @see com.intellij.java.codeInsight.completion.JavaCompletionTestSuite
* @see com.jetbrains.php.slowTests.PhpDumbCompletionTestSuite
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@interface StandardLibraryIndices {
String reason() default "";
}
}
@@ -0,0 +1,157 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testFramework;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbServiceImpl;
import com.intellij.openapi.project.Project;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.UnindexedFilesUpdater;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import org.junit.internal.MethodSorter;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import static junit.framework.TestSuite.warning;
public interface TestIndexingModeSupporter {
enum IndexingMode {
SMART {
@Override
public void setUpTest(@NotNull Project project, @NotNull Disposable testRootDisposable) {}
}, DUMB_FULL_INDEX {
@Override
public void setUpTest(@NotNull Project project, @NotNull Disposable testRootDisposable) {
indexEverythingAndBecomeDumb(project);
}
@Override
public void ensureIndexingStatus(@NotNull Project project) {
DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project);
ApplicationManager.getApplication().invokeAndWait(() -> {
dumbService.setDumb(false);
dumbService.queueTask(new UnindexedFilesUpdater(project));
dumbService.setDumb(true);
});
}
}, DUMB_RUNTIME_ONLY_INDEX {
@Override
public void setUpTest(@NotNull Project project, @NotNull Disposable testRootDisposable) {
becomeDumb(project);
}
}, DUMB_EMPTY_INDEX {
@Override
public void setUpTest(@NotNull Project project, @NotNull Disposable testRootDisposable) {
ServiceContainerUtil
.replaceService(ApplicationManager.getApplication(), FileBasedIndex.class, new EmptyFileBasedIndex(), testRootDisposable);
becomeDumb(project);
}
};
public abstract void setUpTest(@NotNull Project project,
@NotNull Disposable testRootDisposable);
public void ensureIndexingStatus(@NotNull Project project) {
}
private static void becomeDumb(@NotNull Project project) {
ApplicationManager.getApplication().invokeAndWait(() -> {
DumbServiceImpl.getInstance(project).setDumb(true);
});
}
private static void indexEverythingAndBecomeDumb(@NotNull Project project) {
DumbServiceImpl dumbService = DumbServiceImpl.getInstance(project);
ApplicationManager.getApplication().invokeAndWait(() -> {
dumbService.setDumb(false);
dumbService.queueTask(new UnindexedFilesUpdater(project));
dumbService.setDumb(true);
});
}
}
void setIndexingMode(@NotNull IndexingMode mode);
@NotNull IndexingMode getIndexingMode();
static void addTest(@NotNull Class<? extends TestIndexingModeSupporter> aClass,
@NotNull TestIndexingModeSupporter.IndexingModeTestHandler handler,
@NotNull TestSuite parentSuite) {
if (handler.shouldIgnore(aClass)) return;
try {
TestSuite suite = handler.createTestSuite();
suite.setName(aClass.getSimpleName());
boolean foundTests = false;
Constructor<? extends TestIndexingModeSupporter> constructor = aClass.getConstructor();
for (Method declaredMethod : MethodSorter.getDeclaredMethods(aClass)) {
if (!Modifier.isPublic(declaredMethod.getModifiers())) continue;
String methodName = declaredMethod.getName();
if (!methodName.startsWith("test")) continue;
if (TestFrameworkUtil.isPerformanceTest(methodName, aClass.getName())) continue;
if (handler.shouldIgnore(declaredMethod, aClass)) continue;
TestIndexingModeSupporter aCase = constructor.newInstance();
aCase.setIndexingMode(handler.getIndexingMode());
if (aCase instanceof TestCase) {
TestCase testCase = (TestCase)aCase;
testCase.setName(methodName);
suite.addTest(testCase);
}
else {
parentSuite.addTest(warning(aClass.getName() + "is not a TestSuite"));
}
foundTests = true;
}
if (foundTests) {
parentSuite.addTest(suite);
}
}
catch (NoSuchMethodException e) {
parentSuite.addTest(warning("Failed to find default constructor for " + aClass.getName() + ", see log"));
e.printStackTrace();
}
catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
parentSuite.addTest(warning("Failed to instantiate " + aClass.getName() + ", see log"));
e.printStackTrace();
}
}
abstract class IndexingModeTestHandler {
public final String myTestSuiteName;
public final String myTestNamePrefix;
protected IndexingModeTestHandler(@NotNull String testSuiteName, @NotNull String testNamePrefix) {
myTestSuiteName = testSuiteName;
myTestNamePrefix = testNamePrefix;
}
public TestSuite createTestSuite() {
return new NamedTestSuite(myTestSuiteName, myTestNamePrefix);
}
public abstract boolean shouldIgnore(@NotNull Class<? extends TestIndexingModeSupporter> aClass);
public abstract boolean shouldIgnore(@NotNull Method method,
@NotNull Class<? extends TestIndexingModeSupporter> aClass);
public abstract @NotNull TestIndexingModeSupporter.IndexingMode getIndexingMode();
private static class NamedTestSuite extends TestSuite {
private final String myPrefix;
private NamedTestSuite(String name, String prefix) {
super(name);
myPrefix = prefix;
}
@Override
public void setName(String name) {
super.setName(myPrefix + name);
}
}
}
}
@@ -1121,9 +1121,9 @@ public abstract class UsefulTestCase extends TestCase {
EdtTestUtil.runInEdtAndWait(() -> {
Application app = ApplicationManager.getApplication();
if (app != null && !app.isDisposed()) {
FileBasedIndexImpl index = (FileBasedIndexImpl)app.getServiceIfCreated(FileBasedIndex.class);
if (index != null) {
index.getChangedFilesCollector().waitForVfsEventsExecuted(timeout, timeUnit);
FileBasedIndex index = app.getServiceIfCreated(FileBasedIndex.class);
if (index instanceof FileBasedIndexImpl) {
((FileBasedIndexImpl)index).getChangedFilesCollector().waitForVfsEventsExecuted(timeout, timeUnit);
}
DocumentCommitThread commitThread = (DocumentCommitThread)app.getServiceIfCreated(DocumentCommitProcessor.class);