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

Add buildX methods to ITermFactory that preserve the origin of the replaced term #20

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Virtlink
Copy link
Contributor

@Virtlink Virtlink commented Jun 18, 2020

This PR:

  • adds buildX method to ITermFactory that preserve the origin of the replaced term
  • deprecates many of the old ITermFactory methods that do not preserve origins, or have surprising and inconsistent semantics

@Virtlink Virtlink mentioned this pull request Jun 18, 2020
7 tasks
Copy link
Contributor

@Apanatshka Apanatshka left a 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?

org.spoofax.terms/src/org/spoofax/terms/TermFactory.java Outdated Show resolved Hide resolved
Comment on lines 296 to 311
/**
* 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);
}
Copy link
Contributor

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

@Virtlink
Copy link
Contributor Author

Why did the annotations list of terms become nullable everywhere?

They where already nullable, but it was not annotated. See here, for example, where this.annotations is only assigned when the argument is non-null and non-empty, implying that this.annotations is null otherwise. Now it's explicit.

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.
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