mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find method duplicates: detect duplication even id primitive parameters are modified ( IDEA-54921)
This commit is contained in:
@@ -318,9 +318,11 @@ public class DuplicatesFinder {
|
||||
return false;
|
||||
}
|
||||
} else if (pattern instanceof PsiPrefixExpression) {
|
||||
if (checkParameterModification(((PsiPrefixExpression)pattern).getOperand(), ((PsiPrefixExpression)pattern).getOperationTokenType())) return false;
|
||||
if (checkParameterModification(((PsiPrefixExpression)pattern).getOperand(), ((PsiPrefixExpression)pattern).getOperationTokenType(),
|
||||
((PsiPrefixExpression)candidate).getOperand())) return false;
|
||||
} else if (pattern instanceof PsiPostfixExpression) {
|
||||
if (checkParameterModification(((PsiPostfixExpression)pattern).getOperand(), ((PsiPostfixExpression)pattern).getOperationTokenType())) return false;
|
||||
if (checkParameterModification(((PsiPostfixExpression)pattern).getOperand(), ((PsiPostfixExpression)pattern).getOperationTokenType(),
|
||||
((PsiPostfixExpression)candidate).getOperand())) return false;
|
||||
}
|
||||
|
||||
if (pattern instanceof PsiJavaCodeReferenceElement) {
|
||||
@@ -458,9 +460,14 @@ public class DuplicatesFinder {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkParameterModification(final PsiExpression expression, final IElementType sign) {
|
||||
private static boolean checkParameterModification(final PsiExpression expression,
|
||||
final IElementType sign,
|
||||
PsiExpression candidate) {
|
||||
if (expression instanceof PsiReferenceExpression && ((PsiReferenceExpression)expression).resolve() instanceof PsiParameter &&
|
||||
(sign.equals(JavaTokenType.MINUSMINUS)|| sign.equals(JavaTokenType.PLUSPLUS))) {
|
||||
if (candidate instanceof PsiReferenceExpression && ((PsiReferenceExpression)candidate).resolve() instanceof PsiParameter) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
class Test {
|
||||
private double d<caret>d1(int index, double compVal, int numDays) {
|
||||
double aveSlope = 0;
|
||||
|
||||
for (int i = 0; condition(index, numDays, i); i++) {
|
||||
--index;
|
||||
aveSlope = comminSending(index, compVal, aveSlope, i);
|
||||
}
|
||||
return aveSlope;
|
||||
}
|
||||
|
||||
private double ss2(int index, double compVal, int numDays) {
|
||||
double aveSlope = 0;
|
||||
|
||||
for (int i = 0; condition(index, numDays, i); i++) {
|
||||
--index;
|
||||
aveSlope = comminSending(index, compVal, aveSlope, i);
|
||||
}
|
||||
return aveSlope;
|
||||
}
|
||||
|
||||
private boolean condition(int idx, int n, int i){return false;}
|
||||
private double comminSending(int idx, double d, double a, int i){return 0;}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
class Test {
|
||||
private double dd1(int index, double compVal, int numDays) {
|
||||
double aveSlope = 0;
|
||||
|
||||
for (int i = 0; condition(index, numDays, i); i++) {
|
||||
--index;
|
||||
aveSlope = comminSending(index, compVal, aveSlope, i);
|
||||
}
|
||||
return aveSlope;
|
||||
}
|
||||
|
||||
private double ss2(int index, double compVal, int numDays) {
|
||||
double aveSlope = dd1(index, compVal, numDays);
|
||||
return aveSlope;
|
||||
}
|
||||
|
||||
private boolean condition(int idx, int n, int i){return false;}
|
||||
private double comminSending(int idx, double d, double a, int i){return 0;}
|
||||
}
|
||||
@@ -29,4 +29,8 @@ public class FindMethodDuplicatesMiscTest extends FindMethodDuplicatesBaseTest {
|
||||
public void testChangeReturnTypeByReturnValue() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParametersModification() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user