Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit f7417f6

Browse files
authored
Use getParentTreeCursor() in Assertions (#621)
* Use `getParentTreeCursor()` in `Assertions` * Apply suggestions from code review
1 parent 95ed627 commit f7417f6

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/main/java/org/openrewrite/kotlin/Assertions.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,18 +478,15 @@ private boolean inImport() {
478478
}
479479

480480
private boolean isClassName() {
481-
Cursor parent = getCursor().getParent();
482-
return parent != null && parent.getValue() instanceof J.ClassDeclaration;
481+
return getCursor().getParentTreeCursor().getValue() instanceof J.ClassDeclaration;
483482
}
484483

485484
private boolean isMethodName() {
486-
Cursor parent = getCursor().getParent();
487-
return parent != null && parent.getValue() instanceof J.MethodDeclaration;
485+
return getCursor().getParentTreeCursor().getValue() instanceof J.MethodDeclaration;
488486
}
489487

490488
private boolean isMethodInvocationName() {
491-
Cursor parent = getCursor().getParent();
492-
return parent != null && parent.getValue() instanceof J.MethodInvocation;
489+
return getCursor().getParentTreeCursor().getValue() instanceof J.MethodInvocation;
493490
}
494491

495492
private boolean isFieldAccess(J.Identifier ident) {
@@ -515,8 +512,7 @@ private boolean isNewClass(J.Identifier ident) {
515512
}
516513

517514
private boolean isTypeParameter() {
518-
return getCursor().getParent() != null &&
519-
getCursor().getParent().getValue() instanceof J.TypeParameter;
515+
return getCursor().getParentTreeCursor().getValue() instanceof J.TypeParameter;
520516
}
521517

522518
private boolean isMemberReference(J.Identifier ident) {
@@ -550,8 +546,8 @@ private boolean isLabel() {
550546
}
551547

552548
private boolean isAnnotationField(J.Identifier ident) {
553-
Cursor parent = getCursor().getParent();
554-
return parent != null && parent.getValue() instanceof J.Assignment &&
549+
Cursor parent = getCursor().getParentTreeCursor();
550+
return parent.getValue() instanceof J.Assignment &&
555551
(ident == ((J.Assignment) parent.getValue()).getVariable() && getCursor().firstEnclosing(J.Annotation.class) != null);
556552
}
557553

src/test/java/org/openrewrite/kotlin/KotlinTypeMappingTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void coneFlexibleType() {
395395
kotlin(
396396
"""
397397
import java.lang.invoke.TypeDescriptor.OfField
398-
398+
399399
abstract class Foo<T> : OfField<Foo<Any>>
400400
""", spec -> spec.afterRecipe(cu -> {
401401
AtomicBoolean found = new AtomicBoolean(false);
@@ -737,7 +737,7 @@ void parameterizedType() {
737737
kotlin(
738738
"""
739739
import java.util.ArrayList
740-
740+
741741
class Foo {
742742
val l: ArrayList<String> = ArrayList<String>()
743743
}
@@ -862,7 +862,7 @@ void privateToThisModifier() {
862862
@file:Suppress("UNUSED_VARIABLE")
863863
class A<in T>(t: T) {
864864
private val t: T = t // visibility for t is PRIVATE_TO_THIS
865-
865+
866866
fun test() {
867867
val x: T = t // correct
868868
val y: T = this.t // also correct
@@ -882,7 +882,7 @@ void javaTypeFullyQualified() {
882882
@file:Suppress("UNUSED_PARAMETER")
883883
open class Object<T>
884884
class Test(name: String, any: Any)
885-
885+
886886
fun <T> foo(name: String) =
887887
Test(name, object : Object<T>() {})
888888
"""
@@ -937,7 +937,7 @@ void packageStaticModifier() {
937937
kotlin(
938938
"""
939939
import java.rmi.server.RemoteStub
940-
940+
941941
class A : RemoteStub()
942942
"""
943943
)
@@ -976,7 +976,7 @@ interface A
976976
interface B
977977
interface C
978978
interface D
979-
979+
980980
class KotlinTypeGoat<T, S> where S : A, T : D, S : B, T : C
981981
""", spec -> spec.afterRecipe(cu -> {
982982
AtomicBoolean found = new AtomicBoolean(false);
@@ -1611,7 +1611,7 @@ class C
16111611
}
16121612
}
16131613
}
1614-
1614+
16151615
val x = A.B.A.C()
16161616
""",
16171617
spec -> spec.afterRecipe(cu -> {

0 commit comments

Comments
 (0)