Search in sources :

Example 36 with QualifiedName

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));
        }
    }));
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Predicate(com.google.common.base.Predicate)

Example 37 with QualifiedName

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();
}
Also used : AliasedEObjectDescription(org.eclipse.xtext.resource.impl.AliasedEObjectDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 38 with QualifiedName

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;
}
Also used : ISelectable(org.eclipse.xtext.resource.ISelectable) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope)

Example 39 with QualifiedName

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);
    }
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName)

Example 40 with QualifiedName

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);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

QualifiedName (org.eclipse.xtext.naming.QualifiedName)215 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)78 EObject (org.eclipse.emf.ecore.EObject)46 Test (org.junit.Test)46 URI (org.eclipse.emf.common.util.URI)24 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)21 IScope (org.eclipse.xtext.scoping.IScope)21 EClass (org.eclipse.emf.ecore.EClass)18 Resource (org.eclipse.emf.ecore.resource.Resource)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 Set (java.util.Set)10 StyledString (org.eclipse.jface.viewers.StyledString)8 JvmType (org.eclipse.xtext.common.types.JvmType)8 XtextResource (org.eclipse.xtext.resource.XtextResource)8 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 Grammar (org.eclipse.xtext.Grammar)6 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)6 HashMap (java.util.HashMap)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5