use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportScope method getAllElements.
@Override
public Iterable<IEObjectDescription> getAllElements() {
final Iterable<IEObjectDescription> globalElements = getParent().getAllElements();
Iterable<IEObjectDescription> aliased = getAllLocalElements();
final Set<QualifiedName> elements = newHashSet();
for (IEObjectDescription from : aliased) {
QualifiedName qn = getIgnoreCaseAwareQualifiedName(from);
elements.add(qn);
}
return concat(aliased, filter(globalElements, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return !elements.contains(getIgnoreCaseAwareQualifiedName(input));
}
}));
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportScope method getAliasedElements.
protected Iterable<IEObjectDescription> getAliasedElements(Iterable<IEObjectDescription> candidates) {
Multimap<QualifiedName, IEObjectDescription> keyToDescription = LinkedHashMultimap.create();
Multimap<QualifiedName, ImportNormalizer> keyToNormalizer = HashMultimap.create();
for (IEObjectDescription imported : candidates) {
QualifiedName fullyQualifiedName = imported.getName();
for (ImportNormalizer normalizer : normalizers) {
QualifiedName alias = normalizer.deresolve(fullyQualifiedName);
if (alias != null) {
QualifiedName key = alias;
if (isIgnoreCase()) {
key = key.toLowerCase();
}
keyToDescription.put(key, new AliasedEObjectDescription(alias, imported));
keyToNormalizer.put(key, normalizer);
}
}
}
for (QualifiedName name : keyToNormalizer.keySet()) {
if (keyToNormalizer.get(name).size() > 1)
keyToDescription.removeAll(name);
}
return keyToDescription.values();
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProvider method getLocalElementsScope.
protected IScope getLocalElementsScope(IScope parent, final EObject context, final EReference reference) {
IScope result = parent;
ISelectable allDescriptions = getAllDescriptions(context.eResource());
QualifiedName name = getQualifiedNameOfLocalElement(context);
boolean ignoreCase = isIgnoreCase(reference);
final List<ImportNormalizer> namespaceResolvers = getImportedNamespaceResolvers(context, ignoreCase);
if (!namespaceResolvers.isEmpty()) {
if (isRelativeImport() && name != null && !name.isEmpty()) {
ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
}
result = createImportScope(result, namespaceResolvers, null, reference.getEReferenceType(), isIgnoreCase(reference));
}
if (name != null) {
ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
result = createImportScope(result, singletonList(localNormalizer), allDescriptions, reference.getEReferenceType(), isIgnoreCase(reference));
}
return result;
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProvider method createImportedNamespaceResolver.
/**
* Create a new {@link ImportNormalizer} for the given namespace.
* @param namespace the namespace.
* @param ignoreCase <code>true</code> if the resolver should be case insensitive.
* @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be converted to a valid
* qualified name.
*/
protected ImportNormalizer createImportedNamespaceResolver(final String namespace, boolean ignoreCase) {
if (Strings.isEmpty(namespace))
return null;
QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace);
if (importedNamespace == null || importedNamespace.isEmpty()) {
return null;
}
boolean hasWildCard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildCard()) : importedNamespace.getLastSegment().equals(getWildCard());
if (hasWildCard) {
if (importedNamespace.getSegmentCount() <= 1)
return null;
return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase);
} else {
return doCreateImportNormalizer(importedNamespace, false, ignoreCase);
}
}
use of org.eclipse.xtext.naming.QualifiedName in project xtext-core by eclipse.
the class MapBasedScope method createScope.
public static IScope createScope(IScope parent, Iterable<IEObjectDescription> descriptions, boolean ignoreCase) {
Map<QualifiedName, IEObjectDescription> map = null;
for (IEObjectDescription description : descriptions) {
if (map == null)
map = new LinkedHashMap<QualifiedName, IEObjectDescription>(4);
QualifiedName name = ignoreCase ? description.getName().toLowerCase() : description.getName();
IEObjectDescription previous = map.put(name, description);
// however, if the name was already used, the first one should win
if (previous != null) {
map.put(name, previous);
}
}
if (map == null || map.isEmpty()) {
return parent;
}
return new MapBasedScope(parent, map, ignoreCase);
}
Aggregations