From bb7497b4943122e779f695880c6cfdc99f65e012 Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Mon, 15 Aug 2022 23:04:20 +0200 Subject: [PATCH] Fix for issue #6. --- build.gradle | 7 ++++--- .../intellij/plugins/cajon/CommonMatchers.kt | 12 ++++++++++++ .../JoinAssertThatStatementsInspection.kt | 3 ++- .../JoinStatements/JoinStatementsAfter.java | 3 +++ .../JoinStatements/JoinStatementsBefore.java | 3 +++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 79cfdfa..01d8726 100644 --- a/build.gradle +++ b/build.gradle @@ -55,10 +55,11 @@ patchPluginXml { setChangeNotes("""

V1.13 (15-Aug-22)

Full changelog available at Github project site.

""") diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/CommonMatchers.kt b/src/main/java/de/platon42/intellij/plugins/cajon/CommonMatchers.kt index 5f64160..06585f6 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/CommonMatchers.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/CommonMatchers.kt @@ -50,9 +50,21 @@ val MORE_EXTENSION_POINTS = CallMatcher.instanceCall( "singleElement", "hasOnlyOneElementSatisfying", "anyMatch", "noneMatch", "anySatisfy", "noneSatisfy" )!! +val FILTERED_ON = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_ITERABLE_ASSERT_CLASSNAME, "filteredOn", "filteredOnNull", "filteredOnAssertions")!! + val COMPLEX_CALLS_THAT_MAKES_STUFF_TRICKY = CallMatcher.anyOf( + EXTRACTING_CALL_MATCHERS, DESCRIBED_AS, WITH_REPRESENTATION_AND_SUCH, + FILTERED_ON, + USING_COMPARATOR, + IN_HEXADECIMAL_OR_BINARY +)!! + +val COMPLEX_STUFF_THAT_MAKES_JOINING_IMPOSSIBLE = CallMatcher.anyOf( + EXTRACTING_CALL_MATCHERS, + WITH_REPRESENTATION_AND_SUCH, + FILTERED_ON, USING_COMPARATOR, IN_HEXADECIMAL_OR_BINARY )!! diff --git a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspection.kt b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspection.kt index 6105284..7f86d30 100644 --- a/src/main/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspection.kt +++ b/src/main/java/de/platon42/intellij/plugins/cajon/inspections/JoinAssertThatStatementsInspection.kt @@ -72,7 +72,7 @@ class JoinAssertThatStatementsInspection : AbstractAssertJInspection() { if (!statement.hasAssertThat()) return null val assertThatCall = PsiTreeUtil.findChildrenOfType(statement, PsiMethodCallExpression::class.java).find { ALL_ASSERT_THAT_MATCHERS.test(it) } - return assertThatCall?.takeIf { it.findFluentCallTo(EXTRACTING_CALL_MATCHERS) == null } + return assertThatCall?.takeIf { it.findFluentCallTo(COMPLEX_STUFF_THAT_MAKES_JOINING_IMPOSSIBLE) == null } } return null } @@ -83,6 +83,7 @@ class JoinAssertThatStatementsInspection : AbstractAssertJInspection() { val matched = when (element) { is PsiUnaryExpression -> (element.operationTokenType == JavaTokenType.PLUSPLUS) || (element.operationTokenType == JavaTokenType.MINUSMINUS) + is PsiMethodCallExpression -> KNOWN_METHODS_WITH_SIDE_EFFECTS.test(element) else -> false } diff --git a/src/test/resources/inspections/JoinStatements/JoinStatementsAfter.java b/src/test/resources/inspections/JoinStatements/JoinStatementsAfter.java index 7a0ec3a..b196edd 100644 --- a/src/test/resources/inspections/JoinStatements/JoinStatementsAfter.java +++ b/src/test/resources/inspections/JoinStatements/JoinStatementsAfter.java @@ -66,6 +66,9 @@ public class JoinStatements { assertThat(list.get(--i)).isEqualTo("foo"); assertThat(list.get(--i)).isEqualTo("foo"); + assertThat(list).filteredOn("foo", "foo").contains("narf"); + assertThat(list).filteredOn("bar", "bar").contains("puit"); + org.junit.Assert.assertThat(list, null); fail("oh no!"); } diff --git a/src/test/resources/inspections/JoinStatements/JoinStatementsBefore.java b/src/test/resources/inspections/JoinStatements/JoinStatementsBefore.java index 0e5ab90..d202a66 100644 --- a/src/test/resources/inspections/JoinStatements/JoinStatementsBefore.java +++ b/src/test/resources/inspections/JoinStatements/JoinStatementsBefore.java @@ -63,6 +63,9 @@ public class JoinStatements { assertThat(list.get(--i)).isEqualTo("foo"); assertThat(list.get(--i)).isEqualTo("foo"); + assertThat(list).filteredOn("foo", "foo").contains("narf"); + assertThat(list).filteredOn("bar", "bar").contains("puit"); + org.junit.Assert.assertThat(list, null); fail("oh no!"); }