Skip to content

Commit

Permalink
fix: don't mark constructor for inline if anonymous class inline is d…
Browse files Browse the repository at this point in the history
…isabled (#1680)
  • Loading branch information
skylot committed Sep 25, 2022
1 parent b4892ce commit 2f301bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
4 changes: 3 additions & 1 deletion jadx-core/src/main/java/jadx/core/dex/nodes/ClassNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,9 @@ public void setCodegenDeps(List<ClassNode> codegenDeps) {
}

public void addCodegenDep(ClassNode dep) {
this.codegenDeps = ListUtils.safeAdd(this.codegenDeps, dep);
if (!codegenDeps.contains(dep)) {
this.codegenDeps = ListUtils.safeAdd(this.codegenDeps, dep);
}
}

public int getTotalDepsCount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package jadx.core.dex.visitors;

import jadx.core.Consts;
import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.nodes.RootNode;
import jadx.core.dex.visitors.usage.UsageInfoVisitor;
import jadx.core.utils.ListUtils;
import jadx.core.utils.exceptions.JadxException;

@JadxVisitor(
Expand Down Expand Up @@ -45,7 +45,14 @@ private static boolean canInline(MethodNode mth) {
}
AccessInfo accessFlags = mth.getAccessFlags();
boolean isSynthetic = accessFlags.isSynthetic() || mth.getName().contains("$");
return isSynthetic && (accessFlags.isStatic() || mth.isConstructor());
return isSynthetic && canInlineMethod(mth, accessFlags);
}

private static boolean canInlineMethod(MethodNode mth, AccessInfo accessFlags) {
if (accessFlags.isStatic()) {
return true;
}
return mth.isConstructor() && mth.root().getArgs().isInlineAnonymousClasses();
}

private static void fixClassDependencies(MethodNode mth) {
Expand All @@ -54,8 +61,14 @@ private static void fixClassDependencies(MethodNode mth) {
// remove possible cross dependency
// to force class with inline method to be processed before its usage
ClassNode useTopCls = useInMth.getTopParentClass();
parentClass.setDependencies(ListUtils.safeRemoveAndTrim(parentClass.getDependencies(), useTopCls));
useTopCls.addCodegenDep(parentClass);
if (useTopCls != parentClass) {
parentClass.removeDependency(useTopCls);
useTopCls.addCodegenDep(parentClass);
if (Consts.DEBUG_USAGE) {
parentClass.addDebugComment("Remove dependency: " + useTopCls + " to inline " + mth);
useTopCls.addDebugComment("Add dependency: " + parentClass + " to inline " + mth);
}
}
}
}
}

0 comments on commit 2f301bf

Please sign in to comment.