mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-117543 (Bad quickfix for "implicit numeric conversion")
This commit is contained in:
+12
@@ -123,6 +123,18 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
|
||||
PsiReplacementUtil.replaceExpression(expression, convertedExpression);
|
||||
}
|
||||
else {
|
||||
final PsiElement parent = expression.getParent();
|
||||
if (parent instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parent;
|
||||
final PsiJavaToken sign = assignmentExpression.getOperationSign();
|
||||
if (!JavaTokenType.EQ.equals(sign.getTokenType())) {
|
||||
final String lhsText = assignmentExpression.getLExpression().getText();
|
||||
final String newExpressionText =
|
||||
lhsText + "=(" + expectedType.getCanonicalText() + ")(" + lhsText + sign.getText().charAt(0) + expression.getText() + ')';
|
||||
PsiReplacementUtil.replaceExpression(assignmentExpression, newExpressionText);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final String castExpression;
|
||||
if (ParenthesesUtils.getPrecedence(expression) <= ParenthesesUtils.TYPE_CAST_PRECEDENCE) {
|
||||
castExpression = '(' + expectedType.getCanonicalText() + ')' + expression.getText();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class OperatorAssignment {
|
||||
public static void main(String[] args) {
|
||||
int a = 10;
|
||||
double b = 0.5;
|
||||
|
||||
a = (int) (a * b);
|
||||
|
||||
System.out.println(a);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class OperatorAssignment {
|
||||
public static void main(String[] args) {
|
||||
int a = 10;
|
||||
double b = 0.5;
|
||||
|
||||
a *= <caret>b;
|
||||
|
||||
System.out.println(a);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.fixes.numeric;
|
||||
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.IGQuickFixesTestCase;
|
||||
import com.siyeh.ig.numeric.ImplicitNumericConversionInspection;
|
||||
|
||||
/**
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class ImplicitNumericConversionFixTest extends IGQuickFixesTestCase {
|
||||
|
||||
public void testOperatorAssignment() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFixture.enableInspections(new ImplicitNumericConversionInspection());
|
||||
myDefaultHint = InspectionGadgetsBundle.message("implicit.numeric.conversion.make.explicit.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRelativePath() {
|
||||
return "numeric/implicit_numeric_conversion";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user