Search in sources :

Example 1 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.

the class UIParticipant method createLabelProvider.

@Override
public ILabelProvider createLabelProvider() {
    return new ILabelProvider() {

        @Override
        public void removeListener(ILabelProviderListener listener) {
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        }

        @Override
        public String getText(Object element) {
            IReferenceDescription referenceDescription = (IReferenceDescription) element;
            URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
            final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
            IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
            if (resourceDescription != null) {
                for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
                    if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
                        return globalDescriptionsLabelProvider.getText(eObjectDescription);
                    }
                }
            }
            return "unknown";
        }

        @Override
        public Image getImage(Object element) {
            IReferenceDescription referenceDescription = (IReferenceDescription) element;
            URI containerEObjectURI = referenceDescription.getContainerEObjectURI();
            final URI eObjectURI = (containerEObjectURI == null) ? referenceDescription.getSourceEObjectUri() : containerEObjectURI;
            IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI.trimFragment());
            if (resourceDescription != null) {
                for (IEObjectDescription eObjectDescription : resourceDescription.getExportedObjects()) {
                    if (eObjectDescription.getEObjectURI().equals(eObjectURI)) {
                        return globalDescriptionsLabelProvider.getImage(eObjectDescription);
                    }
                }
            }
            return null;
        }
    };
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.

the class EObjectDescriptionBasedStubGeneratorTest method testNested.

@Test
public void testNested() {
    final EObjectDescription _top = new EObjectDescription(QualifiedName.create("foo", "Bar"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.<String, String>emptyMap());
    final EObjectDescription _nested0 = new EObjectDescription(QualifiedName.create("foo", "Bar$Baz0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
    final EObjectDescription _nested1 = new EObjectDescription(QualifiedName.create("foo", "Bar$Baz1"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
    final EObjectDescription _nested10 = new EObjectDescription(QualifiedName.create("foo", "Bar$Baz1$FooBar0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
    final EObjectDescription _nested11 = new EObjectDescription(QualifiedName.create("foo", "Bar$Baz1$FooBar0"), TypesFactory.eINSTANCE.createJvmGenericType(), Collections.singletonMap(JvmTypesResourceDescriptionStrategy.IS_NESTED_TYPE, Boolean.TRUE.toString()));
    IResourceDescription resourceDescription = new AbstractResourceDescription() {

        @Override
        public URI getURI() {
            return null;
        }

        @Override
        public Iterable<IReferenceDescription> getReferenceDescriptions() {
            return Collections.emptyList();
        }

        @Override
        public Iterable<QualifiedName> getImportedNames() {
            return Collections.emptyList();
        }

        @Override
        protected List<IEObjectDescription> computeExportedObjects() {
            return Arrays.asList(new IEObjectDescription[] { _top, _nested0, _nested1, _nested10, _nested11 });
        }
    };
    assertEquals("package foo;\n" + "public class Bar{\n" + "public static class Baz0{\n" + "}\n" + "public static class Baz1{\n" + "public static class FooBar0{\n" + "}\n" + "public static class FooBar0{\n" + "}\n" + "}\n" + "}", gen.getJavaStubSource(_top, resourceDescription));
}
Also used : EObjectDescription(org.eclipse.xtext.resource.EObjectDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) AbstractResourceDescription(org.eclipse.xtext.resource.impl.AbstractResourceDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 3 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.

the class BuilderUtil method getContainedReferences.

public static Set<IReferenceDescription> getContainedReferences(URI uri) {
    Set<IReferenceDescription> desc = Sets.newHashSet();
    Iterable<IResourceDescription> descriptions = getBuilderState().getAllResourceDescriptions();
    for (IResourceDescription res : descriptions) {
        Iterable<IReferenceDescription> descriptions2 = res.getReferenceDescriptions();
        for (IReferenceDescription ref : descriptions2) {
            if (uri.hasFragment()) {
                if (ref.getSourceEObjectUri().equals(uri))
                    desc.add(ref);
            } else {
                if (ref.getSourceEObjectUri().trimFragment().equals(uri.trimFragment()))
                    desc.add(ref);
            }
        }
    }
    return desc;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 4 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.

the class AbstractEMFBasedPersisterTest method testReferencesArePersisted.

@Test
public void testReferencesArePersisted() {
    IResourceDescription resourceDescription = createResourceDescription(0);
    persister.save(singleton(resourceDescription));
    IResourceDescription loaded = persister.load().iterator().next();
    IReferenceDescription next = loaded.getReferenceDescriptions().iterator().next();
    assertNotNull(next.getEReference());
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) Test(org.junit.Test)

Example 5 with IReferenceDescription

use of org.eclipse.xtext.resource.IReferenceDescription in project xtext-eclipse by eclipse.

the class ReferenceDescriptionSorter method sortByResource.

public Multimap<URI, IReferenceDescription> sortByResource(Iterable<IReferenceDescription> referenceDescriptions) {
    Multimap<URI, IReferenceDescription> referencesByResourceURI = HashMultimap.create();
    for (IReferenceDescription referenceDescription : referenceDescriptions) {
        URI sourceResourceUri = referenceDescription.getSourceEObjectUri().trimFragment();
        referencesByResourceURI.put(sourceResourceUri, referenceDescription);
    }
    return referencesByResourceURI;
}
Also used : URI(org.eclipse.emf.common.util.URI) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Aggregations

IReferenceDescription (org.eclipse.xtext.resource.IReferenceDescription)41 URI (org.eclipse.emf.common.util.URI)18 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)16 EObject (org.eclipse.emf.ecore.EObject)12 Test (org.junit.Test)11 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)8 SubMonitor (org.eclipse.core.runtime.SubMonitor)7 EReference (org.eclipse.emf.ecore.EReference)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 EClass (org.eclipse.emf.ecore.EClass)3 EPackage (org.eclipse.emf.ecore.EPackage)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 Main (org.eclipse.xtext.linking.langATestLanguage.Main)3