Skip to content

Commit

Permalink
Use getParentTreeCursor() in Assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 19, 2024
1 parent 95ed627 commit bca5be5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
16 changes: 6 additions & 10 deletions src/main/java/org/openrewrite/kotlin/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void javaLangObject() {
JavaType.Class c = (JavaType.Class) firstMethodParameter("javaType");
assertThat(c.getFullyQualifiedName()).isEqualTo("java.lang.Object");
assertThat(c.getSupertype()).isNull();
assertThat(c.getMethods()).hasSize(12);
assertThat(c.getMethods()).hasSize(13);

// Assert generic type parameters have the correct type bounds.
JavaType.Method method = c.getMethods().stream().filter(it -> "getClass".equals(it.getName())).findFirst().orElse(null);
Expand Down Expand Up @@ -395,7 +395,7 @@ void coneFlexibleType() {
kotlin(
"""
import java.lang.invoke.TypeDescriptor.OfField
abstract class Foo<T> : OfField<Foo<Any>>
""", spec -> spec.afterRecipe(cu -> {
AtomicBoolean found = new AtomicBoolean(false);
Expand Down Expand Up @@ -737,7 +737,7 @@ void parameterizedType() {
kotlin(
"""
import java.util.ArrayList
class Foo {
val l: ArrayList<String> = ArrayList<String>()
}
Expand Down Expand Up @@ -862,7 +862,7 @@ void privateToThisModifier() {
@file:Suppress("UNUSED_VARIABLE")
class A<in T>(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
Expand All @@ -882,7 +882,7 @@ void javaTypeFullyQualified() {
@file:Suppress("UNUSED_PARAMETER")
open class Object<T>
class Test(name: String, any: Any)
fun <T> foo(name: String) =
Test(name, object : Object<T>() {})
"""
Expand Down Expand Up @@ -937,7 +937,7 @@ void packageStaticModifier() {
kotlin(
"""
import java.rmi.server.RemoteStub
class A : RemoteStub()
"""
)
Expand Down Expand Up @@ -976,7 +976,7 @@ interface A
interface B
interface C
interface D
class KotlinTypeGoat<T, S> where S : A, T : D, S : B, T : C
""", spec -> spec.afterRecipe(cu -> {
AtomicBoolean found = new AtomicBoolean(false);
Expand Down Expand Up @@ -1611,7 +1611,7 @@ class C
}
}
}
val x = A.B.A.C()
""",
spec -> spec.afterRecipe(cu -> {
Expand Down

0 comments on commit bca5be5

Please sign in to comment.