mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find method duplicates: respect varargs mix with constants/params; empty args list (IDEA-56076)
This commit is contained in:
@@ -292,13 +292,16 @@ public class DuplicatesFinder {
|
||||
if (pattern instanceof PsiExpressionList && candidate instanceof PsiExpressionList) { //check varargs
|
||||
final PsiExpression[] expressions = ((PsiExpressionList)pattern).getExpressions();
|
||||
final PsiExpression[] childExpressions = ((PsiExpressionList)candidate).getExpressions();
|
||||
if (expressions.length < childExpressions.length && expressions.length > 0 && expressions[expressions.length - 1] instanceof PsiReferenceExpression) {
|
||||
if (expressions.length > 0 && expressions[expressions.length - 1] instanceof PsiReferenceExpression) {
|
||||
final PsiElement resolved = ((PsiReferenceExpression)expressions[expressions.length - 1]).resolve();
|
||||
if (resolved instanceof PsiParameter && ((PsiParameter)resolved).getType() instanceof PsiEllipsisType) {
|
||||
for(int i = 0; i < expressions.length - 1; i++) {
|
||||
final Pair<PsiVariable, PsiType> parameter = expressions[i].getUserData(PARAMETER);
|
||||
if (parameter == null) return false;
|
||||
if (!match.putParameter(parameter, childExpressions[i])) return false;
|
||||
if (parameter == null) {
|
||||
if (!matchPattern(expressions[i], childExpressions[i], candidates, match)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!match.putParameter(parameter, childExpressions[i])) return false;
|
||||
}
|
||||
final Pair<PsiVariable, PsiType> param = expressions[expressions.length - 1].getUserData(PARAMETER);
|
||||
if (param == null) return false;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
void bar(int i){
|
||||
method(1);
|
||||
method(i, "a");
|
||||
method(1, "a", "b");
|
||||
}
|
||||
|
||||
void m<caret>(String... args) {
|
||||
method(1, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
void bar(int i){
|
||||
m(new String[0]);
|
||||
method(i, "a");
|
||||
m("a", "b");
|
||||
}
|
||||
|
||||
void m(String... args) {
|
||||
method(1, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
void bar(int i){
|
||||
method(i);
|
||||
method(i, "a");
|
||||
method(i, "a", "b");
|
||||
}
|
||||
|
||||
void m<caret>(int i, String... args) {
|
||||
method(i, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
void bar(int i){
|
||||
m(i, new String[0]);
|
||||
m(i, "a");
|
||||
m(i, "a", "b");
|
||||
}
|
||||
|
||||
void m(int i, String... args) {
|
||||
method(i, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
{
|
||||
method(1);
|
||||
method(1, "a");
|
||||
method(1, "a", "b");
|
||||
}
|
||||
|
||||
void m<caret>(String... args) {
|
||||
method(1, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
{
|
||||
m(new String[0]);
|
||||
m("a");
|
||||
m("a", "b");
|
||||
}
|
||||
|
||||
void m(String... args) {
|
||||
method(1, args);
|
||||
}
|
||||
|
||||
void method(int i, String... args) {
|
||||
}
|
||||
}
|
||||
@@ -74,5 +74,15 @@ public class FindMethodDuplicatesMiscTest extends FindMethodDuplicatesBaseTest {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVarargsAccess() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIncorrectVarargsAccess() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testVarVarargsAccess() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user