Skip to content

Commit

Permalink
Palish a few more new Parser.Input() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Oct 3, 2024
1 parent c63ab56 commit 0067a10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
19 changes: 7 additions & 12 deletions rewrite-core/src/main/java/org/openrewrite/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ default Stream<SourceFile> parse(String... sources) {

default Stream<SourceFile> parse(ExecutionContext ctx, String... sources) {
return parseInputs(
Arrays.stream(sources).map(source ->
new Input(
sourcePathFromSourceText(Paths.get(Long.toString(System.nanoTime())), source), null,
() -> new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)),
true
)
).collect(toList()),
Arrays.stream(sources)
.map(source ->
Input.fromString(
sourcePathFromSourceText(Paths.get(Long.toString(System.nanoTime())), source), source)
).collect(toList()),
null,
ctx
);
Expand Down Expand Up @@ -204,11 +202,8 @@ public static List<Input> fromResource(String resource, String delimiter) {
public static List<Input> fromResource(String resource, String delimiter, @Nullable Charset charset) {
Charset resourceCharset = charset == null ? StandardCharsets.UTF_8 : charset;
return Arrays.stream(StringUtils.readFully(Objects.requireNonNull(Input.class.getResourceAsStream(resource)), resourceCharset).split(delimiter))
.map(source -> new Parser.Input(
Paths.get(Long.toString(System.nanoTime())), null,
() -> new ByteArrayInputStream(source.getBytes(resourceCharset)),
true
))
.map(source -> Parser.Input.fromString(
Paths.get(Long.toString(System.nanoTime())), source))
.collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
import org.openrewrite.tree.ParseError;
import org.openrewrite.tree.ParsingExecutionContextView;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
Expand Down Expand Up @@ -82,11 +80,7 @@ public Stream<SourceFile> parse(@Language("groovy") String... sources) {
.orElse(Long.toString(System.nanoTime())) + ".java";

Path path = Paths.get(pkg + className);
return new Input(
path, null,
() -> new ByteArrayInputStream(sourceFile.getBytes(StandardCharsets.UTF_8)),
true
);
return Input.fromString(path, sourceFile);
})
.collect(toList()),
null,
Expand Down

0 comments on commit 0067a10

Please sign in to comment.