-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add buildX methods to ITermFactory that preserve the origin of the replaced term #20
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did the annotations list of terms become nullable everywhere?
/** | ||
* Copied the origin of the replaced term to the new term, unless | ||
* the new term already has an origin of its own. | ||
* | ||
* This implementation mutates the new term in-place. | ||
* | ||
* @param newTerm the new term | ||
* @param replacee the term being replaced | ||
*/ | ||
private void preserveOrigins(IStrategoTerm newTerm, IStrategoTerm replacee) { | ||
@Nullable IStrategoTerm curOrigin = OriginAttachment.getOrigin(newTerm); | ||
if (curOrigin != null) { | ||
// The term already has an origin of its own. | ||
return; | ||
} | ||
@Nullable IStrategoTerm newOrigin = OriginAttachment.getOrigin(replacee); | ||
if (newOrigin == null) { | ||
// The replacee doesn't have an origin, | ||
// so we bail out here to avoid creating a null origin attachment. | ||
return; | ||
} | ||
// This mutates the term in-place. | ||
OriginAttachment.setOrigin(newTerm, newOrigin); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the current type hierarchy of term factories, this isn't supposed to be here. Instead the normal TermFactory
doesn't know about attachments, and the OriginTermFactory
does
They where already nullable, but it was not annotated. See here, for example, where |
6967d91
to
51e9e9b
Compare
In StrategoTerm's constructor, this.annotations is only assigned when the argument is non-null and non-empty, implying it stays its default value of null when the argument is null or empty. The @nullable annotations explicate this fact.
This PR:
buildX
method toITermFactory
that preserve the origin of the replaced termITermFactory
methods that do not preserve origins, or have surprising and inconsistent semantics