diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
index 5149d26a1ce5..c606ec48963c 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
@@ -796,6 +796,10 @@
key="if.to.assertion.name" groupBundle="messages.InspectionsBundle"
groupKey="group.names.control.flow.issues" enabledByDefault="true" level="INFORMATION"
implementationClass="com.siyeh.ig.asserttoif.IfToAssertionInspection"/>
+
ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
+ expString = prefix + '(' + lhText + ").equals(" + rhText + ')';
+ }
+ else {
+ expString = prefix + lhText + ".equals(" + rhText + ')';
+ }
+ PsiReplacementUtil.replaceExpression(exp, expString);
+ }
+
+ private static void doSafeFixImpl(PsiElement element) {
+ final PsiBinaryExpression exp = (PsiBinaryExpression)element;
+ final PsiExpression lhs = exp.getLOperand();
+ final PsiExpression rhs = exp.getROperand();
+ if (rhs == null) {
+ return;
+ }
+ final PsiExpression strippedLhs =
+ ParenthesesUtils.stripParentheses(lhs);
+ if (strippedLhs == null) {
+ return;
+ }
+ final PsiExpression strippedRhs =
+ ParenthesesUtils.stripParentheses(rhs);
+ if (strippedRhs == null) {
+ return;
+ }
+ final String lhsText = strippedLhs.getText();
+ final String rhsText = strippedRhs.getText();
+ final PsiJavaToken operationSign = exp.getOperationSign();
+ final IElementType tokenType = operationSign.getTokenType();
+ final String signText = operationSign.getText();
+ @NonNls final StringBuilder newExpression = new StringBuilder();
+ if (PsiUtil.isLanguageLevel7OrHigher(element) && ClassUtils.findClass("java.util.Objects", element) != null) {
+ if (tokenType.equals(JavaTokenType.NE)) {
+ newExpression.append('!');
+ }
+ newExpression.append("java.util.Objects.equals(").append(lhsText).append(',').append(rhsText).append(')');
+ }
+ else {
+ newExpression.append(lhsText).append("==null?").append(rhsText).append(signText).append(" null:");
+ if (tokenType.equals(JavaTokenType.NE)) {
+ newExpression.append('!');
+ }
+ if (ParenthesesUtils.getPrecedence(strippedLhs) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
+ newExpression.append('(').append(lhsText).append(')');
+ }
+ else {
+ newExpression.append(lhsText);
+ }
+ newExpression.append(".equals(").append(rhsText).append(')');
+ }
+ PsiReplacementUtil.replaceExpressionAndShorten(exp, newExpression.toString());
+ }
+
+ private static class SafeEqualsFix extends InspectionGadgetsFix {
+ private final Object[] myInfos;
+
+ public SafeEqualsFix(Object... infos) {
+ myInfos = infos;
+ }
+
+ @Nls
+ @NotNull
+ @Override
+ public String getName() {
+ return InspectionGadgetsBundle.message("replace.equality.with.safe.equals.descriptor", myInfos);
+ }
+
+ @Nls
+ @NotNull
+ @Override
+ public String getFamilyName() {
+ return InspectionGadgetsBundle.message("replace.equality.with.safe.equals.name");
+ }
+
+ @Override
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
+ doSafeFixImpl(descriptor.getPsiElement());
+ }
+ }
+
+ private static class EqualsFix extends InspectionGadgetsFix {
+ private final Object[] myInfos;
+
+ public EqualsFix(Object... infos) {
+ myInfos = infos;
+ }
+
+ @Nls
+ @NotNull
+ @Override
+ public String getName() {
+ return InspectionGadgetsBundle.message("replace.equality.with.equals.descriptor", myInfos);
+ }
+
+ @Nls
+ @NotNull
+ @Override
+ public String getFamilyName() {
+ return InspectionGadgetsBundle.message("replace.equality.with.equals.name");
+ }
+
+ @Override
+ protected void doFix(Project project, ProblemDescriptor descriptor) {
+ doFixImpl(descriptor.getPsiElement());
+ }
+ }
+
+ private static class ObjectEqualityVisitor extends BaseInspectionVisitor {
+ @Override
+ public void visitBinaryExpression(PsiBinaryExpression expression) {
+ super.visitBinaryExpression(expression);
+ final IElementType tokenType = expression.getOperationTokenType();
+ if (!tokenType.equals(JavaTokenType.NE) &&
+ !tokenType.equals(JavaTokenType.EQEQ)) {
+ return;
+ }
+ final PsiExpression lhs = expression.getLOperand();
+ final PsiType lhsType = lhs.getType();
+ if (lhsType == null || lhsType instanceof PsiPrimitiveType || TypeConversionUtil.isEnumType(lhsType)) {
+ return;
+ }
+ final PsiExpression rhs = expression.getROperand();
+ if (rhs == null) {
+ return;
+ }
+ final PsiType rhsType = rhs.getType();
+ if (rhsType == null || rhsType instanceof PsiPrimitiveType || TypeConversionUtil.isEnumType(rhsType)) {
+ return;
+ }
+ final String operationText = expression.getOperationSign().getText();
+ final String prefix = tokenType.equals(JavaTokenType.NE) ? "!" : "";
+ registerError(expression, operationText, prefix);
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceEqualityWithEquals.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceEqualityWithEquals.html
new file mode 100644
index 000000000000..8798c46ffbcc
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceEqualityWithEquals.html
@@ -0,0 +1,6 @@
+
+
+This inspection reports == equality operators that compare two objects
+and offers to replace them with calls of the .equals() method or with the safe .equals() method construct.
+
+
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/EnumComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/EnumComparison.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/EnumComparison.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/EnumComparison.java
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NegatedObjectComparison_after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectComparison.after.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NegatedObjectComparison_after.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectComparison.after.java
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NegatedObjectComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectComparison.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NegatedObjectComparison.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectComparison.java
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.after.java
new file mode 100644
index 000000000000..fbd7591732e4
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.after.java
@@ -0,0 +1,5 @@
+public class NegatedObjectOldSafeComparison {
+ boolean a(Object a, Object b) {
+ return a == null ? b != null : !a.equals(b);
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.java
new file mode 100644
index 000000000000..724039457801
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectOldSafeComparison.java
@@ -0,0 +1,5 @@
+public class NegatedObjectOldSafeComparison {
+ boolean a(Object a, Object b) {
+ return a != b;
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.after.java
new file mode 100644
index 000000000000..216ec9957c66
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.after.java
@@ -0,0 +1,8 @@
+import java.util.Objects;
+
+public class NegatedObjectSafeComparison {
+
+ boolean a(Object a, Object b) {
+ return !Objects.equals(a, b);
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.java
new file mode 100644
index 000000000000..1607a98fa3a9
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NegatedObjectSafeComparison.java
@@ -0,0 +1,6 @@
+public class NegatedObjectSafeComparison {
+
+ boolean a(Object a, Object b) {
+ return a != b;
+ }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NullComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NullComparison.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/NullComparison.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/NullComparison.java
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/PrimitiveComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/PrimitiveComparison.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/PrimitiveComparison.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/PrimitiveComparison.java
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/SimpleObjectComparison_after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectComparison.after.java
similarity index 100%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/SimpleObjectComparison_after.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectComparison.after.java
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/SimpleObjectComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectComparison.java
similarity index 75%
rename from plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/SimpleObjectComparison.java
rename to plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectComparison.java
index baccea789e04..b0636948f52b 100644
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_equals/SimpleObjectComparison.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectComparison.java
@@ -1,6 +1,6 @@
public class SimpleObjectComparison {
boolean a(Object a, Object b) {
- return a == b;
+ return a == b;
}
}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.after.java
new file mode 100644
index 000000000000..255b69a3316b
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.after.java
@@ -0,0 +1,5 @@
+public class SimpleObjectOldSafeComparison {
+ boolean eq(Object a, Object b) {
+ return a == null ? b == null : a.equals(b);
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.java
new file mode 100644
index 000000000000..22c4fc913b63
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectOldSafeComparison.java
@@ -0,0 +1,5 @@
+public class SimpleObjectOldSafeComparison {
+ boolean eq(Object a, Object b) {
+ return a == b;
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.after.java
new file mode 100644
index 000000000000..d2ca4c1de6ea
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.after.java
@@ -0,0 +1,7 @@
+import java.util.Objects;
+
+public class SimpleObjectSafeComparison {
+ boolean eq(Object a, Object b) {
+ return Objects.equals(a, b);
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.java
new file mode 100644
index 000000000000..940fba779bf6
--- /dev/null
+++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/equality/replace_equality_with_equals/SimpleObjectSafeComparison.java
@@ -0,0 +1,5 @@
+public class SimpleObjectSafeComparison {
+ boolean eq(Object a, Object b) {
+ return a == b;
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/equality/ReplaceEqualityWithEqualsInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/equality/ReplaceEqualityWithEqualsInspectionTest.java
new file mode 100644
index 000000000000..58bc2975e722
--- /dev/null
+++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/fixes/equality/ReplaceEqualityWithEqualsInspectionTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2016 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.equality;
+
+import com.intellij.pom.java.LanguageLevel;
+import com.intellij.testFramework.IdeaTestUtil;
+import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.IGQuickFixesTestCase;
+import com.siyeh.ig.equality.ReplaceEqualityWithEqualsInspection;
+
+/**
+ * @see ReplaceEqualityWithEqualsInspection
+ * @author Bas Leijdekkers
+ */
+public class ReplaceEqualityWithEqualsInspectionTest extends IGQuickFixesTestCase {
+
+ public void testEnumComparison() { assertQuickfixNotAvailable(); }
+ public void testNullComparison() { assertQuickfixNotAvailable(); }
+ public void testPrimitiveComparison() { assertQuickfixNotAvailable(); }
+ public void testSimpleObjectComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.equals.descriptor", "==", "")); }
+ public void testNegatedObjectComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.equals.descriptor", "!=", "!")); }
+
+ public void testSimpleObjectSafeComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.safe.equals.descriptor", "==", "")); }
+ public void testNegatedObjectSafeComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.safe.equals.descriptor", "!=", "!")); }
+ public void testSimpleObjectOldSafeComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.safe.equals.descriptor", "==", "")); }
+ public void testNegatedObjectOldSafeComparison() { doTest(InspectionGadgetsBundle.message("replace.equality.with.safe.equals.descriptor", "!=", "!")); }
+
+ @Override
+ protected void tuneFixture(JavaModuleFixtureBuilder builder) throws Exception {
+ super.tuneFixture(builder);
+ if (getTestName(false).contains("Old")) {
+ builder.setLanguageLevel(LanguageLevel.JDK_1_6);
+ }
+ else if (getTestName(false).contains("Safe")) {
+ builder.addJdk(IdeaTestUtil.getMockJdk18Path().getPath()); // MockJdk17 would work if it contained java.util.Objects
+ builder.setLanguageLevel(LanguageLevel.JDK_1_7);
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ myFixture.enableInspections(new ReplaceEqualityWithEqualsInspection());
+ myDefaultHint = "Replace";
+ myRelativePath = "equality/replace_equality_with_equals";
+ }
+}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/META-INF/IntentionPowerPack.xml b/plugins/IntentionPowerPak/src/META-INF/IntentionPowerPack.xml
index a2d50a0038ee..3da3edbc4a5e 100644
--- a/plugins/IntentionPowerPak/src/META-INF/IntentionPowerPack.xml
+++ b/plugins/IntentionPowerPak/src/META-INF/IntentionPowerPack.xml
@@ -91,18 +91,6 @@
intention.category.boolean
-
- com.siyeh.ipp.equality.ReplaceEqualityWithEqualsIntention
- com.siyeh.IntentionPowerPackBundle
- intention.category.boolean
-
-
-
- com.siyeh.ipp.equality.ReplaceEqualityWithSafeEqualsIntention
- com.siyeh.IntentionPowerPackBundle
- intention.category.boolean
-
-
com.siyeh.ipp.trivialif.ExpandBooleanIntention
com.siyeh.IntentionPowerPackBundle
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties
index 3ee5951ecc40..aed173dde8c9 100644
--- a/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties
+++ b/plugins/IntentionPowerPak/src/com/siyeh/IntentionPowerPackBundle.properties
@@ -11,9 +11,6 @@ merge.else.if.intention.name=Merge 'else if'
merge.else.if.intention.family.name=Merge Else If
change.to.end.of.line.comment.intention.name=Replace with end-of-line comment
change.to.end.of.line.comment.intention.family.name=Replace with End Of Line Comment
-replace.equality.with.safe.equals.intention.name=Replace '==' with safe '.equals()'
-replace.equality.with.safe.not.equals.intention.name=Replace '!=' with safe '!equals()'
-replace.equality.with.safe.equals.intention.family.name=Replace Equality with Safe Equals
replace.for.each.loop.with.indexed.for.loop.intention.name=Replace 'for each' loop with indexed 'for' loop
replace.for.each.loop.with.iterator.for.loop.intention.name=Replace 'for each' loop with iterator 'for' loop
replace.for.each.loop.with.indexed.for.loop.intention.family.name=Replace For-each Loop with Indexed For Loop
@@ -79,9 +76,6 @@ char.to.string.intention.name=Replace character literal with string
char.to.string.intention.family.name=Replace Char with String
replace.if.with.conditional.intention.name=Replace 'if else' with '?:'
replace.if.with.conditional.intention.family.name=Replace If Else with Conditional
-replace.equality.with.equals.intention.name=Replace '==' with 'equals()'
-replace.equality.with.not.equals.intention.name=Replace '!=' with '!equals()'
-replace.equality.with.equals.intention.family.name=Replace Equality with Equals
make.call.chain.into.call.sequence.intention.name=Make method call chain into call sequence
make.call.chain.into.call.sequence.intention.family.name=Make Call Chain Into Call Sequence
merge.call.sequence.to.chain.intention.name=Merge sequential method calls into call chain
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java
deleted file mode 100644
index 4bea8688ae32..000000000000
--- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ObjectEqualityPredicate.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
- *
- * 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.ipp.equality;
-
-import com.intellij.psi.*;
-import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.TypeConversionUtil;
-import com.siyeh.ipp.base.PsiElementPredicate;
-
-class ObjectEqualityPredicate implements PsiElementPredicate {
-
- public boolean satisfiedBy(PsiElement element) {
- if (!(element instanceof PsiBinaryExpression)) {
- return false;
- }
- final PsiBinaryExpression expression = (PsiBinaryExpression)element;
- final IElementType tokenType = expression.getOperationTokenType();
- if (!tokenType.equals(JavaTokenType.NE) &&
- !tokenType.equals(JavaTokenType.EQEQ)) {
- return false;
- }
- final PsiExpression lhs = expression.getLOperand();
- final PsiType lhsType = lhs.getType();
- if (lhsType == null || lhsType instanceof PsiPrimitiveType || TypeConversionUtil.isEnumType(lhsType)) {
- return false;
- }
- final PsiExpression rhs = expression.getROperand();
- if (rhs == null) {
- return false;
- }
- final PsiType rhsType = rhs.getType();
- return !(rhsType == null || rhsType instanceof PsiPrimitiveType || TypeConversionUtil.isEnumType(rhsType));
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java
deleted file mode 100644
index cc4014728475..000000000000
--- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntention.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
- *
- * 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.ipp.equality;
-
-import com.intellij.psi.JavaTokenType;
-import com.intellij.psi.PsiBinaryExpression;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiExpression;
-import com.intellij.psi.tree.IElementType;
-import com.siyeh.IntentionPowerPackBundle;
-import com.siyeh.ig.PsiReplacementUtil;
-import com.siyeh.ig.psiutils.ParenthesesUtils;
-import com.siyeh.ipp.base.MutablyNamedIntention;
-import com.siyeh.ipp.base.PsiElementPredicate;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-public class ReplaceEqualityWithEqualsIntention extends MutablyNamedIntention {
-
- @Override
- protected String getTextForElement(PsiElement element) {
- final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)element;
- final IElementType tokenType = binaryExpression.getOperationTokenType();
- if (JavaTokenType.NE.equals(tokenType)) {
- return IntentionPowerPackBundle.message("replace.equality.with.not.equals.intention.name");
- }
- else {
- return IntentionPowerPackBundle.message("replace.equality.with.equals.intention.name");
- }
- }
-
- @NotNull
- public PsiElementPredicate getElementPredicate() {
- return new ObjectEqualityPredicate();
- }
-
- public void processIntention(@NotNull PsiElement element) {
- final PsiBinaryExpression exp = (PsiBinaryExpression)element;
- final PsiExpression lhs = exp.getLOperand();
- final PsiExpression rhs = exp.getROperand();
- if (rhs == null) {
- return;
- }
- final PsiExpression strippedLhs = ParenthesesUtils.stripParentheses(lhs);
- if (strippedLhs == null) {
- return;
- }
- final PsiExpression strippedRhs = ParenthesesUtils.stripParentheses(rhs);
- if (strippedRhs == null) {
- return;
- }
- final String lhText = strippedLhs.getText();
- final String rhText = strippedRhs.getText();
-
- final String prefix = exp.getOperationTokenType().equals(JavaTokenType.EQEQ) ? "" : "!";
- @NonNls final String expString;
- if (ParenthesesUtils.getPrecedence(strippedLhs) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
- expString = prefix + '(' + lhText + ").equals(" + rhText + ')';
- }
- else {
- expString = prefix + lhText + ".equals(" + rhText + ')';
- }
- PsiReplacementUtil.replaceExpression(exp, expString);
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntention.java
deleted file mode 100644
index 12acaa006f54..000000000000
--- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntention.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
- *
- * 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.ipp.equality;
-
-import com.intellij.psi.*;
-import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.util.PsiUtil;
-import com.siyeh.IntentionPowerPackBundle;
-import com.siyeh.ig.PsiReplacementUtil;
-import com.siyeh.ig.psiutils.ClassUtils;
-import com.siyeh.ig.psiutils.ParenthesesUtils;
-import com.siyeh.ipp.base.MutablyNamedIntention;
-import com.siyeh.ipp.base.PsiElementPredicate;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-
-public class ReplaceEqualityWithSafeEqualsIntention extends MutablyNamedIntention {
-
- @Override
- protected String getTextForElement(PsiElement element) {
- final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)element;
- if (JavaTokenType.NE.equals(binaryExpression.getOperationTokenType())) {
- return IntentionPowerPackBundle.message("replace.equality.with.safe.not.equals.intention.name");
- }
- else {
- return IntentionPowerPackBundle.message("replace.equality.with.safe.equals.intention.name");
- }
- }
-
- @NotNull
- public PsiElementPredicate getElementPredicate() {
- return new ObjectEqualityPredicate();
- }
-
- public void processIntention(PsiElement element) {
- final PsiBinaryExpression exp = (PsiBinaryExpression)element;
- final PsiExpression lhs = exp.getLOperand();
- final PsiExpression rhs = exp.getROperand();
- if (rhs == null) {
- return;
- }
- final PsiExpression strippedLhs =
- ParenthesesUtils.stripParentheses(lhs);
- if (strippedLhs == null) {
- return;
- }
- final PsiExpression strippedRhs =
- ParenthesesUtils.stripParentheses(rhs);
- if (strippedRhs == null) {
- return;
- }
- final String lhsText = strippedLhs.getText();
- final String rhsText = strippedRhs.getText();
- final PsiJavaToken operationSign = exp.getOperationSign();
- final IElementType tokenType = operationSign.getTokenType();
- final String signText = operationSign.getText();
- @NonNls final StringBuilder newExpression = new StringBuilder();
- if (PsiUtil.isLanguageLevel7OrHigher(element) && ClassUtils.findClass("java.util.Objects", element) != null) {
- if (tokenType.equals(JavaTokenType.NE)) {
- newExpression.append('!');
- }
- newExpression.append("java.util.Objects.equals(").append(lhsText).append(',').append(rhsText).append(')');
- }
- else {
- newExpression.append(lhsText).append("==null?").append(rhsText).append(signText).append(" null:");
- if (tokenType.equals(JavaTokenType.NE)) {
- newExpression.append('!');
- }
- if (ParenthesesUtils.getPrecedence(strippedLhs) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
- newExpression.append('(').append(lhsText).append(')');
- }
- else {
- newExpression.append(lhsText);
- }
- newExpression.append(".equals(").append(rhsText).append(')');
- }
- PsiReplacementUtil.replaceExpressionAndShorten(exp, newExpression.toString());
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/after.java.template b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/after.java.template
deleted file mode 100644
index 0d3e3d605ed5..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/after.java.template
+++ /dev/null
@@ -1,5 +0,0 @@
-public class X {
- boolean f(Object o) {
- return o.equals(this);
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/before.java.template b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/before.java.template
deleted file mode 100644
index 9f012f7f967b..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/before.java.template
+++ /dev/null
@@ -1,5 +0,0 @@
-public class X {
- boolean f(Object o) {
- return o == this;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/description.html b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/description.html
deleted file mode 100644
index cc050e3a3769..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithEqualsIntention/description.html
+++ /dev/null
@@ -1,3 +0,0 @@
-This intention replaces an == equality operator with an equals() method call.
-
-
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/after.java.template b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/after.java.template
deleted file mode 100644
index 14130a074ce8..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/after.java.template
+++ /dev/null
@@ -1,5 +0,0 @@
-public class X {
- boolean f(Object o) {
- return o == null ? o1 == null : o.equals(o1);
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/before.java.template b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/before.java.template
deleted file mode 100644
index 545d1eab2a09..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/before.java.template
+++ /dev/null
@@ -1,5 +0,0 @@
-public class X {
- boolean f(Object o, Object o1) {
- return o == o1;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/description.html b/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/description.html
deleted file mode 100644
index e72e917cc32e..000000000000
--- a/plugins/IntentionPowerPak/src/intentionDescriptions/ReplaceEqualityWithSafeEqualsIntention/description.html
+++ /dev/null
@@ -1,4 +0,0 @@
-This intention replaces an == equality operator with a safe equals() method call construct.
-
-
-
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/EnumComparison.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/EnumComparison.java
deleted file mode 100644
index 43b16a421c25..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/EnumComparison.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class EnumComparison {
-
- enum E { A, B }
-
- boolean a(E a, E b) {
- return a == b;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison.java
deleted file mode 100644
index 018def909d05..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class NegatedObjectComparison {
-
- boolean a(Object a, Object b) {
- return a != b;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison_after.java
deleted file mode 100644
index b7f48289a4b8..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NegatedObjectComparison_after.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class NegatedObjectComparison {
-
- boolean a(Object a, Object b) {
- return a == null ? b != null : !a.equals(b);
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NullComparison.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NullComparison.java
deleted file mode 100644
index 10aeb19f6fed..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/NullComparison.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class NullComparison {
-
- boolean a(Object a) {
- return a == null;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/PrimitiveComparison.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/PrimitiveComparison.java
deleted file mode 100644
index 8ae058592d0a..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/PrimitiveComparison.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class PrimitiveComparison {
-
- boolean a(int i, int j) {
- return i == j;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison.java
deleted file mode 100644
index 304b06ff67a1..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class SimpleObjectComparison {
-
- boolean a(Object a, Object b) {
- return a == b;
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison_after.java
deleted file mode 100644
index 5ee0ddf5d6df..000000000000
--- a/plugins/IntentionPowerPak/test/com/siyeh/ipp/equality/replace_equality_with_safe_equals/SimpleObjectComparison_after.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.siyeh.ipp.equality.replace_equality_with_safe_equals;
-
-public class SimpleObjectComparison {
-
- boolean a(Object a, Object b) {
- return a == null ? b == null : a.equals(b);
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntentionTest.java
deleted file mode 100644
index f9150050fbdd..000000000000
--- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithEqualsIntentionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2000-2014 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.ipp.equality;
-
-import com.siyeh.IntentionPowerPackBundle;
-import com.siyeh.ipp.IPPTestCase;
-
-/**
- * @see com.siyeh.ipp.equality.ReplaceEqualityWithEqualsIntention
- * @author Bas Leijdekkers
- */
-public class ReplaceEqualityWithEqualsIntentionTest extends IPPTestCase {
-
- public void testEnumComparison() { assertIntentionNotAvailable(); }
- public void testNullComparison() { assertIntentionNotAvailable(); }
- public void testPrimitiveComparison() { assertIntentionNotAvailable(); }
- public void testSimpleObjectComparison() { doTest(); }
- public void testNegatedObjectComparison() { doTest(IntentionPowerPackBundle.message("replace.equality.with.not.equals.intention.name")); }
-
- @Override
- protected String getIntentionName() {
- return IntentionPowerPackBundle.message("replace.equality.with.equals.intention.name");
- }
-
- @Override
- protected String getRelativePath() {
- return "equality/replace_equality_with_equals";
- }
-}
\ No newline at end of file
diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntentionTest.java
deleted file mode 100644
index c2fe09148f9a..000000000000
--- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/equality/ReplaceEqualityWithSafeEqualsIntentionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2000-2014 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.ipp.equality;
-
-import com.siyeh.IntentionPowerPackBundle;
-import com.siyeh.ipp.IPPTestCase;
-
-/**
- * @see com.siyeh.ipp.equality.ReplaceEqualityWithSafeEqualsIntention
- * @author Bas Leijdekkers
- */
-public class ReplaceEqualityWithSafeEqualsIntentionTest extends IPPTestCase {
-
- public void testEnumComparison() { assertIntentionNotAvailable(); }
- public void testNullComparison() { assertIntentionNotAvailable(); }
- public void testPrimitiveComparison() { assertIntentionNotAvailable(); }
- public void testSimpleObjectComparison() { doTest(); }
- public void testNegatedObjectComparison() { doTest(IntentionPowerPackBundle.message("replace.equality.with.safe.not.equals.intention.name")); }
-
- @Override
- protected String getIntentionName() {
- return IntentionPowerPackBundle.message("replace.equality.with.safe.equals.intention.name");
- }
-
- @Override
- protected String getRelativePath() {
- return "equality/replace_equality_with_safe_equals";
- }
-}
\ No newline at end of file