Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
edelta.parent/edelta/src/edelta/scoping/EdeltaScopeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* generated by Xtext 2.21.0 | ||
*/ | ||
package edelta.scoping; | ||
|
||
import static edelta.edelta.EdeltaPackage.Literals.*; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EReference; | ||
import org.eclipse.xtext.scoping.IScope; | ||
import org.eclipse.xtext.scoping.Scopes; | ||
import org.eclipse.xtext.scoping.impl.FilteringScope; | ||
import org.eclipse.xtext.util.IResourceScopeCache; | ||
|
||
import com.google.inject.Inject; | ||
|
||
import edelta.edelta.EdeltaEcoreQualifiedReference; | ||
import edelta.util.EdeltaEcoreHelper; | ||
import edelta.util.EdeltaModelUtil; | ||
|
||
/** | ||
* This class contains custom scoping description. | ||
* | ||
* See | ||
* https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping | ||
* on how and when to use it. | ||
*/ | ||
public class EdeltaScopeProvider extends AbstractEdeltaScopeProvider { | ||
@Inject | ||
private IResourceScopeCache cache; | ||
|
||
@Inject | ||
private EdeltaModelUtil edeltaModelUtil; | ||
|
||
@Inject | ||
private EdeltaEcoreHelper edeltaEcoreHelper; | ||
|
||
@Override | ||
public IScope getScope(final EObject context, final EReference reference) { | ||
if (reference == EDELTA_ECORE_REFERENCE__ENAMEDELEMENT) { | ||
if (context instanceof EdeltaEcoreQualifiedReference) { | ||
return Scopes.scopeFor(edeltaEcoreHelper.getENamedElements( | ||
((EdeltaEcoreQualifiedReference) context).getQualification().getEnamedelement(), | ||
context)); | ||
} | ||
return Scopes.scopeFor(edeltaEcoreHelper.getProgramENamedElements(context)); | ||
} else if (reference == EDELTA_MODIFY_ECORE_OPERATION__EPACKAGE) { | ||
return Scopes.scopeFor(edeltaModelUtil.getProgram(context).getMetamodels()); | ||
} else if (reference == EDELTA_PROGRAM__METAMODELS) { | ||
return cache.get("scopeMetamodels", context.eResource(), | ||
() -> new FilteringScope(delegateGetScope(context, reference), | ||
it -> "false".equals(it.getUserData("nsURI")))); | ||
} | ||
return super.getScope(context, reference); | ||
} | ||
} |