Skip to content

Commit

Permalink
Merge pull request #95 from shanman190/feature/source-set
Browse files Browse the repository at this point in the history
Remove automatic source set addition to compilation units
  • Loading branch information
sambsnyd authored Apr 13, 2023
2 parents 7af4594 + 18ae80a commit dbedf95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/openrewrite/kotlin/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

import org.intellij.lang.annotations.Language;
import org.openrewrite.ExecutionContext;
import org.openrewrite.SourceFile;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.test.SourceSpec;
import org.openrewrite.test.SourceSpecs;

import java.util.function.Consumer;

import static org.openrewrite.java.Assertions.sourceSet;
import static org.openrewrite.test.SourceSpecs.dir;

public final class Assertions {
private Assertions() {
}
Expand Down Expand Up @@ -64,6 +68,22 @@ public static SourceSpecs kotlin(@Language("kotlin") @Nullable String before, @L
return kotlin;
}

public static SourceSpecs srcMainKotlin(Consumer<SourceSpec<SourceFile>> spec, SourceSpecs... kotlinSources) {
return dir("src/main/kotlin", spec, kotlinSources);
}

public static SourceSpecs srcMainKotlin(SourceSpecs... kotlinSources) {
return srcMainKotlin(spec -> sourceSet(spec, "main"), kotlinSources);
}

public static SourceSpecs srcTestKotlin(Consumer<SourceSpec<SourceFile>> spec, SourceSpecs... kotlinSources) {
return dir("src/test/kotlin", spec, kotlinSources);
}

public static SourceSpecs srcTestKotlin(SourceSpecs... kotlinSources) {
return srcTestKotlin(spec -> sourceSet(spec, "test"), kotlinSources);
}

private static void acceptSpec(Consumer<SourceSpec<K.CompilationUnit>> spec, SourceSpec<K.CompilationUnit> kotlin) {
Consumer<K.CompilationUnit> userSuppliedAfterRecipe = kotlin.getAfterRecipe();
kotlin.afterRecipe(userSuppliedAfterRecipe::accept);
Expand Down
23 changes: 5 additions & 18 deletions src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Parser;
import org.openrewrite.Tree;
import org.openrewrite.internal.ListUtils;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.marker.JavaSourceSet;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.kotlin.internal.KotlinParserVisitor;
import org.openrewrite.kotlin.tree.K;
import org.openrewrite.style.NamedStyles;
Expand Down Expand Up @@ -187,27 +185,14 @@ public List<K.CompilationUnit> parseInputs(Iterable<Input> sources, @Nullable Pa
}

Disposer.dispose(disposable);
JavaSourceSet sourceSet = getSourceSet(ctx);
if (!ctx.getMessage(SKIP_SOURCE_SET_TYPE_GENERATION, false)) {
List<JavaType.FullyQualified> classpath = sourceSet.getClasspath();
for (K.CompilationUnit cu : mappedCus) {
for (JavaType type : cu.getTypesInUse().getTypesInUse()) {
if (type instanceof JavaType.FullyQualified) {
classpath.add((JavaType.FullyQualified) type);
}
}
}
sourceSetProvenance = sourceSet.withClasspath(classpath);
}
assert sourceSetProvenance != null;
return ListUtils.map(mappedCus, cu -> cu.withMarkers(cu.getMarkers().add(sourceSetProvenance)));
return mappedCus;
}

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

@Deprecated//(since = "0.4.0", forRemoval = true)
public void setSourceSet(String sourceSet) {
this.sourceSetProvenance = null;
this.sourceSet = sourceSet;
}

@Deprecated//(since = "0.4.0", forRemoval = true)
public JavaSourceSet getSourceSet(ExecutionContext ctx) {
if (sourceSetProvenance == null) {
if (ctx.getMessage(SKIP_SOURCE_SET_TYPE_GENERATION, false)) {
Expand Down

0 comments on commit dbedf95

Please sign in to comment.