Search in sources :

Example 1 with DefaultResourceDescription

use of org.eclipse.xtext.resource.impl.DefaultResourceDescription in project xtext-core by eclipse.

the class NamesAreUniqueValidatorTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    context = Maps.newHashMap();
    validator = new NamesAreUniqueValidator() {

        @Override
        protected Map<Object, Object> getContext() {
            return context;
        }
    };
    validator.setResourceServiceProviderRegistry(this);
    validator.setHelper(this);
    final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            return QualifiedName.create(SimpleAttributeResolver.NAME_RESOLVER.getValue(obj));
        }
    });
    resourceDescriptionManager = new DefaultResourceDescriptionManager() {

        @Override
        public IResourceDescription getResourceDescription(Resource resource) {
            DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource, strategy);
            return resourceDescription;
        }
    };
    callCount = 0;
    resource = new ResourceImpl();
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    resource.getContents().add(EcoreFactory.eINSTANCE.createEClass());
    for (int i = 0; i < resource.getContents().size(); i++) {
        EClass clazz = (EClass) resource.getContents().get(i);
        clazz.setName(String.valueOf(i));
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Resource(org.eclipse.emf.ecore.resource.Resource) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) EClass(org.eclipse.emf.ecore.EClass) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EObject(org.eclipse.emf.ecore.EObject) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Map(java.util.Map)

Example 2 with DefaultResourceDescription

use of org.eclipse.xtext.resource.impl.DefaultResourceDescription in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    with(new IndexTestLanguageStandaloneSetup());
    globalScopeProvider = new ResourceSetGlobalScopeProvider();
    nameProvider = new DefaultDeclarativeQualifiedNameProvider();
    nameConverter = new IQualifiedNameConverter.DefaultImpl();
    final DefaultResourceDescriptionStrategy strategy = new DefaultResourceDescriptionStrategy();
    strategy.setQualifiedNameProvider(nameProvider);
    final DefaultResourceDescriptionManager resourceDescMnr = new DefaultResourceDescriptionManager() {

        @Override
        public IResourceDescription getResourceDescription(Resource resource) {
            DefaultResourceDescription resourceDescription = new DefaultResourceDescription(resource, strategy);
            return resourceDescription;
        }
    };
    final DefaultResourceServiceProvider provider = new DefaultResourceServiceProvider() {

        @Override
        public Manager getResourceDescriptionManager() {
            return resourceDescMnr;
        }
    };
    globalScopeProvider.setGlobalResourceDecriptionProvider(new GlobalResourceDescriptionProvider(new ResourceServiceProviderRegistryImpl() {

        @Override
        public IResourceServiceProvider getResourceServiceProvider(URI uri, String contentType) {
            return provider;
        }
    }));
    CaseInsensitivityHelper caseInsensitivityHelper = new CaseInsensitivityHelper();
    globalScopeProvider.setCaseInsensitivityHelper(caseInsensitivityHelper);
    scopeProvider = new ImportedNamespaceAwareLocalScopeProvider(globalScopeProvider, nameProvider, nameConverter, caseInsensitivityHelper);
}
Also used : DefaultResourceServiceProvider(org.eclipse.xtext.resource.impl.DefaultResourceServiceProvider) DefaultDeclarativeQualifiedNameProvider(org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) IQualifiedNameConverter(org.eclipse.xtext.naming.IQualifiedNameConverter) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) IndexTestLanguageStandaloneSetup(org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup) URI(org.eclipse.emf.common.util.URI) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) ResourceServiceProviderRegistryImpl(org.eclipse.xtext.resource.impl.ResourceServiceProviderRegistryImpl)

Example 3 with DefaultResourceDescription

use of org.eclipse.xtext.resource.impl.DefaultResourceDescription in project xtext-core by eclipse.

the class DefaultResourceDescriptionManagerTest method setUp.

@Before
public void setUp() throws Exception {
    EObject copy = EcoreUtil.copy(EcorePackage.eINSTANCE);
    resource = new ResourceImpl();
    resource.getContents().add(copy);
    IQualifiedNameProvider nameProvider = new IQualifiedNameProvider.AbstractImpl() {

        @Override
        public QualifiedName getFullyQualifiedName(EObject obj) {
            if (obj instanceof ENamedElement)
                return QualifiedName.create(((ENamedElement) obj).getName());
            return null;
        }
    };
    DefaultResourceDescriptionStrategy descriptionStrategy = new DefaultResourceDescriptionStrategy();
    descriptionStrategy.setQualifiedNameProvider(nameProvider);
    resourceDescription = new DefaultResourceDescription(resource, descriptionStrategy) {

        @Override
        public Iterable<QualifiedName> getImportedNames() {
            return importedNames;
        }
    };
    manager = new DefaultResourceDescriptionManager();
    importedNames = Collections.emptySet();
}
Also used : ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) IQualifiedNameProvider(org.eclipse.xtext.naming.IQualifiedNameProvider) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) EObject(org.eclipse.emf.ecore.EObject) ENamedElement(org.eclipse.emf.ecore.ENamedElement) DefaultResourceDescriptionManager(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager) DefaultResourceDescriptionStrategy(org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy) Before(org.junit.Before)

Example 4 with DefaultResourceDescription

use of org.eclipse.xtext.resource.impl.DefaultResourceDescription in project dsl-devkit by dsldevkit.

the class CachingStateBasedContainerManager method getContainersForHandlesAndResource.

/**
 * Returns the containers for the given handles, where one of the containers will also include {@code desc} when appropriate.
 *
 * @param handles
 *          handles to get containers for, must not be {@code null}
 * @param desc
 *          description to add, must not be {@code null}
 * @param resourceDescriptions
 *          resource descriptions, must not be {@code null}
 * @return list of containers, never {@code null}
 */
protected List<IContainer> getContainersForHandlesAndResource(final List<String> handles, final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
    List<IContainer> result = getVisibleContainers(handles, resourceDescriptions);
    if (!result.isEmpty()) {
        URI descURI = desc.getURI();
        for (int i = 0; i < result.size(); i++) {
            if (result.get(i).getResourceDescription(descURI) != null) {
                return result;
            }
        }
        // getEObjectDescriptions(), leading to a stack overflow since it may in turn invoke getVisibleContainers() again.
        if (desc instanceof DefaultResourceDescription) {
            DefaultResourceDescription d = (DefaultResourceDescription) desc;
            if (BuildPhases.isIndexing(d.getResource())) {
                return result;
            }
        }
        // the IResourceDescription was found nowhere, add it to the first one that matches the description's domain.
        IDomain descDomain = mapper.map(descURI);
        IContainer wrappedContainer = null;
        int index = 0;
        for (int i = 0; i < result.size(); i++) {
            IContainer container = result.get(i);
            IDomain containerDomain = mapper.map(container);
            if (containerDomain != null && containerDomain.equals(descDomain)) {
                wrappedContainer = new DescriptionAddingContainer(desc, container);
                result.set(index, wrappedContainer);
                return result;
            }
            index++;
        }
        // If we get here, we found no container with a matching domain. Add to the first, but use a DescriptionAddingContainer that
        // will add the description at the end.
        wrappedContainer = new DescriptionAtEndAddingContainer(desc, result.get(0));
        result.set(0, wrappedContainer);
    }
    return result;
}
Also used : IDomain(com.avaloq.tools.ddk.xtext.scoping.IDomain) DefaultResourceDescription(org.eclipse.xtext.resource.impl.DefaultResourceDescription) IContainer(org.eclipse.xtext.resource.IContainer) DescriptionAddingContainer(org.eclipse.xtext.resource.containers.DescriptionAddingContainer) URI(org.eclipse.emf.common.util.URI)

Aggregations

DefaultResourceDescription (org.eclipse.xtext.resource.impl.DefaultResourceDescription)4 DefaultResourceDescriptionManager (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager)3 DefaultResourceDescriptionStrategy (org.eclipse.xtext.resource.impl.DefaultResourceDescriptionStrategy)3 URI (org.eclipse.emf.common.util.URI)2 EObject (org.eclipse.emf.ecore.EObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ResourceImpl (org.eclipse.emf.ecore.resource.impl.ResourceImpl)2 IQualifiedNameProvider (org.eclipse.xtext.naming.IQualifiedNameProvider)2 IDomain (com.avaloq.tools.ddk.xtext.scoping.IDomain)1 Map (java.util.Map)1 EClass (org.eclipse.emf.ecore.EClass)1 ENamedElement (org.eclipse.emf.ecore.ENamedElement)1 IndexTestLanguageStandaloneSetup (org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup)1 DefaultDeclarativeQualifiedNameProvider (org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider)1 IQualifiedNameConverter (org.eclipse.xtext.naming.IQualifiedNameConverter)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 IContainer (org.eclipse.xtext.resource.IContainer)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 DescriptionAddingContainer (org.eclipse.xtext.resource.containers.DescriptionAddingContainer)1