mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RedundantArrayForVarargsCallInspection: support parenthesized array
This commit is contained in:
+2
-1
@@ -9,6 +9,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.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.refactoring.util.InlineUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -86,7 +87,7 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
|
||||
if (parameters.length != args.length) {
|
||||
return;
|
||||
}
|
||||
PsiExpression lastArg = args[args.length - 1];
|
||||
PsiExpression lastArg = PsiUtil.skipParenthesizedExprDown(args[args.length - 1]);
|
||||
PsiParameter lastParameter = parameters[args.length - 1];
|
||||
if (!lastParameter.isVarArgs()) {
|
||||
return;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -208,7 +209,7 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
public static void inlineArrayCreationForVarargs(final PsiNewExpression arrayCreation) {
|
||||
PsiExpressionList argumentList = (PsiExpressionList)arrayCreation.getParent();
|
||||
PsiExpressionList argumentList = (PsiExpressionList)PsiUtil.skipParenthesizedExprUp(arrayCreation.getParent());
|
||||
if (argumentList == null) return;
|
||||
PsiExpression[] args = argumentList.getExpressions();
|
||||
PsiArrayInitializerExpression arrayInitializer = arrayCreation.getArrayInitializer();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
display((new //c1
|
||||
S<caret>tring[]{
|
||||
"hi"
|
||||
}));
|
||||
}
|
||||
|
||||
private static void display(String... messages) { }
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
display(//c1
|
||||
<caret>"hi");
|
||||
}
|
||||
|
||||
private static void display(String... messages) { }
|
||||
}
|
||||
+1
@@ -38,6 +38,7 @@ public class RedundantArray4VarargsCallInspectionTest extends LightCodeInsightFi
|
||||
|
||||
public void testPreserveComments() { doTest(); }
|
||||
public void testRemoveTailingCommas() { doTest(); }
|
||||
public void testParentheses() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
String name = getTestName(false);
|
||||
|
||||
Reference in New Issue
Block a user