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;
}
};
}
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));
}
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;
}
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());
}
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;
}
Aggregations