add cast: don't unbox for null types (IDEA-193174)

This commit is contained in:
Anna Kozlova
2018-06-04 18:44:40 +03:00
parent 97205bb35a
commit 0d0354fdab
3 changed files with 17 additions and 1 deletions
@@ -93,7 +93,7 @@ public abstract class ArgumentFixerActionFactory {
if (parameterType instanceof PsiWildcardType) continue;
if (!GenericsUtil.isFromExternalTypeLanguage(parameterType)) continue;
if (suggestedCasts.contains(parameterType.getCanonicalText())) continue;
if (exprType instanceof PsiPrimitiveType && parameterType instanceof PsiClassType) {
if (TypeConversionUtil.isPrimitiveAndNotNull(exprType) && parameterType instanceof PsiClassType) {
PsiType unboxedParameterType = PsiPrimitiveType.getUnboxedType(parameterType);
if (unboxedParameterType != null) {
parameterType = unboxedParameterType;
@@ -0,0 +1,8 @@
// "Cast parameter to 'java.lang.Integer'" "true"
class a {
void m(Integer i){}
void m(String s) {}
void f() {
m((Integer) null);
}
}
@@ -0,0 +1,8 @@
// "Cast parameter to 'java.lang.Integer'" "true"
class a {
void m(Integer i){}
void m(String s) {}
void f() {
m(<caret>null);
}
}