mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java-inspections] UseHashCodeMethodInspection: fix inspection name, support boxed Long type
IDEA-338114, IDEA-339366 GitOrigin-RevId: 5e51384d160e29f3c81b99c9c50260cb883d9c46
This commit is contained in:
committed by
intellij-monorepo-bot
parent
13239eecf6
commit
b7d4e8a3b2
@@ -6,6 +6,7 @@ import com.intellij.modcommand.ModPsiUpdater;
|
||||
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiPrecedenceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
@@ -41,12 +42,11 @@ public class UseHashCodeMethodInspection extends AbstractBaseJavaLocalInspection
|
||||
PsiJavaToken operationSign = binaryExpression.getOperationSign();
|
||||
if (operationSign.getTokenType() != JavaTokenType.XOR) return null;
|
||||
|
||||
|
||||
PsiExpression leftOperand = PsiUtil.skipParenthesizedExprDown(binaryExpression.getLOperand());
|
||||
PsiExpression rightOperand = PsiUtil.skipParenthesizedExprDown(binaryExpression.getROperand());
|
||||
|
||||
if (leftOperand == null || rightOperand == null) return null;
|
||||
if (!PsiTypes.longType().equals(leftOperand.getType())) return null;
|
||||
if (!PsiTypes.longType().equals(PsiPrimitiveType.getOptionallyUnboxedType(leftOperand.getType()))) return null;
|
||||
|
||||
if (isXorShift(leftOperand, rightOperand)) return leftOperand;
|
||||
if (isXorShift(rightOperand, leftOperand)) return rightOperand;
|
||||
@@ -79,8 +79,12 @@ public class UseHashCodeMethodInspection extends AbstractBaseJavaLocalInspection
|
||||
PsiTypeCastExpression element = (PsiTypeCastExpression)startElement;
|
||||
PsiExpression operand = getHashCodeOperand(element);
|
||||
if (operand != null) {
|
||||
PsiType type = operand.getType();
|
||||
CommentTracker ct = new CommentTracker();
|
||||
ct.replace(element, "Long.hashCode(" + ct.text(operand) + ")");
|
||||
String call = PsiTypes.longType().equals(type)
|
||||
? "Long.hashCode(" + ct.text(operand) + ")"
|
||||
: ct.text(operand, PsiPrecedenceUtil.METHOD_CALL_PRECEDENCE) + ".hashCode()";
|
||||
ct.replace(element, call);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1742,7 +1742,7 @@
|
||||
<localInspection groupPathKey="group.path.names.java.language.level.specific.issues.and.migration.aids" language="JAVA" shortName="UseHashCodeMethodInspection"
|
||||
groupKey="group.names.language.level.specific.issues.and.migration.aids8" groupBundle="messages.InspectionsBundle" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="com.intellij.codeInspection.UseHashCodeMethodInspection"
|
||||
key="inspection.convert.2.streamapi.display.name" bundle="messages.JavaBundle"/>
|
||||
key="inspection.name.can.be.replaced.with.long.hashcode" bundle="messages.JavaAnalysisBundle"/>
|
||||
<localInspection groupPath="Java" language="JAVA" shortName="FuseStreamOperations"
|
||||
bundle="messages.JavaBundle" key="inspection.fuse.stream.operations.display.name"
|
||||
groupKey="group.names.code.style.issues" groupBundle="messages.InspectionsBundle" enabledByDefault="true" level="WARNING"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with 'Long.hashCode()'" "true-preview"
|
||||
public class Test {
|
||||
Long var = 1234567890123456789L;
|
||||
|
||||
public void testMethod() {
|
||||
int result = var.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace with 'Long.hashCode()'" "true-preview"
|
||||
public class Test {
|
||||
Long var = 1234567890123456789L;
|
||||
Long var1 = 1234567890123456784L;
|
||||
|
||||
public void testMethod(boolean f) {
|
||||
int result = (f ? var : var1).hashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with 'Long.hashCode()'" "true-preview"
|
||||
public class Test {
|
||||
Long var = 1234567890123456789L;
|
||||
|
||||
public void testMethod() {
|
||||
int result = (int<caret>)(var ^ (var >>> /*shift amount*/ 32));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Replace with 'Long.hashCode()'" "true-preview"
|
||||
public class Test {
|
||||
Long var = 1234567890123456789L;
|
||||
Long var1 = 1234567890123456784L;
|
||||
|
||||
public void testMethod(boolean f) {
|
||||
int result = (int<caret>)((f ? var : var1) ^ ((f ? var : var1) >>> /*shift amount*/ 32));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user