Revert "IJ-CR-102037 [java-inspections] IDEA-311705. Add uncapture top level wildcard for records"

This reverts commit b9454add238bcbee31dbbe8965f41e6496cdddd8.

GitOrigin-RevId: 12ab120168763ad3c3e0b18284b40716af408553
This commit is contained in:
Mikhail Pyltsin
2023-02-03 00:32:30 +00:00
committed by intellij-monorepo-bot
parent 838311cfdb
commit cb01ed8c62
6 changed files with 7 additions and 40 deletions
@@ -2033,7 +2033,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!TypeConversionUtil.areTypesConvertible(itemType, patternType)) {
add(HighlightUtil.createIncompatibleTypeHighlightInfo(itemType, patternType, pattern.getTextRange(), 0));
}
else if (JavaGenericsUtil.isUncheckedCast(PsiUtil.uncaptureToplevelWildcards(patternType), itemType)) {
else if (JavaGenericsUtil.isUncheckedCast(patternType, itemType)) {
String message = JavaErrorBundle.message("unsafe.cast.in.instanceof", JavaHighlightUtil.formatType(itemType),
JavaHighlightUtil.formatType(patternType));
add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(pattern).descriptionAndTooltip(message));
@@ -70,7 +70,7 @@ final class PatternHighlightingModel {
holder.add(builder.create());
}
}
else if (JavaGenericsUtil.isUncheckedCast(PsiUtil.uncaptureToplevelWildcards(Objects.requireNonNull(deconstructionComponentType)),
else if (JavaGenericsUtil.isUncheckedCast(Objects.requireNonNull(deconstructionComponentType),
GenericsUtil.getVariableTypeByExpressionType(substitutedRecordComponentType))) {
hasMismatchedPattern = true;
if (recordComponents.length == deconstructionComponents.length) {
@@ -316,6 +316,9 @@ public final class JavaGenericsUtil {
PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getClassSubstitutor(owner, aClass, substitutor);
if (superClassSubstitutor == null) return null;
PsiType itemType = superClassSubstitutor.substitute(typeParameter);
if (itemType != null) {
itemType = PsiUtil.captureToplevelWildcards(itemType, aClass);
}
return itemType == null ? PsiType.getJavaLangObject(manager, aClass.getResolveScope()) : itemType;
}
if (type instanceof PsiIntersectionType) {
@@ -826,32 +826,6 @@ public final class PsiUtil extends PsiUtilCore {
return null;
}
@NotNull
public static PsiType uncaptureToplevelWildcards(@NotNull PsiType type) {
if (type instanceof PsiClassType) {
PsiClassType.ClassResolveResult result = ((PsiClassType)type).resolveGenerics();
PsiClass aClass = result.getElement();
if (aClass != null) {
PsiSubstitutor substitutor = result.getSubstitutor();
PsiSubstitutor uncaptureSubstitutor = substitutor;
boolean hasCaptured = false;
for (PsiTypeParameter typeParameter : typeParametersIterable(aClass)) {
PsiType substituted = substitutor.substitute(typeParameter);
if (substituted instanceof PsiCapturedWildcardType) {
hasCaptured = true;
uncaptureSubstitutor = uncaptureSubstitutor.put(typeParameter, ((PsiCapturedWildcardType)substituted).getWildcard());
}
}
if (hasCaptured) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(aClass.getProject());
return factory.createType(aClass, uncaptureSubstitutor);
}
}
}
return type;
}
/**
* Applies capture conversion to the type in context
*/
@@ -345,11 +345,7 @@ public final class JavaResolveUtil {
if (iteratedValue == null) {
return null;
}
PsiType itemType = JavaGenericsUtil.getCollectionItemType(iteratedValue);
if (itemType != null) {
itemType = PsiUtil.captureToplevelWildcards(itemType, parent);
}
return itemType;
return JavaGenericsUtil.getCollectionItemType(iteratedValue);
}
if (parent instanceof PsiCaseLabelElementList) {
PsiSwitchLabelStatementBase label = ObjectUtils.tryCast(parent.getParent(), PsiSwitchLabelStatementBase.class);
@@ -219,13 +219,7 @@ public class DeconstructionInferenceTest extends LightJavaCodeInsightFixtureTest
System.out.println(x.isEmpty());
}
}
public static void test3(List<Box<? extends Box<? extends Box<? extends String>>>> records) {
for (Box(Box(Box(var x))) : records) {
System.out.println(x.isEmpty());
}
}
}
}
""");
myFixture.enableInspections(new RawUseOfParameterizedTypeInspection());
myFixture.checkHighlighting();