mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
add javac quirks case for object-primitive comparison (IDEA-168944)
This commit is contained in:
@@ -145,6 +145,25 @@ public class JavacQuirksInspectionVisitor extends JavaElementVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBinaryExpression(PsiBinaryExpression expression) {
|
||||
super.visitBinaryExpression(expression);
|
||||
if (myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_7) && !myLanguageLevel.isAtLeast(LanguageLevel.JDK_1_8)) {
|
||||
PsiType ltype = expression.getLOperand().getType();
|
||||
PsiExpression rOperand = expression.getROperand();
|
||||
if (rOperand != null) {
|
||||
PsiType rtype = rOperand.getType();
|
||||
if (ltype != null && rtype != null &&
|
||||
(ltype.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) ^ rtype.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) &&
|
||||
(TypeConversionUtil.isPrimitiveAndNotNull(ltype) ^ TypeConversionUtil.isPrimitiveAndNotNull(rtype)) &&
|
||||
TypeConversionUtil.isBinaryOperatorApplicable(expression.getOperationTokenType(), ltype, rtype, false) &&
|
||||
TypeConversionUtil.areTypesConvertible(rtype, ltype)) {
|
||||
myHolder.registerProblem(expression.getOperationSign(), "Comparision between Object and primitive is illegal and is accepted in java 7 only", ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ReplaceAssignmentOperatorWithAssignmentFix implements LocalQuickFix {
|
||||
private final String myOperationSign;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class Test {
|
||||
System.out.println((<warning descr="Casting 'c1' to 'char' is redundant">char</warning>) c1 == (char) o);
|
||||
|
||||
// Although a reference comparison, the cast on the wrapper has a side effect; not redundant.
|
||||
System.out.println(o == (char) c1);
|
||||
System.out.println((char) c1 == o);
|
||||
System.out.println(o <warning descr="Comparision between Object and primitive is illegal and is accepted in java 7 only">==</warning> (char) c1);
|
||||
System.out.println((char) c1 <warning descr="Comparision between Object and primitive is illegal and is accepted in java 7 only">==</warning> o);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user