-
Notifications
You must be signed in to change notification settings - Fork 497
Use K2Compiler via JvmFirPipeline to support Kotlin v2 #6338
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
base: main
Are you sure you want to change the base?
Conversation
rewrite-kotlin/src/main/java/org/openrewrite/kotlin/KotlinParser.java
Outdated
Show resolved
Hide resolved
26310be to
7abd4c2
Compare
|
@timtebeek @shanman190 @jkschneider PR is now ready for proper review FYI: I also tested adding support for properly compiling |
timtebeek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your continued efforts here @Crustack ! For the uninitiated (me) could you explain a bit about the what the FIR processing is / adds, and any trade offs as compared to what we had before, and impact on say Kotlin v1 support? That would mean we're better able to review this work, as it seems promising but it's a bit hard to say without more context.
| // TODO: Compiler Source File args need to be an actual file path therefore copying synthetic file to temp folder | ||
| public static String tempFile(ExecutionContext ctx, Input source, AtomicInteger idx) { | ||
| String fileName; | ||
| if ("openRewriteFile.kt".equals(source.getPath().toString())) { | ||
| fileName = "openRewriteFile" + idx.getAndIncrement() + ".kt"; | ||
| } else if ("openRewriteFile.kts".equals(source.getPath().toString())) { | ||
| fileName = "openRewriteFile" + idx.getAndIncrement() + ".kts"; | ||
| } else { | ||
| fileName = source.getPath().toString(); | ||
| } | ||
| if(TEMP_SOURCE_DIR == null) { | ||
| try { | ||
| TEMP_SOURCE_DIR = Files.createTempDirectory("rewrite"); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| addJvmClasspathRoot(compilerConfiguration, PathUtil.getResourcePathForClass(AnnotationTarget.class)); | ||
| Path tempFile = TEMP_SOURCE_DIR.resolve(fileName); | ||
| try { | ||
| Files.createDirectories(tempFile.getParent()); | ||
| Files.copy(source.getSource(ctx), tempFile, StandardCopyOption.REPLACE_EXISTING); | ||
| } catch (FileAlreadyExistsException ignored) { | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| return tempFile.toAbsolutePath().toString(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this out for my colleagues as creating files on disk might be a little different when it concerns the CLI / workers.
| is IrSimpleType -> { | ||
| when (type.getPrimitiveType()) { | ||
| PrimitiveType.INT -> JavaType.Primitive.Int | ||
| PrimitiveType.BOOLEAN -> JavaType.Primitive.Boolean | ||
| PrimitiveType.BYTE -> JavaType.Primitive.Byte | ||
| PrimitiveType.CHAR -> JavaType.Primitive.Char | ||
| PrimitiveType.DOUBLE -> JavaType.Primitive.Double | ||
| PrimitiveType.FLOAT -> JavaType.Primitive.Float | ||
| PrimitiveType.LONG -> JavaType.Primitive.Long | ||
| PrimitiveType.SHORT -> JavaType.Primitive.Short | ||
| else -> when { | ||
| type.isStringClassType() -> JavaType.Primitive.String | ||
| type.isNothing() || type.isNullableNothing() -> JavaType.Primitive.None | ||
| else -> JavaType.Primitive.None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that you've thought to do this as well; it's been a bit of a sore point to me that some Spring migration method patterns failed to match because they were using Java primitives instead of Kotlin primitives.
What's changed?
2.2.21JvmFirPipelineto use current K2 phased compiler API (with disabled fail on compile errors) to generateFirFilesKotlinIrTypeMapping,IrTreeVisitor,KotlinTypeIrSignatureBuilderto be compilable, but they are not used atmKotlinTypeMapping,KotlinTypeSignatureBuilder,PsiElementAssociationsfor new compiler dependency versions to be compilablerewrite-kotlinandrewrite-gradletests still work and adjustKotlinTypeMapping,KotlinTypeSignatureBuilder,PsiElementAssociationsif necessaryWhat's your motivation?
Anyone you would like to review specifically?
@shanman190
@jkschneider
Checklist