mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-tests] Convert some tests from Groovy to Java
GitOrigin-RevId: 76852e3d8bcf640e91d2bb47dea6b403a279a70d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0dfd299f9b
commit
ca9047e41d
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.codeInsight.completion
|
||||
|
||||
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.NeedsIndex
|
||||
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
|
||||
|
||||
@CompileStatic
|
||||
class MagicConstantCompletion4Test extends LightJavaCodeInsightFixtureTestCase {
|
||||
LightProjectDescriptor projectDescriptor = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
Sdk getSdk() {
|
||||
return PsiTestUtil.addJdkAnnotations(IdeaTestUtil.mockJdk14)
|
||||
}
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void "test suppress class constants in MagicConstant presence"() {
|
||||
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 {
|
||||
static void foo(Calendar c) {
|
||||
c.setFirstDayOfWeek(<caret>)
|
||||
}
|
||||
}
|
||||
"""
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'FRIDAY', 'MONDAY'
|
||||
assert !(myFixture.lookupElementStrings.contains('JANUARY'))
|
||||
assert !(myFixture.lookupElementStrings.contains('Calendar.JANUARY'))
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
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 org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MagicConstantCompletion4Test extends LightJavaCodeInsightFixtureTestCase {
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void test_suppress_class_constants_in_MagicConstant_presence() {
|
||||
FileBasedIndex.getInstance().ignoreDumbMode(DumbModeAccessType.RELIABLE_DATA_ONLY, () -> {
|
||||
assertNull(myFixture.getJavaFacade().findClass(MagicConstant.class.getName(), GlobalSearchScope.allScope(myFixture.getProject())));
|
||||
});
|
||||
|
||||
myFixture.configureByText("a.java",
|
||||
"import java.util.*;\nclass Bar {\n static void foo(Calendar c) {\n c.setFirstDayOfWeek(<caret>)\n }\n}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "FRIDAY", "MONDAY");
|
||||
assertFalse(myFixture.getLookupElementStrings().contains("JANUARY"));
|
||||
assertFalse(myFixture.getLookupElementStrings().contains("Calendar.JANUARY"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DefaultLightProjectDescriptor getProjectDescriptor() {
|
||||
return projectDescriptor;
|
||||
}
|
||||
|
||||
private static final DefaultLightProjectDescriptor projectDescriptor = new DefaultLightProjectDescriptor() {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return PsiTestUtil.addJdkAnnotations(IdeaTestUtil.getMockJdk14());
|
||||
}
|
||||
};
|
||||
}
|
||||
-232
@@ -1,232 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.codeInsight.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.testFramework.NeedsIndex
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
import groovy.transform.CompileStatic
|
||||
import org.intellij.lang.annotations.Language
|
||||
|
||||
@CompileStatic
|
||||
class MagicConstantCompletionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
@NeedsIndex.Full
|
||||
void "test in method argument"() {
|
||||
addModifierList()
|
||||
myFixture.configureByText "a.java", """
|
||||
class Foo {
|
||||
static void foo(ModifierList ml) {
|
||||
ml.hasModifierProperty(<caret>)
|
||||
}
|
||||
}
|
||||
"""
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'PROTECTED', 'PUBLIC'
|
||||
}
|
||||
|
||||
void "test nothing after dot"() {
|
||||
addModifierList()
|
||||
myFixture.configureByText "a.java", """
|
||||
class Foo {
|
||||
static void foo(ModifierList ml) {
|
||||
ml.hasModifierProperty(Foo.<caret>)
|
||||
}
|
||||
}
|
||||
"""
|
||||
assert !myFixture.complete(CompletionType.SMART)
|
||||
}
|
||||
|
||||
void "test magic constant in equality"() {
|
||||
addMagicConstant()
|
||||
|
||||
myFixture.configureByText "a.java", """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(flagsFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
"""
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
LookupManager.getInstance(project).hideActiveLookup()
|
||||
|
||||
myFixture.complete(CompletionType.BASIC)
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void "test completion in enum constructor"() {
|
||||
addMagicConstant()
|
||||
myFixture.configureByText "a.java", """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
enum MagicConstantTest {
|
||||
FOO(<caret>),
|
||||
;
|
||||
|
||||
private final int magicConstant;
|
||||
|
||||
MagicConstantTest(@MagicConstant(valuesFromClass = MagicConstantIds.class) int magicConstant) {
|
||||
this.magicConstant = magicConstant;
|
||||
}
|
||||
}
|
||||
class MagicConstantIds {
|
||||
static final int ONE = 1;
|
||||
static final int TWO = 2;
|
||||
}
|
||||
"""
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'ONE', 'TWO'
|
||||
}
|
||||
|
||||
void "test magic constant in equality before another equality"() {
|
||||
addMagicConstant()
|
||||
|
||||
myFixture.configureByText "a.java", """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>getConstant() == 2) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(flagsFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
"""
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
}
|
||||
|
||||
private PsiClass addModifierList() {
|
||||
addMagicConstant()
|
||||
|
||||
myFixture.addClass """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
interface PsiModifier {
|
||||
@NonNls String PUBLIC = "public";
|
||||
@NonNls String PROTECTED = "protected";
|
||||
|
||||
@MagicConstant(stringValues = { PUBLIC, PROTECTED })
|
||||
@interface ModifierConstant { }
|
||||
}
|
||||
|
||||
interface ModifierList {
|
||||
boolean hasModifierProperty(@PsiModifier.ModifierConstant String m) {}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
private PsiClass addMagicConstant() {
|
||||
myFixture.addClass """
|
||||
package org.intellij.lang.annotations;
|
||||
public @interface MagicConstant {
|
||||
String[] stringValues() default {};
|
||||
Class flagsFromClass() default void.class;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
void testVariableAssignedFromMagicMethodEqEq() {
|
||||
addMagicConstant()
|
||||
|
||||
@Language("JAVA")
|
||||
def s = """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
int flags = getConstant();
|
||||
if (flags == <caret>) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(valuesFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
"""
|
||||
myFixture.configureByText "a.java", s
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'BAR', 'FOO'
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testVarargMethodCall() {
|
||||
addMagicConstant()
|
||||
|
||||
@Language("JAVA")
|
||||
def s = """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
public class VarargMethodCall {
|
||||
private static class Constants {
|
||||
public static final int ONE = 1;
|
||||
public static final int TWO = 2;
|
||||
}
|
||||
public static void testAnnotation2(@MagicConstant(valuesFromClass = Constants.class) int... vars) {
|
||||
}
|
||||
public static void testMethod() {
|
||||
testAnnotation2(<caret>);
|
||||
}
|
||||
}
|
||||
"""
|
||||
myFixture.configureByText "a.java", s
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'ONE', 'TWO'
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testVarargMethodCall2() {
|
||||
addMagicConstant()
|
||||
|
||||
@Language("JAVA")
|
||||
def s = """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
public class VarargMethodCall {
|
||||
private static class Constants {
|
||||
public static final int ONE = 1;
|
||||
public static final int TWO = 2;
|
||||
}
|
||||
public static void testAnnotation2(@MagicConstant(valuesFromClass = Constants.class) int... vars) {
|
||||
}
|
||||
public static void testMethod() {
|
||||
testAnnotation2(Constants.ONE, <caret>);
|
||||
}
|
||||
}
|
||||
"""
|
||||
myFixture.configureByText "a.java", s
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
myFixture.assertPreferredCompletionItems 0, 'ONE', 'TWO'
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
|
||||
public class MagicConstantCompletionTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
@NeedsIndex.Full
|
||||
public void test_in_method_argument() {
|
||||
addModifierList();
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
static void foo(ModifierList ml) {
|
||||
ml.hasModifierProperty(<caret>)
|
||||
}
|
||||
}
|
||||
""");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "PROTECTED", "PUBLIC");
|
||||
}
|
||||
|
||||
public void test_nothing_after_dot() {
|
||||
addModifierList();
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
static void foo(ModifierList ml) {
|
||||
ml.hasModifierProperty(Foo.<caret>)
|
||||
}
|
||||
}
|
||||
""");
|
||||
assertEquals(0, myFixture.complete(CompletionType.SMART).length);
|
||||
}
|
||||
|
||||
public void test_magic_constant_in_equality() {
|
||||
addMagicConstant();
|
||||
|
||||
myFixture.configureByText("a.java", """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(flagsFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
""");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "BAR", "FOO");
|
||||
LookupManager.getInstance(getProject()).hideActiveLookup();
|
||||
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
myFixture.assertPreferredCompletionItems(0, "BAR", "FOO");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void test_completion_in_enum_constructor() {
|
||||
addMagicConstant();
|
||||
myFixture.configureByText("a.java", """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
enum MagicConstantTest {
|
||||
FOO(<caret>),
|
||||
;
|
||||
|
||||
private final int magicConstant;
|
||||
|
||||
MagicConstantTest(@MagicConstant(valuesFromClass = MagicConstantIds.class) int magicConstant) {
|
||||
this.magicConstant = magicConstant;
|
||||
}
|
||||
}
|
||||
class MagicConstantIds {
|
||||
static final int ONE = 1;
|
||||
static final int TWO = 2;
|
||||
}
|
||||
""");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "ONE", "TWO");
|
||||
}
|
||||
|
||||
public void test_magic_constant_in_equality_before_another_equality() {
|
||||
addMagicConstant();
|
||||
|
||||
myFixture.configureByText("a.java", """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
if (getConstant() == <caret>getConstant() == 2) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(flagsFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
""");
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "BAR", "FOO");
|
||||
}
|
||||
|
||||
private void addModifierList() {
|
||||
addMagicConstant();
|
||||
|
||||
myFixture.addClass("""
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
interface PsiModifier {
|
||||
@NonNls String PUBLIC = "public";
|
||||
@NonNls String PROTECTED = "protected";
|
||||
|
||||
@MagicConstant(stringValues = { PUBLIC, PROTECTED })
|
||||
@interface ModifierConstant { }
|
||||
}
|
||||
|
||||
interface ModifierList {
|
||||
boolean hasModifierProperty(@PsiModifier.ModifierConstant String m) {}
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
private void addMagicConstant() {
|
||||
myFixture.addClass("""
|
||||
package org.intellij.lang.annotations;
|
||||
public @interface MagicConstant {
|
||||
String[] stringValues() default {};
|
||||
Class<?> flagsFromClass() default void.class;
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
public void testVariableAssignedFromMagicMethodEqEq() {
|
||||
addMagicConstant();
|
||||
|
||||
@Language("JAVA") String s = """
|
||||
class Bar {
|
||||
static void foo() {
|
||||
int flags = getConstant();
|
||||
if (flags == <caret>) {}
|
||||
}
|
||||
|
||||
@org.intellij.lang.annotations.MagicConstant(valuesFromClass = Foo.class)
|
||||
public native int getConstant();
|
||||
}
|
||||
|
||||
interface Foo {
|
||||
int FOO = 1;
|
||||
int BAR = 2;
|
||||
}
|
||||
""";
|
||||
myFixture.configureByText("a.java", s);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "BAR", "FOO");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testVarargMethodCall() {
|
||||
addMagicConstant();
|
||||
|
||||
@Language("JAVA") String s = """
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
public class VarargMethodCall {
|
||||
private static class Constants {
|
||||
public static final int ONE = 1;
|
||||
public static final int TWO = 2;
|
||||
}
|
||||
public static void testAnnotation2(@MagicConstant(valuesFromClass = Constants.class) int... vars) {
|
||||
}
|
||||
public static void testMethod() {
|
||||
testAnnotation2(<caret>);
|
||||
}
|
||||
}
|
||||
""";
|
||||
myFixture.configureByText("a.java", s);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "ONE", "TWO");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testVarargMethodCall2() {
|
||||
addMagicConstant();
|
||||
|
||||
@Language("JAVA") String s =
|
||||
"""
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
|
||||
public class VarargMethodCall {
|
||||
private static class Constants {
|
||||
public static final int ONE = 1;
|
||||
public static final int TWO = 2;
|
||||
}
|
||||
public static void testAnnotation2(@MagicConstant(valuesFromClass = Constants.class) int... vars) {
|
||||
}
|
||||
public static void testMethod() {
|
||||
testAnnotation2(Constants.ONE, <caret>);
|
||||
}
|
||||
}
|
||||
""";
|
||||
myFixture.configureByText("a.java", s);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
myFixture.assertPreferredCompletionItems(0, "ONE", "TWO");
|
||||
}
|
||||
}
|
||||
-101
@@ -1,101 +0,0 @@
|
||||
// Copyright 2000-2018 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.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.NeedsIndex
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class Normal11CompletionTest extends NormalCompletionTestCase {
|
||||
final LightProjectDescriptor projectDescriptor = JAVA_11
|
||||
|
||||
void "test local var"() {
|
||||
assert completeVar("{ <caret> }")
|
||||
}
|
||||
|
||||
void "test local final var"() {
|
||||
assert completeVar("{ final <caret> }")
|
||||
}
|
||||
|
||||
void "test local var before identifier"() {
|
||||
assert completeVar("{ <caret>name }")
|
||||
}
|
||||
|
||||
void "test resource var"() {
|
||||
assert completeVar("{ try (<caret>) }")
|
||||
}
|
||||
|
||||
void "test empty foreach var"() {
|
||||
assert completeVar("{ for (<caret>) }")
|
||||
}
|
||||
|
||||
void "test non-empty foreach var"() {
|
||||
assert completeVar("{ for (<caret>x y: z) }")
|
||||
}
|
||||
|
||||
void "test lambda parameter var"() {
|
||||
assert completeVar("I f = (v<caret>x) -> {};")
|
||||
}
|
||||
|
||||
void "test no var in lambda parameter name"() {
|
||||
assert !completeVar("I f = (String v<caret>x) -> {};")
|
||||
}
|
||||
|
||||
void "test no var in method parameters"() {
|
||||
assert !completeVar("void foo(<caret>) {}")
|
||||
}
|
||||
|
||||
void "test no var in catch"() {
|
||||
assert !completeVar("{ try {} catch(<caret>) {} }")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
void "test var initializer type"() {
|
||||
def source = "class X {boolean test() {var x = <caret>; return x;}}"
|
||||
myFixture.configureByText "Test.java", source
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
assert myFixture.lookupElementStrings == ['equals', 'false', 'true', 'test']
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
void "test var initializer type 3"() {
|
||||
def source = "class X {boolean test() {var x = <caret>;var y = x;var z = y; return z;}}"
|
||||
myFixture.configureByText "Test.java", source
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
assert myFixture.lookupElementStrings == ['equals', 'false', 'true', 'test']
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
void "test var initializer type 4"() {
|
||||
def source = "class X {boolean test() {var x = <caret>;var y = x;var z = y;var w = z;return w;}}"
|
||||
myFixture.configureByText "Test.java", source
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
// too many hops to track `x` type
|
||||
assert myFixture.lookupElementStrings == []
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
void "test var initializer type used twice"() {
|
||||
def source = "class X {boolean test() {var x = <caret>;if (Math.random() > 0.5) return x;return x;}}"
|
||||
myFixture.configureByText "Test.java", source
|
||||
myFixture.complete(CompletionType.SMART)
|
||||
assert myFixture.lookupElementStrings == ['equals', 'false', 'true', 'test']
|
||||
}
|
||||
|
||||
private LookupElement completeVar(String text) {
|
||||
def fullText = "class F { $text }"
|
||||
myFixture.configureByText "a.java", fullText
|
||||
def var = myFixture.completeBasic().find { it.lookupString == 'var' }
|
||||
myFixture.checkResult(fullText)
|
||||
return var
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testToUnmodifiable() {
|
||||
configureByTestName()
|
||||
myFixture.assertPreferredCompletionItems 0, 'collect(Collectors.toUnmodifiableList())', 'collect(Collectors.toUnmodifiableSet())'
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Normal11CompletionTest extends NormalCompletionTestCase {
|
||||
public void test_local_var() {
|
||||
assertNotNull(completeVar("{ <caret> }"));
|
||||
}
|
||||
|
||||
public void test_local_final_var() {
|
||||
assertNotNull(completeVar("{ final <caret> }"));
|
||||
}
|
||||
|
||||
public void test_local_var_before_identifier() {
|
||||
assertNotNull(completeVar("{ <caret>name }"));
|
||||
}
|
||||
|
||||
public void test_resource_var() {
|
||||
assertNotNull(completeVar("{ try (<caret>) }"));
|
||||
}
|
||||
|
||||
public void test_empty_foreach_var() {
|
||||
assertNotNull(completeVar("{ for (<caret>) }"));
|
||||
}
|
||||
|
||||
public void test_non_empty_foreach_var() {
|
||||
assertNotNull(completeVar("{ for (<caret>x y: z) }"));
|
||||
}
|
||||
|
||||
public void test_lambda_parameter_var() {
|
||||
assertNotNull(completeVar("I f = (v<caret>x) -> {})"));
|
||||
}
|
||||
|
||||
public void test_no_var_in_lambda_parameter_name() {
|
||||
assertNull(completeVar("I f = (String v<caret>x) -> {};"));
|
||||
}
|
||||
|
||||
public void test_no_var_in_method_parameters() {
|
||||
assertNull(completeVar("void foo(<caret>) {}"));
|
||||
}
|
||||
|
||||
public void test_no_var_in_catch() {
|
||||
assertNull(completeVar("{ try {} catch(<caret>) {} }"));
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
public void test_var_initializer_type() {
|
||||
String source = "class X {boolean test() {var x = <caret>; return x;}}";
|
||||
myFixture.configureByText("Test.java", source);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
assertEquals(myFixture.getLookupElementStrings(), Arrays.asList("equals", "false", "true", "test"));
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
public void test_var_initializer_type_3() {
|
||||
String source = "class X {boolean test() {var x = <caret>;var y = x;var z = y; return z;}}";
|
||||
myFixture.configureByText("Test.java", source);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
assertEquals(myFixture.getLookupElementStrings(), Arrays.asList("equals", "false", "true", "test"));
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
public void test_var_initializer_type_4() {
|
||||
String source = "class X {boolean test() {var x = <caret>;var y = x;var z = y;var w = z;return w;}}";
|
||||
myFixture.configureByText("Test.java", source);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
// too many hops to track `x` type
|
||||
assertEquals(myFixture.getLookupElementStrings(), List.of());
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "To display 'equals' suggestion")
|
||||
public void test_var_initializer_type_used_twice() {
|
||||
String source = "class X {boolean test() {var x = <caret>;if (Math.random() > 0.5) return x;return x;}}";
|
||||
myFixture.configureByText("Test.java", source);
|
||||
myFixture.complete(CompletionType.SMART);
|
||||
assertEquals(myFixture.getLookupElementStrings(),Arrays.asList("equals", "false", "true", "test"));
|
||||
}
|
||||
|
||||
private LookupElement completeVar(String text) {
|
||||
String fullText = "class F { " + text + " }";
|
||||
myFixture.configureByText("a.java", fullText);
|
||||
LookupElement var = ContainerUtil.find(myFixture.completeBasic(), it -> it.getLookupString().equals("var"));
|
||||
myFixture.checkResult(fullText);
|
||||
return var;
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testToUnmodifiable() {
|
||||
configureByTestName();
|
||||
myFixture.assertPreferredCompletionItems(0, "collect(Collectors.toUnmodifiableList())", "collect(Collectors.toUnmodifiableSet())");
|
||||
}
|
||||
|
||||
@Override
|
||||
public final @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_11;
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
// Copyright 2000-2017 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.testFramework.NeedsIndex
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class Normal6CompletionTest extends NormalCompletionTestCase {
|
||||
|
||||
void testMakeMultipleArgumentsFinalWhenInInner() {
|
||||
configure()
|
||||
def item = lookup.items.find { 'a, b' == it.lookupString }
|
||||
assert item
|
||||
lookup.currentItem = item
|
||||
type '\n'
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testOverwriteGenericsAfterNew() { doTest('\n') }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testExplicitTypeArgumentsWhenParameterTypesDoNotDependOnTypeParameters() { doTest() }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testClassNameWithGenericsTab2() { doTest('\t') }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testClassNameGenerics() { doTest('\n') }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testDoubleExpectedTypeFactoryMethod() throws Throwable {
|
||||
configure()
|
||||
assertStringItems('Key', 'create', 'create')
|
||||
assert renderElement(myItems[1]).itemText == 'Key.<Boolean>create'
|
||||
assert renderElement(myItems[2]).itemText == 'Key.create'
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
public class Normal6CompletionTest extends NormalCompletionTestCase {
|
||||
public void testMakeMultipleArgumentsFinalWhenInInner() {
|
||||
configure();
|
||||
LookupElement item = ContainerUtil.find(getLookup().getItems(), it -> "a, b".equals(it.getLookupString()));
|
||||
assertNotNull(item);
|
||||
getLookup().setCurrentItem(item);
|
||||
type("\n");
|
||||
checkResult();
|
||||
}
|
||||
|
||||
public void testOverwriteGenericsAfterNew() { doTest("\n"); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testExplicitTypeArgumentsWhenParameterTypesDoNotDependOnTypeParameters() { doTest(); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testClassNameWithGenericsTab2() { doTest("\t"); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testClassNameGenerics() { doTest("\n"); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testDoubleExpectedTypeFactoryMethod() {
|
||||
configure();
|
||||
assertStringItems("Key", "create", "create");
|
||||
assertEquals("Key.<Boolean>create", NormalCompletionTestCase.renderElement(myItems[1]).getItemText());
|
||||
assertEquals("Key.create", NormalCompletionTestCase.renderElement(myItems[2]).getItemText());
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// Copyright 2000-2019 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.testFramework.LightProjectDescriptor
|
||||
import groovy.transform.CompileStatic
|
||||
@CompileStatic
|
||||
class Normal7CompletionTest extends NormalCompletionTestCase {
|
||||
final LightProjectDescriptor projectDescriptor = JAVA_1_7
|
||||
|
||||
void testGenericInsideDiamond() { doTest() }
|
||||
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Normal7CompletionTest extends NormalCompletionTestCase {
|
||||
public void testGenericInsideDiamond() { doTest(); }
|
||||
|
||||
@Override
|
||||
public final @NotNull LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_1_7;
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. 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.codeInsight.template.impl.LiveTemplateCompletionContributor
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.NeedsIndex
|
||||
import groovy.transform.CompileStatic
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@CompileStatic
|
||||
class NormalSwitchCompletionTest extends NormalCompletionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_17
|
||||
}
|
||||
|
||||
void testDefaultInRuleSwitch() { doTest() }
|
||||
void testLabelInRuleSwitch() { doTest() }
|
||||
void testSecondLabelInOldSwitch() { doTest() }
|
||||
void testSecondLabelInRuleSwitch() { doTest() }
|
||||
void testSwitchExpressionStart() { doTest() }
|
||||
void testYieldInSwitchExpression() { doTest() }
|
||||
void testInsideYieldInSwitchExpression() { doTest() }
|
||||
void testInsideRuleInSwitchExpression() { doTest() }
|
||||
void testBreakDeepInsideSwitchExpression() { doTest() }
|
||||
|
||||
@NeedsIndex.Full
|
||||
void testCompletePatternVariableInSwitchExpr() { doTest() }
|
||||
@NeedsIndex.Full
|
||||
void testCompletePatternVariableInSwitchStmt() { doTest() }
|
||||
|
||||
void testCompleteReturnInSwitch() { doTest() }
|
||||
|
||||
@NeedsIndex.Full
|
||||
void testCompleteConstantInSwitchExpr() { doTest('\n') }
|
||||
@NeedsIndex.Full
|
||||
void testCompleteConstantInSwitchStmt() { doTest('\n') }
|
||||
|
||||
void testCompleteNullInSwitchStmt() { doTest() }
|
||||
void testCompleteNullInSwitchExpr() { doTest() }
|
||||
|
||||
void testCompleteDefaultInSwitchStmt() { doTest() }
|
||||
void testCompleteDefaultInSwitchExpr() { doTest() }
|
||||
|
||||
void testCompletePatternVariableSwitchStmt() { doTest() }
|
||||
void testCompletePatternVariableSwitchExpr() { doTest() }
|
||||
|
||||
void testCompleteSealedLabelSwitch() { doTest() }
|
||||
|
||||
void testCompleteReturnInSwitchRule() { doTest() }
|
||||
void testCompleteReturnInSwitchRule2() { doTest() }
|
||||
void testCompleteThrowInSwitchRule() { doTest() }
|
||||
|
||||
@NeedsIndex.Full(reason = "Other options do not appear if there's no index. As a result, '\n' goes right into the editor")
|
||||
void testCompleteIfInSwitchRule() { doTest('\n') }
|
||||
|
||||
void testCompleteSwitchObjectSelectorPostfix() { doTestPostfixCompletion() }
|
||||
void testCompleteSwitchSealedSelectorPostfix() { doTestPostfixCompletion() }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testCompleteReferencesInExpressionSwitch() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testCompleteFinalInsideSwitch() { doTest('\n') }
|
||||
void testCompleteYieldInsideSwitch() { doTest() }
|
||||
|
||||
private void doTestPostfixCompletion() {
|
||||
LiveTemplateCompletionContributor.setShowTemplatesInTests(true, myFixture.testRootDisposable)
|
||||
configure()
|
||||
myFixture.type('\t' as char)
|
||||
checkResult()
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NormalSwitchCompletionTest extends NormalCompletionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_17;
|
||||
}
|
||||
|
||||
public void testDefaultInRuleSwitch() { doTest(); }
|
||||
|
||||
public void testLabelInRuleSwitch() { doTest(); }
|
||||
|
||||
public void testSecondLabelInOldSwitch() { doTest(); }
|
||||
|
||||
public void testSecondLabelInRuleSwitch() { doTest(); }
|
||||
|
||||
public void testSwitchExpressionStart() { doTest(); }
|
||||
|
||||
public void testYieldInSwitchExpression() { doTest(); }
|
||||
|
||||
public void testInsideYieldInSwitchExpression() { doTest(); }
|
||||
|
||||
public void testInsideRuleInSwitchExpression() { doTest(); }
|
||||
|
||||
public void testBreakDeepInsideSwitchExpression() { doTest(); }
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompletePatternVariableInSwitchExpr() { doTest(); }
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompletePatternVariableInSwitchStmt() { doTest(); }
|
||||
|
||||
public void testCompleteReturnInSwitch() { doTest(); }
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompleteConstantInSwitchExpr() { doTest("\n"); }
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompleteConstantInSwitchStmt() { doTest("\n"); }
|
||||
|
||||
public void testCompleteNullInSwitchStmt() { doTest(); }
|
||||
|
||||
public void testCompleteNullInSwitchExpr() { doTest(); }
|
||||
|
||||
public void testCompleteDefaultInSwitchStmt() { doTest(); }
|
||||
|
||||
public void testCompleteDefaultInSwitchExpr() { doTest(); }
|
||||
|
||||
public void testCompletePatternVariableSwitchStmt() { doTest(); }
|
||||
|
||||
public void testCompletePatternVariableSwitchExpr() { doTest(); }
|
||||
|
||||
public void testCompleteSealedLabelSwitch() { doTest(); }
|
||||
|
||||
public void testCompleteReturnInSwitchRule() { doTest(); }
|
||||
|
||||
public void testCompleteReturnInSwitchRule2() { doTest(); }
|
||||
|
||||
public void testCompleteThrowInSwitchRule() { doTest(); }
|
||||
|
||||
@NeedsIndex.Full(reason = "Other options do not appear if there's no index. As a result, '\n' goes right into the editor")
|
||||
public void testCompleteIfInSwitchRule() { doTest("\n"); }
|
||||
|
||||
public void testCompleteSwitchObjectSelectorPostfix() { doTestPostfixCompletion(); }
|
||||
|
||||
public void testCompleteSwitchSealedSelectorPostfix() { doTestPostfixCompletion(); }
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testCompleteReferencesInExpressionSwitch() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testCompleteFinalInsideSwitch() { doTest("\n"); }
|
||||
|
||||
public void testCompleteYieldInsideSwitch() { doTest(); }
|
||||
|
||||
private void doTestPostfixCompletion() {
|
||||
LiveTemplateCompletionContributor.setShowTemplatesInTests(true, myFixture.getTestRootDisposable());
|
||||
configure();
|
||||
myFixture.type('\t');
|
||||
checkResult();
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. 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.JavaTestUtil
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.NeedsIndex
|
||||
import groovy.transform.CompileStatic
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
@CompileStatic
|
||||
class NormalSwitchCompletionVariantsTest extends LightFixtureCompletionTestCase {
|
||||
private static final String[] COMMON_VARIANTS = ["case", "default"]
|
||||
private static final String[] COMMON_OBJECT_VARIANTS = COMMON_VARIANTS + ["case null", "case default"]
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/variants/"
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_17
|
||||
}
|
||||
|
||||
void testCompletionPrimitiveTypeExpr() { doTest(COMMON_VARIANTS) }
|
||||
void testCompletionPrimitiveTypeStmt() { doTest(COMMON_VARIANTS) }
|
||||
void testCompletionVariantsInStmt() { doTest(COMMON_OBJECT_VARIANTS) }
|
||||
void testCompletionVariantsInExpr() { doTest(COMMON_OBJECT_VARIANTS) }
|
||||
|
||||
@NeedsIndex.Full
|
||||
void testCompletionSealedHierarchyStmt() { doTest(COMMON_OBJECT_VARIANTS + ["case Variant1", "case Variant2"]) }
|
||||
|
||||
@NeedsIndex.Full
|
||||
void testCompletionSealedHierarchyExpr() { doTest(COMMON_OBJECT_VARIANTS + ["case Variant1", "case Variant2"]) }
|
||||
|
||||
private void doTest(String[] variants) {
|
||||
myFixture.configureByFile(getTestName(false) + ".java")
|
||||
myFixture.complete(CompletionType.BASIC)
|
||||
|
||||
final List<String> lookupElementStrings = myFixture.getLookupElementStrings()
|
||||
assertSameElements(lookupElementStrings, variants)
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
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.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NormalSwitchCompletionVariantsTest extends LightFixtureCompletionTestCase {
|
||||
private static final String[] COMMON_VARIANTS = {"case", "default"};
|
||||
private static final String[] COMMON_OBJECT_VARIANTS = ArrayUtil.mergeArrays(COMMON_VARIANTS, "case null", "case default");
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/completion/normal/variants/";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_17;
|
||||
}
|
||||
|
||||
public void testCompletionPrimitiveTypeExpr() { doTest(COMMON_VARIANTS); }
|
||||
public void testCompletionPrimitiveTypeStmt() { doTest(COMMON_VARIANTS); }
|
||||
public void testCompletionVariantsInStmt() { doTest(COMMON_OBJECT_VARIANTS); }
|
||||
public void testCompletionVariantsInExpr() { doTest(COMMON_OBJECT_VARIANTS); }
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompletionSealedHierarchyStmt() {
|
||||
doTest(ArrayUtil.mergeArrays(COMMON_OBJECT_VARIANTS, "case Variant1", "case Variant2"));
|
||||
}
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testCompletionSealedHierarchyExpr() {
|
||||
doTest(ArrayUtil.mergeArrays(COMMON_OBJECT_VARIANTS, "case Variant1", "case Variant2"));
|
||||
}
|
||||
|
||||
private void doTest(String[] variants) {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
myFixture.complete(CompletionType.BASIC);
|
||||
|
||||
final List<String> lookupElementStrings = myFixture.getLookupElementStrings();
|
||||
assertSameElements(lookupElementStrings, variants);
|
||||
}
|
||||
}
|
||||
-392
@@ -1,392 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.java.codeInsight.completion
|
||||
|
||||
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.NeedsIndex
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
@CompileStatic
|
||||
class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
public static final String FILE_PREFIX = "/codeInsight/completion/variables/"
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath()
|
||||
}
|
||||
|
||||
void testObjectVariable() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java")
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
void testStringVariable() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java")
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
@NeedsIndex.Full
|
||||
void testInputMethodEventVariable() throws Exception {
|
||||
myFixture.addClass("package java.awt.event; public interface InputMethodEvent {}")
|
||||
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java")
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testLocals1() throws Exception {
|
||||
doSelectTest("TestSource1.java", "TestResult1.java")
|
||||
}
|
||||
|
||||
void testInterfaceMethod() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "InterfaceMethod.java")
|
||||
assertStringItems("calcGooBarDoo", "calcBarDoo", "calcDoo")
|
||||
}
|
||||
|
||||
void testLocals2() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "TestSource2.java")
|
||||
myFixture.assertPreferredCompletionItems 0, 'abc', 'aaa'
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "TestResult2.java")
|
||||
}
|
||||
|
||||
void testLocals3() throws Exception {
|
||||
doTest("TestSource3.java", "TestResult3.java")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void testLocals4() throws Exception {
|
||||
doSelectTest("TestSource4.java", "TestResult4.java")
|
||||
}
|
||||
|
||||
void testLocals5() throws Exception {
|
||||
doTest("TestSource5.java", "TestResult5.java")
|
||||
}
|
||||
|
||||
void testLocals6() throws Exception {
|
||||
doSelectTest("TestSource6.java", "TestResult6.java")
|
||||
}
|
||||
|
||||
void testLocals7() throws Exception {
|
||||
doTest("TestSource7.java", "TestResult7.java")
|
||||
}
|
||||
|
||||
void testLocalReserved() throws Exception {
|
||||
doTest("LocalReserved.java", "LocalReserved_after.java")
|
||||
}
|
||||
|
||||
void testLocalReserved2() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "LocalReserved2.java")
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "LocalReserved2.java")
|
||||
assert !myFixture.lookupElementStrings
|
||||
}
|
||||
|
||||
void testUniqueNameInFor() throws Exception {
|
||||
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
void testWithBuilderParameter() throws Exception {
|
||||
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
private void doTest(String before, String after) throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + before)
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after)
|
||||
}
|
||||
|
||||
private void doSelectTest(String before, String after) throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + before)
|
||||
myFixture.type('\n')
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after)
|
||||
}
|
||||
|
||||
void testLocals8() throws Exception {
|
||||
doTest("TestSource8.java", "TestResult8.java")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(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")
|
||||
}
|
||||
|
||||
void testFieldNameCompletion1() throws Exception {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
doSelectTest("FieldNameCompletion1.java", "FieldNameCompletion1-result.java")
|
||||
}
|
||||
|
||||
void testFieldNameCompletion2() throws Exception {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2.java")
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2-result.java")
|
||||
}
|
||||
|
||||
void testFieldNameCompletion3() throws Exception {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3.java")
|
||||
complete()
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3-result.java")
|
||||
}
|
||||
|
||||
void testLocals9() throws Exception {
|
||||
doSelectTest("TestSource9.java", "TestResult9.java")
|
||||
}
|
||||
|
||||
void testFieldOutOfAnonymous() throws Exception {
|
||||
doTest("TestFieldOutOfAnonymous.java", "TestFieldOutOfAnonymousResult.java")
|
||||
}
|
||||
|
||||
void testUnresolvedMethodName() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java")
|
||||
complete()
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName_after.java")
|
||||
}
|
||||
|
||||
void testArrayMethodName() throws Throwable {
|
||||
doTest("ArrayMethodName.java", "ArrayMethodName-result.java")
|
||||
}
|
||||
|
||||
void "test suggest fields that could be initialized by super constructor"() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, """
|
||||
class Foo extends java.util.ArrayList {
|
||||
int field;
|
||||
int field2;
|
||||
Foo() {
|
||||
super();
|
||||
field2 = f<caret>;
|
||||
}
|
||||
}""")
|
||||
complete()
|
||||
myFixture.assertPreferredCompletionItems 0, 'field', 'float'
|
||||
}
|
||||
|
||||
void "test suggest fields initialized by init"() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, """
|
||||
class Foo {
|
||||
final Integer field;
|
||||
|
||||
{ field = 42; }
|
||||
|
||||
Foo() {
|
||||
equals(f<caret>);
|
||||
}
|
||||
}""")
|
||||
complete()
|
||||
myFixture.assertPreferredCompletionItems 0, 'field'
|
||||
}
|
||||
|
||||
void "test suggest fields in their modification inside constructor"() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, """
|
||||
class Foo {
|
||||
int total;
|
||||
|
||||
Foo() {
|
||||
this.total = 0;
|
||||
this.total += this.to<caret>tal
|
||||
}
|
||||
}
|
||||
""")
|
||||
complete()
|
||||
myFixture.assertPreferredCompletionItems 0, 'total'
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(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()
|
||||
assertStringItems("foo")
|
||||
}
|
||||
|
||||
void testFieldInitializerMatters() throws Exception {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class Foo { String f<caret>x = getFoo(); String getFoo() {}; }")
|
||||
complete()
|
||||
assertStringItems("foo", "fString")
|
||||
}
|
||||
|
||||
void testNoKeywordsInForLoopVariableName() throws Throwable {
|
||||
configure()
|
||||
assertStringItems("stringBuffer", "buffer")
|
||||
}
|
||||
|
||||
void testDontIterateOverLoopVariable() throws Throwable {
|
||||
configure()
|
||||
myFixture.assertPreferredCompletionItems 0, 'nodes', 'new', 'null'
|
||||
}
|
||||
|
||||
void testDuplicateSuggestionsFromUsage() {
|
||||
configure()
|
||||
assertStringItems("preferencePolicy", "policy", "aPreferencePolicy")
|
||||
}
|
||||
|
||||
void testSuggestVariablesInTypePosition() {
|
||||
configure()
|
||||
assertStringItems("myField", "myField2")
|
||||
}
|
||||
|
||||
void configure() {
|
||||
configureByFile(FILE_PREFIX + getTestName(false) + ".java")
|
||||
}
|
||||
|
||||
void testAnnotationValue() {
|
||||
configure()
|
||||
checkResultByFile(FILE_PREFIX + getTestName(false) + "_after.java")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(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")
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(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"
|
||||
settings.PARAMETER_NAME_PREFIX = "p"
|
||||
|
||||
configure()
|
||||
|
||||
assertStringItems("pColor")
|
||||
}
|
||||
|
||||
void "test finish with ="() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooFoo {
|
||||
FooFoo f<caret>
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'fooFoo', 'foo'
|
||||
myFixture.type '='
|
||||
myFixture.checkResult '''
|
||||
class FooFoo {
|
||||
FooFoo fooFoo = <caret>
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
void "test suggest variable names by non-getter initializer call"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooFoo {
|
||||
{ long <caret>x = System.nanoTime(); }
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'l', 'nanoTime', 'time'
|
||||
}
|
||||
|
||||
void "test use superclass for inner class variable name suggestion"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooFoo {
|
||||
{ Rectangle2D.Double <caret>x }
|
||||
}
|
||||
class Rectangle2D {
|
||||
static class Double extends Rectangle2D {}
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'aDouble', 'rectangle2D'
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
void "test suggest field-shadowing parameter name"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooFoo {
|
||||
private final Collection<MaterialQuality> materialQualities;
|
||||
|
||||
public Inventory setMaterialQualities(Iterable<MaterialQuality> <caret>) {
|
||||
|
||||
}}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'materialQualities', 'materialQualities1', 'qualities', 'materialQualityIterable', 'qualityIterable', 'iterable'
|
||||
}
|
||||
|
||||
void "test suggest parameter name from javadoc"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class FooFoo {
|
||||
/**
|
||||
* @param existing
|
||||
* @param abc
|
||||
* @param def
|
||||
* @param <T>
|
||||
*/
|
||||
void set(int existing, int <caret>) {}
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
assert myFixture.lookupElementStrings as Set == ['abc', 'def', 'i'] as Set
|
||||
}
|
||||
|
||||
void "test no name suggestions when the type is unresolved because it is actually a mistyped keyword"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class C {
|
||||
{
|
||||
retur Fi<caret>x
|
||||
}
|
||||
}
|
||||
'''
|
||||
assert myFixture.completeBasic()?.size() == 0
|
||||
}
|
||||
|
||||
void "test suggest variable name when the type is unresolved but does not seem a mistyped keyword"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class C {
|
||||
{
|
||||
UndefinedType <caret>
|
||||
}
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'undefinedType', 'type'
|
||||
}
|
||||
|
||||
void "test class-based suggestions for exception type"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class C {
|
||||
{
|
||||
try { } catch (java.io.IOException <caret>)
|
||||
}
|
||||
}
|
||||
'''
|
||||
myFixture.completeBasic()
|
||||
myFixture.assertPreferredCompletionItems 0, 'e', 'ioException', 'exception'
|
||||
}
|
||||
|
||||
void "test no shadowed static field suggestions"() {
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class C extends Super {
|
||||
static final String FOO = "c";
|
||||
{
|
||||
C.FO<caret>x
|
||||
}
|
||||
}
|
||||
|
||||
class Super {
|
||||
static final String FOO = "super";
|
||||
}
|
||||
'''
|
||||
def items = myFixture.completeBasic()
|
||||
assertStringItems('FOO')
|
||||
assert NormalCompletionTest.renderElement(items[0]).tailText == ' ( = "c")'
|
||||
}
|
||||
|
||||
}
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight.completion;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.NeedsIndex;
|
||||
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return JavaTestUtil.getRelativeJavaTestDataPath();
|
||||
}
|
||||
|
||||
public void testObjectVariable() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testStringVariable() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
@NeedsIndex.Full
|
||||
public void testInputMethodEventVariable() {
|
||||
myFixture.addClass("package java.awt.event; public interface InputMethodEvent {}");
|
||||
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testLocals1() {
|
||||
doSelectTest("TestSource1.java", "TestResult1.java");
|
||||
}
|
||||
|
||||
public void testInterfaceMethod() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "InterfaceMethod.java");
|
||||
assertStringItems("calcGooBarDoo", "calcBarDoo", "calcDoo");
|
||||
}
|
||||
|
||||
public void testLocals2() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "TestSource2.java");
|
||||
myFixture.assertPreferredCompletionItems(0, "abc", "aaa");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "TestResult2.java");
|
||||
}
|
||||
|
||||
public void testLocals3() {
|
||||
doTest("TestSource3.java", "TestResult3.java");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void testLocals4() {
|
||||
doSelectTest("TestSource4.java", "TestResult4.java");
|
||||
}
|
||||
|
||||
public void testLocals5() {
|
||||
doTest("TestSource5.java", "TestResult5.java");
|
||||
}
|
||||
|
||||
public void testLocals6() {
|
||||
doSelectTest("TestSource6.java", "TestResult6.java");
|
||||
}
|
||||
|
||||
public void testLocals7() {
|
||||
doTest("TestSource7.java", "TestResult7.java");
|
||||
}
|
||||
|
||||
public void testLocalReserved() {
|
||||
doTest("LocalReserved.java", "LocalReserved_after.java");
|
||||
}
|
||||
|
||||
public void testLocalReserved2() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "LocalReserved2.java");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "LocalReserved2.java");
|
||||
assert !DefaultGroovyMethods.asBoolean(myFixture.getLookupElementStrings());
|
||||
}
|
||||
|
||||
public void testUniqueNameInFor() {
|
||||
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testWithBuilderParameter() {
|
||||
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
private void doTest(String before, String after) {
|
||||
configureByFile(FILE_PREFIX + "locals/" + before);
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after);
|
||||
}
|
||||
|
||||
private void doSelectTest(String before, String after) {
|
||||
configureByFile(FILE_PREFIX + "locals/" + before);
|
||||
myFixture.type("\n");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + after);
|
||||
}
|
||||
|
||||
public void testLocals8() {
|
||||
doTest("TestSource8.java", "TestResult8.java");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "With empty indices 'Object' may be considered variable name, and instanceof is ok here; Object is not resolved thus not replaced with 'o'")
|
||||
public void testUnresolvedReference() throws Exception {
|
||||
configureByFile(FILE_PREFIX + "locals/" + getTestName(false) + ".java");
|
||||
assertStringItems("o", "psiClass");
|
||||
}
|
||||
|
||||
public void testFieldNameCompletion1() {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
doSelectTest("FieldNameCompletion1.java", "FieldNameCompletion1-result.java");
|
||||
}
|
||||
|
||||
public void testFieldNameCompletion2() {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2.java");
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2-result.java");
|
||||
}
|
||||
|
||||
public void testFieldNameCompletion3() {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3.java");
|
||||
complete();
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3-result.java");
|
||||
}
|
||||
|
||||
public void testLocals9() {
|
||||
doSelectTest("TestSource9.java", "TestResult9.java");
|
||||
}
|
||||
|
||||
public void testFieldOutOfAnonymous() {
|
||||
doTest("TestFieldOutOfAnonymous.java", "TestFieldOutOfAnonymousResult.java");
|
||||
}
|
||||
|
||||
public void testUnresolvedMethodName() {
|
||||
configureByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java");
|
||||
complete();
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName_after.java");
|
||||
}
|
||||
|
||||
public void testArrayMethodName() {
|
||||
doTest("ArrayMethodName.java", "ArrayMethodName-result.java");
|
||||
}
|
||||
|
||||
public void test_suggest_fields_that_could_be_initialized_by_super_constructor() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE,
|
||||
"\nclass Foo extends java.util.ArrayList {\n int field;\n int field2;\n Foo() {\n super();\n field2 = f<caret>; \n } \n}");
|
||||
complete();
|
||||
myFixture.assertPreferredCompletionItems(0, "field", "float");
|
||||
}
|
||||
|
||||
public void test_suggest_fields_initialized_by_init() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE,
|
||||
"\nclass Foo {\n final Integer field;\n \n { field = 42; }\n \n Foo() {\n equals(f<caret>); \n } \n}");
|
||||
complete();
|
||||
myFixture.assertPreferredCompletionItems(0, "field");
|
||||
}
|
||||
|
||||
public void test_suggest_fields_in_their_modification_inside_constructor() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE,
|
||||
"\nclass Foo {\n int total;\n\n Foo() {\n this.total = 0;\n this.total += this.to<caret>tal\n }\n}\n");
|
||||
complete();
|
||||
myFixture.assertPreferredCompletionItems(0, "total");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "On empty indices String is not resolved and replaced with name 's', filtered out in JavaMemberNameCompletionContributor.getOverlappedNameVersions for being short")
|
||||
public void testInitializerMatters() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class Foo {{ String f<caret>x = getFoo(); }; String getFoo() {}; }");
|
||||
complete();
|
||||
assertStringItems("foo");
|
||||
}
|
||||
|
||||
public void testFieldInitializerMatters() {
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class Foo { String f<caret>x = getFoo(); String getFoo() {}; }");
|
||||
complete();
|
||||
assertStringItems("foo", "fString");
|
||||
}
|
||||
|
||||
public void testNoKeywordsInForLoopVariableName() {
|
||||
configure();
|
||||
assertStringItems("stringBuffer", "buffer");
|
||||
}
|
||||
|
||||
public void testDontIterateOverLoopVariable() {
|
||||
configure();
|
||||
myFixture.assertPreferredCompletionItems(0, "nodes", "new", "null");
|
||||
}
|
||||
|
||||
public void testDuplicateSuggestionsFromUsage() {
|
||||
configure();
|
||||
assertStringItems("preferencePolicy", "policy", "aPreferencePolicy");
|
||||
}
|
||||
|
||||
public void testSuggestVariablesInTypePosition() {
|
||||
configure();
|
||||
assertStringItems("myField", "myField2");
|
||||
}
|
||||
|
||||
public void configure() {
|
||||
configureByFile(FILE_PREFIX + getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testAnnotationValue() {
|
||||
configure();
|
||||
checkResultByFile(FILE_PREFIX + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(reason = "On empty indices String is not resolved and replaced with name 's', filtered out in JavaMemberNameCompletionContributor.getOverlappedNameVersions for being short")
|
||||
public void testConstructorParameterName() {
|
||||
configure();
|
||||
assertStringItems("color");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary(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")
|
||||
public void testConstructorParameterNameWithPrefix() {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
settings.PARAMETER_NAME_PREFIX = "p";
|
||||
|
||||
configure();
|
||||
|
||||
assertStringItems("pColor");
|
||||
}
|
||||
|
||||
public void test_finish_with__() {
|
||||
myFixture.configureByText("a.java", "\nclass FooFoo {\n FooFoo f<caret>\n}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "fooFoo", "foo");
|
||||
myFixture.type("=");
|
||||
myFixture.checkResult("\nclass FooFoo {\n FooFoo fooFoo = <caret>\n}\n");
|
||||
}
|
||||
|
||||
public void test_suggest_variable_names_by_non_getter_initializer_call() {
|
||||
myFixture.configureByText("a.java", "\nclass FooFoo {\n { long <caret>x = System.nanoTime(); }\n}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "l", "nanoTime", "time");
|
||||
}
|
||||
|
||||
public void test_use_superclass_for_inner_class_variable_name_suggestion() {
|
||||
myFixture.configureByText("a.java",
|
||||
"\nclass FooFoo {\n { Rectangle2D.Double <caret>x }\n}\nclass Rectangle2D {\n static class Double extends Rectangle2D {}\n}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "aDouble", "rectangle2D");
|
||||
}
|
||||
|
||||
@NeedsIndex.ForStandardLibrary
|
||||
public void test_suggest_field_shadowing_parameter_name() {
|
||||
myFixture.configureByText("a.java",
|
||||
"\nclass FooFoo {\n private final Collection<MaterialQuality> materialQualities;\n\n public Inventory setMaterialQualities(Iterable<MaterialQuality> <caret>) {\n\n }}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "materialQualities", "materialQualities1", "qualities", "materialQualityIterable",
|
||||
"qualityIterable", "iterable");
|
||||
}
|
||||
|
||||
public void test_suggest_parameter_name_from_javadoc() {
|
||||
myFixture.configureByText("a.java",
|
||||
"\nclass FooFoo {\n /**\n * @param existing\n * @param abc\n * @param def\n * @param <T>\n */\n void set(int existing, int <caret>) {}\n}\n");
|
||||
myFixture.completeBasic();
|
||||
assertEquals(Set.copyOf(myFixture.getLookupElementStrings()), Set.of("abc", "def", "i"));
|
||||
}
|
||||
|
||||
public void test_no_name_suggestions_when_the_type_is_unresolved_because_it_is_actually_a_mistyped_keyword() {
|
||||
myFixture.configureByText("a.java", "\nclass C {\n { \n retur Fi<caret>x\n }\n }\n");
|
||||
assertEquals(0, myFixture.completeBasic().length);
|
||||
}
|
||||
|
||||
public void test_suggest_variable_name_when_the_type_is_unresolved_but_does_not_seem_a_mistyped_keyword() {
|
||||
myFixture.configureByText("a.java", "\nclass C {\n { \n UndefinedType <caret>\n }\n }\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "undefinedType", "type");
|
||||
}
|
||||
|
||||
public void test_class_based_suggestions_for_exception_type() {
|
||||
myFixture.configureByText("a.java", "\nclass C {\n { \n try { } catch (java.io.IOException <caret>)\n }\n}\n");
|
||||
myFixture.completeBasic();
|
||||
myFixture.assertPreferredCompletionItems(0, "e", "ioException", "exception");
|
||||
}
|
||||
|
||||
public void test_no_shadowed_static_field_suggestions() {
|
||||
myFixture.configureByText("a.java",
|
||||
"\nclass C extends Super {\n static final String FOO = \"c\";\n { \n C.FO<caret>x\n }\n}\n\nclass Super {\n static final String FOO = \"super\";\n}\n");
|
||||
LookupElement[] items = myFixture.completeBasic();
|
||||
assertStringItems("FOO");
|
||||
assertEquals(" ( = \"c\")", NormalCompletionTestCase.renderElement(items[0]).getTailText());
|
||||
}
|
||||
|
||||
private static final String FILE_PREFIX = "/codeInsight/completion/variables/";
|
||||
}
|
||||
Reference in New Issue
Block a user