File tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed
main/kotlin/org/openrewrite/kotlin
test/java/org/openrewrite/kotlin/tree Expand file tree Collapse file tree 2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change @@ -224,9 +224,15 @@ class KotlinTypeMapping(
224224 return null
225225 }
226226
227- // If the symbol is not resolvable we return a NEW ShallowClass to prevent caching on a potentially resolvable class type.
228- val sym = type.importedFqName!! .topLevelClassAsmType().classId.toSymbol(firSession) ? : return ShallowClass .build(signature)
229- return type(sym.fir, signature)
227+ // If the symbol is not resolvable, we return a NEW ShallowClass to prevent caching on a potentially resolvable class type.
228+ return type.importedFqName!! .topLevelClassAsmType().classId.toSymbol(firSession)
229+ ?.let { type(it.fir, signature) }
230+ ? : ShallowClass .build(signature)
231+ .withOwningClass(
232+ (type as ? FirResolvedImport )?.resolvedParentClassId?.toSymbol(firSession)
233+ ?.let { it as ? FirRegularClassSymbol }
234+ ?.let { TypeUtils .asFullyQualified(type(it.fir, signature)) }
235+ )
230236 }
231237
232238 private fun packageDirective (signature : String ): JavaType ? {
Original file line number Diff line number Diff line change 2020import org .junit .jupiter .params .provider .CsvSource ;
2121import org .openrewrite .Issue ;
2222import org .openrewrite .java .tree .J ;
23+ import org .openrewrite .java .tree .JavaType ;
24+ import org .openrewrite .java .tree .TypeUtils ;
2325import org .openrewrite .kotlin .KotlinIsoVisitor ;
2426import org .openrewrite .test .RewriteTest ;
2527
@@ -182,4 +184,45 @@ void quotedImportWithDollar() {
182184 )
183185 );
184186 }
187+
188+ @ Test
189+ void interfaceInformation () {
190+ rewriteRun (
191+ kotlin (
192+ """
193+ package org.example
194+ interface SuperShared {
195+ fun one() = "one"
196+ }
197+ interface Shared : SuperShared
198+ class A {
199+ companion object : Shared
200+ }
201+ """
202+ ),
203+ kotlin (
204+ """
205+ import org.example.A.Companion.one
206+ """ ,
207+ spec -> spec .afterRecipe (cu -> {
208+ JavaType firstImportType = cu .getImports ().getFirst ().getQualid ().getType ();
209+ JavaType .FullyQualified fullyQualified = TypeUtils .asFullyQualified (firstImportType );
210+
211+ //noinspection DataFlowIssue
212+ assertThat (fullyQualified .getOwningClass ().getInterfaces ())
213+ .singleElement ()
214+ .satisfies (sharedInterface -> {
215+ assertThat (sharedInterface .getFullyQualifiedName ()).isEqualTo ("org.example.Shared" );
216+ assertThat (sharedInterface .getInterfaces ())
217+ .singleElement ()
218+ .satisfies (it -> {
219+ assertThat (it .getFullyQualifiedName ()).isEqualTo ("org.example.SuperShared" );
220+ assertThat (it .getMethods ()).singleElement ().extracting (JavaType .Method ::getName ).isEqualTo ("one" );
221+ });
222+ });
223+ }
224+ )
225+ )
226+ );
227+ }
185228}
You can’t perform that action at this time.
0 commit comments