ST6RI-894 (alt) Inconsistent name resolution for qualified name as target of redefinition #717
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug that could case inconsistent name resolution for a qualified name used as the target of a nested redefinition. It also revises the name resolution cases affected by the bug fix, so that the resolution that resulted from the bug actually becomes the expected resolution.
(This PR is an alternative to PR #714. The "Background" and "Cause" sections below are the same as in the other PR.)
Background
Consider the following SysML model:
When a file with this model is initially opened in the Eclipse Xtext editor, and the attribute usage nested in
B::x(commented) is viewed in the outline, the targetx::yof the redefinition is shown as resolving to the attribute usage itself (that isB::x::y). Previously, however, if a space was typed so that the model was re-parsed and validated, the outline then showed that the target of the redefinition had resolved instead to the attribute usageA::x::y. On the other hand, if the model is entered in Jupyter, the attribute usage in question generates the error “Featuring types of redefining feature and redefined feature cannot be the same”, indicating thatx::yhas resolved toB::x::y, making the redefinition invalid.Cause
x::yhas to be resolved as the target of a redefinition.x::ytoA::x::y, which determines that the effective name of the redefining attribute isy.B(the parent ofB::x),x::ythen resolves toB::x::y, and the resolution is updated to this element (i.e., the redefining attribute usage itself).Redefinitionrelationship, it checks the generalRelationship::targetvalue before theRedefinition::redefinedFeaturevalue.sourceandtargetfor any kind ofSpecializationare lists containing the single values of thespecificandgeneralproperties of theSpecialization, respectively. ThegetSourceandgetTargetmethods inSpecializationImplimplement this by creating a list and then inserting thespecificorgeneralvalues into the list.getSpecificandgetGeneralmethods are used, which will resolve proxies if necessary, so the returned lists never contain (resolvable) proxies. However, Previously, these calls had been replaced by calls tobasicGetSpecificandbasicGetGeneral, which do not do proxy resolution.targetof theRedefinitionwas found to be a proxy, Xtext resolved the proxy and then updated thetargetlist with the resolved element. However, since the list was created in thegetTargetmethod, this did not result in theredefinedFeatureproperty value actually being updated for theRedefinition, so the value was left as the earlier resolution toA::x::y.Changes
SpecializationImpl.java– Replaced the non-generated versions ofgetSourceandgetTargetwith the generated versions. (A comment in the code indicated that the changes had been made to these methods to prevent circular name resolution. However, testing indicated that the generated version without the changes no longer caused circular resolution errors.)x::ywould always resolve toB::x::y. However, this resolution is not particularly useful, since it always results in an error, requiring additional qualification to resolve toA::x::y. It would be more intuitive for the name resolution ofx::yin the example be consistently toA::x::yrather thanB::x::y. The changes below achieve this.KerMLScope.xtend– Updated theownedmethod so that an owned membership of a namespace is skipped if the owned member element is the owning feature of a redefinition relationship that is being skipped.attribute :>> x::y;is skipped when considering the resolution ofx::y. So,yis not considered to be redefined during this resolution process, and the segmentyof the qualified name resolves to the featureyinherited fromA::x. As a result,x::yresolves toA::x::y, as desired.KerMLScopeProvider.xtend– Updated so that the first feature name in a feature chain that is a target of a redefinition is resolved in the same way as regular feature name that is the target of a redefinition.TypeUtil.java– Updated methodgetFeaturesRedefinedByso that it is passed an owned feature to skip when collecting redefined features from the owned features of a given type.FeatureUtil.java,FeatureAdapter.java– Updated the methodsFeatureUtil::getRedefinedFeaturesWithComputedOfandFeaturAdapter::getRedefinedFeaturesWithComputedso that they are no longer passed askipargument.ConstructorExpressionAdapter.java– Revised the adding of the implied result type to the result parameter of a constructor expression so that it is added immediately when the result parameter is added.Redefinition_Scoping.kerml.xt– Added a KerML Xpect test using a KerML version of the above example model, to check that the nested redefinition is parsed and validates without error.