use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method toListOfNames.
protected List<QualifiedName> toListOfNames(Iterable<IEObjectDescription> elements) {
List<QualifiedName> result = Lists.newArrayList();
for (IEObjectDescription e : elements) {
if (!result.contains(e.getName()))
result.add(e.getName());
}
Collections.sort(result);
return result;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method testImports_03.
@Test
public void testImports_03() throws Exception {
XtextResource resource = getResource(new StringInputStream("import foo.bar"), URI.createURI("import.indextestlanguage"));
resource.getResourceSet().createResource(URI.createURI("foo.indextestlanguage")).load(new StringInputStream("foo.bar { " + " entity Person { " + " String name " + " } " + " datatype String " + "}"), null);
IScope scope = scopeProvider.getScope(resource.getContents().get(0), IndexTestLanguagePackage.eINSTANCE.getFile_Elements());
List<QualifiedName> names = toListOfNames(scope.getAllElements());
assertEquals(names.toString(), 4, names.size());
assertTrue(names.contains(nameConverter.toQualifiedName("bar")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar.Person")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar.String")));
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class DefaultResourceDescriptionManager method isAffected.
@Override
public boolean isAffected(Collection<Delta> deltas, IResourceDescription candidate, IResourceDescriptions context) {
Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(candidate);
if (!outgoingReferences.isEmpty()) {
for (IResourceDescription.Delta delta : deltas) if (hasChanges(delta, candidate) && outgoingReferences.contains(delta.getUri()))
return true;
}
// this is a tradeoff - we could either check whether a given delta uri is contained
// in a reachable container and check for intersecting names afterwards, or we can do
// the other way round
// unfortunately there is no way to decide reliably which algorithm scales better
// note that this method is called for each description so we have something like a
// number of deltas x number of resources which is not really nice
List<IContainer> containers = null;
Collection<QualifiedName> importedNames = getImportedNames(candidate);
for (IResourceDescription.Delta delta : deltas) {
if (hasChanges(delta, candidate)) {
// not a java resource - delta's resource should be contained in a visible container
// as long as we did not delete the resource
URI uri = delta.getUri();
if ((uri.isPlatform() || uri.isArchive()) && delta.getNew() != null) {
if (containers == null)
containers = containerManager.getVisibleContainers(candidate, context);
boolean descriptionIsContained = false;
for (int i = 0; i < containers.size() && !descriptionIsContained; i++) {
descriptionIsContained = containers.get(i).hasResourceDescription(uri);
}
if (!descriptionIsContained)
return false;
}
if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) {
return true;
}
}
}
return false;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class EObjectDescriptionLookUp method putIntoMap.
protected void putIntoMap(Map<QualifiedName, List<IEObjectDescription>> nameToObjects, IEObjectDescription description) {
QualifiedName indexKey = description.getName().toLowerCase();
List<IEObjectDescription> values = nameToObjects.get(indexKey);
if (values == null) {
values = Lists.newArrayListWithExpectedSize(2);
nameToObjects.put(indexKey, values);
}
values.add(description);
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class EObjectDescriptionLookUp method getNameToObjects.
protected Map<QualifiedName, List<IEObjectDescription>> getNameToObjects() {
if (nameToObjects == null) {
synchronized (this) {
if (nameToObjects == null) {
Map<QualifiedName, List<IEObjectDescription>> nameToObjects = Maps.newHashMapWithExpectedSize(allDescriptions.size());
if (allDescriptions instanceof RandomAccess) {
for (int i = 0; i < allDescriptions.size(); i++) {
IEObjectDescription description = allDescriptions.get(i);
putIntoMap(nameToObjects, description);
}
} else {
for (IEObjectDescription description : allDescriptions) {
putIntoMap(nameToObjects, description);
}
}
this.nameToObjects = nameToObjects;
}
}
}
return this.nameToObjects;
}
Aggregations