Search in sources :

Example 16 with JavaClass

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

the class DbgUtils method getTopClassBySig.

public static JClass getTopClassBySig(String clsSig, MainWindow mainWindow) {
    clsSig = DbgUtils.classSigToFullName(clsSig);
    JavaClass cls = mainWindow.getWrapper().getDecompiler().searchJavaClassOrItsParentByOrigFullName(clsSig);
    if (cls != null) {
        JClass jc = mainWindow.getCacheObject().getNodeCache().makeFrom(cls);
        return jc.getRootClass();
    }
    return null;
}
Also used : JavaClass(jadx.api.JavaClass) JClass(jadx.gui.treemodel.JClass)

Example 17 with JavaClass

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

the class JadxTokenMaker method mergeLongClassNames.

@NotNull
private Token mergeLongClassNames(Token prev, Token current, boolean annotation) {
    int offset = current.getTextOffset();
    if (annotation) {
        offset++;
    }
    JavaNode javaNode = codeArea.getJavaNodeAtOffset(offset);
    if (javaNode instanceof JavaClass) {
        String name = javaNode.getName();
        String lexeme = current.getLexeme();
        if (annotation && lexeme.length() > 1) {
            lexeme = lexeme.substring(1);
        }
        if (!lexeme.equals(name) && isClassNameStart(javaNode, lexeme)) {
            // try to replace long class name with one token
            Token replace = concatTokensUntil(current, name);
            if (replace != null && prev instanceof TokenImpl) {
                TokenImpl impl = ((TokenImpl) prev);
                impl.setNextToken(replace);
                current = replace;
            }
        }
    }
    return current;
}
Also used : JavaClass(jadx.api.JavaClass) TokenImpl(org.fife.ui.rsyntaxtextarea.TokenImpl) Token(org.fife.ui.rsyntaxtextarea.Token) JavaNode(jadx.api.JavaNode) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with JavaClass

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

the class RenameDialog method processPackage.

private void processPackage(List<JavaNode> toUpdate) {
    String rawFullPkg = ((JPackage) node).getFullName();
    String rawFullPkgDot = rawFullPkg + ".";
    for (JavaClass cls : mainWindow.getWrapper().getClasses()) {
        String clsPkg = cls.getClassNode().getClassInfo().getPackage();
        // search all classes in package
        if (clsPkg.equals(rawFullPkg) || clsPkg.startsWith(rawFullPkgDot)) {
            toUpdate.add(cls);
            // also include all usages (for import fix)
            toUpdate.addAll(cls.getUseIn());
        }
    }
}
Also used : JavaClass(jadx.api.JavaClass) JPackage(jadx.gui.treemodel.JPackage)

Example 19 with JavaClass

use of jadx.api.JavaClass 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)

Example 20 with JavaClass

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

the class CodeLinesInfo method addClass.

private void addClass(JavaClass cls, boolean includeFields) {
    map.put(cls.getDecompiledLine(), cls);
    for (JavaClass innerCls : cls.getInnerClasses()) {
        map.put(innerCls.getDecompiledLine(), innerCls);
        addClass(innerCls, includeFields);
    }
    for (JavaMethod mth : cls.getMethods()) {
        map.put(mth.getDecompiledLine(), mth);
    }
    if (includeFields) {
        for (JavaField field : cls.getFields()) {
            map.put(field.getDecompiledLine(), field);
        }
    }
}
Also used : JavaField(jadx.api.JavaField) JavaClass(jadx.api.JavaClass) JavaMethod(jadx.api.JavaMethod)

Aggregations

JavaClass (jadx.api.JavaClass)20 JavaMethod (jadx.api.JavaMethod)7 JavaField (jadx.api.JavaField)5 JavaNode (jadx.api.JavaNode)3 JNode (jadx.gui.treemodel.JNode)3 CodePosition (jadx.api.CodePosition)2 JClass (jadx.gui.treemodel.JClass)2 CodeLinesInfo (jadx.gui.utils.CodeLinesInfo)2 JNodeCache (jadx.gui.utils.JNodeCache)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 JavaVariable (jadx.api.JavaVariable)1 IJavaNodeRef (jadx.api.data.IJavaNodeRef)1 ICodeRawOffset (jadx.api.data.annotations.ICodeRawOffset)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 JadxWrapper (jadx.gui.JadxWrapper)1 CodeNode (jadx.gui.treemodel.CodeNode)1 JField (jadx.gui.treemodel.JField)1 JMethod (jadx.gui.treemodel.JMethod)1