Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: push down the equality checking code in EqualsVisitor #1853

Merged
merged 6 commits into from
Feb 18, 2018

Conversation

monperrus
Copy link
Collaborator

the design here was quite broken. this PR fixes it.

CtAbstractVisitor <- CtBiScannerDefault (generated from CtBiScannerTemplate) <- EqualVisitor

@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
return isNotEqual;
}
/** This method is called to compare `element` and `other` when traversing two trees in parallel.*/
public abstract boolean biScan(CtElement element, CtElement other);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CtAbstractBiScanner sounds now like general purpose bi-scanner. Do I understood it well? If yes, then please change comments here (it is no more about "compare") and change return value from boolean to void
WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CtAbstractBiScanner sounds now like general purpose bi-scanner. Do I understood it well?

yes, correct.

I agree with you, done.

return isNotEqual;
}

stack.push(other);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move stack.push(other); and stack,pop() somewhere into CtBiScannerDefault? I looks like implementation of CtBiScannerDefault in this PR is useless without calls of stack.push(other); and stack,pop(). Because CtBiScannerDefault calls stack.peek(), but nobody pushes data there.
WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done.

@pvojtechovsky
Copy link
Collaborator

It would be probably more readable if all biScan methods would return void instead of boolean which is on most places ignored. The only place where return value is actually used is

public class EqualsVisitor extends CtBiScannerDefault {
	public static boolean equals(CtElement element, CtElement other) {
		return !new EqualsVisitor().biScan(element, other);
	}

which might be replaced by

	public static boolean equals(CtElement element, CtElement other) {
		return new EqualsVisitor().isEqual(element, other);
	}
...
boolean isEqual(CtElement element, CtElement other) {
  biScan(element, other);
  return !isNotEqual;
}

}

protected boolean biScan(CtRole role, Collection<? extends CtElement> elements, Collection<? extends CtElement> others) {
for (Iterator<? extends CtElement> firstIt = elements.iterator(), secondIt = others.iterator(); (firstIt.hasNext()) && (secondIt.hasNext());) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this code does not work for Set since beginning, because you cannot assure that elements in 2 Sets are iterated in consistent pairs. I wonder why it works ... WDYT?

@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@monperrus
Copy link
Collaborator Author

for the beauty of it, added a test to do a parallel biscan visit of the same tree.

@pvojtechovsky
Copy link
Collaborator

How does biscan work on Set of children elements? For example CtType#superInterfaces? How is there assured that items from both Sets are paired correctly?

@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@INRIA INRIA deleted a comment from spoon-bot Feb 17, 2018
@monperrus
Copy link
Collaborator Author

This is a question we discussed when we introduced it.

A strong assumption -- even a a requirement -- is we only use implementations of Set which have a deterministic iterator order.

@pvojtechovsky pvojtechovsky merged commit 0eefdc5 into INRIA:master Feb 18, 2018
@pvojtechovsky
Copy link
Collaborator

we only use implementations of Set which have a deterministic iterator order
Interesting! Good to know! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants