use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.
the class STextScopeProvider method scope_FeatureCall_feature.
public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
Expression owner = context.getOwner();
EObject element = null;
if (owner instanceof ElementReferenceExpression) {
element = ((ElementReferenceExpression) owner).getReference();
} else if (owner instanceof FeatureCall) {
element = ((FeatureCall) owner).getFeature();
} else {
return getDelegate().getScope(context, reference);
}
IScope scope = IScope.NULLSCOPE;
InferenceResult result = typeInferrer.infer(owner);
Type ownerType = result != null ? result.getType() : null;
if (element instanceof Scope) {
scope = Scopes.scopeFor(((Scope) element).getDeclarations());
return new FilteringScope(scope, predicate);
} else if (ownerType != null) {
scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
}
if (ownerType instanceof ComplexType) {
return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
}
if (ownerType instanceof EnumerationType) {
return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
}
return scope;
}
use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.
the class StextImportAwareScopeProvider method getLocalElementsScope.
protected IScope getLocalElementsScope(IScope parent, final EObject context, final EReference reference) {
IScope result = parent;
ISelectable allDescriptions = getAllDescriptions(context.eResource());
QualifiedName name = getQualifiedNameOfLocalElement(context);
boolean ignoreCase = isIgnoreCase(reference);
final List<ImportNormalizer> namespaceResolvers = getImportedNamespaceResolvers(context, ignoreCase);
if (!namespaceResolvers.isEmpty()) {
if (isRelativeImport() && name != null && !name.isEmpty()) {
ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
}
result = createImportScope(result, namespaceResolvers, null, reference.getEReferenceType(), isIgnoreCase(reference));
}
if (name != null) {
ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
}
return result;
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractScopingTest method assertScopedObjects.
/**
* Checks if the scope of the given reference for the given context contains only the expected objects.
* In addition, checks that the reference of the given context references at least one of the expected
* objects. If the reference has multiplicity > 1, then every reference must reference at least
* one of the expected objects.
*
* @param context
* {@link EObject} from which the given objects shall be referenced, must not be {@code null}
* @param reference
* the structural feature of {@code context} for which the scope should be asserted, must not be {@code null} and part of the context element
* @param expectedObjects
* the objects expected in the scope, must not be {@code null}
*/
protected void assertScopedObjects(final EObject context, final EReference reference, final Collection<? extends EObject> expectedObjects) {
Assert.isNotNull(context, PARAMETER_CONTEXT);
Assert.isNotNull(reference, PARAMETER_REFERENCE);
Assert.isNotNull(expectedObjects, PARAMETER_EXPECTED_OBJECTS);
Assert.isTrue(context.eClass().getEAllReferences().contains(reference), String.format("Contract for argument '%s' failed: Parameter is not within specified range (Expected: %s, Actual: %s).", PARAMETER_CONTEXT, "The context object must contain the given reference.", "Reference not contained by the context object!"));
Set<URI> expectedUriSet = Sets.newHashSet();
for (EObject object : expectedObjects) {
expectedUriSet.add(EcoreUtil.getURI(object));
}
IScope scope = getScopeProvider().getScope(context, reference);
Iterable<IEObjectDescription> allScopedElements = scope.getAllElements();
Set<URI> scopedUriSet = Sets.newHashSet();
for (IEObjectDescription description : allScopedElements) {
URI uri = description.getEObjectURI();
scopedUriSet.add(uri);
}
if (!expectedUriSet.equals(scopedUriSet)) {
fail("The scope must exactly consist of the expected URIs. Missing " + Sets.difference(expectedUriSet, scopedUriSet) + " extra " + Sets.difference(scopedUriSet, expectedUriSet));
}
// test that link resolving worked
boolean elementResolved;
if (reference.isMany()) {
@SuppressWarnings("unchecked") EList<EObject> objects = (EList<EObject>) context.eGet(reference, true);
// NOPMD
elementResolved = !objects.isEmpty();
for (Iterator<EObject> objectIter = objects.iterator(); objectIter.hasNext() && elementResolved; ) {
EObject eObject = EcoreUtil.resolve(objectIter.next(), context);
elementResolved = expectedUriSet.contains(EcoreUtil.getURI(eObject));
}
} else {
EObject resolvedObject = (EObject) context.eGet(reference, true);
elementResolved = expectedUriSet.contains(EcoreUtil.getURI(resolvedObject));
}
assertTrue("Linking must have resolved one of the expected objects.", elementResolved);
}
use of org.eclipse.xtext.scoping.IScope in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scope_ColumnSourceRef_column.
public IScope scope_ColumnSourceRef_column(final ColumnSourceRef context, final EReference reference) {
SelectSource _source = context.getSource();
boolean _equals = Objects.equal(_source, null);
if (_equals) {
IScope scope = this.buildScopeForColumnSourceRef_column(context, context);
return scope;
} else {
SelectSource _source_1 = context.getSource();
if ((_source_1 instanceof SingleSourceTable)) {
SelectSource _source_2 = context.getSource();
SingleSourceTable tableSource = ((SingleSourceTable) _source_2);
DDLStatement _ancestorOfType = ModelUtil.<DDLStatement>getAncestorOfType(tableSource, DDLStatement.class);
TableDefinition _tableReference = tableSource.getTableReference();
ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(_ancestorOfType, _tableReference);
return Scopes.scopeFor(_findColumnDefs);
} else {
SelectSource _source_3 = context.getSource();
if ((_source_3 instanceof SingleSourceSelectStatement)) {
SelectSource _source_4 = context.getSource();
SingleSourceSelectStatement selectStmtSource = ((SingleSourceSelectStatement) _source_4);
SelectStatement _selectStatement = selectStmtSource.getSelectStatement();
SelectCoreExpression _core = _selectStatement.getCore();
ArrayList<EObject> _allReferenceableColumns = ModelUtil.getAllReferenceableColumns(_core);
return Scopes.scopeFor(_allReferenceableColumns);
}
}
}
return IScope.NULLSCOPE;
}
use of org.eclipse.xtext.scoping.IScope in project n4js by eclipse.
the class ImportsAwareReferenceProposalCreator method lookupCrossReference.
/**
* Retrieves possible reference targets from scope, including erroneous solutions (e.g., not visible targets). This
* list is further filtered here. This is a general pattern: Do not change or modify scoping for special content
* assist requirements, instead filter here.
*
* @param proposalFactory
* usually this will be an instance of
* {@link AbstractJavaBasedContentProposalProvider.DefaultProposalCreator DefaultProposalCreator}.
* @param filter
* by default an instance of {@link N4JSCandidateFilter} will be provided here.
*/
@SuppressWarnings("javadoc")
public void lookupCrossReference(EObject model, EReference reference, ContentAssistContext context, ICompletionProposalAcceptor acceptor, Predicate<IEObjectDescription> filter, Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
if (model != null) {
final IScope scope = ((IContentAssistScopeProvider) scopeProvider).getScopeForContentAssist(model, reference);
// iterate over candidates, filter them, and create ICompletionProposals for them
final Iterable<IEObjectDescription> candidates = scope.getAllElements();
// don't use candidates.forEach since we want an early exit
for (IEObjectDescription candidate : candidates) {
if (!acceptor.canAcceptMoreProposals())
return;
if (filter.apply(candidate)) {
QualifiedName qfn = candidate.getQualifiedName();
String tmodule = null;
if (qfn.getSegmentCount() >= 2) {
tmodule = qfn.getSegment(qfn.getSegmentCount() - 2);
}
// In case of main module, adjust the qualified name, e.g. index.Element -> react.Element
IN4JSProject project = n4jsCore.findProject(candidate.getEObjectURI()).orNull();
QualifiedName candidateName;
if (project != null && tmodule != null && tmodule.equals(project.getMainModule())) {
candidateName = QualifiedName.create(project.getProjectId(), candidate.getQualifiedName().getLastSegment().toString());
} else {
candidateName = candidate.getQualifiedName();
}
final ICompletionProposal proposal = getProposal(candidate, model, scope, reference, context, filter, proposalFactory);
if (proposal instanceof ConfigurableCompletionProposal && candidate.getName().getSegmentCount() > 1) {
ConfigurableCompletionProposal castedProposal = (ConfigurableCompletionProposal) proposal;
castedProposal.setAdditionalData(FQNImporter.KEY_QUALIFIED_NAME, candidateName);
// Original qualified name is the qualified name before adjustment
castedProposal.setAdditionalData(FQNImporter.KEY_ORIGINAL_QUALIFIED_NAME, candidate.getQualifiedName());
}
acceptor.accept(proposal);
}
}
}
}
Aggregations