Added first version of AssertThatPathExpression for a limited number transformations (more stuff is possible, but requires detection and transformation of static Files-methods).
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
package de.platon42.intellij.plugins.cajon.inspections
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.JavaElementVisitor
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiExpressionStatement
|
||||
import com.siyeh.ig.callMatcher.CallMatcher
|
||||
|
||||
|
||||
class AssertThatPathExpressionInspection : AbstractMoveOutInspection() {
|
||||
|
||||
companion object {
|
||||
private const val DISPLAY_NAME = "Asserting a path specific expression"
|
||||
private const val JAVA_NIO_PATH = "java.nio.file.Path"
|
||||
|
||||
private val MAPPINGS = listOf(
|
||||
MoveOutMapping(
|
||||
CallMatcher.instanceCall(JAVA_NIO_PATH, "isAbsolute").parameterCount(0),
|
||||
"isAbsolute", "isRelative", expectBoolean = true
|
||||
),
|
||||
MoveOutMapping(
|
||||
CallMatcher.instanceCall(JAVA_NIO_PATH, "startsWith").parameterTypes(JAVA_NIO_PATH),
|
||||
"startsWithRaw", expectBoolean = true
|
||||
),
|
||||
MoveOutMapping(
|
||||
CallMatcher.instanceCall(JAVA_NIO_PATH, "endsWith").parameterTypes(JAVA_NIO_PATH),
|
||||
"endsWithRaw", expectBoolean = true
|
||||
),
|
||||
MoveOutMapping(
|
||||
CallMatcher.instanceCall(JAVA_NIO_PATH, "getParent").parameterCount(0),
|
||||
"hasParentRaw",
|
||||
expectedMatcher = IS_EQUAL_TO_OBJECT
|
||||
),
|
||||
MoveOutMapping(
|
||||
CallMatcher.instanceCall(JAVA_NIO_PATH, "getParent").parameterCount(0),
|
||||
"hasNoParentRaw", expectNullNonNull = true
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun getDisplayName() = DISPLAY_NAME
|
||||
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||
return object : JavaElementVisitor() {
|
||||
override fun visitExpressionStatement(statement: PsiExpressionStatement) {
|
||||
super.visitExpressionStatement(statement)
|
||||
createInspectionsForMappings(statement, holder, MAPPINGS)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@
|
||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatCollectionOrMapExpressionInspection"/>
|
||||
<localInspection groupPath="Java" shortName="AssertThatFileExpression" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatFileExpressionInspection"/>
|
||||
<localInspection groupPath="Java" shortName="AssertThatPathExpression" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatPathExpressionInspection"/>
|
||||
|
||||
<localInspection groupPath="Java" shortName="JoinAssertThatStatements" enabledByDefault="true" level="WARNING"
|
||||
implementationClass="de.platon42.intellij.plugins.cajon.inspections.JoinAssertThatStatementsInspection"/>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Operates on assertions on objects of type Path. Turns assertThat(file.someMethod(arg)).someAssertion() into assertThat(path).someMethod(arg).
|
||||
<!-- tooltip end -->
|
||||
<br>someMethod() can be isAbsolute(), getParent(), startsWith() and endsWith().
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user