java redundant cast: keep same conditional expression type based on cast type & opposite operand (IDEA-235896)

GitOrigin-RevId: 7e454f0db256ad843c7abb890953c8d264af0257
This commit is contained in:
Anna Kozlova
2020-05-05 11:29:06 +00:00
committed by intellij-monorepo-bot
parent 0ed0e007ee
commit 2832d5f81c
2 changed files with 15 additions and 2 deletions
@@ -512,8 +512,7 @@ public class RedundantCastUtil {
final PsiExpression thenExpression = ((PsiConditionalExpression)parent).getThenExpression();
final PsiExpression elseExpression = ((PsiConditionalExpression)parent).getElseExpression();
final PsiExpression opposite = thenExpression == typeCast ? elseExpression : thenExpression;
if (opposite == null || conditionalType instanceof PsiPrimitiveType &&
!Comparing.equal(conditionalType, opposite.getType())) return;
if (opposite == null || !Comparing.equal(conditionalType, opposite.getType())) return;
}
}
else if (parent instanceof PsiSynchronizedStatement &&
@@ -6,3 +6,17 @@ class Foo {
System.out.println(s);
}
}
class NonPrimitiveType {
@SuppressWarnings("unchecked")
public <T> void apply(Fun<Class<?>, ?> defaultGetter,
Class<T> configType,
Fun<Class<T>, T> getter) {
(getter == null ? (Fun)defaultGetter : getter).apply(configType);
}
interface Fun<T, R> {
R apply(T t);
}
}