Fix for issue #6.

This commit is contained in:
Chris Hodges 2022-08-15 23:04:20 +02:00
parent 1ba1363dd2
commit bb7497b494
5 changed files with 24 additions and 4 deletions

View File

@ -55,10 +55,11 @@ patchPluginXml {
setChangeNotes("""
<h4>V1.13 (15-Aug-22)</h4>
<ul>
<li>Maintenance. Updated various dependencies (Kotlin 1.70.0) and AssertJ 3.23.1 and AssertJ-Guava 3.5.0.
<li>Tried to fix unreproducable issue#9.
<li>Maintenance. Updated various dependencies (Kotlin 1.7.10) and AssertJ 3.23.1 and AssertJ-Guava 3.5.0.
<li>Tried to fix unreproducable issue #9.
<li>Added workaround for upcoming API change in IntelliJ breaking older releases.
<li>Added AssertThatIsZeroOne inspection demanded by issue#5.
<li>Added AssertThatIsZeroOne inspection demanded by issue #5.
<li>Fix for wrongly joining statements that cannot be trivially joined (e.g. with filteredOn). Fixes issue #6.
</ul>
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
""")

View File

@ -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
)!!

View File

@ -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
}

View File

@ -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!");
}

View File

@ -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!");
}