Skip to content

Commit 4644d1d

Browse files
committed
fix(gui): correct class init method actions and highlight (#2412)
1 parent 7b8fc01 commit 4644d1d

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

jadx-core/src/main/java/jadx/core/codegen/MethodGen.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public MethodNode getMethodNode() {
8181

8282
public boolean addDefinition(ICodeWriter code) {
8383
if (mth.getMethodInfo().isClassInit()) {
84+
code.startLine();
8485
code.attachDefinition(mth);
85-
code.startLine("static");
86+
code.add("static");
8687
return true;
8788
}
8889
if (mth.contains(AFlag.ANONYMOUS_CONSTRUCTOR)) {

jadx-gui/src/main/java/jadx/gui/ui/codearea/CodeArea.java

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public int adjustOffsetForWordToken(int offset) {
186186
if (type == TokenTypes.ANNOTATION && token.length() > 1) {
187187
return token.getOffset() + 1;
188188
}
189+
if (type == TokenTypes.RESERVED_WORD && token.length() == 6 && token.getLexeme().equals("static")) {
190+
// maybe a class init method
191+
return token.getOffset();
192+
}
189193
} else if (type == TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE) {
190194
return token.getOffset() + 1; // skip quote at start (")
191195
}

jadx-gui/src/main/java/jadx/gui/ui/codearea/MouseHoverHighlighter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import javax.swing.text.Highlighter;
77

88
import org.fife.ui.rsyntaxtextarea.Token;
9-
import org.fife.ui.rsyntaxtextarea.TokenTypes;
109
import org.fife.ui.rtextarea.SmartHighlightPainter;
1110
import org.slf4j.Logger;
1211
import org.slf4j.LoggerFactory;
@@ -44,7 +43,7 @@ private boolean addHighlight(MouseEvent e) {
4443
}
4544
try {
4645
Token token = codeArea.viewToToken(e.getPoint());
47-
if (token == null || token.getType() != TokenTypes.IDENTIFIER) {
46+
if (token == null) {
4847
return false;
4948
}
5049
int tokenOffset = token.getOffset();

0 commit comments

Comments
 (0)