Search in sources :

Example 1 with ICodeRawOffset

use of jadx.api.data.annotations.ICodeRawOffset in project jadx by skylot.

the class CaretPositionFix method save.

/**
 * Save caret position by anchor to token under caret
 */
public void save() {
    try {
        linesCount = codeArea.getLineCount();
        int pos = codeArea.getCaretPosition();
        line = codeArea.getLineOfOffset(pos);
        lineOffset = pos - codeArea.getLineStartOffset(line);
        tokenInfo = getTokenInfoByOffset(codeArea.getTokenListForLine(line), pos);
        JClass cls = codeArea.getJClass();
        if (cls != null) {
            JavaClass topParentClass = cls.getJavaNode().getTopParentClass();
            Object ann = topParentClass.getAnnotationAt(new CodePosition(line));
            if (ann instanceof ICodeRawOffset) {
                codeRawOffset = ((ICodeRawOffset) ann).getOffset();
                CodeLinesInfo codeLinesInfo = new CodeLinesInfo(topParentClass);
                JavaNode javaNodeAtLine = codeLinesInfo.getJavaNodeByLine(line);
                if (javaNodeAtLine != null) {
                    javaNodeLine = javaNodeAtLine.getDecompiledLine();
                }
            }
        }
        LOG.debug("Saved position data: line={}, lineOffset={}, token={}, codeRawOffset={}, javaNodeLine={}", line, lineOffset, tokenInfo, codeRawOffset, javaNodeLine);
    } catch (Exception e) {
        LOG.error("Failed to save caret position before refresh", e);
        line = -1;
    }
}
Also used : CodePosition(jadx.api.CodePosition) JavaClass(jadx.api.JavaClass) JClass(jadx.gui.treemodel.JClass) ICodeRawOffset(jadx.api.data.annotations.ICodeRawOffset) JavaNode(jadx.api.JavaNode)

Aggregations

CodePosition (jadx.api.CodePosition)1 JavaClass (jadx.api.JavaClass)1 JavaNode (jadx.api.JavaNode)1 ICodeRawOffset (jadx.api.data.annotations.ICodeRawOffset)1 JClass (jadx.gui.treemodel.JClass)1