IDEA-234256 QuickFix for "Unnecessary call to 'toString'" could be more explicit

GitOrigin-RevId: d8ec1a80004ae2405f78b42a50df0ca2c994d5d3
This commit is contained in:
Tagir Valeev
2020-03-04 05:37:23 +00:00
committed by intellij-monorepo-bot
parent ebda994e59
commit 13b04e6d06
3 changed files with 9 additions and 8 deletions
@@ -1,4 +1,4 @@
// "Fix all 'Unnecessary call to 'toString()'' problems in file" "true"
// "Remove redundant 'toString()' call" "true"
class X {
void test(Object x) {
System.out.println(x);
@@ -1,4 +1,4 @@
// "Fix all 'Unnecessary call to 'toString()'' problems in file" "true"
// "Remove redundant 'toString()' call" "true"
class X {
void test(Object x) {
System.out.println(x.toStri<caret>ng());
@@ -36,8 +36,7 @@ public class UnnecessaryToStringCallInspection extends BaseInspection implements
@Override
@NotNull
protected String buildErrorString(Object... infos) {
final String text = (String)infos[0];
return InspectionGadgetsBundle.message("unnecessary.tostring.call.problem.descriptor", text);
return InspectionGadgetsBundle.message("unnecessary.tostring.call.problem.descriptor");
}
@Override
@@ -48,16 +47,18 @@ public class UnnecessaryToStringCallInspection extends BaseInspection implements
}
private static class UnnecessaryToStringCallFix extends InspectionGadgetsFix {
private final @Nullable String replacementText;
private final String replacementText;
private UnnecessaryToStringCallFix(String replacementText) {
private UnnecessaryToStringCallFix(@Nullable String replacementText) {
this.replacementText = replacementText;
}
@Override
@NotNull
public String getName() {
if (replacementText == null) {
return InspectionGadgetsBundle.message("inspection.redundant.string.remove.fix.name", "toString");
}
return CommonQuickFixBundle.message("fix.replace.with.x", replacementText);
}
@@ -98,7 +99,7 @@ public class UnnecessaryToStringCallInspection extends BaseInspection implements
if (referenceNameElement == null) return;
PsiExpression qualifier = ExpressionUtils.getEffectiveQualifier(methodExpression);
if (qualifier == null) return;
registerError(referenceNameElement, ProblemHighlightType.LIKE_UNUSED_SYMBOL, qualifier.getText());
registerError(referenceNameElement, ProblemHighlightType.LIKE_UNUSED_SYMBOL, qualifier.isPhysical() ? null : qualifier.getText());
}
}