Skip to content

Commit

Permalink
Added NameStyles from Parser to Py.CU.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Jul 11, 2023
1 parent f487df7 commit 5149579
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/openrewrite/python/PythonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

@SuppressWarnings("unused")
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class PythonParser implements Parser {
private final LanguageLevel languageLevel;
private final List<NamedStyles> styles;
private final Collection<NamedStyles> styles;
private final boolean logCompilationWarningsAndErrors;
private final JavaTypeCache typeCache;
@Override
Expand Down Expand Up @@ -71,7 +72,7 @@ public Stream<SourceFile> parseInputs(Iterable<Input> inputs, @Nullable Path rel
return acceptedInputs(inputs).map(sourceFile -> {
Path path = sourceFile.getRelativePath(relativeTo);
try (EncodingDetectingInputStream is = sourceFile.getSource(ctx)) {
Py.CompilationUnit py = new PsiPythonMapper(path, is.getCharset(), is.isCharsetBomMarked(), mapLanguageLevel(languageLevel))
Py.CompilationUnit py = new PsiPythonMapper(path, is.getCharset(), is.isCharsetBomMarked(), styles, mapLanguageLevel(languageLevel))
.mapSource(is.readFully());
parsingListener.parsed(sourceFile, py);
return py;
Expand Down Expand Up @@ -189,7 +190,7 @@ public static class Builder extends Parser.Builder {
private LanguageLevel languageLevel = LanguageLevel.PYTHON_312;
private JavaTypeCache typeCache = new JavaTypeCache();
private boolean logCompilationWarningsAndErrors;
private final List<NamedStyles> styles = new ArrayList<>();
private final Collection<NamedStyles> styles = new ArrayList<>();

public Builder() {
super(Py.CompilationUnit.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openrewrite.python.marker.*;
import org.openrewrite.python.tree.Py;
import org.openrewrite.python.tree.PySpace;
import org.openrewrite.style.NamedStyles;

import java.nio.charset.Charset;
import java.nio.file.Path;
Expand All @@ -55,15 +56,18 @@ public class PsiPythonMapper {
private final Path path;
private final Charset charset;
private final boolean isCharsetBomMarked;
private final Collection<NamedStyles> styles;
private final LanguageLevel languageLevel;

public PsiPythonMapper(Path path,
Charset charset,
boolean isCharsetBomMarked,
Collection<NamedStyles> styles,
LanguageLevel languageLevel) {
this.path = path;
this.charset = charset;
this.isCharsetBomMarked = isCharsetBomMarked;
this.styles = styles;
this.languageLevel = languageLevel;
}

Expand Down Expand Up @@ -127,9 +131,9 @@ public Py.CompilationUnit mapFile(PyFile element) {
mapBlock(element, null, element.getStatements(), ctx)
);

Markers markers = EMPTY;
Markers markers = Markers.build(styles);
if (!element.getText().endsWith("\n")) {
markers = Markers.build(singletonList(new SuppressNewline(randomId())));
markers = markers.addIfAbsent(new SuppressNewline(randomId()));
}

Space eof = ctx.paddingCursor.consumeRemainingAndExpectEOF();
Expand Down

0 comments on commit 5149579

Please sign in to comment.