use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class EObjectDescriptionLookUp method getExportedObjects.
@Override
public Iterable<IEObjectDescription> getExportedObjects(final EClass type, final QualifiedName name, boolean ignoreCase) {
if (allDescriptions.isEmpty())
return Collections.emptyList();
QualifiedName lowerCase = name.toLowerCase();
List<IEObjectDescription> values = getNameToObjects().get(lowerCase);
if (values == null)
return Collections.emptyList();
Predicate<IEObjectDescription> predicate = ignoreCase ? new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return EcoreUtil2.isAssignableFrom(type, input.getEClass());
}
} : new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return name.equals(input.getName()) && EcoreUtil2.isAssignableFrom(type, input.getEClass());
}
};
return Iterables.filter(values, predicate);
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ResourceDescriptionsData method copyLookupMap.
protected Map<QualifiedName, Object> copyLookupMap() {
Map<QualifiedName, Object> result = Maps.newLinkedHashMap(lookupMap);
for (Map.Entry<QualifiedName, Object> entry : result.entrySet()) {
Object value = entry.getValue();
if (value instanceof Set<?>) {
@SuppressWarnings("unchecked") Set<IResourceDescription> copiedValue = new LinkedHashSet<IResourceDescription>((Set<? extends IResourceDescription>) value);
if (copiedValue.size() <= 1)
throw new IllegalStateException("Unexpected number of elements in the value set: " + copiedValue.size() + " for " + entry.getKey());
entry.setValue(copiedValue);
}
}
return result;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ResourceDescriptionsData method removeDescription.
public void removeDescription(URI uri) {
IResourceDescription oldDescription = resourceDescriptionMap.remove(uri);
if (oldDescription != null) {
for (IEObjectDescription object : oldDescription.getExportedObjects()) {
QualifiedName objectName = object.getName().toLowerCase();
Object existing = lookupMap.get(objectName);
if (existing == oldDescription) {
lookupMap.remove(objectName);
} else if (existing instanceof Set<?>) {
Set<?> casted = (Set<?>) existing;
if (casted.remove(oldDescription)) {
if (casted.size() == 1) {
lookupMap.put(objectName, casted.iterator().next());
} else if (casted.isEmpty()) {
lookupMap.remove(objectName);
}
}
}
}
}
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ResourceDescriptionsData method registerDescription.
@SuppressWarnings("unchecked")
protected void registerDescription(IResourceDescription description, Map<QualifiedName, Object> target) {
for (IEObjectDescription object : description.getExportedObjects()) {
QualifiedName lowerCase = object.getName().toLowerCase();
Object existing = target.put(lowerCase, description);
if (existing != null && existing != description) {
Set<IResourceDescription> set = null;
if (existing instanceof IResourceDescription) {
set = Sets.newLinkedHashSetWithExpectedSize(2);
set.add((IResourceDescription) existing);
} else {
set = (Set<IResourceDescription>) existing;
}
set.add(description);
target.put(lowerCase, set);
}
}
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportScope method getLocalElementsByName.
@Override
protected Iterable<IEObjectDescription> getLocalElementsByName(QualifiedName name) {
List<IEObjectDescription> result = newArrayList();
QualifiedName resolvedQualifiedName = null;
ISelectable importFrom = getImportFrom();
for (ImportNormalizer normalizer : normalizers) {
final QualifiedName resolvedName = normalizer.resolve(name);
if (resolvedName != null) {
Iterable<IEObjectDescription> resolvedElements = importFrom.getExportedObjects(type, resolvedName, isIgnoreCase());
for (IEObjectDescription resolvedElement : resolvedElements) {
if (resolvedQualifiedName == null)
resolvedQualifiedName = resolvedName;
else if (!resolvedQualifiedName.equals(resolvedName)) {
if (result.get(0).getEObjectOrProxy() != resolvedElement.getEObjectOrProxy()) {
return emptyList();
}
}
QualifiedName alias = normalizer.deresolve(resolvedElement.getName());
if (alias == null)
throw new IllegalStateException("Couldn't deresolve " + resolvedElement.getName() + " with import " + normalizer);
final AliasedEObjectDescription aliasedEObjectDescription = new AliasedEObjectDescription(alias, resolvedElement);
result.add(aliasedEObjectDescription);
}
}
}
return result;
}
Aggregations