use of jadx.api.CodePosition in project jadx by skylot.
the class AnnotatedCodeWriter method add.
@Override
public ICodeWriter add(ICodeWriter cw) {
if ((!(cw instanceof AnnotatedCodeWriter))) {
buf.append(cw.getCodeStr());
return this;
}
AnnotatedCodeWriter code = ((AnnotatedCodeWriter) cw);
line--;
int startLine = line;
int startPos = getLength();
for (Map.Entry<CodePosition, Object> entry : code.annotations.entrySet()) {
CodePosition codePos = entry.getKey();
int newLine = startLine + codePos.getLine();
int newPos = startPos + codePos.getPos();
attachAnnotation(entry.getValue(), new CodePosition(newLine, codePos.getOffset(), newPos));
}
for (Map.Entry<Integer, Integer> entry : code.lineMap.entrySet()) {
attachSourceLine(line + entry.getKey(), entry.getValue());
}
line += code.line;
offset = code.offset;
buf.append(code.buf);
return this;
}
use of jadx.api.CodePosition in project jadx by skylot.
the class IntegrationTest method printCodeWithOffsets.
private void printCodeWithOffsets(ICodeInfo code) {
String codeStr = code.getCodeStr();
Map<CodePosition, Object> annotations = code.getAnnotations();
String[] lines = codeStr.split(ICodeWriter.NL);
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
int curLine = i + 1;
Object ann = annotations.get(new CodePosition(curLine, 0));
String offsetStr = "";
if (ann instanceof InsnCodeOffset) {
int offset = ((InsnCodeOffset) ann).getOffset();
offsetStr = "/* " + leftPad(String.valueOf(offset), 5) + " */";
}
System.out.println(rightPad(offsetStr, 12) + line);
}
}
use of jadx.api.CodePosition 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;
}
}
use of jadx.api.CodePosition in project jadx by skylot.
the class CodeArea method buildCodePosFromOffset.
private CodePosition buildCodePosFromOffset(int offset) throws BadLocationException {
int start = getWordStart(offset);
if (start == -1) {
start = offset;
}
int line = getLineOfOffset(start);
int lineOffset = start - getLineStartOffset(line);
return new CodePosition(line + 1, lineOffset + 1, start);
}
use of jadx.api.CodePosition in project jadx by skylot.
the class CodeArea method getDefPosForNodeAtOffset.
/**
* Search node by offset in {@code jCls} code and return its definition position
* (useful for jumps from usage)
*/
@Nullable
public JumpPosition getDefPosForNodeAtOffset(int offset) {
if (offset == -1) {
return null;
}
JavaNode foundNode = getJavaNodeAtOffset(offset);
if (foundNode == null) {
return null;
}
CodePosition pos = getDecompiler().getDefinitionPosition(foundNode);
if (pos == null) {
return null;
}
JNode jNode = convertJavaNode(foundNode);
return new JumpPosition(jNode.getRootClass(), pos);
}
Aggregations