mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Restore cast in possibly important context; fix ReplaceInefficientStreamCount tests
GitOrigin-RevId: 84ef59c2941462b3060c31cfea85f90ee6d39af8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bec9b23504
commit
7bc2b6c529
@@ -766,7 +766,13 @@ public class RedundantCastUtil {
|
||||
PsiType castType = typeElement.getType();
|
||||
if (castType instanceof PsiPrimitiveType) {
|
||||
if (opType instanceof PsiPrimitiveType) {
|
||||
return !TypeConversionUtil.isSafeConversion(castType, opType); // let's suppose that casts losing precision are important
|
||||
PsiElement parent = PsiUtil.skipParenthesizedExprUp(typeCast.getParent());
|
||||
if (parent instanceof PsiReturnStatement || parent instanceof PsiMethodCallExpression || parent instanceof PsiVariable ||
|
||||
parent instanceof PsiAssignmentExpression) {
|
||||
return !TypeConversionUtil.isSafeConversion(castType, opType); // let's suppose that casts losing precision are important
|
||||
} else {
|
||||
return !castType.equals(opType); // cast might be necessary (e.g. ((double)1)/5)
|
||||
}
|
||||
}
|
||||
final PsiPrimitiveType unboxedOpType = PsiPrimitiveType.getUnboxedType(opType);
|
||||
if (unboxedOpType != null && !unboxedOpType.equals(castType) ) {
|
||||
|
||||
@@ -5,6 +5,6 @@ import java.util.Arrays;
|
||||
class Test {
|
||||
long cnt() {
|
||||
/*count*/
|
||||
return (long) Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
|
||||
return Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,5 +4,5 @@ import java.util.Arrays;
|
||||
|
||||
class Test {
|
||||
/*count*/
|
||||
long cnt = (long) Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
|
||||
long cnt = Arrays.asList('d', 'e', 'f')./*stream*/size()/*after*/;
|
||||
}
|
||||
+1
-1
@@ -7,6 +7,6 @@ public class Main {
|
||||
public static long test() {
|
||||
List<String> s = new ArrayList<>();
|
||||
/* unused parameter */
|
||||
return (long) s.size();
|
||||
return s.size();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user