fix(gui): correct class init method actions and highlight (#2412)

This commit is contained in:
Skylot
2025-02-17 20:38:00 +00:00
parent 7b8fc01319
commit 4644d1d8ac
3 changed files with 7 additions and 3 deletions
@@ -81,8 +81,9 @@ public class MethodGen {
public boolean addDefinition(ICodeWriter code) {
if (mth.getMethodInfo().isClassInit()) {
code.startLine();
code.attachDefinition(mth);
code.startLine("static");
code.add("static");
return true;
}
if (mth.contains(AFlag.ANONYMOUS_CONSTRUCTOR)) {
@@ -186,6 +186,10 @@ public final class CodeArea extends AbstractCodeArea {
if (type == TokenTypes.ANNOTATION && token.length() > 1) {
return token.getOffset() + 1;
}
if (type == TokenTypes.RESERVED_WORD && token.length() == 6 && token.getLexeme().equals("static")) {
// maybe a class init method
return token.getOffset();
}
} else if (type == TokenTypes.MARKUP_TAG_ATTRIBUTE_VALUE) {
return token.getOffset() + 1; // skip quote at start (")
}
@@ -6,7 +6,6 @@ import java.awt.event.MouseMotionAdapter;
import javax.swing.text.Highlighter;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenTypes;
import org.fife.ui.rtextarea.SmartHighlightPainter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,7 +43,7 @@ class MouseHoverHighlighter extends MouseMotionAdapter {
}
try {
Token token = codeArea.viewToToken(e.getPoint());
if (token == null || token.getType() != TokenTypes.IDENTIFIER) {
if (token == null) {
return false;
}
int tokenOffset = token.getOffset();