1 | package com.framsticks.framclipse.resource; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.eclipse.emf.ecore.EObject; |
---|
6 | import org.eclipse.emf.ecore.resource.Resource; |
---|
7 | import org.eclipse.xtext.resource.IDefaultResourceDescriptionStrategy; |
---|
8 | import org.eclipse.xtext.resource.IEObjectDescription; |
---|
9 | import org.eclipse.xtext.resource.impl.DefaultResourceDescription; |
---|
10 | |
---|
11 | import com.framsticks.framclipse.framScript.Code; |
---|
12 | import com.framsticks.framclipse.framScript.Property; |
---|
13 | import com.framsticks.framclipse.framScript.State; |
---|
14 | import com.framsticks.framclipse.framScript.VariableDeclaration; |
---|
15 | import com.framsticks.framclipse.framScript.VariableDeclarations; |
---|
16 | import com.google.common.base.Predicate; |
---|
17 | import com.google.common.collect.Iterables; |
---|
18 | import com.google.common.collect.Lists; |
---|
19 | |
---|
20 | public 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 | } |
---|