Search in sources :

Example 26 with IScope

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;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 27 with IScope

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;
}
Also used : ISelectable(org.eclipse.xtext.resource.ISelectable) ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope)

Example 28 with IScope

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);
}
Also used : EObjectResolvingEList(org.eclipse.emf.ecore.util.EObjectResolvingEList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 29 with IScope

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;
}
Also used : SelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SelectStatement) SingleSourceSelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceSelectStatement) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) SingleSourceSelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceSelectStatement) SelectCoreExpression(com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition) SelectSource(com.robotoworks.mechanoid.db.sqliteModel.SelectSource)

Example 30 with IScope

use of org.eclipse.xtext.scoping.IScope in project xtext-xtend by eclipse.

the class XtendImportedNamespaceScopeProvider method getSuperTypeOfLocalTypeNonResolving.

protected JvmDeclaredType getSuperTypeOfLocalTypeNonResolving(JvmDeclaredType declarator) {
    AnonymousClass anonymousClass = associations.getAnonymousClass(declarator);
    if (anonymousClass != null) {
        IScope typeScope = getScope(anonymousClass, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        JvmDeclaredType superType = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
        if (superType != null) {
            return superType;
        }
    }
    return null;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) IScope(org.eclipse.xtext.scoping.IScope) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

IScope (org.eclipse.xtext.scoping.IScope)148 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)57 Test (org.junit.Test)53 EObject (org.eclipse.emf.ecore.EObject)43 QualifiedName (org.eclipse.xtext.naming.QualifiedName)26 XtextResource (org.eclipse.xtext.resource.XtextResource)19 EReference (org.eclipse.emf.ecore.EReference)17 EClass (org.eclipse.emf.ecore.EClass)15 StringInputStream (org.eclipse.xtext.util.StringInputStream)15 URI (org.eclipse.emf.common.util.URI)12 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)12 ArrayList (java.util.ArrayList)10 Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 AbstractScopingTest (com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest)8 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)8 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)7 Predicate (com.google.common.base.Predicate)6 EClassifier (org.eclipse.emf.ecore.EClassifier)6 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)6