Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getParentTreeCursor() in Assertions #621

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java
Original file line number Diff line number Diff line change
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
Loading