Skip to content

Commit

Permalink
Call StringUtilRt.convertLineSeparators on sourceCode before creati…
Browse files Browse the repository at this point in the history
…ng LVF.

Added code to generate IR to KotlinParser.
Updated names in ClassDeclarationTest#companionObject to prevent namespace conflicts.
  • Loading branch information
traceyyoshima committed Oct 16, 2023
1 parent 7907471 commit 2c04664
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
20 changes: 17 additions & 3 deletions src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt;
import org.jetbrains.kotlin.com.intellij.openapi.Disposable;
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer;
import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtilRt;
import org.jetbrains.kotlin.com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.kotlin.com.intellij.psi.FileViewProvider;
import org.jetbrains.kotlin.com.intellij.psi.PsiManager;
Expand All @@ -43,8 +44,7 @@
import org.jetbrains.kotlin.fir.FirSession;
import org.jetbrains.kotlin.fir.declarations.FirFile;
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider;
import org.jetbrains.kotlin.fir.pipeline.AnalyseKt;
import org.jetbrains.kotlin.fir.pipeline.FirUtilsKt;
import org.jetbrains.kotlin.fir.pipeline.*;
import org.jetbrains.kotlin.fir.resolve.ScopeSession;
import org.jetbrains.kotlin.fir.session.FirSessionConfigurator;
import org.jetbrains.kotlin.fir.session.FirSessionFactoryHelper;
Expand All @@ -56,6 +56,7 @@
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices;
import org.jetbrains.kotlin.utils.PathUtil;
import org.junit.platform.commons.util.StringUtils;
import org.openrewrite.*;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaParser;
Expand Down Expand Up @@ -369,7 +370,7 @@ public CompiledSource parse(List<Parser.Input> sources, Disposable disposable, E
fileName = source.getPath().toString();
}

VirtualFile vFile = new LightVirtualFile(fileName, KotlinFileType.INSTANCE, source.getSource(ctx).readFully());
VirtualFile vFile = new LightVirtualFile(fileName, KotlinFileType.INSTANCE, StringUtilRt.convertLineSeparators(source.getSource(ctx).readFully()));
final FileViewProvider fileViewProvider = new SingleRootFileViewProvider(
PsiManager.getInstance(environment.getProject()),
vFile
Expand Down Expand Up @@ -431,6 +432,19 @@ public CompiledSource parse(List<Parser.Input> sources, Disposable disposable, E
List<FirFile> rawFir = FirUtilsKt.buildFirFromKtFiles(firSession, ktFiles);
Pair<ScopeSession, List<FirFile>> result = AnalyseKt.runResolution(firSession, rawFir);
AnalyseKt.runCheckers(firSession, result.getFirst(), result.getSecond(), diagnosticsReporter);
// ModuleCompilerAnalyzedOutput analyzedOutput = new ModuleCompilerAnalyzedOutput(firSession, result.getFirst(), result.getSecond());
// FirResult firResult = new FirResult(singletonList(analyzedOutput));
//
// Fir2IrExtensions extensions = Fir2IrExtensions.Default.INSTANCE;
// Fir2IrConfiguration irConfiguration = new Fir2IrConfiguration(
// languageVersionSettings,
// compilerConfiguration.getBoolean(JVMConfigurationKeys.LINK_VIA_SIGNATURES),
// compilerConfiguration.putIfAbsent(EVALUATED_CONST_TRACKER, EvaluatedConstTracker.Companion.create())
// );
// // TODO: add generation extensions
// List<IrGenerationExtension> irGenerationExtensions = new ArrayList<>();
// Fir2IrActualizedResult actualizedResult = convertToIrAndActualizeForJvm(firResult, extensions, irConfiguration, irGenerationExtensions, diagnosticsReporter);

assert kotlinSources.size() == result.getSecond().size();
List<FirFile> second = result.getSecond();
for (int i = 0; i < second.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ import kotlin.collections.HashMap
import kotlin.math.max
import kotlin.math.min


class KotlinParserVisitor(
kotlinSource: KotlinSource,
relativeTo: Path?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,21 @@ void companionObject() {
kotlin("object Companion"),
kotlin(
"""
class Test {
class TestA {
companion object
}
"""
),
kotlin(
"""
class Test {
class TestB {
companion object Foo
}
"""
),
kotlin(
"""
class Test {
class TestC {
companion object Companion
}
"""
Expand Down

0 comments on commit 2c04664

Please sign in to comment.