-
Notifications
You must be signed in to change notification settings - Fork 316
/
ImportNamespacesScopingFragment2.java
314 lines (296 loc) · 13.8 KB
/
ImportNamespacesScopingFragment2.java
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/**
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.xtext.generator.scoping;
import com.google.inject.Inject;
import com.google.inject.name.Names;
import java.util.Objects;
import java.util.Set;
import org.eclipse.xtend.lib.annotations.AccessorType;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend2.lib.StringConcatenationClient;
import org.eclipse.xtext.Grammar;
import org.eclipse.xtext.GrammarUtil;
import org.eclipse.xtext.scoping.IGlobalScopeProvider;
import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.scoping.IgnoreCaseLinking;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import org.eclipse.xtext.scoping.impl.DefaultGlobalScopeProvider;
import org.eclipse.xtext.scoping.impl.DelegatingScopeProvider;
import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xtext.generator.AbstractInheritingFragment;
import org.eclipse.xtext.xtext.generator.XtextGeneratorNaming;
import org.eclipse.xtext.xtext.generator.model.FileAccessFactory;
import org.eclipse.xtext.xtext.generator.model.GeneratedJavaFileAccess;
import org.eclipse.xtext.xtext.generator.model.GuiceModuleAccess;
import org.eclipse.xtext.xtext.generator.model.ManifestAccess;
import org.eclipse.xtext.xtext.generator.model.TypeReference;
import org.eclipse.xtext.xtext.generator.util.GrammarUtil2;
import org.eclipse.xtext.xtext.generator.xbase.XbaseUsageDetector;
@SuppressWarnings("all")
public class ImportNamespacesScopingFragment2 extends AbstractInheritingFragment {
@Inject
@Extension
private XtextGeneratorNaming _xtextGeneratorNaming;
@Inject
@Extension
private XbaseUsageDetector _xbaseUsageDetector;
@Inject
private FileAccessFactory fileAccessFactory;
@Accessors({ AccessorType.PUBLIC_SETTER, AccessorType.PROTECTED_GETTER })
private boolean ignoreCase = false;
protected TypeReference getScopeProviderClass(final Grammar grammar) {
String _name = grammar.getName();
boolean _equals = Objects.equals(_name, "org.eclipse.xtext.xbase.Xbase");
if (_equals) {
return TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider");
}
String _name_1 = grammar.getName();
boolean _equals_1 = Objects.equals(_name_1, "org.eclipse.xtext.xbase.annotations.XbaseWithAnnotations");
if (_equals_1) {
return TypeReference.typeRef("org.eclipse.xtext.xbase.annotations.typesystem.XbaseWithAnnotationsBatchScopeProvider");
}
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(grammar);
String _plus = (_runtimeBasePackage + ".scoping.");
String _simpleName = GrammarUtil.getSimpleName(grammar);
String _plus_1 = (_plus + _simpleName);
String _plus_2 = (_plus_1 + "ScopeProvider");
return new TypeReference(_plus_2);
}
protected TypeReference getAbstractScopeProviderClass(final Grammar grammar) {
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(grammar);
String _plus = (_runtimeBasePackage + ".scoping.");
String _plus_1 = (_plus + "Abstract");
String _simpleName = GrammarUtil.getSimpleName(grammar);
String _plus_2 = (_plus_1 + _simpleName);
String _plus_3 = (_plus_2 + "ScopeProvider");
return new TypeReference(_plus_3);
}
protected TypeReference getScopeProviderSuperClass(final Grammar grammar) {
final Grammar superGrammar = GrammarUtil2.getNonTerminalsSuperGrammar(grammar);
if ((this.isInheritImplementation() && (superGrammar != null))) {
return this.getScopeProviderClass(superGrammar);
} else {
return this.getDefaultScopeProviderSuperClass();
}
}
protected TypeReference getDefaultScopeProviderSuperClass() {
TypeReference _xifexpression = null;
boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
if (_inheritsXbase) {
_xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.batch.XbaseBatchScopeProvider");
} else {
_xifexpression = TypeReference.typeRef(DelegatingScopeProvider.class);
}
return _xifexpression;
}
protected TypeReference getDelegateScopeProvider() {
TypeReference _xifexpression = null;
boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
if (_inheritsXbase) {
_xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider");
} else {
_xifexpression = TypeReference.typeRef(ImportedNamespaceAwareLocalScopeProvider.class);
}
return _xifexpression;
}
protected TypeReference getGlobalScopeProvider() {
return TypeReference.typeRef(DefaultGlobalScopeProvider.class);
}
@Override
public void generate() {
this.contributeRuntimeGuiceBindings();
this.generateGenScopeProvider();
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
boolean _isGenerateXtendStub = this.isGenerateXtendStub();
if (_isGenerateXtendStub) {
this.generateXtendScopeProvider();
} else {
this.generateJavaScopeProvider();
}
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
String _packageName = this.getScopeProviderClass(this.getGrammar()).getPackageName();
_exportedPackages.add(_packageName);
boolean _isGenerateXtendStub_1 = this.isGenerateXtendStub();
if (_isGenerateXtendStub_1) {
Set<String> _requiredBundles = this.getProjectConfig().getRuntime().getManifest().getRequiredBundles();
String _xbaseLibVersionLowerBound = this.getProjectConfig().getRuntime().getXbaseLibVersionLowerBound();
String _plus = ("org.eclipse.xtext.xbase.lib;bundle-version=\"" + _xbaseLibVersionLowerBound);
String _plus_1 = (_plus + "\"");
_requiredBundles.add(_plus_1);
}
}
}
}
protected void contributeRuntimeGuiceBindings() {
final GuiceModuleAccess.BindingFactory bindingFactory = new GuiceModuleAccess.BindingFactory();
TypeReference _xifexpression = null;
boolean _inheritsXbase = this._xbaseUsageDetector.inheritsXbase(this.getLanguage().getGrammar());
if (_inheritsXbase) {
_xifexpression = TypeReference.typeRef("org.eclipse.xtext.xbase.scoping.batch.IBatchScopeProvider");
} else {
_xifexpression = TypeReference.typeRef(IScopeProvider.class);
}
final TypeReference targetType = _xifexpression;
bindingFactory.addTypeToType(targetType, this.getScopeProviderClass(this.getGrammar()));
String _simpleName = IScopeProvider.class.getSimpleName();
String _plus = (_simpleName + "Delegate");
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IScopeProvider.class);
_builder.append(".class).annotatedWith(");
_builder.append(Names.class);
_builder.append(".named(");
_builder.append(AbstractDeclarativeScopeProvider.class);
_builder.append(".NAMED_DELEGATE)).to(");
TypeReference _delegateScopeProvider = ImportNamespacesScopingFragment2.this.getDelegateScopeProvider();
_builder.append(_delegateScopeProvider);
_builder.append(".class);");
}
};
bindingFactory.addConfiguredBinding(_plus, _client);
bindingFactory.addTypeToType(TypeReference.typeRef(IGlobalScopeProvider.class), this.getGlobalScopeProvider());
String _simpleName_1 = IgnoreCaseLinking.class.getSimpleName();
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bindConstant().annotatedWith(");
_builder.append(IgnoreCaseLinking.class);
_builder.append(".class).to(");
_builder.append(ImportNamespacesScopingFragment2.this.ignoreCase);
_builder.append(");");
}
};
bindingFactory.addConfiguredBinding(_simpleName_1, _client_1);
bindingFactory.contributeTo(this.getLanguage().getRuntimeGenModule());
}
protected void generateGenScopeProvider() {
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getAbstractScopeProviderClass(this.getGrammar());
} else {
_xifexpression = this.getScopeProviderClass(this.getGrammar());
}
final TypeReference genClass = _xifexpression;
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(genClass);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = ImportNamespacesScopingFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = genClass.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _scopeProviderSuperClass = ImportNamespacesScopingFragment2.this.getScopeProviderSuperClass(ImportNamespacesScopingFragment2.this.getGrammar());
_builder.append(_scopeProviderSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
file.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
protected void generateJavaScopeProvider() {
TypeReference _scopeProviderClass = this.getScopeProviderClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* This class contains custom scoping description.");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
_builder.newLine();
_builder.append(" ");
_builder.append("* on how and when to use it.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public class ");
String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
_builder.append(_abstractScopeProviderClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createJavaFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
protected void generateXtendScopeProvider() {
TypeReference _scopeProviderClass = this.getScopeProviderClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* This class contains custom scoping description.");
_builder.newLine();
_builder.append(" ");
_builder.append("* ");
_builder.newLine();
_builder.append(" ");
_builder.append("* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping");
_builder.newLine();
_builder.append(" ");
_builder.append("* on how and when to use it.");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("class ");
String _simpleName = ImportNamespacesScopingFragment2.this.getScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _abstractScopeProviderClass = ImportNamespacesScopingFragment2.this.getAbstractScopeProviderClass(ImportNamespacesScopingFragment2.this.getGrammar());
_builder.append(_abstractScopeProviderClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createXtendFile(_scopeProviderClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
@Pure
protected boolean isIgnoreCase() {
return this.ignoreCase;
}
public void setIgnoreCase(final boolean ignoreCase) {
this.ignoreCase = ignoreCase;
}
}