Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8fd88e4d85f756f8c4057a45c08d9d8bc77d96d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package org.eclipse.emf.parsley.dsl.generator;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.parsley.dsl.generator.EmfParsleyDslOutputConfigurationProvider;
import org.eclipse.emf.parsley.dsl.jvmmodel.EmfParsleyDslJvmModelInferrer;
import org.eclipse.emf.parsley.dsl.model.Module;
import org.eclipse.emf.parsley.dsl.model.PartSpecification;
import org.eclipse.emf.parsley.dsl.model.ViewSpecification;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.common.types.JvmTypeReference;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;

@SuppressWarnings("all")
public class EmfParsleyDslPluginXmlGenerator implements IGenerator {
  @Inject
  private EmfParsleyDslJvmModelInferrer inferrer;
  
  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    TreeIterator<EObject> _allContents = resource.getAllContents();
    Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(_allContents);
    Iterable<Module> _filter = Iterables.<Module>filter(_iterable, Module.class);
    for (final Module module : _filter) {
      {
        final CharSequence contents = this.generatePluginXml(module);
        int _length = 0;
        if (contents!=null) {
          _length=contents.length();
        }
        boolean _greaterThan = (_length > 0);
        if (_greaterThan) {
          fsa.generateFile(
            EmfParsleyDslOutputConfigurationProvider.PLUGIN_XML_EMFPARSLEY_GEN_PATH, 
            EmfParsleyDslOutputConfigurationProvider.PROJECT_ROOT_OUTPUT, contents);
        }
      }
    }
  }
  
  public CharSequence generatePluginXml(final Module module) {
    CharSequence _xblockexpression = null;
    {
      EList<PartSpecification> _parts = null;
      if (module!=null) {
        _parts=module.getParts();
      }
      final EList<PartSpecification> partSpecs = _parts;
      CharSequence _xifexpression = null;
      boolean _or = false;
      boolean _equals = Objects.equal(partSpecs, null);
      if (_equals) {
        _or = true;
      } else {
        boolean _isEmpty = partSpecs.isEmpty();
        _or = (_equals || _isEmpty);
      }
      if (_or) {
        StringConcatenation _builder = new StringConcatenation();
        return _builder.toString();
      } else {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("<extension");
        _builder_1.newLine();
        _builder_1.append("      ");
        _builder_1.append("point=\"org.eclipse.ui.views\">");
        _builder_1.newLine();
        _builder_1.append("    ");
        final Function1<PartSpecification,CharSequence> _function = new Function1<PartSpecification,CharSequence>() {
            public CharSequence apply(final PartSpecification it) {
              CharSequence _generateExtensionPoint = EmfParsleyDslPluginXmlGenerator.this.generateExtensionPoint(it);
              return _generateExtensionPoint;
            }
          };
        List<CharSequence> _map = ListExtensions.<PartSpecification, CharSequence>map(partSpecs, _function);
        String _join = IterableExtensions.join(_map, "");
        _builder_1.append(_join, "    ");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("</extension>");
        _builder_1.newLine();
        CharSequence _generatePluginXml = this.generatePluginXml(_builder_1);
        _xifexpression = _generatePluginXml;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
  
  protected CharSequence _generateExtensionPoint(final PartSpecification partSpecification) {
    return null;
  }
  
  protected CharSequence _generateExtensionPoint(final ViewSpecification viewSpecification) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<view");
    _builder.newLine();
    _builder.append("      ");
    _builder.append("category=\"");
    String _xifexpression = null;
    boolean _or = false;
    String _category = viewSpecification.getCategory();
    boolean _equals = Objects.equal(_category, null);
    if (_equals) {
      _or = true;
    } else {
      String _category_1 = viewSpecification.getCategory();
      boolean _isEmpty = _category_1.isEmpty();
      _or = (_equals || _isEmpty);
    }
    if (_or) {
      _xifexpression = "org.eclipse.emf.parsley";
    } else {
      String _category_2 = viewSpecification.getCategory();
      _xifexpression = _category_2;
    }
    _builder.append(_xifexpression, "      ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("      ");
    _builder.append("class=\"");
    String _executableExtensionFactoryQN = this.inferrer.executableExtensionFactoryQN(viewSpecification);
    _builder.append(_executableExtensionFactoryQN, "      ");
    _builder.append(":");
    JvmTypeReference _type = viewSpecification.getType();
    String _identifier = _type.getIdentifier();
    _builder.append(_identifier, "      ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("      ");
    _builder.append("id=\"");
    String _id = viewSpecification.getId();
    _builder.append(_id, "      ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("      ");
    _builder.append("name=\"");
    String _viewName = viewSpecification.getViewName();
    _builder.append(_viewName, "      ");
    _builder.append("\"");
    _builder.newLineIfNotEmpty();
    _builder.append("      ");
    _builder.append("restorable=\"true\">");
    _builder.newLine();
    _builder.append("</view>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence generatePluginXml(final CharSequence contents) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    _builder.newLine();
    _builder.append("<?eclipse version=\"3.4\"?>");
    _builder.newLine();
    _builder.append("<plugin>");
    _builder.newLine();
    _builder.append("\t");
    _builder.append(contents, "	");
    _builder.newLineIfNotEmpty();
    _builder.append("</plugin>");
    _builder.newLine();
    return _builder;
  }
  
  public CharSequence generateExtensionPoint(final PartSpecification viewSpecification) {
    if (viewSpecification instanceof ViewSpecification) {
      return _generateExtensionPoint((ViewSpecification)viewSpecification);
    } else if (viewSpecification != null) {
      return _generateExtensionPoint(viewSpecification);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(viewSpecification).toString());
    }
  }
}

Back to the top