mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: ensure lambda return statements are not mixed with those from containing method (IDEA-138724)
This commit is contained in:
@@ -159,7 +159,7 @@ public class RedundantCastUtil {
|
||||
}
|
||||
|
||||
@Override public void visitReturnStatement(PsiReturnStatement statement) {
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
|
||||
final PsiMethod method = PsiTreeUtil.getParentOfType(statement, PsiMethod.class, true, PsiLambdaExpression.class);
|
||||
if (method != null) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
final PsiExpression returnValue = statement.getReturnValue();
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import java.util.Optional;
|
||||
|
||||
class CommandTest {
|
||||
public Object getObject() {
|
||||
Optional<Object> o = Optional.of("x");
|
||||
return o.map(bx -> {
|
||||
return (Object)"";
|
||||
})
|
||||
.orElse(new Integer(1));
|
||||
}
|
||||
|
||||
public Object getObject1() {
|
||||
Optional<Object> o = Optional.of("x");
|
||||
return o.map(bx -> {
|
||||
return (<warning descr="Casting 'new Object()' to 'Object' is redundant">Object</warning>)new Object();
|
||||
})
|
||||
.orElse(new Integer(1));
|
||||
}
|
||||
}
|
||||
+1
@@ -37,6 +37,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testIntersection() { doTest(); }
|
||||
public void testSer() { doTest(); }
|
||||
public void testLambdaReturnExpressions() { doTest(); }
|
||||
public void testLambdaReturnExpressions1() { doTest(); }
|
||||
private void doTest() {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user