mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
add tests for completion with casts
This commit is contained in:
@@ -150,10 +150,10 @@ public class ChainSearcher {
|
||||
|
||||
private static boolean addChainIfTerminal(CallChain currentChain, List<CallChain> result, int pathMaximalLength,
|
||||
ChainCompletionContext context) {
|
||||
RefChainOperation signature = currentChain.getHeadSignature();
|
||||
if (!(signature instanceof MethodIncompleteSignature)) return false;
|
||||
RefChainOperation signature = currentChain.getLastMethodSign();
|
||||
RefChainOperation head = currentChain.getHeadSignature();
|
||||
if (((MethodIncompleteSignature)signature).isStatic() ||
|
||||
context.hasQualifier(context.resolvePsiClass(((MethodIncompleteSignature)signature).getOwnerRef())) ||
|
||||
context.hasQualifier(context.resolvePsiClass(head.getOwnerRef1())) ||
|
||||
currentChain.length() >= pathMaximalLength) {
|
||||
addChainIfNotPresent(currentChain, result);
|
||||
return true;
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -57,14 +56,16 @@ public class MethodChainLookupRangingHelper {
|
||||
matchedParametersInContext += info.getSecond();
|
||||
|
||||
if (chainLookupElement == null) {
|
||||
LookupElement qualifierLookupElement = createQualifierLookupElement(method, chain.getQualifierClass(), context);
|
||||
LookupElement qualifierLookupElement = method.hasModifierProperty(PsiModifier.STATIC) ? null : createQualifierLookupElement(chain.getQualifierClass(), context);
|
||||
LookupElement headLookupElement = createMethodLookupElement(method);
|
||||
chainLookupElement = qualifierLookupElement == null ? headLookupElement : new JavaChainLookupElement(qualifierLookupElement, headLookupElement);
|
||||
} else {
|
||||
chainLookupElement = new JavaChainLookupElement(chainLookupElement, new JavaMethodCallElement(method));
|
||||
}
|
||||
} else {
|
||||
if (chainLookupElement == null) throw new IllegalStateException();
|
||||
if (chainLookupElement == null) {
|
||||
chainLookupElement = createQualifierLookupElement(chain.getQualifierClass(), context);
|
||||
}
|
||||
PsiClass castClass = ((ChainOperation.TypeCast)op).getCastClass();
|
||||
PsiClassType type = JavaPsiFacade.getElementFactory(castClass.getProject()).createType(castClass);
|
||||
chainLookupElement = CastingLookupElementDecorator.createCastingElement(chainLookupElement, type);
|
||||
@@ -109,9 +110,9 @@ public class MethodChainLookupRangingHelper {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static LookupElement createQualifierLookupElement(@NotNull PsiMethod method, @NotNull PsiClass qualifierClass, @NotNull ChainCompletionContext context) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) return null;
|
||||
@NotNull
|
||||
private static LookupElement createQualifierLookupElement(@NotNull PsiClass qualifierClass,
|
||||
@NotNull ChainCompletionContext context) {
|
||||
PsiNamedElement element = context.getQualifiers(qualifierClass).findFirst().orElse(null);
|
||||
if (element == null) {
|
||||
return new ChainCompletionNewVariableLookupElement(qualifierClass, context);
|
||||
|
||||
@@ -28,6 +28,10 @@ import java.util.function.Predicate
|
||||
class MethodIncompleteSignature(val ref: LightRef.JavaLightMethodRef,
|
||||
private val signatureData: SignatureData,
|
||||
private val refService: CompilerReferenceServiceEx): RefChainOperation {
|
||||
override fun getOwnerRef1(): LightRef.LightClassHierarchyElementDef {
|
||||
return ownerRef
|
||||
}
|
||||
|
||||
override fun getOwner1(): String {
|
||||
return owner
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.jps.backwardRefs.LightRef;
|
||||
|
||||
public interface RefChainOperation {
|
||||
String getOwner1();
|
||||
LightRef.LightClassHierarchyElementDef getOwnerRef1();
|
||||
|
||||
LightRef getRef1();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ class TypeCast(val operandRef: LightRef.LightClassHierarchyElementDef,
|
||||
val castTypeRef: LightRef.LightClassHierarchyElementDef,
|
||||
refService: CompilerReferenceServiceEx,
|
||||
val occurrences: Int): RefChainOperation {
|
||||
override fun getOwnerRef1(): LightRef.LightClassHierarchyElementDef {
|
||||
return operandRef
|
||||
}
|
||||
|
||||
override fun getOwner1(): String {
|
||||
return operandName
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
interface Editor {}
|
||||
interface EditorEx extends Editor {
|
||||
MarkupModelEx getMarkupModel();
|
||||
}
|
||||
interface MarkupModelEx {}
|
||||
|
||||
class Test {
|
||||
void m(Editor editor) {
|
||||
MarkupModelEx m = <caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
interface Editor {}
|
||||
interface EditorEx extends Editor {
|
||||
MarkupModelEx getMarkupModel();
|
||||
}
|
||||
interface MarkupModelEx {}
|
||||
|
||||
class Test {
|
||||
void m(Editor editor) {
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
interface InspectionManager {
|
||||
static InspectionManager getInstance() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
interface InspectionManagerEx extends InspectionManager {
|
||||
GlobalInspectionContext createContext();
|
||||
}
|
||||
interface GlobalInspectionContext {}
|
||||
|
||||
class Test {
|
||||
void m() {
|
||||
GlobalInspectionContext c = <caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
interface InspectionManager {
|
||||
static InspectionManager getInstance() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
interface InspectionManagerEx extends InspectionManager {
|
||||
GlobalInspectionContext createContext();
|
||||
}
|
||||
interface GlobalInspectionContext {}
|
||||
|
||||
class Test {
|
||||
void m() {
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
((InspectionManagerEx)InspectionManager.getInstance()).createContext();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
interface Editor {}
|
||||
interface EditorEx extends Editor {
|
||||
MarkupModelEx getMarkupModel();
|
||||
}
|
||||
interface MarkupModelEx {}
|
||||
|
||||
class Test {
|
||||
void m() {
|
||||
MarkupModelEx m = <caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
interface Editor {}
|
||||
interface EditorEx extends Editor {
|
||||
MarkupModelEx getMarkupModel();
|
||||
}
|
||||
interface MarkupModelEx {}
|
||||
|
||||
class Test {
|
||||
void m(Editor editor) {
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
((EditorEx)editor).getMarkupModel();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.compiler.chainsSearch.ChainRelevance;
|
||||
import com.intellij.compiler.chainsSearch.completion.MethodChainCompletionContributor;
|
||||
import com.intellij.compiler.chainsSearch.completion.lookup.JavaRelevantChainLookupElement;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.SkipSlowTestLocally;
|
||||
import com.intellij.util.SmartList;
|
||||
|
||||
@@ -44,6 +46,7 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
Registry.get(MethodChainCompletionContributor.REGISTRY_KEY).setValue(true, myFixture.getTestRootDisposable());
|
||||
myDefaultAutoCompleteOnCodeCompletion = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION;
|
||||
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = false;
|
||||
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -240,6 +243,20 @@ public class MethodChainsCompletionTest extends AbstractCompilerAwareTest {
|
||||
assertEquals("psiElement.getProject", element.getLookupString());
|
||||
}
|
||||
|
||||
public void testChainWithCastOnContextVariable() {
|
||||
JavaRelevantChainLookupElement element = assertOneElement(doCompletion());
|
||||
assertEquals("(EditorEx)editor.getMarkupModel", element.toString());
|
||||
}
|
||||
|
||||
public void testChainWithCastOnVariableOutsideContext() {
|
||||
assertEmpty(doCompletion());
|
||||
}
|
||||
|
||||
public void testChainWithCastOnStaticMethod() {
|
||||
JavaRelevantChainLookupElement element = assertOneElement(doCompletion());
|
||||
assertEquals("(InspectionManagerEx)getInstance().createContext", element.toString());
|
||||
}
|
||||
|
||||
public void assertAdvisorLookupElementEquals(String lookupText,
|
||||
int unreachableParametersCount,
|
||||
int chainSize,
|
||||
|
||||
Reference in New Issue
Block a user