mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
[java-inspections] EA-1160494 - IOE: BasicJavaParserUtil.parseFragment
GitOrigin-RevId: 5a13ceb97f8105766928d67336fe9a87df62053a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab6fad9379
commit
49ed49dc2d
@@ -73,9 +73,8 @@ public final class IntegerMultiplicationImplicitCastToLongInspection extends Bas
|
||||
@SuppressWarnings("PublicField")
|
||||
public boolean ignoreNonOverflowingCompileTimeConstants = true;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected LocalQuickFix buildFix(Object... infos) {
|
||||
protected @NotNull LocalQuickFix buildFix(Object... infos) {
|
||||
return new IntegerMultiplicationImplicitCastToLongInspectionFix();
|
||||
}
|
||||
|
||||
@@ -180,8 +179,8 @@ public final class IntegerMultiplicationImplicitCastToLongInspection extends Bas
|
||||
else {
|
||||
exprToCast = Arrays.stream(operands)
|
||||
.map(operand -> PsiUtil.deparenthesizeExpression(operand))
|
||||
.filter(operand -> operand instanceof PsiLiteralExpression ||
|
||||
operand instanceof PsiPrefixExpression && ((PsiPrefixExpression)operand).getOperand() instanceof PsiLiteral)
|
||||
.filter(operand -> isIntegerLiteral(operand) ||
|
||||
operand instanceof PsiPrefixExpression prefixExpr && isIntegerLiteral(prefixExpr.getOperand()))
|
||||
.findFirst()
|
||||
.orElse(operands[0]);
|
||||
}
|
||||
@@ -189,6 +188,10 @@ public final class IntegerMultiplicationImplicitCastToLongInspection extends Bas
|
||||
addCast(exprToCast);
|
||||
}
|
||||
|
||||
private static boolean isIntegerLiteral(@Nullable PsiExpression operand) {
|
||||
return operand instanceof PsiLiteralExpression literal && literal.getValue() instanceof Integer;
|
||||
}
|
||||
|
||||
private static void addCast(@NotNull PsiExpression expression) {
|
||||
if (expression instanceof PsiPrefixExpression) {
|
||||
final PsiExpression operand = ((PsiPrefixExpression)expression).getOperand();
|
||||
@@ -196,7 +199,7 @@ public final class IntegerMultiplicationImplicitCastToLongInspection extends Bas
|
||||
}
|
||||
|
||||
final String replacementText;
|
||||
if (expression instanceof PsiLiteralExpression) {
|
||||
if (isIntegerLiteral(expression)) {
|
||||
replacementText = expression.getText() + "L";
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Fix all 'Integer multiplication or shift implicitly cast to 'long'' problems in file" "true"
|
||||
class X {
|
||||
void test(int x) {
|
||||
long y = (long) x * 'a';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Fix all 'Integer multiplication or shift implicitly cast to 'long'' problems in file" "true"
|
||||
class X {
|
||||
void test(int x) {
|
||||
long y = x *<caret> 'a';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user