Tests - fixed CallNodes to correctly allow duplicates

This commit is contained in:
dragonmacher
2019-12-03 13:08:24 -05:00
parent 551ecd1ada
commit 063358fc27
3 changed files with 16 additions and 31 deletions

View File

@@ -48,11 +48,13 @@ public abstract class CallNode extends GTreeSlowLoadingNode {
/**
* Returns a location that represents the caller of the callee.
* @return the location
*/
public abstract ProgramLocation getLocation();
/**
* Returns the address that for the caller of the callee.
* @return the address
*/
public abstract Address getSourceAddress();
@@ -83,34 +85,23 @@ public abstract class CallNode extends GTreeSlowLoadingNode {
}
/**
* Signals that this node should not override the equals method to treat all nodes with the
* same name as the same. When the user wants to see duplicates, each node should rely on
* Java's default notion of equality; otherwise, the JTree goes out to lunch.
* True allows this node to contains children with the same name
*
* @param allowDuplicates true to allow duplicate nodes
*/
protected void setAllowsDuplicates(boolean allowDuplicates) {
this.allowDuplicates = allowDuplicates;
}
@Override
public boolean equals(Object other) {
protected void addNode(List<GTreeNode> nodes, GTreeNode node) {
if (allowDuplicates) {
return super.equals(other);
nodes.add(node);
return;
}
if (other == this) {
return true;
if (!nodes.contains(node)) {
nodes.add(node);
}
if (other == null) {
return false;
}
if (!getClass().equals(other.getClass())) {
return false;
}
CallNode otherCallNode = (CallNode) other;
return getName().equals(otherCallNode.getName());
}
protected class CallNodeComparator implements Comparator<GTreeNode> {

View File

@@ -91,13 +91,13 @@ public class IncomingCallNode extends CallNode {
for (Address fromAddress : addresses) {
monitor.checkCanceled();
Function callerFunction = functionManager.getFunctionContaining(fromAddress);
if (callerFunction != null) {
IncomingCallNode node = new IncomingCallNode(program, callerFunction, fromAddress,
filterDuplicates, filterDepth);
if (!nodes.contains(node)) {
nodes.add(node);
}
if (callerFunction == null) {
continue;
}
IncomingCallNode node = new IncomingCallNode(program, callerFunction, fromAddress,
filterDuplicates, filterDepth);
addNode(nodes, node);
}
Collections.sort(nodes, new CallNodeComparator());

View File

@@ -148,12 +148,6 @@ public abstract class OutgoingCallNode extends CallNode {
return calledFunction.isExternal();
}
private void addNode(List<GTreeNode> nodes, GTreeNode node) {
if (!nodes.contains(node)) {
nodes.add(node);
}
}
private boolean isCallReference(Reference reference) {
RefType type = reference.getReferenceType();
if (type.isCall()) {