diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java index df13c76f8..4e1a40fcb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/util/BytecodeViewPanelUpdater.java @@ -118,9 +118,9 @@ public void processDisplay() 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 @@ else if (isPanelEditable && decompiler == Decompiler.KRAKATAU_DISASSEMBLER) @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 void mouseMoved(MouseEvent e) @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 @@ private void markOccurrences(RSyntaxTextArea textArea, ClassFileContainer classF if (token == null) { highlighterEx.clearMarkOccurrencesHighlights(); - errorStripe.refreshMarkers(); return; } } @@ -513,7 +518,6 @@ private void markOccurrences(RSyntaxTextArea textArea, ClassFileContainer classF if (token == null) { highlighterEx.clearMarkOccurrencesHighlights(); - errorStripe.refreshMarkers(); return; } @@ -614,7 +618,7 @@ private void markMethod(RSyntaxTextArea textArea, ClassFileContainer classFileCo * @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 @@ private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileConta { 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 @@ private static void markMethodParameter(RSyntaxTextArea textArea, ClassFileConta * @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 @@ private static void markMethodLocalVariable(RSyntaxTextArea textArea, ClassFileC { 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()); } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java index 3e8c4bbbf..50e71bb6f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/ClassFileContainer.java @@ -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 ClassFileContainer(String className, String content, ResourceContainer re /** * 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 void parse() 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() diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java index 4ac3f3e95..b5b25283a 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/classcontainer/parser/MyVoidVisitor.java @@ -2,6 +2,7 @@ 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 @@ else if (scope instanceof ThisExpr) 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 void visit(ConstructorDeclaration n, Object arg) 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> bodyDeclarations = objectCreationExpr.getAnonymousClassBody().get(); + if (bodyDeclarations.getFirst().get().equals(n)) + { + return; + } + } + ResolvedConstructorDeclaration resolve = n.resolve(); String signature = resolve.getQualifiedSignature(); String parameters = "";