java: missed type cast suggestion on annotated types (IDEA-256942)

GitOrigin-RevId: 86dd16b919e602d375267b868c84384eb4e097cd
This commit is contained in:
Anna Kozlova
2020-12-04 20:39:36 +01:00
committed by intellij-monorepo-bot
parent d18b2a7398
commit 6a0c39b3ee
4 changed files with 31 additions and 6 deletions

View File

@@ -90,8 +90,7 @@ public abstract class ArgumentFixerActionFactory {
PsiSubstitutor substitutor = candidate.getSubstitutor();
PsiType originalParameterType = PsiTypesUtil.getParameterType(method.getParameterList().getParameters(), i, true);
PsiType parameterType = substitutor.substitute(originalParameterType);
if (parameterType instanceof PsiWildcardType) continue;
if (!GenericsUtil.isFromExternalTypeLanguage(parameterType)) continue;
if (!PsiTypesUtil.isDenotableType(parameterType, call)) continue;
if (suggestedCasts.contains(parameterType.getCanonicalText())) continue;
if (TypeConversionUtil.isPrimitiveAndNotNull(exprType) && parameterType instanceof PsiClassType) {
PsiType unboxedParameterType = PsiPrimitiveType.getUnboxedType(parameterType);

View File

@@ -279,10 +279,6 @@ public final class GenericsUtil {
return null;
}
public static boolean isFromExternalTypeLanguage(@NotNull PsiType type) {
return type.getInternalCanonicalText().equals(type.getCanonicalText());
}
@Contract("null -> null; !null->!null")
public static PsiType getVariableTypeByExpressionType(@Nullable PsiType type) {
return type == null ? null : getVariableTypeByExpressionType(type, true);

View File

@@ -0,0 +1,15 @@
// "Cast parameter to 'java.lang.@Anno String'" "true"
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target(ElementType.TYPE_USE)
@interface Anno {}
class a {
void f(@Anno String s) { }
void m(Object o) {
if (o instanceof String) {
f((String) o);
}
}
}

View File

@@ -0,0 +1,15 @@
// "Cast parameter to 'java.lang.@Anno String'" "true"
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Target(ElementType.TYPE_USE)
@interface Anno {}
class a {
void f(@Anno String s) { }
void m(Object o) {
if (o instanceof String) {
f(<caret>o);
}
}
}