Search in sources :

Example 21 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class SGenScopeProvider method scope_GeneratorEntry_elementRef.

protected IScope scope_GeneratorEntry_elementRef(final EObject context, final EReference reference) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil2.getRootContainer(context);
    String id = generatorModel.getGeneratorId();
    final IGeneratorDescriptor desc = GeneratorExtensions.getGeneratorDescriptor(id);
    if (desc == null)
        return IScope.NULLSCOPE;
    final String elementRefType = desc.getElementRefType();
    IScope scope = new FilteringScope(getDelegate().getScope(context, reference), new Predicate<IEObjectDescription>() {

        public boolean apply(IEObjectDescription input) {
            EList<EClass> allSuperTypes = input.getEClass().getESuperTypes();
            for (EClass eClass : allSuperTypes) {
                if (elementRefType.equals(eClass.getInstanceClassName()))
                    return true;
            }
            return elementRefType.equals(input.getEClass().getInstanceClassName());
        }
    });
    return new SimpleScope(scope.getAllElements());
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EList(org.eclipse.emf.common.util.EList) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 22 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class STextGlobalScopeProvider method getScope.

public IScope getScope(Resource context, EReference reference, Predicate<IEObjectDescription> filter) {
    IScope parentScope = super.getScope(context, reference, filter);
    parentScope = new SimpleScope(parentScope, filterPropertiesOfLibrary(context, reference, filter).getAllElements());
    final Statechart statechart = getStatechart(context);
    parentScope = new TypeSystemAwareScope(parentScope, typeSystem, qualifiedNameProvider, reference.getEReferenceType());
    IScope result = new FilteringScope(parentScope, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            String userData = input.getUserData(DomainRegistry.DOMAIN_ID);
            if (userData == null)
                return true;
            return statechart.getDomainID().equals(userData);
        }
    });
    result = filterAnnotations(reference, result);
    return new FilteringScope(result, input -> {
        String isVisible = input.getUserData(TypedResourceDescriptionStrategy.IS_VISIBLE_TYPE);
        return isVisible == null || Boolean.valueOf(isVisible);
    });
}
Also used : SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) Statechart(org.yakindu.sct.model.sgraph.Statechart) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 23 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class STextGlobalScopeProvider method getScope.

/**
 * Overidden to avoid scope nesting which is not required and slows down because
 * of shadowing testing.
 */
@Override
protected IScope getScope(Resource resource, boolean ignoreCase, EClass type, Predicate<IEObjectDescription> filter) {
    final LinkedHashSet<URI> uniqueImportURIs = getImportedUris(resource);
    IResourceDescriptions descriptions = getResourceDescriptions(resource, uniqueImportURIs);
    List<URI> urisAsList = Lists.newArrayList(uniqueImportURIs);
    Collections.reverse(urisAsList);
    List<IEObjectDescription> objectDescriptions = new ArrayList<IEObjectDescription>();
    for (URI uri : urisAsList) {
        IScope scope = createLazyResourceScope(IScope.NULLSCOPE, uri, descriptions, type, filter, ignoreCase);
        Iterables.addAll(objectDescriptions, scope.getAllElements());
    }
    return MapBasedScope.createScope(IScope.NULLSCOPE, objectDescriptions);
}
Also used : IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 24 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class STextScopeProvider method scope_ElementReferenceExpression_reference.

public IScope scope_ElementReferenceExpression_reference(final EObject context, EReference reference) {
    IScope namedScope = getNamedTopLevelScope(context, reference);
    IScope unnamedScope = getUnnamedTopLevelScope(context, reference);
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    unnamedScope = new FilteringScope(unnamedScope, predicate);
    return new SimpleScope(unnamedScope, namedScope.getAllElements());
}
Also used : SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 25 with IScope

use of org.eclipse.xtext.scoping.IScope in project statecharts by Yakindu.

the class STextScopeProvider method scope_ActiveStateReferenceExpression_value.

public IScope scope_ActiveStateReferenceExpression_value(EObject context, EReference reference) {
    Statechart statechart = getStatechart(context);
    if (statechart == null)
        return IScope.NULLSCOPE;
    List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
    IScope scope = Scopes.scopeFor(allStates, nameProvider, IScope.NULLSCOPE);
    return new ImportScope(getActiveStateNormalizer(context), scope, new EObjectDescriptionLookUp(Lists.newArrayList(scope.getAllElements())), reference.getEReferenceType(), false);
}
Also used : EObjectDescriptionLookUp(org.eclipse.xtext.resource.impl.EObjectDescriptionLookUp) State(org.yakindu.sct.model.sgraph.State) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Statechart(org.yakindu.sct.model.sgraph.Statechart) IScope(org.eclipse.xtext.scoping.IScope)

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