Search in sources :

Example 31 with QualifiedName

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

Example 32 with QualifiedName

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) LinkedHashSet(java.util.LinkedHashSet) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 33 with QualifiedName

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);
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) LinkedHashSet(java.util.LinkedHashSet) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 34 with QualifiedName

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);
        }
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) EObject(org.eclipse.emf.ecore.EObject) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 35 with QualifiedName

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

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