mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-111537 (False negatives for "Auto-unboxing" inspection)
This commit is contained in:
+34
-2
@@ -90,11 +90,11 @@ public class ExpectedTypeUtils {
|
||||
operatorAssignmentOps.add(JavaTokenType.GTGTGTEQ);
|
||||
}
|
||||
|
||||
private final PsiExpression wrappedExpression;
|
||||
@NotNull private final PsiExpression wrappedExpression;
|
||||
private final boolean calculateTypeForComplexReferences;
|
||||
private PsiType expectedType = null;
|
||||
|
||||
ExpectedTypeVisitor(PsiExpression wrappedExpression, boolean calculateTypeForComplexReferences) {
|
||||
ExpectedTypeVisitor(@NotNull PsiExpression wrappedExpression, boolean calculateTypeForComplexReferences) {
|
||||
this.wrappedExpression = wrappedExpression;
|
||||
this.calculateTypeForComplexReferences = calculateTypeForComplexReferences;
|
||||
}
|
||||
@@ -116,6 +116,17 @@ public class ExpectedTypeUtils {
|
||||
expectedType = variable.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAssertStatement(PsiAssertStatement statement) {
|
||||
final PsiExpression condition = statement.getAssertCondition();
|
||||
if (wrappedExpression == condition) {
|
||||
expectedType = PsiType.BOOLEAN;
|
||||
}
|
||||
else {
|
||||
expectedType = TypeUtils.getStringType(statement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitArrayInitializerExpression(PsiArrayInitializerExpression initializer) {
|
||||
final PsiType type = initializer.getType();
|
||||
@@ -268,6 +279,22 @@ public class ExpectedTypeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitSwitchStatement(PsiSwitchStatement statement) {
|
||||
final PsiExpression expression = statement.getExpression();
|
||||
if (expression == null) {
|
||||
return;
|
||||
}
|
||||
final PsiType type = expression.getType();
|
||||
final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(type);
|
||||
if (unboxedType != null) {
|
||||
expectedType = unboxedType;
|
||||
}
|
||||
else {
|
||||
expectedType = type;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWhileStatement(@NotNull PsiWhileStatement whileStatement) {
|
||||
expectedType = PsiType.BOOLEAN;
|
||||
@@ -376,6 +403,11 @@ public class ExpectedTypeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInstanceOfExpression(PsiInstanceOfExpression expression) {
|
||||
expectedType = TypeUtils.getObjectType(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDeclarationStatement(PsiDeclarationStatement declaration) {
|
||||
final PsiElement[] declaredElements = declaration.getDeclaredElements();
|
||||
|
||||
@@ -40,4 +40,17 @@ public class AutoUnboxing {
|
||||
private boolean noWarn(Integer i1, Integer i2) {
|
||||
return i1 == i2;
|
||||
}
|
||||
|
||||
void m(Boolean b) {
|
||||
assert b;
|
||||
}
|
||||
|
||||
void n(Integer i) {
|
||||
switch(i) {
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@
|
||||
<description>Auto-unboxing <code>Boolean.TRUE</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
|
||||
<problem>
|
||||
<file>AutoUnboxing.java</file>
|
||||
<line>37</line>
|
||||
@@ -72,4 +71,18 @@
|
||||
<description>Auto-unboxing <code>Integer.valueOf(2)</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>AutoUnboxing.java</file>
|
||||
<line>45</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Auto-unboxing</problem_class>
|
||||
<description>Auto-unboxing <code>b</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>AutoUnboxing.java</file>
|
||||
<line>49</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Auto-unboxing</problem_class>
|
||||
<description>Auto-unboxing <code>i</code> #loc</description>
|
||||
</problem>
|
||||
|
||||
</problems>
|
||||
Reference in New Issue
Block a user