diff --git a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt index fbe847f..b07c282 100644 --- a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt +++ b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleInspectionsTest.kt @@ -11,7 +11,14 @@ class MethodHandleInspectionsTest : LightJavaCodeInsightFixtureTestCase() { } private fun doTypeCheckingTest() { - myFixture.enableInspections(MethodHandleTypeHelperInspection()) + doTypeCheckingTest(false) + } + + private fun doTypeCheckingTest(onlyAtCaret: Boolean) { + val methodHandleTypeHelperInspection = + if (onlyAtCaret) MethodHandleTypeHelperInspection { it == myFixture.elementAtCaret } + else MethodHandleTypeHelperInspection { true } + myFixture.enableInspections(methodHandleTypeHelperInspection) myFixture.testHighlighting(false, true, false, getTestName(false) + ".java") } @@ -29,4 +36,28 @@ class MethodHandleInspectionsTest : LightJavaCodeInsightFixtureTestCase() { fun testSimpleIdentity() = doTypeCheckingTest() + fun testMethodTypeAppendParameterTypes() = doTypeCheckingTest() + + fun testMethodTypeChangeParameterType() = doTypeCheckingTest() + + fun testMethodTypeChangeReturnType() = doTypeCheckingTest() + + fun testMethodTypeCreateBasic() = doTypeCheckingTest() + + fun testMethodTypeCreateWithParameters() = doTypeCheckingTest() + + fun testMethodTypeDropParameterTypes() = doTypeCheckingTest() + + fun testMethodTypeErase() = doTypeCheckingTest() + + fun testMethodTypeGeneric() = doTypeCheckingTest() + + fun testMethodTypeGenericMethodType() = doTypeCheckingTest() + + fun testMethodTypeInsertParameterTypes() = doTypeCheckingTest() + + fun testMethodTypeWrap() = doTypeCheckingTest() + + fun testMethodTypeUnwrap() = doTypeCheckingTest() + } \ No newline at end of file diff --git a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleTypeHelperInspection.kt b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleTypeHelperInspection.kt index 59c07ad..6c2d511 100644 --- a/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleTypeHelperInspection.kt +++ b/src/test/kotlin/de/sirywell/methodhandleplugin/mhtype/MethodHandleTypeHelperInspection.kt @@ -12,11 +12,12 @@ import de.sirywell.methodhandleplugin.TypeData * 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() { +class MethodHandleTypeHelperInspection(private val elementFilter: (PsiElement) -> Boolean) : LocalInspectionTool() { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { return object : PsiElementVisitor() { override fun visitElement(element: PsiElement) { + if (!elementFilter(element)) return val foundType = TypeData.forFile(element.containingFile)[element] ?: return holder.registerProblem(element, foundType.toString(), ProblemHighlightType.INFORMATION) } diff --git a/src/test/testData/MethodTypeAppendParameterTypes.java b/src/test/testData/MethodTypeAppendParameterTypes.java new file mode 100644 index 0000000..a01ba81 --- /dev/null +++ b/src/test/testData/MethodTypeAppendParameterTypes.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeAppendParameterTypes { + private static final MethodType A = MethodType.methodType(int.class, boolean.class).appendParameterTypes(String.class, double.class); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeChangeParameterType.java b/src/test/testData/MethodTypeChangeParameterType.java new file mode 100644 index 0000000..25e8d91 --- /dev/null +++ b/src/test/testData/MethodTypeChangeParameterType.java @@ -0,0 +1,8 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeChangeParameterType { + private static final MethodType A = MethodType.methodType(void.class, boolean.class, int.class).changeParameterType(0, double.class); + private static final MethodType B = MethodType.methodType(void.class, boolean.class, int.class).changeParameterType(1, double.class); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeChangeReturnType.java b/src/test/testData/MethodTypeChangeReturnType.java new file mode 100644 index 0000000..fd8f639 --- /dev/null +++ b/src/test/testData/MethodTypeChangeReturnType.java @@ -0,0 +1,8 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeChangeReturnType { + private static final MethodType A = MethodType.methodType(void.class, boolean.class, int.class).changeReturnType(double.class); + private static final MethodType B = MethodType.methodType(int.class).changeReturnType(double.class); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeCreateBasic.java b/src/test/testData/MethodTypeCreateBasic.java new file mode 100644 index 0000000..45c2e72 --- /dev/null +++ b/src/test/testData/MethodTypeCreateBasic.java @@ -0,0 +1,8 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeWrap { + private static final MethodType A = MethodType.methodType(void.class); + private static final MethodType B = MethodType.methodType(int.class, String.class); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeCreateWithParameters.java b/src/test/testData/MethodTypeCreateWithParameters.java new file mode 100644 index 0000000..4e335b6 --- /dev/null +++ b/src/test/testData/MethodTypeCreateWithParameters.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeWrap { + private static final MethodType A = MethodType.methodType(void.class, MethodType.methodType(String.class, int.class, float.class)); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeDropParameterTypes.java b/src/test/testData/MethodTypeDropParameterTypes.java new file mode 100644 index 0000000..baec8df --- /dev/null +++ b/src/test/testData/MethodTypeDropParameterTypes.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeDropParameterTypes { + private static final MethodType A = MethodType.methodType(void.class, boolean.class, int.class, double.class, float.class, long.class).dropParameterTypes(1, 3); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeErase.java b/src/test/testData/MethodTypeErase.java new file mode 100644 index 0000000..f313018 --- /dev/null +++ b/src/test/testData/MethodTypeErase.java @@ -0,0 +1,5 @@ +import java.lang.invoke.MethodType; + +class MethodTypeErase { + private static final MethodType A = MethodType.methodType(void.class, String.class, int.class, double.class, Object.class, Integer.class).erase(); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeGeneric.java b/src/test/testData/MethodTypeGeneric.java new file mode 100644 index 0000000..926e33f --- /dev/null +++ b/src/test/testData/MethodTypeGeneric.java @@ -0,0 +1,5 @@ +import java.lang.invoke.MethodType; + +class MethodTypeGeneric { + private static final MethodType A = MethodType.methodType(void.class, String.class, int.class, double.class, Object.class, long.class).generic(); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeGenericMethodType.java b/src/test/testData/MethodTypeGenericMethodType.java new file mode 100644 index 0000000..d5639bd --- /dev/null +++ b/src/test/testData/MethodTypeGenericMethodType.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodType; + +class MethodTypeGenericMethodType { + private static final MethodType A = MethodType.genericMethodType(3); + private static final MethodType B = MethodType.genericMethodType(4, true); + private static final MethodType C = MethodType.genericMethodType(5, false); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeInsertParameterTypes.java b/src/test/testData/MethodTypeInsertParameterTypes.java new file mode 100644 index 0000000..7aeff8c --- /dev/null +++ b/src/test/testData/MethodTypeInsertParameterTypes.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeInsertParameterTypes { + private static final MethodType A = MethodType.methodType(void.class, boolean.class, float.class, long.class).insertParameterTypes(1, int.class, double.class); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeUnwrap.java b/src/test/testData/MethodTypeUnwrap.java new file mode 100644 index 0000000..c0775e8 --- /dev/null +++ b/src/test/testData/MethodTypeUnwrap.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeUnwrap { + private static final MethodType A = MethodType.methodType(Integer.class, Boolean.class, String.class, Double.class).unwrap(); +} \ No newline at end of file diff --git a/src/test/testData/MethodTypeWrap.java b/src/test/testData/MethodTypeWrap.java new file mode 100644 index 0000000..fa18c43 --- /dev/null +++ b/src/test/testData/MethodTypeWrap.java @@ -0,0 +1,7 @@ +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +class MethodTypeWrap { + private static final MethodType A = MethodType.methodType(int.class, boolean.class, String.class, double.class).wrap(); +} \ No newline at end of file