Skip to content

Commit

Permalink
Update writer
Browse files Browse the repository at this point in the history
  • Loading branch information
noties committed Nov 1, 2023
1 parent eaac754 commit 24f76bf
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/main/java/io/noties/enhance/EnhanceWriterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,6 @@ private String processJavaFile(@Nonnull File file) {
return out;
}

@Nonnull
private static CompilationUnit compile(@Nonnull JavaParser javaParser, @Nonnull File file) {
final CompilationUnit unit;
try {
final ParseResult<CompilationUnit> result = javaParser.parse(file);
if (result.isSuccessful()) {
//noinspection OptionalGetWithoutIsPresent
unit = result.getResult().get();
} else {
throw new RuntimeException(result.toString());
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return unit;
}

private static class ApiInfoVisitor extends VoidVisitorAdapter<ApiInfoStore> {

private final ApiVersionFormatter formatter;
Expand Down Expand Up @@ -337,9 +320,14 @@ private static class Parser11 implements Parser {
@Nonnull
@Override
public CompilationUnit parse(@Nonnull File file) {
return parse(javaParser11, file);
}

@Nonnull
protected static CompilationUnit parse(@Nonnull JavaParser javaParser, @Nonnull File file) {
final CompilationUnit unit;
try {
final ParseResult<CompilationUnit> result = javaParser11.parse(file);
final ParseResult<CompilationUnit> result = javaParser.parse(file);
if (result.isSuccessful()) {
//noinspection OptionalGetWithoutIsPresent
unit = result.getResult().get();
Expand Down Expand Up @@ -368,7 +356,7 @@ public CompilationUnit parse(@Nonnull File file) {
// there are classes that contain illegal variable names: `sealed` and `permits`
CompilationUnit compilationUnit = null;
try {
compilationUnit = compile(javaParser17, file);
compilationUnit = parse(javaParser17, file);
} catch (Throwable t) {
log("[Enhance] Exception parsing with java-17");
//noinspection CallToPrintStackTrace
Expand Down

0 comments on commit 24f76bf

Please sign in to comment.