Remove empty public constructors
This commit is contained in:
@@ -98,8 +98,6 @@ public class Main {
|
||||
if (args.isRawCFGOutput())
|
||||
passes.add(new DotGraphVisitor(args.getOutDir(), false, true));
|
||||
|
||||
passes.add(new ClassModifier());
|
||||
|
||||
passes.add(new ModVisitor());
|
||||
passes.add(new EnumVisitor());
|
||||
|
||||
@@ -115,6 +113,7 @@ public class Main {
|
||||
if (args.isCFGOutput())
|
||||
passes.add(new DotGraphVisitor(args.getOutDir(), true));
|
||||
|
||||
passes.add(new ClassModifier());
|
||||
passes.add(new CleanRegions());
|
||||
}
|
||||
passes.add(new CodeGen(args));
|
||||
|
||||
@@ -37,6 +37,18 @@ public class AccessInfo {
|
||||
return new AccessInfo(f, type);
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return (accFlags & AccessFlags.ACC_PUBLIC) != 0;
|
||||
}
|
||||
|
||||
public boolean isProtected() {
|
||||
return (accFlags & AccessFlags.ACC_PROTECTED) != 0;
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
return (accFlags & AccessFlags.ACC_PRIVATE) != 0;
|
||||
}
|
||||
|
||||
public boolean isAbstract() {
|
||||
return (accFlags & AccessFlags.ACC_ABSTRACT) != 0;
|
||||
}
|
||||
@@ -87,13 +99,13 @@ public class AccessInfo {
|
||||
|
||||
public String makeString() {
|
||||
StringBuilder code = new StringBuilder();
|
||||
if ((accFlags & AccessFlags.ACC_PUBLIC) != 0)
|
||||
if (isPublic())
|
||||
code.append("public ");
|
||||
|
||||
if ((accFlags & AccessFlags.ACC_PRIVATE) != 0)
|
||||
if (isPrivate())
|
||||
code.append("private ");
|
||||
|
||||
if ((accFlags & AccessFlags.ACC_PROTECTED) != 0)
|
||||
if (isProtected())
|
||||
code.append("protected ");
|
||||
|
||||
if (isStatic())
|
||||
|
||||
@@ -5,12 +5,12 @@ import jadx.dex.instructions.args.ArgType;
|
||||
import jadx.dex.nodes.DexNode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public final class ClassInfo {
|
||||
|
||||
private static final Map<ArgType, ClassInfo> CLASSINFO_CACHE = new HashMap<ArgType, ClassInfo>();
|
||||
private static final Map<ArgType, ClassInfo> CLASSINFO_CACHE = new WeakHashMap<ArgType, ClassInfo>();
|
||||
private static final String DEFAULT_PACKAGE_NAME = "defpackage";
|
||||
|
||||
private final String clsName;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package jadx.dex.visitors;
|
||||
|
||||
import jadx.dex.info.AccessInfo;
|
||||
import jadx.dex.nodes.BlockNode;
|
||||
import jadx.dex.nodes.ClassNode;
|
||||
import jadx.dex.nodes.MethodNode;
|
||||
import jadx.utils.exceptions.JadxException;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassModifier extends AbstractVisitor {
|
||||
|
||||
@@ -21,10 +23,32 @@ public class ClassModifier extends AbstractVisitor {
|
||||
|
||||
// remove bridge methods
|
||||
if (af.isBridge() && af.isSynthetic()) {
|
||||
// TODO make some checks before deleting
|
||||
it.remove();
|
||||
if (!isMethodIdUniq(cls, mth)) {
|
||||
// TODO add more checks before method deletion
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// remove public empty constructors
|
||||
if (af.isConstructor()
|
||||
&& af.isPublic()
|
||||
&& mth.getArguments(false).isEmpty()) {
|
||||
List<BlockNode> bb = mth.getBasicBlocks();
|
||||
if (bb.isEmpty() || (bb.size() == 1 && bb.get(0).getInstructions().isEmpty())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isMethodIdUniq(ClassNode cls, MethodNode mth) {
|
||||
String shortId = mth.getMethodInfo().getShortId();
|
||||
for (MethodNode otherMth : cls.getMethods()) {
|
||||
if (otherMth.getMethodInfo().getShortId().equals(shortId)
|
||||
&& otherMth != mth)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user