mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-125258 ("Unnecessary boxing" inspection is triggered wrongly with overloaded constructors)
This commit is contained in:
+11
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -294,34 +294,35 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
|
||||
return unboxedType != null && unboxedType.isAssignableFrom(rhsType);
|
||||
}
|
||||
}
|
||||
final PsiMethodCallExpression containingMethodCallExpression = getParentMethodCallExpression(expression);
|
||||
final PsiCallExpression containingMethodCallExpression = getParentMethodCallExpression(expression);
|
||||
return containingMethodCallExpression == null || isSameMethodCalledWithoutBoxing(containingMethodCallExpression, expression);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiMethodCallExpression getParentMethodCallExpression(@NotNull PsiElement expression) {
|
||||
private PsiCallExpression getParentMethodCallExpression(@NotNull PsiElement expression) {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiParenthesizedExpression || parent instanceof PsiExpressionList) {
|
||||
return getParentMethodCallExpression(parent);
|
||||
}
|
||||
else if (parent instanceof PsiMethodCallExpression) {
|
||||
return (PsiMethodCallExpression)parent;
|
||||
else if (parent instanceof PsiCallExpression) {
|
||||
return (PsiCallExpression)parent;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSameMethodCalledWithoutBoxing(@NotNull PsiMethodCallExpression methodCallExpression,
|
||||
private boolean isSameMethodCalledWithoutBoxing(@NotNull PsiCallExpression methodCallExpression,
|
||||
@NotNull PsiExpression boxingExpression) {
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
if (argumentList == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression[] expressions = argumentList.getExpressions();
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final PsiElement element = methodExpression.resolve();
|
||||
if (!(element instanceof PsiMethod)) {
|
||||
final PsiMethod originalMethod = methodCallExpression.resolveMethod();
|
||||
if (originalMethod == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiMethod originalMethod = (PsiMethod)element;
|
||||
final String name = originalMethod.getName();
|
||||
final PsiClass containingClass = originalMethod.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
|
||||
+25
@@ -54,4 +54,29 @@ public class UnnecessaryBoxing {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
class IntIntegerTest {
|
||||
public IntIntegerTest(Integer val) {
|
||||
System.out.println("behavoiur 1");
|
||||
}
|
||||
|
||||
public IntIntegerTest(int val) {
|
||||
System.out.println("behavoiur 2");
|
||||
}
|
||||
|
||||
public static void f(Integer val) {
|
||||
System.out.println("behavoiur 1");
|
||||
}
|
||||
|
||||
public static void f(int val) {
|
||||
System.out.println("behavoiur 2");
|
||||
}
|
||||
|
||||
public IntIntegerTest() {
|
||||
}
|
||||
|
||||
public void test() {
|
||||
new IntIntegerTest(new Integer(1)); // <-- incorrectly triggered
|
||||
f(new Integer(1)); // <-- not triggered
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user