mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
UnnecessaryBoxing: don't warn if inferred variable type will change (IDEA-193096)
This commit is contained in:
+5
@@ -250,6 +250,11 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
|
||||
parent instanceof PsiSynchronizedStatement) {
|
||||
return true;
|
||||
}
|
||||
else if (parent instanceof PsiVariable) {
|
||||
PsiTypeElement typeElement = ((PsiVariable)parent).getTypeElement();
|
||||
// Inferred type may change if boxing is removed; if it's possible
|
||||
if (typeElement != null && typeElement.isInferredType()) return true;
|
||||
}
|
||||
else if (parent instanceof PsiTypeCastExpression) {
|
||||
final PsiTypeCastExpression castExpression = (PsiTypeCastExpression)parent;
|
||||
return TypeUtils.isTypeParameter(castExpression.getType());
|
||||
|
||||
+7
@@ -135,4 +135,11 @@ class WithLambdaUnfriendlyOverloads {
|
||||
System.out.println("hello");
|
||||
}
|
||||
}
|
||||
|
||||
void testVar() {
|
||||
var x = Integer.valueOf(5);
|
||||
Integer y = <warning descr="Unnecessary boxing 'Integer.valueOf(5)'">Integer.valueOf(5)</warning>;
|
||||
System.out.println(x.getClass());
|
||||
System.out.println(y.getClass());
|
||||
}
|
||||
}
|
||||
+7
@@ -4,10 +4,17 @@
|
||||
package com.siyeh.ig.migration;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UnnecessaryBoxingInspectionTest extends LightInspectionTestCase {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_10;
|
||||
}
|
||||
|
||||
public void testUnnecessaryBoxing() {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user