Search in sources :

Example 26 with QualifiedName

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

Example 27 with QualifiedName

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")));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 28 with QualifiedName

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;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IContainer(org.eclipse.xtext.resource.IContainer) URI(org.eclipse.emf.common.util.URI)

Example 29 with QualifiedName

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

Example 30 with QualifiedName

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