mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] Disallow PatternVariableCanBeUsed inspection on upcasting
GitOrigin-RevId: 89f15c8cbcc84d339973bb5ad1978c7409805fa3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6fe2638869
commit
b9161cc09c
+5
-1
@@ -28,10 +28,14 @@ public class PatternVariableCanBeUsedInspection extends AbstractBaseJavaLocalIns
|
||||
if (identifier == null) return;
|
||||
PsiTypeCastExpression cast = ObjectUtils.tryCast(PsiUtil.skipParenthesizedExprDown(variable.getInitializer()),
|
||||
PsiTypeCastExpression.class);
|
||||
if (cast == null || cast.getOperand() == null || cast.getCastType() == null) return;
|
||||
if (cast == null || cast.getCastType() == null) return;
|
||||
PsiExpression operand = cast.getOperand();
|
||||
if (operand == null) return;
|
||||
PsiType castType = cast.getCastType().getType();
|
||||
if (castType instanceof PsiPrimitiveType) return;
|
||||
if (!variable.getType().equals(castType)) return;
|
||||
PsiType operandType = operand.getType();
|
||||
if (operandType == null || castType.isAssignableFrom(operandType)) return;
|
||||
PsiElement scope = PsiUtil.getVariableCodeBlock(variable, null);
|
||||
if (scope == null) return;
|
||||
PsiDeclarationStatement declaration = ObjectUtils.tryCast(variable.getParent(), PsiDeclarationStatement.class);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace 'obj' with pattern variable" "false"
|
||||
class X {
|
||||
void test(String s) {
|
||||
if (s instanceof Object) {
|
||||
Object <caret>obj = (Object) s;
|
||||
System.out.println(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user