mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
inference: restore probably partial raw inference as this way expected raw types are preserved and Objects won't be inferred in place where raw types were expected
This commit is contained in:
@@ -34,9 +34,14 @@ public class FunctionalInterfaceParameterizationUtil {
|
||||
}
|
||||
}
|
||||
if (classType instanceof PsiClassType) {
|
||||
for (PsiType type : ((PsiClassType)classType).getParameters()) {
|
||||
if (type instanceof PsiWildcardType) {
|
||||
return true;
|
||||
final PsiClassType.ClassResolveResult result = ((PsiClassType)classType).resolveGenerics();
|
||||
final PsiClass aClass = result.getElement();
|
||||
if (aClass != null) {
|
||||
final PsiSubstitutor substitutor = result.getSubstitutor();
|
||||
for (PsiTypeParameter parameter : aClass.getTypeParameters()) {
|
||||
if (substitutor.substitute(parameter) instanceof PsiWildcardType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -164,17 +169,16 @@ public class FunctionalInterfaceParameterizationUtil {
|
||||
*/
|
||||
@Nullable
|
||||
public static PsiType getNonWildcardParameterization(PsiClassType psiClassType) {
|
||||
final PsiClass psiClass = psiClassType.resolve();
|
||||
final PsiClassType.ClassResolveResult result = psiClassType.resolveGenerics();
|
||||
final PsiClass psiClass = result.getElement();
|
||||
if (psiClass != null) {
|
||||
final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
|
||||
final PsiType[] parameters = psiClassType.getParameters();
|
||||
final PsiType[] newParameters = new PsiType[parameters.length];
|
||||
|
||||
if (parameters.length != typeParameters.length) return null;
|
||||
final PsiType[] newParameters = new PsiType[typeParameters.length];
|
||||
|
||||
final PsiSubstitutor substitutor = result.getSubstitutor();
|
||||
final HashSet<PsiTypeParameter> typeParametersSet = ContainerUtil.newHashSet(typeParameters);
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiType paramType = parameters[i];
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
PsiType paramType = substitutor.substitute(typeParameters[i]);
|
||||
if (paramType instanceof PsiWildcardType) {
|
||||
for (PsiClassType paramBound : typeParameters[i].getExtendsListTypes()) {
|
||||
if (PsiPolyExpressionUtil.mentionsTypeParameters(paramBound, typeParametersSet)) {
|
||||
|
||||
@@ -1156,7 +1156,7 @@ public class InferenceSession {
|
||||
type = PsiType.getJavaLangRuntimeException(myManager, GlobalSearchScope.allScope(myManager.getProject()));
|
||||
}
|
||||
else {
|
||||
type = upperBound;
|
||||
type = myErased ? null : upperBound;
|
||||
}
|
||||
|
||||
if (type instanceof PsiIntersectionType) {
|
||||
|
||||
@@ -7,8 +7,8 @@ public class Sample {
|
||||
<B> B bar(G<B> gb) {return null;}
|
||||
|
||||
void f(G1 g1) {
|
||||
G<String> l11 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
|
||||
String l1 = bar<error descr="'bar(Sample.G<B>)' in 'Sample' cannot be applied to '(Sample.G1)'">(g1)</error>;
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'Sample.G<java.lang.String>'">G<String> l11 = bar(g1);</error>
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String l1 = bar(g1);</error>
|
||||
Object o = bar(g1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Collection children = new ArrayList<>();
|
||||
List<String> actualNodes = <warning descr="Unchecked assignment: 'java.util.ArrayList' to 'java.util.List<java.lang.String>'"><warning descr="Unchecked call to 'ArrayList(Collection<? extends E>)' as a member of raw type 'java.util.ArrayList'">new ArrayList<>(children)</warning></warning>;
|
||||
System.out.println(actualNodes);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.Set;
|
||||
abstract class Test {
|
||||
|
||||
public void foo(List list) {
|
||||
set<error descr="Ambiguous method call: both 'Test.set(Set<List>, List)' and 'Test.set(Set<Object>, List<?>)' match">(get(), list)</error>;
|
||||
set<error descr="Ambiguous method call: both 'Test.set(Set<List>, List)' and 'Test.set(Set, List)' match">(get(), list)</error>;
|
||||
}
|
||||
|
||||
abstract <Y> Set<Y> get();
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.daemon.lambda;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -418,6 +419,12 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPartialRawSubstitutionToAvoidInferringObjectsWhenRawExpected() throws Exception {
|
||||
final UncheckedWarningLocalInspection localInspection = new UncheckedWarningLocalInspection();
|
||||
enableInspectionTool(localInspection);
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
public void testVariableNamesOfNestedCalls() throws Exception {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
|
||||
|
||||
Reference in New Issue
Block a user