Search in sources :

Example 1 with StringRef

use of jadx.gui.utils.search.StringRef in project jadx by skylot.

the class IndexService method indexCls.

/**
 * Warning! Not ready for parallel execution. Use only in a single thread.
 */
public boolean indexCls(JavaClass cls) {
    try {
        TextSearchIndex index = cache.getTextIndex();
        if (index == null) {
            return false;
        }
        // get code from cache to avoid decompilation here
        String code = getCodeFromCache(cls);
        if (code == null) {
            return cls.isNoCode();
        }
        List<StringRef> lines = splitLines(code);
        CodeLinesInfo linesInfo = new CodeLinesInfo(cls);
        index.indexCode(cls, linesInfo, lines);
        index.indexNames(cls);
        indexSet.add(cls);
        return true;
    } catch (Exception e) {
        LOG.error("Index error in class: {}", cls.getFullName(), e);
        return false;
    }
}
Also used : TextSearchIndex(jadx.gui.utils.search.TextSearchIndex) StringRef(jadx.gui.utils.search.StringRef) CodeLinesInfo(jadx.gui.utils.CodeLinesInfo)

Example 2 with StringRef

use of jadx.gui.utils.search.StringRef 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)

Example 3 with StringRef

use of jadx.gui.utils.search.StringRef in project jadx by skylot.

the class CodeUsageInfo method addUsage.

private void addUsage(JNode jNode, JavaClass javaClass, CodeLinesInfo linesInfo, CodePosition codePosition, List<StringRef> lines) {
    UsageInfo usageInfo = usageMap.get(jNode);
    if (usageInfo == null) {
        usageInfo = new UsageInfo();
        usageMap.put(jNode, usageInfo);
    }
    int line = codePosition.getLine();
    JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(line);
    StringRef codeLine = lines.get(line - 1);
    JNode node = nodeCache.makeFrom(javaNodeByLine == null ? javaClass : javaNodeByLine);
    CodeNode codeNode = new CodeNode(node, line, codeLine);
    usageInfo.getUsageList().add(codeNode);
}
Also used : CodeNode(jadx.gui.treemodel.CodeNode) StringRef(jadx.gui.utils.search.StringRef) JNode(jadx.gui.treemodel.JNode) JavaNode(jadx.api.JavaNode)

Aggregations

StringRef (jadx.gui.utils.search.StringRef)3 JavaNode (jadx.api.JavaNode)2 CodeNode (jadx.gui.treemodel.CodeNode)2 JNode (jadx.gui.treemodel.JNode)2 CodeLinesInfo (jadx.gui.utils.CodeLinesInfo)2 CodePosition (jadx.api.CodePosition)1 JavaClass (jadx.api.JavaClass)1 TextSearchIndex (jadx.gui.utils.search.TextSearchIndex)1