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));
}
}
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);
}
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();
}
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;
}
Aggregations