Add a little documentation and rename a few variables for clarity.

This commit is contained in:
Cody 2024-09-18 20:26:39 -06:00
parent e756324245
commit 00319e9537

AI 샘플 코드 생성 중입니다

Loading...
3 changed files with 100 additions and 83 deletions

View File

@ -17,6 +17,8 @@ import java.awt.event.ActionEvent;
import java.util.HashMap;
/**
* This action is triggered by a user typing (CTRL+B). This goes to a specific variables declaration whether it be in the opened class, or a class within the jar.
* <p>
* Created by Bl3nd.
* Date: 9/7/2024
*/
@ -98,14 +100,20 @@ public class GoToAction extends AbstractAction
}));
}
/**
* Open a class that contains the declaration of a field.
*
* @param field The field to jump to
* @param textArea The text area of the current class (not the class we are opening)
*/
private void openFieldClass(ClassFieldLocation field, RSyntaxTextArea textArea)
{
String token = textArea.modelToToken(textArea.getCaretPosition()).getLexeme();
ResourceContainer resourceContainer = BytecodeViewer.getFileContainer(container.getParentContainer());
if (resourceContainer != null)
{
String s = container.getImport(field.owner);
BytecodeViewer.viewer.workPane.addClassResource(resourceContainer, s + ".class");
String className = container.getImport(field.owner);
BytecodeViewer.viewer.workPane.addClassResource(resourceContainer, className + ".class");
ClassViewer activeResource = (ClassViewer) BytecodeViewer.viewer.workPane.getActiveResource();
HashMap<String, ClassFileContainer> classFiles = BytecodeViewer.viewer.workPane.classFiles;
Thread thread = new Thread(() -> {
@ -121,8 +129,8 @@ public class GoToAction extends AbstractAction
BytecodeViewer.updateBusyStatus(false);
}
String s2 = activeResource.resource.workingName + "-" + this.container.getDecompiler();
ClassFileContainer classFileContainer = classFiles.get(s2);
String containerName = activeResource.resource.workingName + "-" + this.container.getDecompiler();
ClassFileContainer classFileContainer = classFiles.get(containerName);
classFileContainer.fieldMembers.forEach((field1, field2) -> {
if (field1.equals(token))
{
@ -162,7 +170,6 @@ public class GoToAction extends AbstractAction
}
panel.textArea.requestFocusInWindow();
break;
}
}

View File

@ -17,102 +17,110 @@ import java.util.NavigableMap;
import java.util.TreeMap;
/**
* This is a container for a specific class. The container name is based on the actual class name and the decompiler used.
* <p>
* Created by Bl3nd.
* Date: 8/26/2024
*/
public class ClassFileContainer
{
public transient NavigableMap<String, ArrayList<ClassFieldLocation>> fieldMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassParameterLocation>> methodParameterMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassLocalVariableLocation>> methodLocalMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassMethodLocation>> methodMembers = new TreeMap<>();
public transient NavigableMap<String, String> imports = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassFieldLocation>> fieldMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassParameterLocation>> methodParameterMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassLocalVariableLocation>> methodLocalMembers = new TreeMap<>();
public transient NavigableMap<String, ArrayList<ClassMethodLocation>> methodMembers = new TreeMap<>();
public transient NavigableMap<String, String> imports = new TreeMap<>();
public boolean hasBeenParsed = false;
public final String className;
private final String content;
private final String parentContainer;
public boolean hasBeenParsed = false;
public final String className;
private final String content;
private final String parentContainer;
public ClassFileContainer(String className, String content, String parentContainer)
{
this.className = className;
this.content = content;
this.parentContainer = parentContainer;
}
public ClassFileContainer(String className, String content, String parentContainer)
{
this.className = className;
this.content = content;
this.parentContainer = parentContainer;
}
public void parse()
{
try
{
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver()));
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
} catch (ParseProblemException e)
{
System.err.println("Parsing error!");
}
}
/**
* Parse the class content with JavaParser.
*/
public void parse()
{
try
{
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver()));
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
} catch (ParseProblemException e)
{
System.err.println("Parsing error!");
}
}
public String getName() {
return this.className.substring(this.className.lastIndexOf('.') + 1);
}
public String getName()
{
return this.className.substring(this.className.lastIndexOf('.') + 1);
}
public String getDecompiler() {
return getName().substring(6);
}
public String getDecompiler()
{
return getName().substring(6);
}
public String getParentContainer()
{
return this.parentContainer;
}
public String getParentContainer()
{
return this.parentContainer;
}
public void putField(String key, ClassFieldLocation value)
{
this.fieldMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public void putField(String key, ClassFieldLocation value)
{
this.fieldMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public List<ClassFieldLocation> getFieldLocationsFor(String fieldName)
{
return fieldMembers.getOrDefault(fieldName, new ArrayList<>());
}
public List<ClassFieldLocation> getFieldLocationsFor(String fieldName)
{
return fieldMembers.getOrDefault(fieldName, new ArrayList<>());
}
public void putParameter(String key, ClassParameterLocation value)
{
this.methodParameterMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public void putParameter(String key, ClassParameterLocation value)
{
this.methodParameterMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public List<ClassParameterLocation> getParameterLocationsFor(String key)
{
return methodParameterMembers.getOrDefault(key, new ArrayList<>());
}
public List<ClassParameterLocation> getParameterLocationsFor(String key)
{
return methodParameterMembers.getOrDefault(key, new ArrayList<>());
}
public void putLocalVariable(String key, ClassLocalVariableLocation value)
{
this.methodLocalMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public void putLocalVariable(String key, ClassLocalVariableLocation value)
{
this.methodLocalMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public List<ClassLocalVariableLocation> getLocalLocationsFor(String key)
{
return methodLocalMembers.getOrDefault(key, new ArrayList<>());
}
public List<ClassLocalVariableLocation> getLocalLocationsFor(String key)
{
return methodLocalMembers.getOrDefault(key, new ArrayList<>());
}
public void putMethod(String key, ClassMethodLocation value)
{
this.methodMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public void putMethod(String key, ClassMethodLocation value)
{
this.methodMembers.computeIfAbsent(key, v -> new ArrayList<>()).add(value);
}
public List<ClassMethodLocation> getMethodLocationsFor(String key)
{
return methodMembers.getOrDefault(key, new ArrayList<>());
}
public List<ClassMethodLocation> getMethodLocationsFor(String key)
{
return methodMembers.getOrDefault(key, new ArrayList<>());
}
public void putImport(String key, String value)
{
this.imports.put(key, value);
}
public void putImport(String key, String value)
{
this.imports.put(key, value);
}
public String getImport(String key) {
String value = this.imports.get(key);
return value + "/" + key;
}
public String getImport(String key)
{
String value = this.imports.get(key);
return value + "/" + key;
}
}

View File

@ -20,6 +20,8 @@ import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Our custom visitor that allows us to get the information from JavaParser we need.
* <p>
* Created by Bl3nd.
* Date: 9/5/2024
*/
@ -1315,7 +1317,7 @@ public class MyVoidVisitor extends VoidVisitorAdapter<Object>
/**
* Visit all {@link LambdaExpr}'s.
*
* @param n The current {@code LambdaExpr}
* @param n The current {@code LambdaExpr}
* @param arg Don't worry about it.
*/
@Override