mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] CastCanBeRemoved: process captured wildcards (IDEA-279096)
GitOrigin-RevId: 163695bf4d40bad340fea28fc9dbaa29c985acbd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
849769445d
commit
02fdcefaa3
+12
@@ -0,0 +1,12 @@
|
||||
// "Change type of 'obj' to 'Reference<?>' and remove cast" "true"
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
class CastToRef {
|
||||
private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Reference<?> obj = queue.remove();
|
||||
obj.clear();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change type of 'obj' to 'Reference<?>' and remove cast" "true"
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
|
||||
class CastToRef {
|
||||
private static final ReferenceQueue<Object> queue = new ReferenceQueue<>();
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Object obj = queue.remove();
|
||||
((<caret>Reference<?>)obj).clear();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -28,7 +28,7 @@ public class CastCanBeRemovedNarrowingVariableTypeInspection extends AbstractBas
|
||||
public void visitTypeCastExpression(PsiTypeCastExpression cast) {
|
||||
PsiTypeElement castTypeElement = cast.getCastType();
|
||||
if (castTypeElement == null || castTypeElement.getAnnotations().length > 0) return;
|
||||
PsiType castType = cast.getType();
|
||||
PsiType castType = GenericsUtil.getVariableTypeByExpressionType(cast.getType());
|
||||
if (!(castType instanceof PsiClassType) || ((PsiClassType)castType).isRaw()) return;
|
||||
PsiReferenceExpression ref = tryCast(PsiUtil.skipParenthesizedExprDown(cast.getOperand()), PsiReferenceExpression.class);
|
||||
if (ref == null) return;
|
||||
@@ -56,7 +56,7 @@ public class CastCanBeRemovedNarrowingVariableTypeInspection extends AbstractBas
|
||||
else {
|
||||
PsiExpression variableInitializer = variable.getInitializer();
|
||||
if (variableInitializer != null) {
|
||||
PsiType initializerType = variableInitializer.getType();
|
||||
PsiType initializerType = GenericsUtil.getVariableTypeByExpressionType(variableInitializer.getType());
|
||||
if (initializerType == null || !castType.isAssignableFrom(initializerType)) return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user