1
1
package the .bytecode .club .bytecodeviewer .resources .classcontainer ;
2
2
3
- import com .github .javaparser .StaticJavaParser ;
3
+ import com .github .javaparser .* ;
4
4
import com .github .javaparser .ast .CompilationUnit ;
5
5
import com .github .javaparser .resolution .TypeSolver ;
6
6
import com .github .javaparser .symbolsolver .JavaSymbolSolver ;
10
10
import the .bytecode .club .bytecodeviewer .decompilers .Decompiler ;
11
11
import the .bytecode .club .bytecodeviewer .resources .ResourceContainer ;
12
12
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 ;
14
14
15
15
import java .io .IOException ;
16
16
import java .util .ArrayList ;
@@ -57,8 +57,20 @@ public boolean parse()
57
57
if (shouldParse ())
58
58
{
59
59
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
+
62
74
compilationUnit .accept (new MyVoidVisitor (this , compilationUnit ), null );
63
75
return true ;
64
76
}
@@ -67,11 +79,6 @@ public boolean parse()
67
79
{
68
80
throw new RuntimeException (e );
69
81
}
70
- catch (Exception e )
71
- {
72
- System .err .println ("Parsing error: " + className );
73
- e .printStackTrace ();
74
- }
75
82
76
83
return false ;
77
84
}
@@ -88,7 +95,10 @@ public boolean shouldParse()
88
95
89
96
public String getName ()
90
97
{
91
- return this .className .substring (this .className .lastIndexOf ('/' ) + 1 , this .className .lastIndexOf ('.' ));
98
+ if (this .className .contains ("/" ))
99
+ return this .className .substring (this .className .lastIndexOf ('/' ) + 1 , this .className .lastIndexOf ('.' ));
100
+ else
101
+ return this .className .substring (0 , this .className .lastIndexOf ('.' ));
92
102
}
93
103
94
104
public String getDecompiler ()
0 commit comments