Skip to content

Commit ec47a2d

Browse files
committed
Switch from using StaticJavaParser to JavaParser so we can handle if the parse was successful.
1 parent a5f0aed commit ec47a2d

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package the.bytecode.club.bytecodeviewer.resources.classcontainer;
22

3-
import com.github.javaparser.StaticJavaParser;
3+
import com.github.javaparser.*;
44
import com.github.javaparser.ast.CompilationUnit;
55
import com.github.javaparser.resolution.TypeSolver;
66
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
@@ -10,7 +10,7 @@
1010
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
1111
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
1212
import the.bytecode.club.bytecodeviewer.resources.classcontainer.locations.*;
13-
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.MyVoidVisitor;
13+
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.MyVoidVisitor;
1414

1515
import java.io.IOException;
1616
import java.util.ArrayList;
@@ -57,8 +57,20 @@ public boolean parse()
5757
if (shouldParse())
5858
{
5959
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path));
60-
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
61-
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
60+
JavaParser parser = new JavaParser();
61+
parser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
62+
ParseResult<CompilationUnit> parse = parser.parse(this.content);
63+
if (!parse.isSuccessful())
64+
{
65+
System.err.println("Failed to parse: " + this.getName());
66+
parse.getProblems().forEach(System.out::println);
67+
return false;
68+
}
69+
70+
CompilationUnit compilationUnit = parse.getResult().orElse(null);
71+
if (compilationUnit == null)
72+
return false;
73+
6274
compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
6375
return true;
6476
}
@@ -67,11 +79,6 @@ public boolean parse()
6779
{
6880
throw new RuntimeException(e);
6981
}
70-
catch (Exception e)
71-
{
72-
System.err.println("Parsing error: " + className);
73-
e.printStackTrace();
74-
}
7582

7683
return false;
7784
}

0 commit comments

Comments
 (0)