Search in sources :

Example 1 with CodePosition

use of jadx.api.CodePosition in project jadx by skylot.

the class CodeUsageInfo method processClass.

public void processClass(JavaClass javaClass, CodeLinesInfo linesInfo, List<StringRef> lines) {
    Map<CodePosition, JavaNode> usage = javaClass.getUsageMap();
    for (Map.Entry<CodePosition, JavaNode> entry : usage.entrySet()) {
        CodePosition codePosition = entry.getKey();
        JavaNode javaNode = entry.getValue();
        addUsage(nodeCache.makeFrom(javaNode), javaClass, linesInfo, codePosition, lines);
    }
}
Also used : CodePosition(jadx.api.CodePosition) Map(java.util.Map) HashMap(java.util.HashMap) JavaNode(jadx.api.JavaNode)

Example 2 with CodePosition

use of jadx.api.CodePosition in project jadx by skylot.

the class CodeArea method getDefPosition.

static Position getDefPosition(JClass jCls, RSyntaxTextArea textArea, int offset) {
    JavaNode node = getJavaNodeAtOffset(jCls, textArea, offset);
    if (node == null) {
        return null;
    }
    CodePosition pos = jCls.getCls().getDefinitionPosition(node);
    if (pos == null) {
        return null;
    }
    return new Position(pos);
}
Also used : CodePosition(jadx.api.CodePosition) CodePosition(jadx.api.CodePosition) Position(jadx.gui.utils.Position) JavaNode(jadx.api.JavaNode)

Example 3 with CodePosition

use of jadx.api.CodePosition in project jadx by skylot.

the class CodeWriter method finish.

public void finish() {
    removeFirstEmptyLine();
    buf.trimToSize();
    code = buf.toString();
    buf = null;
    Iterator<Map.Entry<CodePosition, Object>> it = annotations.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<CodePosition, Object> entry = it.next();
        Object v = entry.getValue();
        if (v instanceof DefinitionWrapper) {
            LineAttrNode l = ((DefinitionWrapper) v).getNode();
            l.setDecompiledLine(entry.getKey().getLine());
            it.remove();
        }
    }
}
Also used : CodePosition(jadx.api.CodePosition) LineAttrNode(jadx.core.dex.attributes.nodes.LineAttrNode) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 4 with CodePosition

use of jadx.api.CodePosition in project jadx by skylot.

the class AnnotatedCodeWriter method attachDefinition.

@Override
public void attachDefinition(ILineAttributeNode obj) {
    if (obj == null) {
        return;
    }
    attachAnnotation(obj);
    attachAnnotation(new DefinitionWrapper(obj), new CodePosition(line, offset, getLength()));
}
Also used : CodePosition(jadx.api.CodePosition)

Example 5 with CodePosition

use of jadx.api.CodePosition in project jadx by skylot.

the class UsageDialog method processUsageClass.

private void processUsageClass(JavaNode usageNode) {
    JavaClass cls = usageNode.getTopParentClass();
    String code = cls.getCodeInfo().getCodeStr();
    CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
    List<? extends JavaNode> targetNodes = getMethodWithOverride();
    for (JavaNode javaNode : targetNodes) {
        List<CodePosition> usage = cls.getUsageFor(javaNode);
        for (CodePosition pos : usage) {
            if (javaNode.getTopParentClass().equals(cls) && pos.getPos() == javaNode.getDefPos()) {
                // skip declaration
                continue;
            }
            StringRef line = getLineStrAt(code, pos.getPos());
            if (line.startsWith("import ")) {
                continue;
            }
            JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(pos.getLine());
            JNode useAtNode = javaNodeByLine == null ? node : getNodeCache().makeFrom(javaNodeByLine);
            usageList.add(new CodeNode(useAtNode, line, pos.getLine(), pos.getPos()));
        }
    }
}
Also used : CodePosition(jadx.api.CodePosition) JavaClass(jadx.api.JavaClass) CodeNode(jadx.gui.treemodel.CodeNode) CodeLinesInfo(jadx.gui.utils.CodeLinesInfo) StringRef(jadx.gui.utils.search.StringRef) JNode(jadx.gui.treemodel.JNode) JavaNode(jadx.api.JavaNode)

Aggregations

CodePosition (jadx.api.CodePosition)15 JavaNode (jadx.api.JavaNode)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InsnCodeOffset (jadx.api.data.annotations.InsnCodeOffset)3 TreeMap (java.util.TreeMap)3 JavaClass (jadx.api.JavaClass)2 JNode (jadx.gui.treemodel.JNode)2 CodeLinesInfo (jadx.gui.utils.CodeLinesInfo)2 Nullable (org.jetbrains.annotations.Nullable)2 ICodeInfo (jadx.api.ICodeInfo)1 ICodeWriter (jadx.api.ICodeWriter)1 JavaMethod (jadx.api.JavaMethod)1 ICodeRawOffset (jadx.api.data.annotations.ICodeRawOffset)1 JadxCodeComment (jadx.api.data.impl.JadxCodeComment)1 JadxNodeRef (jadx.api.data.impl.JadxNodeRef)1 JsonCodeLine (jadx.core.codegen.json.cls.JsonCodeLine)1 ILineAttributeNode (jadx.core.dex.attributes.ILineAttributeNode)1 LineAttrNode (jadx.core.dex.attributes.nodes.LineAttrNode)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1