generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce type-checking tests via custom inspection
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleTypeHelperInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.sirywell.methodhandleplugin.mhtype | ||
|
||
import com.intellij.codeInspection.LocalInspectionTool | ||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiElementVisitor | ||
import de.sirywell.methodhandleplugin.TypeData | ||
|
||
/** | ||
* We (mis)use this inspection to add the type info as highlighting to the source code. | ||
* This way, we can reuse existing test infrastructure that is meant to assert presence of inspection results. | ||
* I'm aware this is a bit hacky, but it's just too simple to go a different route. | ||
*/ | ||
class MethodHandleTypeHelperInspection : LocalInspectionTool() { | ||
|
||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | ||
return object : PsiElementVisitor() { | ||
override fun visitElement(element: PsiElement) { | ||
val foundType = TypeData.forFile(element.containingFile)[element] ?: return | ||
holder.registerProblem(element, foundType.toString(), ProblemHighlightType.INFORMATION) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
|
||
class SimpleIdentity { | ||
<info descr="(int)int">private static final MethodHandle A = <info descr="(int)int">MethodHandles.identity(int.class)</info>;</info> | ||
} |