use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class AbstractPolymorphicScopeProvider method newContainerScope.
/**
* Create a new container scope using the results of a given query as its contents.
*
* @param id
* Human-readable name of the scope, typically used to identify where the scope was created. Useful for debugging.
* @param outer
* The outer scope of the new scope.
* @param context
* The context
* @param query
* The query that defines the scope's contents
* @param nameFunctions
* The name functions to apply
* @param originalResource
* The original resource
* @param caseInsensitive
* indicates whether the new scope shall be case insensitive
* @return The new scope
*/
protected IScope newContainerScope(final String id, final IScope outer, final EObject context, final ContainerQuery query, final Resource originalResource, final Iterable<INameFunction> nameFunctions, final boolean caseInsensitive) {
IScope result = outer;
final List<String> domains = query.getDomains();
for (final IContainer container : Lists.reverse(getVisibleContainers(context, originalResource))) {
if (!domains.isEmpty()) {
final IDomain domain = domainMapper.map(container);
if (domain != null && !domains.contains(domain.getName())) {
// Query not applicable to this container.
continue;
}
}
result = new ContainerBasedScope(id, result, container, query, nameFunctions, caseInsensitive);
}
return result;
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class DelegatingScope method toString.
@SuppressWarnings("nls")
@Override
public String toString() {
final StringBuilder result = new StringBuilder(getClass().getName());
result.append('@');
result.append(Integer.toHexString(hashCode()));
result.append(" (id: ");
result.append(getId());
final Iterable<IScope> delegateScopes = getDelegates();
if (delegateScopes != null && !Iterables.isEmpty(delegateScopes)) {
result.append(", delegates: ");
result.append(Iterables.toString(delegateScopes));
}
result.append(')');
final IScope outerScope = getParent();
if (outerScope != IScope.NULLSCOPE) {
result.append("\n >> ");
result.append(outerScope.toString().replaceAll("\\\n", "\n "));
}
return result.toString();
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class PrefixedContainerBasedScope method toString.
@SuppressWarnings("nls")
@Override
public String toString() {
final StringBuilder result = new StringBuilder(getClass().getName());
result.append('@');
result.append(Integer.toHexString(hashCode()));
result.append(" (id: ");
result.append(getId());
result.append(", prefix: ");
result.append(prefix);
result.append(", query: ");
result.append(criteria);
result.append(", container: ");
result.append(container);
result.append(')');
final IScope parent = getParent();
if (parent != IScope.NULLSCOPE) {
result.append("\n >> ");
result.append(parent.toString().replaceAll("\\\n", "\n "));
}
return result.toString();
}
use of org.eclipse.xtext.scoping.IScope in project dsl-devkit by dsldevkit.
the class ValidScopingTest method testEStructuralFeatureScope.
/**
* Tests that validations may be declared on existing EClass and EStructuralFeature instances.
*/
@Test
public void testEStructuralFeatureScope() throws IOException {
final ValidModel validModel = (ValidModel) getTestSource().getModel();
final NativeContext context = getXtextTestUtil().getFirstInstanceOf(validModel, NativeContext.class);
// Check context feature reference
IScope scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_FEATURE);
IEObjectDescription name = scope.getSingleElement(QualifiedName.create("name"));
assertNotNull("Found valid EStructuralFeature \"name\"", name);
final EObject resolvedName = name.getEObjectOrProxy();
assertNotNull("Valid EStructuralFeature \"name\" can be resolved", resolvedName);
// Check context type reference
scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_TYPE);
assertEquals("Scope provider returns correct context type", context.getContextType(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
assertEquals("Container of \"name\" reference instance is \"Model\" instance", resolvedName.eContainer(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
// Check marker type reference
scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_TYPE);
assertEquals("Scope provider returns correct marker type", context.getMarkerType(), scope.getSingleElement(QualifiedName.create("Element")).getEObjectOrProxy());
// Check marker feature reference
scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_FEATURE);
assertEquals("Scope provider returns correct marker feature", context.getMarkerFeature(), scope.getSingleElement(QualifiedName.create("name")).getEObjectOrProxy());
}
use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.
the class OperationOverloadingLinkingService method getLinkedOperation.
public List<EObject> getLinkedOperation(ArgumentExpression context, EReference ref, INode node) {
final EClass requiredType = ref.getEReferenceType();
if (requiredType == null) {
return Collections.<EObject>emptyList();
}
final String crossRefString = getCrossRefNodeAsString(node);
if (crossRefString == null || crossRefString.equals("")) {
return Collections.<EObject>emptyList();
}
final IScope scope = getScope(context, ref);
final QualifiedName qualifiedLinkName = qualifiedNameConverter.toQualifiedName(crossRefString);
// Adoption to super class implementation here to return multi elements
final Iterable<IEObjectDescription> eObjectDescription = scope.getElements(qualifiedLinkName);
int size = Iterables.size(eObjectDescription);
if (size == 0)
return Collections.emptyList();
if (size == 1)
return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
// Two operation with same name found here
List<IEObjectDescription> candidates = new ArrayList<>();
for (IEObjectDescription currentDescription : eObjectDescription) {
if (currentDescription.getEClass().isSuperTypeOf(TypesPackage.Literals.OPERATION)) {
candidates.add(currentDescription);
}
}
Optional<Operation> operation = operationsLinker.linkOperation(candidates, context);
if (operation.isPresent()) {
return Collections.singletonList(operation.get());
}
// Link to first operation to get parameter errors instead of linking errors
return Collections.singletonList(Iterables.getFirst(eObjectDescription, null).getEObjectOrProxy());
}
Aggregations