mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 15:41:26 +07:00
JavaCompletionUtil: do not add an unnecessary cast if hierarchy signature has several levels
Fixes IDEA-185554 Redundant cast on autocompletion
This commit is contained in:
@@ -366,7 +366,7 @@ public class JavaCompletionUtil {
|
||||
PsiClassType.ClassResolveResult plainResult = ((PsiClassType)plainQualifier).resolveGenerics();
|
||||
PsiClass plainClass = plainResult.getElement();
|
||||
HierarchicalMethodSignature signature = method.getHierarchicalMethodSignature();
|
||||
if (plainClass != null && StreamEx.of(signature.getSuperSignatures()).prepend(signature)
|
||||
if (plainClass != null && StreamEx.ofTree(signature, s -> StreamEx.of(s.getSuperSignatures()))
|
||||
.anyMatch(sig -> MethodSignatureUtil.findMethodBySignature(plainClass, sig, true) != null)) {
|
||||
PsiClass castClass = ((PsiClassType)castType).resolveGenerics().getElement();
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
class MyTest {
|
||||
interface Container<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
interface Container2<K, V> extends Container<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
interface Container3<K, V> extends Container2<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
void test(Container3<String, String> c3) {
|
||||
Container<String, String> c = c3;
|
||||
c.re<caret>
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
class MyTest {
|
||||
interface Container<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
interface Container2<K, V> extends Container<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
interface Container3<K, V> extends Container2<K, V> {
|
||||
V read(K k);
|
||||
}
|
||||
|
||||
void test(Container3<String, String> c3) {
|
||||
Container<String, String> c = c3;
|
||||
c.read()
|
||||
}
|
||||
}
|
||||
+1
@@ -54,6 +54,7 @@ class NormalCompletionDfaTest extends NormalCompletionTestCase {
|
||||
void testGenericTypeDfa() { doTest() }
|
||||
void testNoUnnecessaryCastDfa() { doTest() }
|
||||
void testNoUnnecessaryCastRawDfa() { doTest() }
|
||||
void testNoUnnecessaryCastDeepHierarchy() { doTest() }
|
||||
void testInstanceOfAfterFunction() { doTest() }
|
||||
void testComplexInstanceOfDfa() {
|
||||
configureByTestName()
|
||||
|
||||
Reference in New Issue
Block a user