mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
warn about raw arrays passed to varargs method (IDEA-16977)
This commit is contained in:
+8
-2
@@ -23,6 +23,7 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.util.InlineUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -108,8 +109,13 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
|
||||
PsiParameter lastParameter = parameters[args.length - 1];
|
||||
PsiType lastParamType = lastParameter.getType();
|
||||
LOG.assertTrue(lastParamType instanceof PsiEllipsisType);
|
||||
if (!(lastArg instanceof PsiNewExpression) ||
|
||||
!substitutor.substitute(((PsiEllipsisType)lastParamType).toArrayType()).equals(lastArg.getType())) {
|
||||
if (!(lastArg instanceof PsiNewExpression)) {
|
||||
return;
|
||||
}
|
||||
final PsiType substitutedLastParamType = substitutor.substitute(((PsiEllipsisType)lastParamType).toArrayType());
|
||||
final PsiType lastArgType = lastArg.getType();
|
||||
if (lastArgType == null || !lastArgType.equals(substitutedLastParamType) &&
|
||||
!lastArgType.equals(TypeConversionUtil.erasure(substitutedLastParamType))) {
|
||||
return;
|
||||
}
|
||||
PsiExpression[] initializers = getInitializers((PsiNewExpression)lastArg);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>4</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Redundant array creation</problem_class>
|
||||
<description>Redundant array creation for calling varargs method</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Test {
|
||||
{
|
||||
try {
|
||||
String.class.getConstructor(new Class[]{String.class});
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -23,4 +23,5 @@ public class RedundantArrayForVarargsCallInspectionTest extends InspectionTestCa
|
||||
public void testNestedArray() throws Exception { doTest(); }
|
||||
public void testCheckEnumConstant() throws Exception { doTest(); }
|
||||
public void testGeneric() throws Exception { doTest(); }
|
||||
public void testRawArray() throws Exception { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user