source: java/Framclipse/com.framsticks.framclipse/src/com/framsticks/framclipse/resource/FramScriptResourceDescription.java @ 440

Last change on this file since 440 was 440, checked in by Mateusz Poszwa, 8 years ago
  • Updated Xtext-based Framclipse
  • Deleted previous version of Framclipse
  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1package com.framsticks.framclipse.resource;
2
3import java.util.List;
4
5import org.eclipse.emf.ecore.EObject;
6import org.eclipse.emf.ecore.resource.Resource;
7import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy;
8import org.eclipse.xtext.resource.IEObjectDescription;
9import org.eclipse.xtext.resource.impl.DefaultResourceDescription;
10
11import com.framsticks.framclipse.framScript.Code;
12import com.framsticks.framclipse.framScript.Property;
13import com.framsticks.framclipse.framScript.State;
14import com.framsticks.framclipse.framScript.VariableDeclaration;
15import com.framsticks.framclipse.framScript.VariableDeclarations;
16import com.google.common.base.Predicate;
17import com.google.common.collect.Iterables;
18import com.google.common.collect.Lists;
19
20public class FramScriptResourceDescription extends DefaultResourceDescription {
21
22        private Resource resource;
23
24        public FramScriptResourceDescription(Resource resource,
25                        IDefaultResourceDescriptionStrategy resourceDescriptionStrategy) {
26                super(resource, resourceDescriptionStrategy);
27                this.resource = resource;
28        }
29
30        @Override
31        protected List<IEObjectDescription> computeExportedObjects() {
32                List<IEObjectDescription> objects = super.computeExportedObjects();
33                Iterable<IEObjectDescription> filter = Iterables.filter(objects,
34                                new Predicate<IEObjectDescription>() {
35
36                                        @Override
37                                        public boolean apply(IEObjectDescription desc) {
38                                                EObject input = desc.getEObjectOrProxy();
39                                                return shouldExport(input);
40                                        }
41
42                                });
43                return Lists.newArrayList(filter);
44        }
45
46        protected boolean shouldExport(EObject input) {
47                return input instanceof com.framsticks.framclipse.framScript.Function
48                                || input instanceof Property || input instanceof State
49                                || isGlobal(input);
50        }
51
52        private boolean isGlobal(EObject input) {
53                if (input instanceof VariableDeclaration) {
54                        VariableDeclaration dec = (VariableDeclaration) input;
55                        EObject decs = dec.eContainer();
56                        return decs instanceof VariableDeclarations &&
57                                        (decs.eContainer() instanceof Code ||
58                                                        "inc".equals(resource.getURI().fileExtension()) &&
59                                                        decs.eContainer().eContainer() == null);
60                }
61                return false;
62        }
63
64}
Note: See TracBrowser for help on using the repository browser.