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

fix: MainTest#checkModelIsTree needs less memory #1596

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/test/java/spoon/test/main/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,25 @@ protected void exit(CtElement e) {
assertEquals("All parents have to be consistent", 0, inconsistentParents.size());
}



/*
* contract: each element is used only once
* For example this is always true: field.getType() != field.getDeclaringType()
*/
private void checkModelIsTree(CtPackage rootPackage) {
Exception dummyException = new Exception("STACK");
PrinterHelper problems = new PrinterHelper(rootPackage.getFactory().getEnvironment());
Map<CtElement, Exception> allElements = new IdentityHashMap<>();
rootPackage.filterChildren(null).forEach((CtElement ele) -> {
Exception secondStack = new Exception("STACK");
//uncomment this line to get stacktrace of real problem. The dummyException is used to avoid OutOfMemoryException
// Exception secondStack = new Exception("STACK");
Exception secondStack = dummyException;
Exception firstStack = allElements.put(ele, secondStack);
if (firstStack != null) {
if(firstStack == dummyException) {
Assert.fail("The Spoon model is not a tree. The " + ele.getClass().getSimpleName() + ":" + ele.toString() + " is shared");
}
//the element ele was already visited. It means it used on more places
//report the stacktrace of first and second usage, so that place can be found easily
problems.write("The element " + ele.getClass().getSimpleName()).writeln()
Expand Down