mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
bound promotion for super wildcard (? super A (bound extends A) == A)
This commit is contained in:
@@ -17,6 +17,7 @@ package com.intellij.psi;
|
||||
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
@@ -24,27 +25,44 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class PsiCapturedWildcardType extends PsiType {
|
||||
@NotNull private final PsiWildcardType myExistential;
|
||||
@NotNull private final PsiElement myContext;
|
||||
@Nullable private final PsiTypeParameter myParameter;
|
||||
|
||||
public boolean equals(final Object o) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof PsiCapturedWildcardType)) return false;
|
||||
final PsiCapturedWildcardType captured = (PsiCapturedWildcardType)o;
|
||||
return myContext.equals(captured.myContext) &&
|
||||
myExistential.equals(captured.myExistential);
|
||||
if (!myContext.equals(captured.myContext) ||
|
||||
!myExistential.equals(captured.myExistential)) return false;
|
||||
|
||||
if (myContext instanceof PsiReferenceExpression) {
|
||||
if (myParameter != null ? !myParameter.equals(captured.myParameter) : captured.myParameter != null) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myExistential.hashCode() + 31 * myContext.hashCode();
|
||||
}
|
||||
|
||||
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
|
||||
private PsiCapturedWildcardType(@NotNull PsiWildcardType existential, @NotNull PsiElement context, @Nullable PsiTypeParameter parameter) {
|
||||
super(PsiAnnotation.EMPTY_ARRAY);//todo
|
||||
myExistential = existential;
|
||||
myContext = context;
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential, @NotNull PsiElement context) {
|
||||
return new PsiCapturedWildcardType(existential, context);
|
||||
return create(existential, context, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiCapturedWildcardType create(@NotNull PsiWildcardType existential,
|
||||
@NotNull PsiElement context,
|
||||
PsiTypeParameter parameter) {
|
||||
return new PsiCapturedWildcardType(existential, context, parameter);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -687,7 +687,7 @@ public final class PsiUtil extends PsiUtilCore {
|
||||
final PsiType substituted = substitutor.substitute(typeParameter);
|
||||
if (substituted instanceof PsiWildcardType) {
|
||||
if (substitutionMap == null) substitutionMap = new HashMap<PsiTypeParameter, PsiType>(substitutor.getSubstitutionMap());
|
||||
substitutionMap.put(typeParameter, PsiCapturedWildcardType.create((PsiWildcardType)substituted, context));
|
||||
substitutionMap.put(typeParameter, PsiCapturedWildcardType.create((PsiWildcardType)substituted, context, typeParameter));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
|
||||
|
||||
if (captureContext != null) {
|
||||
substituted = oldSubstituted instanceof PsiCapturedWildcardType && substituted == ((PsiCapturedWildcardType)oldSubstituted).getWildcard()
|
||||
? oldSubstituted : PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext);
|
||||
? oldSubstituted : PsiCapturedWildcardType.create((PsiWildcardType)substituted, captureContext, typeParameter);
|
||||
}
|
||||
return substituted;
|
||||
}
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ class WithingBounds {
|
||||
A<A<<error descr="Type parameter 'A' is not within its bound; should extend 'A<A>'">A</error>>> a3;
|
||||
|
||||
A<? extends A> a4;
|
||||
A<<error descr="Type parameter '? super A' is not within its bound; should extend 'A<? super A>'">? super A</error>> a5;
|
||||
A<<error descr="Type parameter '? super A' is not within its bound; should extend 'A<A<T>>'">? super A</error>> a5;
|
||||
A<<error descr="Type parameter 'A[]' is not within its bound; should extend 'A<A[]>'">A[]</error>> a7;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ class WithingBounds {
|
||||
A<A<<error descr="Type parameter 'A' is not within its bound; should extend 'A<A>'">A</error>>> a3;
|
||||
|
||||
A<? extends A> a4;
|
||||
A<<error descr="Type parameter '? super A' is not within its bound; should extend 'A<? super A>'">? super A</error>> a5;
|
||||
A<<error descr="Type parameter '? super A' is not within its bound; should extend 'A<A<T>>'">? super A</error>> a5;
|
||||
A<<error descr="Type parameter 'A[]' is not within its bound; should extend 'A<A[]>'">A[]</error>> a7;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user