mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup anonymous type when asked for variable type
check that effective cast type will help (IDEA-190473)
This commit is contained in:
+2
-1
@@ -385,7 +385,8 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
if (expression == null) return false;
|
||||
PsiType rType = expression.getType();
|
||||
return rType != null && toType != null && TypeConversionUtil.areTypesConvertible(rType, toType);
|
||||
PsiType castType = GenericsUtil.getVariableTypeByExpressionType(toType);
|
||||
return rType != null && toType != null && TypeConversionUtil.areTypesConvertible(rType, toType) && toType.isAssignableFrom(castType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -303,6 +303,10 @@ public class GenericsUtil {
|
||||
@Contract("null, _ -> null")
|
||||
public static PsiType getVariableTypeByExpressionType(@Nullable PsiType type, final boolean openCaptured) {
|
||||
if (type == null) return null;
|
||||
PsiClass refClass = PsiUtil.resolveClassInType(type);
|
||||
if (refClass instanceof PsiAnonymousClass) {
|
||||
type = ((PsiAnonymousClass)refClass).getBaseClassType();
|
||||
}
|
||||
if (type instanceof PsiCapturedWildcardType) {
|
||||
type = ((PsiCapturedWildcardType)type).getUpperBound();
|
||||
}
|
||||
|
||||
@@ -46,10 +46,6 @@ public class RefactoringChangeUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PsiClass refClass = PsiUtil.resolveClassInType(type);
|
||||
if (refClass instanceof PsiAnonymousClass) {
|
||||
type = ((PsiAnonymousClass)refClass).getBaseClassType();
|
||||
}
|
||||
|
||||
return GenericsUtil.getVariableTypeByExpressionType(type);
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Cast to 'java.lang.Object'" "false"
|
||||
class Scope<T> {
|
||||
T val;
|
||||
void f() {
|
||||
var y = new Object();
|
||||
var x = new Object() {
|
||||
int a = 12;
|
||||
};
|
||||
x =<caret> val;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Cast to 'java.lang.Object'" "false"
|
||||
class A {
|
||||
void f() {
|
||||
var y = new Object();
|
||||
var x = new Object() {
|
||||
int a = 12;
|
||||
};
|
||||
x = <caret>y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user