Search in sources :

Example 1 with SimpleScope

use of org.eclipse.xtext.scoping.impl.SimpleScope 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 2 with SimpleScope

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

the class SGenScopeProvider method getLibraryScope.

protected SimpleScope getLibraryScope(Resource resource) {
    GeneratorModel generatorModel = (GeneratorModel) EcoreUtil.getObjectByType(resource.getContents(), SGenPackage.Literals.GENERATOR_MODEL);
    Assert.isNotNull(generatorModel);
    String generatorId = generatorModel.getGeneratorId();
    IGeneratorDescriptor generatorDescriptor = GeneratorExtensions.getGeneratorDescriptor(generatorId);
    Iterable<IEObjectDescription> allElements = Lists.newArrayList();
    if (generatorDescriptor != null) {
        Iterable<ILibraryDescriptor> libraryDescriptor = LibraryExtensions.getLibraryDescriptors(generatorDescriptor.getLibraryIDs());
        for (ILibraryDescriptor desc : libraryDescriptor) {
            Resource library = resourceSet.getResource(desc.getURI(), true);
            FeatureResourceDescription description = new FeatureResourceDescription(library);
            injector.injectMembers(description);
            allElements = Iterables.concat(allElements, description.getExportedObjects());
        }
    }
    return new SimpleScope(allElements);
}
Also used : FeatureResourceDescription(org.yakindu.sct.generator.genmodel.resource.FeatureResourceDescription) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) Resource(org.eclipse.emf.ecore.resource.Resource) GeneratorModel(org.yakindu.sct.model.sgen.GeneratorModel) IGeneratorDescriptor(org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ILibraryDescriptor(org.yakindu.sct.generator.core.extensions.ILibraryDescriptor)

Example 3 with SimpleScope

use of org.eclipse.xtext.scoping.impl.SimpleScope 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 4 with SimpleScope

use of org.eclipse.xtext.scoping.impl.SimpleScope 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 5 with SimpleScope

use of org.eclipse.xtext.scoping.impl.SimpleScope in project xtext-core by eclipse.

the class XtextScopeProvider method createEPackageScope.

protected IScope createEPackageScope(final Grammar grammar) {
    final List<Grammar> allGrammars = getAllGrammars(grammar);
    IScope current = new SimpleScope(IScope.NULLSCOPE, Iterables.transform(EPackage.Registry.INSTANCE.keySet(), new Function<String, IEObjectDescription>() {

        @Override
        public IEObjectDescription apply(String from) {
            InternalEObject proxyPackage = (InternalEObject) EcoreFactory.eINSTANCE.createEPackage();
            proxyPackage.eSetProxyURI(URI.createURI(from));
            return EObjectDescription.create(QualifiedName.create(from), proxyPackage, Collections.singletonMap("nsURI", "true"));
        }
    }));
    for (int i = allGrammars.size() - 1; i >= 0; i--) {
        current = createEPackageScope(allGrammars.get(i), current);
    }
    return current;
}
Also used : Function(com.google.common.base.Function) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) IScope(org.eclipse.xtext.scoping.IScope) Grammar(org.eclipse.xtext.Grammar) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Aggregations

SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)9 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)8 IScope (org.eclipse.xtext.scoping.IScope)6 QualifiedName (org.eclipse.xtext.naming.QualifiedName)3 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)3 EClass (org.eclipse.emf.ecore.EClass)2 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Grammar (org.eclipse.xtext.Grammar)2 IGeneratorDescriptor (org.yakindu.sct.generator.core.extensions.IGeneratorDescriptor)2 GeneratorModel (org.yakindu.sct.model.sgen.GeneratorModel)2 AbstractNameFunction (com.avaloq.tools.ddk.xtext.scoping.AbstractNameFunction)1 Function (com.google.common.base.Function)1 ArrayList (java.util.ArrayList)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 EList (org.eclipse.emf.common.util.EList)1 URI (org.eclipse.emf.common.util.URI)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Registry (org.eclipse.emf.ecore.EPackage.Registry)1