Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Parser] Add examples of what each visitor visits among other things #517

Merged
merged 6 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+ -->
</properties>
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