Skip to content

Commit

Permalink
Merge pull request #517 from Bl3nd/go-to-enhancement
Browse files Browse the repository at this point in the history
[Parser] Add examples of what each visitor visits among other things
  • Loading branch information
Konloch authored Oct 6, 2024
2 parents 471ae44 + 29d29e1 commit 14c7ed2
Show file tree
Hide file tree
Showing 12 changed files with 2,296 additions and 1,733 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<treelayout.version>1.0.3</treelayout.version>
<webp-imageio.version>a8f700b</webp-imageio.version>
<xpp3.version>1.1.4c</xpp3.version>
<java-parser.version>3.26.1</java-parser.version>
<java-parser.version>3.26.2</java-parser.version>
<taskmanager.version>1.0.1</taskmanager.version>
<google-java-format.version>1.7</google-java-format.version> <!-- Newer versions require Java 11+ -->
<disk-lib.version>1.2.0</disk-lib.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void actionPerformed(ActionEvent e)
}
else
{
methods.stream().filter(classMethodLocation -> classMethodLocation.owner.equals(method.owner)).forEach(classMethodLocation ->
methods.stream().filter(classMethodLocation -> classMethodLocation.signature.equals(method.signature)).forEach(classMethodLocation ->
{
if (classMethodLocation.decRef.equalsIgnoreCase("declaration"))
{
Expand Down Expand Up @@ -211,7 +211,9 @@ else if (method)
if (packagePath.startsWith("java") || packagePath.startsWith("javax") || packagePath.startsWith("com.sun"))
return null;

String resourceName = packagePath + "/" + classMethodLocation.owner;
String resourceName = classMethodLocation.owner;
if (!packagePath.isEmpty())
resourceName = packagePath + "/" + classMethodLocation.owner;

if (resourceContainer.resourceClasses.containsKey(resourceName))
{
Expand All @@ -229,7 +231,11 @@ else if (method)
if (packagePath.startsWith("java") || packagePath.startsWith("javax") || packagePath.startsWith("com.sun"))
return null;

String resourceName = packagePath + "/" + lexeme;
String resourceName = lexeme;
if (!packagePath.isEmpty())
{
resourceName = packagePath + "/" + lexeme;
}

if (resourceContainer.resourceClasses.containsKey(resourceName))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package the.bytecode.club.bytecodeviewer.resources.classcontainer;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.*;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.resolution.TypeSolver;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
Expand All @@ -10,7 +10,7 @@
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.resources.classcontainer.locations.*;
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.MyVoidVisitor;
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.visitors.MyVoidVisitor;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -57,8 +57,20 @@ public boolean parse()
if (shouldParse())
{
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path));
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
JavaParser parser = new JavaParser();
parser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
ParseResult<CompilationUnit> parse = parser.parse(this.content);
if (!parse.isSuccessful())
{
System.err.println("Failed to parse: " + this.getName());
parse.getProblems().forEach(System.out::println);
return false;
}

CompilationUnit compilationUnit = parse.getResult().orElse(null);
if (compilationUnit == null)
return false;

compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
return true;
}
Expand All @@ -67,11 +79,6 @@ public boolean parse()
{
throw new RuntimeException(e);
}
catch (Exception e)
{
System.err.println("Parsing error: " + className);
e.printStackTrace();
}

return false;
}
Expand All @@ -88,7 +95,10 @@ public boolean shouldParse()

public String getName()
{
return this.className.substring(this.className.lastIndexOf('/') + 1, this.className.lastIndexOf('.'));
if (this.className.contains("/"))
return this.className.substring(this.className.lastIndexOf('/') + 1, this.className.lastIndexOf('.'));
else
return this.className.substring(0, this.className.lastIndexOf('.'));
}

public String getDecompiler()
Expand Down
Loading

0 comments on commit 14c7ed2

Please sign in to comment.