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.naming.IQualifiedNameProvider; |
---|
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.google.common.base.Predicate; |
---|
16 | import com.google.common.collect.Iterables; |
---|
17 | import com.google.common.collect.Lists; |
---|
18 | |
---|
19 | public class FramScriptResourceDescription extends DefaultResourceDescription { |
---|
20 | |
---|
21 | public FramScriptResourceDescription(Resource resource, |
---|
22 | IQualifiedNameProvider nameProvider) { |
---|
23 | super(resource, nameProvider); |
---|
24 | } |
---|
25 | |
---|
26 | @Override |
---|
27 | protected List<IEObjectDescription> computeExportedObjects() { |
---|
28 | List<IEObjectDescription> objects = super.computeExportedObjects(); |
---|
29 | Iterable<IEObjectDescription> filter = Iterables.filter(objects, |
---|
30 | new Predicate<IEObjectDescription>() { |
---|
31 | |
---|
32 | @Override |
---|
33 | public boolean apply(IEObjectDescription desc) { |
---|
34 | EObject input = desc.getEObjectOrProxy(); |
---|
35 | return shouldExport(input); |
---|
36 | } |
---|
37 | |
---|
38 | }); |
---|
39 | return Lists.newArrayList(filter); |
---|
40 | } |
---|
41 | |
---|
42 | protected boolean shouldExport(EObject input) { |
---|
43 | return input instanceof com.framsticks.framclipse.framScript.Function |
---|
44 | || input instanceof Property || input instanceof State |
---|
45 | || isGlobal(input); |
---|
46 | } |
---|
47 | |
---|
48 | private boolean isGlobal(EObject input) { |
---|
49 | if (input instanceof VariableDeclaration) { |
---|
50 | VariableDeclaration dec = (VariableDeclaration) input; |
---|
51 | return dec.eContainer().eContainer() instanceof Code; |
---|
52 | } |
---|
53 | return false; |
---|
54 | } |
---|
55 | |
---|
56 | } |
---|