diff --git a/src/main/java/org/openrewrite/kotlin/Assertions.java b/src/main/java/org/openrewrite/kotlin/Assertions.java index 7e10c00c..a7f4145b 100644 --- a/src/main/java/org/openrewrite/kotlin/Assertions.java +++ b/src/main/java/org/openrewrite/kotlin/Assertions.java @@ -478,18 +478,15 @@ private boolean inImport() { } private boolean isClassName() { - Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.ClassDeclaration; + return getCursor().getParentTreeCursor().getValue() instanceof J.ClassDeclaration; } private boolean isMethodName() { - Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.MethodDeclaration; + return getCursor().getParentTreeCursor().getValue() instanceof J.MethodDeclaration; } private boolean isMethodInvocationName() { - Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.MethodInvocation; + return getCursor().getParentTreeCursor().getValue() instanceof J.MethodInvocation; } private boolean isFieldAccess(J.Identifier ident) { @@ -515,8 +512,7 @@ private boolean isNewClass(J.Identifier ident) { } private boolean isTypeParameter() { - return getCursor().getParent() != null && - getCursor().getParent().getValue() instanceof J.TypeParameter; + return getCursor().getParentTreeCursor().getValue() instanceof J.TypeParameter; } private boolean isMemberReference(J.Identifier ident) { @@ -550,8 +546,8 @@ private boolean isLabel() { } private boolean isAnnotationField(J.Identifier ident) { - Cursor parent = getCursor().getParent(); - return parent != null && parent.getValue() instanceof J.Assignment && + Cursor parent = getCursor().getParentTreeCursor(); + return parent.getValue() instanceof J.Assignment && (ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null); } diff --git a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java index 04743d05..e627e100 100644 --- a/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java +++ b/src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java @@ -395,7 +395,7 @@ void coneFlexibleType() { kotlin( """ import java.lang.invoke.TypeDescriptor.OfField - + abstract class Foo : OfField> """, spec -> spec.afterRecipe(cu -> { AtomicBoolean found = new AtomicBoolean(false); @@ -737,7 +737,7 @@ void parameterizedType() { kotlin( """ import java.util.ArrayList - + class Foo { val l: ArrayList = ArrayList() } @@ -862,7 +862,7 @@ void privateToThisModifier() { @file:Suppress("UNUSED_VARIABLE") class A(t: T) { private val t: T = t // visibility for t is PRIVATE_TO_THIS - + fun test() { val x: T = t // correct val y: T = this.t // also correct @@ -882,7 +882,7 @@ void javaTypeFullyQualified() { @file:Suppress("UNUSED_PARAMETER") open class Object class Test(name: String, any: Any) - + fun foo(name: String) = Test(name, object : Object() {}) """ @@ -937,7 +937,7 @@ void packageStaticModifier() { kotlin( """ import java.rmi.server.RemoteStub - + class A : RemoteStub() """ ) @@ -976,7 +976,7 @@ interface A interface B interface C interface D - + class KotlinTypeGoat where S : A, T : D, S : B, T : C """, spec -> spec.afterRecipe(cu -> { AtomicBoolean found = new AtomicBoolean(false); @@ -1611,7 +1611,7 @@ class C } } } - + val x = A.B.A.C() """, spec -> spec.afterRecipe(cu -> {