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

Ensure root is set in both worlds. #174

Merged
merged 11 commits into from
Apr 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import com.sun.source.tree.BinaryTree;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.LambdaExpressionTree;
Expand Down Expand Up @@ -374,6 +375,27 @@ private NullSpecAnnotatedTypeFactory(
}
}

/** To ensure setRoot is called on both worlds exactly once. */
private boolean settingRoot = false;

/**
* Ensure setRoot is called on both worlds exactly once whenever it is called on one of the
* worlds.
*/
@Override
public void setRoot(@Nullable CompilationUnitTree root) {
if (!settingRoot) {
settingRoot = true;
super.setRoot(root);
if (withLeastConvenientWorld != this) {
withLeastConvenientWorld.setRoot(root);
} else {
withMostConvenientWorld.setRoot(root);
}
settingRoot = false;
}
}

@Override
protected void addCheckedCodeDefaults(QualifierDefaults defs) {
// TODO: add false for subpackages once overload is added to CF. Shouldn't really matter.
Expand Down
Loading