mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
ChangeStringLiteralToCharInMethodCallFix: support parenthesized args
This commit is contained in:
@@ -25,7 +25,9 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -137,7 +139,7 @@ public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction
|
||||
* @return {@code true} if exact TYPEs match
|
||||
*/
|
||||
private static boolean findMatchingExpressions(final PsiExpression[] arguments, final PsiMethod existingMethod,
|
||||
final Set<PsiLiteralExpression> result) {
|
||||
final Set<PsiLiteralExpression>result) {
|
||||
final PsiParameterList parameterList = existingMethod.getParameterList();
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
|
||||
@@ -146,19 +148,20 @@ public class ChangeStringLiteralToCharInMethodCallFix implements IntentionAction
|
||||
}
|
||||
|
||||
boolean typeMatch = true;
|
||||
for (int i = 0; i < parameters.length && i < arguments.length; i++) {
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
final PsiParameter parameter = parameters[i];
|
||||
final PsiType parameterType = parameter.getType();
|
||||
final PsiType argumentType = arguments[i].getType();
|
||||
|
||||
typeMatch &= Comparing.equal(parameterType, argumentType);
|
||||
|
||||
if (arguments[i] instanceof PsiLiteralExpression && ! result.contains(arguments[i]) &&
|
||||
PsiLiteralExpression argument = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(arguments[i]), PsiLiteralExpression.class);
|
||||
if (argument != null && !result.contains(argument) &&
|
||||
(charToString(parameterType, argumentType) || charToString(argumentType, parameterType))) {
|
||||
|
||||
final String value = String.valueOf(((PsiLiteralExpression) arguments[i]).getValue());
|
||||
final String value = String.valueOf(argument.getValue());
|
||||
if (value != null && value.length() == 1) {
|
||||
result.add((PsiLiteralExpression) arguments[i]);
|
||||
result.add(argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ class Simple {
|
||||
public void m1(final int i, final char ch) {}
|
||||
|
||||
public void test() {
|
||||
m1("does not matter", <caret>'1');
|
||||
m1("does not matter", (('1')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ class Simple {
|
||||
public void m1(final int i, final char ch) {}
|
||||
|
||||
public void test() {
|
||||
m1("does not matter", <caret>"1");
|
||||
m1("does not matter", ((<caret>"1")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user