Remove unused methods

This commit is contained in:
Adam
2015-04-25 15:30:22 -04:00
parent a9f953b46a
commit 267efc7940
5 changed files with 77 additions and 4 deletions

View File

@@ -70,6 +70,28 @@ public class Method
{
return (Code) attributes.findType(AttributeType.CODE);
}
public List<Method> getOverriddenMethods()
{
List<Method> m = new ArrayList<Method>();
ClassFile parent = methods.getClassFile().getParent();
if (parent != null)
{
Method other = parent.getMethods().findMethod(getName(), getDescriptor());
if (other != null)
m.add(other);
}
for (ClassFile inter : methods.getClassFile().getInterfaces().getInterfaces())
{
Method other = inter.getMethods().findMethod(getName(), getDescriptor());
if (other != null)
m.add(other);
}
return m;
}
public void buildInstructionGraph()
{
@@ -87,6 +109,20 @@ public class Method
code.buildCallGraph();
}
public boolean isUsed()
{
if (!callsFrom.isEmpty())
return true;
for (Method sm : getOverriddenMethods())
{
if (sm.isUsed())
return true;
}
return false;
}
public void addCallTo(Instruction ins, Method method)
{
Node node = new Node(this, method, ins);