mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
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:
committed by
intellij-monorepo-bot
parent
838311cfdb
commit
cb01ed8c62
+1
-1
@@ -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));
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
+3
@@ -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);
|
||||
|
||||
+1
-7
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user