source: default/trunk/de.ugoe.cs.swe.bnftools.ebnf/src/de/ugoe/cs/swe/bnftools/utils/EObjectResolver.java @ 5

Last change on this file since 5 was 5, checked in by zeiss, 14 years ago
  • Property svn:mime-type set to text/plain
File size: 1.7 KB
Line 
1package de.ugoe.cs.swe.bnftools.utils;
2
3import java.util.Iterator;
4
5import org.eclipse.emf.common.util.URI;
6import org.eclipse.emf.ecore.EObject;
7import org.eclipse.emf.ecore.util.EcoreUtil;
8import org.eclipse.xtext.resource.IEObjectDescription;
9import org.eclipse.xtext.resource.IResourceDescription;
10import org.eclipse.xtext.resource.IResourceDescriptions;
11import org.eclipse.xtext.resource.XtextResource;
12import org.eclipse.xtext.util.concurrent.IUnitOfWork;
13import com.google.common.base.Predicate;
14import com.google.common.collect.Iterables;
15
16public class EObjectResolver implements
17                IUnitOfWork<IEObjectDescription, XtextResource> {
18        private IResourceDescriptions resourceDescriptions;
19        private EObject element;
20
21        public EObjectResolver(EObject element,
22                        IResourceDescriptions resourceDescriptions) {
23                this.element = element;
24                this.resourceDescriptions = resourceDescriptions;
25        }
26
27        public IEObjectDescription exec(XtextResource state) throws Exception {
28                if (element != null) {
29                        final URI eObjectURI = EcoreUtil.getURI(element);
30                        IResourceDescription resourceDescription = resourceDescriptions
31                                        .getResourceDescription(eObjectURI.trimFragment());
32                        if (resourceDescription != null) {
33                                Iterator<IEObjectDescription> eObjectDescriptions = Iterables
34                                                .filter(resourceDescription.getExportedObjects(),
35                                                                new Predicate<IEObjectDescription>() {
36                                                                        public boolean apply(
37                                                                                        IEObjectDescription input) {
38                                                                                return input.getEObjectURI().equals(
39                                                                                                eObjectURI);
40                                                                        }
41                                                                }).iterator();
42                                if (eObjectDescriptions.hasNext()) {
43                                        return eObjectDescriptions.next();
44                                }
45                        }
46                }
47                return null;
48        }
49}
Note: See TracBrowser for help on using the repository browser.