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

Commit dbedf95

Browse files
authored
Merge pull request #95 from shanman190/feature/source-set
Remove automatic source set addition to compilation units
2 parents 7af4594 + 18ae80a commit dbedf95

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818

1919
import org.intellij.lang.annotations.Language;
2020
import org.openrewrite.ExecutionContext;
21+
import org.openrewrite.SourceFile;
2122
import org.openrewrite.internal.lang.Nullable;
2223
import org.openrewrite.kotlin.tree.K;
2324
import org.openrewrite.test.SourceSpec;
2425
import org.openrewrite.test.SourceSpecs;
2526

2627
import java.util.function.Consumer;
2728

29+
import static org.openrewrite.java.Assertions.sourceSet;
30+
import static org.openrewrite.test.SourceSpecs.dir;
31+
2832
public final class Assertions {
2933
private Assertions() {
3034
}
@@ -64,6 +68,22 @@ public static SourceSpecs kotlin(@Language("kotlin") @Nullable String before, @L
6468
return kotlin;
6569
}
6670

71+
public static SourceSpecs srcMainKotlin(Consumer<SourceSpec<SourceFile>> spec, SourceSpecs... kotlinSources) {
72+
return dir("src/main/kotlin", spec, kotlinSources);
73+
}
74+
75+
public static SourceSpecs srcMainKotlin(SourceSpecs... kotlinSources) {
76+
return srcMainKotlin(spec -> sourceSet(spec, "main"), kotlinSources);
77+
}
78+
79+
public static SourceSpecs srcTestKotlin(Consumer<SourceSpec<SourceFile>> spec, SourceSpecs... kotlinSources) {
80+
return dir("src/test/kotlin", spec, kotlinSources);
81+
}
82+
83+
public static SourceSpecs srcTestKotlin(SourceSpecs... kotlinSources) {
84+
return srcTestKotlin(spec -> sourceSet(spec, "test"), kotlinSources);
85+
}
86+
6787
private static void acceptSpec(Consumer<SourceSpec<K.CompilationUnit>> spec, SourceSpec<K.CompilationUnit> kotlin) {
6888
Consumer<K.CompilationUnit> userSuppliedAfterRecipe = kotlin.getAfterRecipe();
6989
kotlin.afterRecipe(userSuppliedAfterRecipe::accept);

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@
6161
import org.openrewrite.InMemoryExecutionContext;
6262
import org.openrewrite.Parser;
6363
import org.openrewrite.Tree;
64-
import org.openrewrite.internal.ListUtils;
6564
import org.openrewrite.internal.lang.Nullable;
6665
import org.openrewrite.java.JavaParser;
6766
import org.openrewrite.java.internal.JavaTypeCache;
6867
import org.openrewrite.java.marker.JavaSourceSet;
69-
import org.openrewrite.java.tree.JavaType;
7068
import org.openrewrite.kotlin.internal.KotlinParserVisitor;
7169
import org.openrewrite.kotlin.tree.K;
7270
import org.openrewrite.style.NamedStyles;
@@ -187,27 +185,14 @@ public List<K.CompilationUnit> parseInputs(Iterable<Input> sources, @Nullable Pa
187185
}
188186

189187
Disposer.dispose(disposable);
190-
JavaSourceSet sourceSet = getSourceSet(ctx);
191-
if (!ctx.getMessage(SKIP_SOURCE_SET_TYPE_GENERATION, false)) {
192-
List<JavaType.FullyQualified> classpath = sourceSet.getClasspath();
193-
for (K.CompilationUnit cu : mappedCus) {
194-
for (JavaType type : cu.getTypesInUse().getTypesInUse()) {
195-
if (type instanceof JavaType.FullyQualified) {
196-
classpath.add((JavaType.FullyQualified) type);
197-
}
198-
}
199-
}
200-
sourceSetProvenance = sourceSet.withClasspath(classpath);
201-
}
202-
assert sourceSetProvenance != null;
203-
return ListUtils.map(mappedCus, cu -> cu.withMarkers(cu.getMarkers().add(sourceSetProvenance)));
188+
return mappedCus;
204189
}
205190

206191
/**
207192
* @param disposable disposable to use for the compiler environment. THIS MUST BE DISPOSED BY THE CALLER.
208-
* @param sources input sources to parse.
193+
* @param sources input sources to parse.
209194
* @param relativeTo path to relativize input paths against.
210-
* @param ctx Execution context to use for collecting parsing failures.
195+
* @param ctx Execution context to use for collecting parsing failures.
211196
* @return FirSession associated to type attributing the CompiledKotlinSources.
212197
*/
213198
Map<FirSession, List<CompiledKotlinSource>> parseInputsToCompilerAst(Disposable disposable, Iterable<Input> sources, @Nullable Path relativeTo, ExecutionContext ctx) {
@@ -372,11 +357,13 @@ public KotlinParser reset() {
372357
return this;
373358
}
374359

360+
@Deprecated//(since = "0.4.0", forRemoval = true)
375361
public void setSourceSet(String sourceSet) {
376362
this.sourceSetProvenance = null;
377363
this.sourceSet = sourceSet;
378364
}
379365

366+
@Deprecated//(since = "0.4.0", forRemoval = true)
380367
public JavaSourceSet getSourceSet(ExecutionContext ctx) {
381368
if (sourceSetProvenance == null) {
382369
if (ctx.getMessage(SKIP_SOURCE_SET_TYPE_GENERATION, false)) {

0 commit comments

Comments
 (0)