mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
java redundant cast: fixed multiple casts in synchronized stmt
GitOrigin-RevId: 49a7d8dbcd26a3aa905c57db97d386bcbd285464
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f0233d4e68
commit
fdc80d017c
@@ -680,18 +680,20 @@ public class RedundantCastUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitSynchronizedStatement(PsiSynchronizedStatement statement) {
|
||||
PsiExpression lockExpression = deparenthesizeExpression(statement.getLockExpression());
|
||||
if (lockExpression instanceof PsiTypeCastExpression) {
|
||||
PsiExpression operand = deparenthesizeExpression(((PsiTypeCastExpression)lockExpression).getOperand());
|
||||
while (operand instanceof PsiTypeCastExpression) {
|
||||
operand = deparenthesizeExpression(((PsiTypeCastExpression)operand).getOperand());
|
||||
}
|
||||
if (operand != null) {
|
||||
PsiType opType = operand.getType();
|
||||
if (operand instanceof PsiFunctionalExpression || opType instanceof PsiPrimitiveType || opType == null) {
|
||||
return;
|
||||
if (!(operand instanceof PsiFunctionalExpression) && !(opType instanceof PsiPrimitiveType) && opType != null) {
|
||||
addIfNarrowing((PsiTypeCastExpression)lockExpression, opType, null);
|
||||
}
|
||||
addIfNarrowing((PsiTypeCastExpression)lockExpression, opType, null);
|
||||
}
|
||||
}
|
||||
super.visitSynchronizedStatement(statement);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyTest {
|
||||
|
||||
void dblCast() {
|
||||
synchronized ((Runnable) (<warning descr="Casting '() -> {...}' to 'Runnable' is redundant">Runnable</warning>) () -> {}) {}
|
||||
synchronized ((Runnable) (<warning descr="Casting '(Runnable)() -> {...}' to 'Runnable' is redundant">Runnable</warning>)(<warning descr="Casting '() -> {...}' to 'Runnable' is redundant">Runnable</warning>) () -> {}) {}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testCastInNeighbourArgument() { doTest(); }
|
||||
public void testErasedTargetType() { doTest(); }
|
||||
public void testThrowsStatementInLambdaBody() { doTest(); }
|
||||
public void testSynchronizeCasts() { doTest(); }
|
||||
public void testRejectReturnTypeChange() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user