Merge pull request #516 from Bl3nd/go-to-enhancement

A few fixes for parsing
This commit is contained in:
Konloch 2024-09-29 06:44:51 -07:00 committed by GitHub
commit 95eeee0e15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

AI 샘플 코드 생성 중입니다

Loading...
3 changed files with 57 additions and 32 deletions

View File

@ -118,9 +118,9 @@ public class BytecodeViewPanelUpdater implements Runnable
if (!BytecodeViewer.viewer.workPane.classFiles.containsKey(workingDecompilerName))
{
container.parse();
boolean parsed = container.parse();
BytecodeViewer.viewer.workPane.classFiles.put(workingDecompilerName, container);
container.hasBeenParsed = true;
container.hasBeenParsed = parsed;
}
//set the swing components on the swing thread
@ -449,24 +449,27 @@ public class BytecodeViewPanelUpdater implements Runnable
@Override
public void mouseMoved(MouseEvent e)
{
if (e.isControlDown())
if (classFileContainer.hasBeenParsed)
{
RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource();
Token token = textArea.viewToToken(e.getPoint());
if (token != null)
if (e.isControlDown())
{
String lexeme = token.getLexeme();
if (classFileContainer.fieldMembers.containsKey(lexeme) || classFileContainer.methodMembers.containsKey(lexeme) || classFileContainer.methodLocalMembers.containsKey(lexeme) || classFileContainer.methodParameterMembers.containsKey(lexeme) || classFileContainer.classReferences.containsKey(lexeme))
RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource();
Token token = textArea.viewToToken(e.getPoint());
if (token != null)
{
textArea.setCursor(new Cursor(Cursor.HAND_CURSOR));
String lexeme = token.getLexeme();
if (classFileContainer.fieldMembers.containsKey(lexeme) || classFileContainer.methodMembers.containsKey(lexeme) || classFileContainer.methodLocalMembers.containsKey(lexeme) || classFileContainer.methodParameterMembers.containsKey(lexeme) || classFileContainer.classReferences.containsKey(lexeme))
{
textArea.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
}
}
}
else
{
if (bytecodeViewPanel.textArea.getCursor().getType() != Cursor.TEXT_CURSOR)
else
{
bytecodeViewPanel.textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR));
if (bytecodeViewPanel.textArea.getCursor().getType() != Cursor.TEXT_CURSOR)
{
bytecodeViewPanel.textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR));
}
}
}
}
@ -477,10 +480,13 @@ public class BytecodeViewPanelUpdater implements Runnable
@Override
public void mouseClicked(MouseEvent e)
{
if (e.isControlDown())
if (classFileContainer.hasBeenParsed)
{
RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource();
textArea.getActionMap().get("goToAction").actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, "goToAction"));
if (e.isControlDown())
{
RSyntaxTextArea textArea = (RSyntaxTextArea) e.getSource();
textArea.getActionMap().get("goToAction").actionPerformed(new ActionEvent(textArea, ActionEvent.ACTION_PERFORMED, "goToAction"));
}
}
}
});
@ -504,7 +510,6 @@ public class BytecodeViewPanelUpdater implements Runnable
if (token == null)
{
highlighterEx.clearMarkOccurrencesHighlights();
errorStripe.refreshMarkers();
return;
}
}
@ -513,7 +518,6 @@ public class BytecodeViewPanelUpdater implements Runnable
if (token == null)
{
highlighterEx.clearMarkOccurrencesHighlights();
errorStripe.refreshMarkers();
return;
}
@ -614,7 +618,7 @@ public class BytecodeViewPanelUpdater implements Runnable
* @param finalToken the token
* @param highlighterEx the highlighter
*/
private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx)
private void markMethodParameter(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx)
{
classFileContainer.methodParameterMembers.values().forEach(parameters -> parameters.forEach(parameter ->
{
@ -631,7 +635,6 @@ public class BytecodeViewPanelUpdater implements Runnable
{
int startOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnStart - 1);
int endOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnEnd - 1);
highlighterEx.addMarkedOccurrenceHighlight(startOffset, endOffset, new SmartHighlightPainter());
}
}
@ -654,7 +657,7 @@ public class BytecodeViewPanelUpdater implements Runnable
* @param finalToken the token
* @param highlighterEx the highlighter
*/
private static void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx)
private void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileContainer classFileContainer, int line, int column, Token finalToken, RSyntaxTextAreaHighlighterEx highlighterEx)
{
classFileContainer.methodLocalMembers.values().forEach(localVariables -> localVariables.forEach(localVariable ->
{
@ -671,7 +674,6 @@ public class BytecodeViewPanelUpdater implements Runnable
{
int startOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnStart - 1);
int endOffset = root.getElement(location.line - 1).getStartOffset() + (location.columnEnd - 1);
highlighterEx.addMarkedOccurrenceHighlight(startOffset, endOffset, new SmartHighlightPainter());
}
}

View File

@ -1,14 +1,13 @@
package the.bytecode.club.bytecodeviewer.resources.classcontainer;
import com.github.javaparser.ParseProblemException;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.resolution.TypeSolver;
import com.github.javaparser.resolution.UnsolvedSymbolException;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
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;
@ -51,14 +50,18 @@ public class ClassFileContainer
/**
* Parse the class content with JavaParser.
*/
public void parse()
public boolean parse()
{
try
{
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path));
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
if (shouldParse())
{
TypeSolver typeSolver = new CombinedTypeSolver(new ReflectionTypeSolver(false), new JarTypeSolver(path));
StaticJavaParser.getParserConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit compilationUnit = StaticJavaParser.parse(this.content);
compilationUnit.accept(new MyVoidVisitor(this, compilationUnit), null);
return true;
}
}
catch (IOException e)
{
@ -69,6 +72,17 @@ public class ClassFileContainer
System.err.println("Parsing error: " + className);
e.printStackTrace();
}
return false;
}
public boolean shouldParse()
{
return !getDecompiler().equals(Decompiler.BYTECODE_DISASSEMBLER.getDecompilerName())
&& !getDecompiler().equals(Decompiler.KRAKATAU_DISASSEMBLER.getDecompilerName())
&& !getDecompiler().equals(Decompiler.JAVAP_DISASSEMBLER.getDecompilerName())
&& !getDecompiler().equals(Decompiler.SMALI_DISASSEMBLER.getDecompilerName())
&& !getDecompiler().equals(Decompiler.ASM_TEXTIFY_DISASSEMBLER.getDecompilerName());
}
public String getName()

View File

@ -2,6 +2,7 @@ package the.bytecode.club.bytecodeviewer.resources.classcontainer.parser;
import com.github.javaparser.Range;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.stmt.*;
@ -175,8 +176,6 @@ public class MyVoidVisitor extends VoidVisitorAdapter<Object>
ResolvedType resolvedType = n.getSymbolResolver().calculateType(thisExpr);
String qualifiedName = resolvedType.asReferenceType().getQualifiedName();
String className = qualifiedName.substring(qualifiedName.lastIndexOf('.') + 1);
String packageName = qualifiedName.substring(0, qualifiedName.lastIndexOf('.'));
this.classFileContainer.putClassReference(className, new ClassReferenceLocation(getOwner(), packageName.replace('.', '/'), fieldName, "reference", line, columnStart, columnEnd + 1));
this.classFileContainer.putField(fieldName, new ClassFieldLocation(className, "reference", line, columnStart, columnEnd + 1));
}
}
@ -207,6 +206,16 @@ public class MyVoidVisitor extends VoidVisitorAdapter<Object>
this.classFileContainer.putParameter(parameterName, new ClassParameterLocation(getOwner(), n.getDeclarationAsString(false, false), "declaration", line, columnStart, columnEnd + 1));
});
if (n.getParentNode().get() instanceof ObjectCreationExpr)
{
ObjectCreationExpr objectCreationExpr = (ObjectCreationExpr) n.getParentNode().get();
NodeList<BodyDeclaration<?>> bodyDeclarations = objectCreationExpr.getAnonymousClassBody().get();
if (bodyDeclarations.getFirst().get().equals(n))
{
return;
}
}
ResolvedConstructorDeclaration resolve = n.resolve();
String signature = resolve.getQualifiedSignature();
String parameters = "";