Skip to content

Commit

Permalink
Fixed variable owner names.
Browse files Browse the repository at this point in the history
Added signature builder tests for top level properties and functions.
  • Loading branch information
traceyyoshima committed Oct 9, 2023
1 parent c83e881 commit 1999e40
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/openrewrite/kotlin/KotlinTypeGoat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package org.openrewrite.kotlin

import java.lang.Object

// TODO: FIX ME. Files needs to declare fields and methods to assert type mapping.
const val field = 10
fun function() {}

@AnnotationWithRuntimeRetention
@AnnotationWithSourceRetention
abstract class KotlinTypeGoat<T, S> where S: PT<S>, S: C {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ class KotlinTypeSignatureBuilder(private val firSession: FirSession) : JavaTypeS
}
} else if (ownerSymbol is FirFunctionSymbol<*>) {
owner = methodDeclarationSignature(ownerSymbol, null)
} else if (ownerSymbol is FirFileSymbol) {
owner = convertFileNameToFqn(ownerSymbol.fir.name)
} else if (ownerSymbol != null) {
owner = classSignature(ownerSymbol.fir)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ public String methodSignature(String methodName) {
.getSymbol(), null);
}

@Test
void fileField() {
FirProperty firProperty = getCompiledSource().getDeclarations().stream()
.filter(it -> it instanceof FirProperty && "field".equals(((FirProperty) it).getName().asString()))
.map(it -> (FirProperty) it).findFirst().orElseThrow();
assertThat(signatureBuilder().variableSignature(firProperty.getSymbol(), getCompiledSource().getSymbol()))
.isEqualTo("KotlinTypeGoatKt{name=field,type=kotlin.Int}");
}

@Test
void fileFunction() {
FirSimpleFunction function = getCompiledSource().getDeclarations().stream()
.filter(it -> it instanceof FirSimpleFunction && "function".equals(((FirSimpleFunction) it).getName().asString()))
.map(it -> (FirSimpleFunction) it).findFirst().orElseThrow();
assertThat(signatureBuilder().methodDeclarationSignature(function.getSymbol(), getCompiledSource().getSymbol()))
.isEqualTo("KotlinTypeGoatKt{name=function,return=kotlin.Unit,parameters=[]}");
}

@Test
void constructor() {
assertThat(constructorSignature())
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/KotlinTypeGoat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package org.openrewrite.kotlin

import java.lang.Object

// TODO: FIX ME. Files needs to declare fields and methods to assert type mapping.
const val field = 10
fun function() {}

@AnnotationWithRuntimeRetention
@AnnotationWithSourceRetention
abstract class KotlinTypeGoat<T, S> where S: PT<S>, S: C {
Expand Down

0 comments on commit 1999e40

Please sign in to comment.