redundant cast: trim too long messages (IDEA-182666)

This commit is contained in:
Anna Kozlova
2018-06-19 12:04:10 +03:00
parent 2adff83708
commit 201de8dd01
10 changed files with 11 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiExpressionTrimRenderer;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.RedundantCastUtil;
import org.jdom.Element;
@@ -102,7 +103,7 @@ public class RedundantCastInspection extends GenericsInspectionToolBase {
}
String message = InspectionsBundle.message("inspection.redundant.cast.problem.descriptor",
"<code>" + operand.getText() + "</code>", "<code>#ref</code> #loc");
"<code>" + PsiExpressionTrimRenderer.render(operand) + "</code>", "<code>#ref</code> #loc");
return manager.createProblemDescriptor(castType, message, myQuickFixAction, ProblemHighlightType.LIKE_UNUSED_SYMBOL, onTheFly);
}

View File

@@ -22,6 +22,6 @@ class Test {
strings.forEach((IoFunction<String>) arg -> {throw new IOException();});
strings.forEach((IFunction<String>) arg -> {});
strings.forEach((IIFunction<String>) arg -> {});
strings.forEach((<warning descr="Casting 'arg -> {}' to 'Consumer<String>' is redundant">Consumer<String></warning>) arg -> {});
strings.forEach((<warning descr="Casting 'arg -> {...}' to 'Consumer<String>' is redundant">Consumer<String></warning>) arg -> {});
}
}

View File

@@ -4,6 +4,6 @@ import java.util.stream.Stream;
class MyTest {
private static void getArguments(final Stream<Class<String>> classStream) {
final Class<?>[] classes = classStream.toArray(((<warning descr="Casting '(value) -> new Class<?>[value]' to 'IntFunction<Class<?>[]>' is redundant">IntFunction<Class<?>[]></warning>) (value) -> new Class<?>[value]) );
final Class<?>[] classes = classStream.toArray(((<warning descr="Casting '(value) -> {...}' to 'IntFunction<Class<?>[]>' is redundant">IntFunction<Class<?>[]></warning>) (value) -> new Class<?>[value]) );
}
}

View File

@@ -3,7 +3,7 @@ import java.util.function.Supplier;
class Test {
{
Object o = true ? ((Supplier<String>) () -> "") : null;
Supplier<String> s1 = true ? ((<warning descr="Casting '() -> \"\"' to 'Supplier<String>' is redundant">Supplier<String></warning>) () -> "") : null;
Supplier<String> s1 = true ? ((<warning descr="Casting '() -> {...}' to 'Supplier<String>' is redundant">Supplier<String></warning>) () -> "") : null;
Supplier<String> s2 = true ? ((A) () -> "") : null;
}

View File

@@ -6,7 +6,7 @@ abstract class LambdaConvert {
public abstract <T> T query(Function<Double, T> rse);
public void with() {
addSingle(query((<warning descr="Casting 'resultSet -> \"\"' to 'Function<Double, String>' is redundant">Function<Double, String></warning>)resultSet -> ""));
addSingle(query((<warning descr="Casting 'resultSet -> {...}' to 'Function<Double, String>' is redundant">Function<Double, String></warning>)resultSet -> ""));
add(query((Function<Double, String>)resultSet -> ""));
}

View File

@@ -8,7 +8,7 @@
<problem>
<file>DoubleCast3.java</file>
<line>6</line>
<description>Casting '(String) s' to String is redundant</description>
<description>Casting '(String)s' to String is redundant</description>
</problem>
<problem>
<file>DoubleCast3.java</file>

View File

@@ -3,7 +3,7 @@
<problem>
<file>DoubleCast4.java</file>
<line>4</line>
<description>Casting '(String) o' to Object is redundant</description>
<description>Casting '(String)o' to Object is redundant</description>
</problem>
<problem>
<file>DoubleCast4.java</file>

View File

@@ -3,7 +3,7 @@
<problem>
<file>A.java</file>
<line>13</line>
<description>Casting prices.get(null) to BidAsk is redundant</description>
<description>Casting <code>prices.get(...)</code>code> to <code>BidAsk</code> is redundant</description>
</problem>
</problems>

View File

@@ -9,7 +9,7 @@ class Main {
}
public BreakpointState foo2(String type, BreakpointState<?, ?, ?> defaults) {
return (<warning descr="Casting 'myBreakpointsDefaults.computeIfAbsent(type, k -> defaults)' to 'BreakpointState' is redundant">BreakpointState</warning>) myBreakpointsDefaults.computeIfAbsent(type, k -> defaults);
return (<warning descr="Casting 'myBreakpointsDefaults.computeIfAbsent(...)' to 'BreakpointState' is redundant">BreakpointState</warning>) myBreakpointsDefaults.computeIfAbsent(type, k -> defaults);
}
private static class BreakpointState<A, B, C> {}

View File

@@ -4,7 +4,7 @@ class Test {
}
{
((I)s -> s.endsWith(".java")).getClass();
I i = (<warning descr="Casting 's -> s.endsWith(\".java\")' to 'I' is redundant">I</warning>)s -> s.endsWith(".java");
I i = (<warning descr="Casting 's -> {...}' to 'I' is redundant">I</warning>)s -> s.endsWith(".java");
}
}