use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createEclipsePluginGenModule.
public JavaFileAccess createEclipsePluginGenModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
TypeReference _elvis = null;
TypeReference _superClass = langConfig.getEclipsePluginGenModule().getSuperClass();
if (_superClass != null) {
_elvis = _superClass;
} else {
TypeReference _eclipsePluginDefaultModule = this.naming.getEclipsePluginDefaultModule(it);
_elvis = _eclipsePluginDefaultModule;
}
final TypeReference superClass = _elvis;
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getEclipsePluginGenModule(it));
file.setImportNestedTypeThreshold(JavaFileAccess.DONT_IMPORT_NESTED_TYPES);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Manual modifications go to {@link ");
String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginModule(it).getSimpleName();
_builder.append(_simpleName, " ");
_builder.append("}.");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
}
};
file.setTypeComment(_client);
List<IClassAnnotation> _annotations = file.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public abstract class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
String _simpleName_1 = XtextGeneratorTemplates.this.naming.getEclipsePluginGenModule(it).getSimpleName();
_builder.append(_simpleName_1, "\t");
_builder.append("(");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.ui.plugin.AbstractUIPlugin");
_builder.append(_typeRef, "\t");
_builder.append(" plugin) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("super(plugin);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
{
Set<GuiceModuleAccess.Binding> _bindings = langConfig.getEclipsePluginGenModule().getBindings();
for (final GuiceModuleAccess.Binding binding : _bindings) {
_builder.append("\t");
StringConcatenationClient _createBindingMethod = XtextGeneratorTemplates.this.createBindingMethod(binding);
_builder.append(_createBindingMethod, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client_1);
file.setMarkedAsGenerated(true);
return file;
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class BuilderIntegrationFragment2 method addRuntimeGuiceBindings.
protected void addRuntimeGuiceBindings() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IResourceDescriptions.class);
_builder.append(".class).to(");
_builder.append(ResourceSetBasedResourceDescriptions.class);
_builder.append(".class);");
}
};
final StringConcatenationClient statement1 = _client;
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IResourceDescriptions.class);
_builder.append(".class).annotatedWith(");
_builder.append(Names.class);
_builder.append(".named(");
_builder.append(ResourceDescriptionsProvider.class);
_builder.append(".PERSISTED_DESCRIPTIONS)).to(");
_builder.append(ResourceSetBasedResourceDescriptions.class);
_builder.append(".class);");
}
};
final StringConcatenationClient statement2 = _client_1;
GuiceModuleAccess.BindingFactory _addConfiguredBinding = new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IContainer.Manager.class), TypeReference.typeRef(StateBasedContainerManager.class)).addTypeToType(TypeReference.typeRef(IAllContainersState.Provider.class), TypeReference.typeRef(ResourceSetBasedAllContainersStateProvider.class)).addConfiguredBinding(IResourceDescriptions.class.getSimpleName(), statement1);
String _simpleName = IResourceDescriptions.class.getSimpleName();
String _plus = (_simpleName + "Persisted");
_addConfiguredBinding.addConfiguredBinding(_plus, statement2).contributeTo(this.getLanguage().getRuntimeGenModule());
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method generate.
@Override
public void generate() {
boolean _isEmpty = IterableExtensions.isEmpty(Iterables.<GeneratedMetamodel>filter(this.getGrammar().getMetamodelDeclarations(), GeneratedMetamodel.class));
if (_isEmpty) {
return;
}
try {
final Grammar clonedGrammar = this.cloneGrammarIntoNewResourceSet(this.getGrammar());
final ResourceSet workingResourceSet = clonedGrammar.eResource().getResourceSet();
final Function1<GeneratedMetamodel, EPackage> _function = (GeneratedMetamodel it) -> {
return it.getEPackage();
};
final List<EPackage> generatedPackages = IterableExtensions.<EPackage>toList(IterableExtensions.<GeneratedMetamodel, EPackage>map(Iterables.<GeneratedMetamodel>filter(clonedGrammar.getMetamodelDeclarations(), GeneratedMetamodel.class), _function));
if ((this.genModel != null)) {
this.registerUsedGenModel(workingResourceSet.getURIConverter(), clonedGrammar);
}
boolean _isEmpty_1 = generatedPackages.isEmpty();
boolean _not = (!_isEmpty_1);
if (_not) {
final Map<String, EPackage> usedEPackages = this.findAllUsedEPackages(generatedPackages);
final Map<String, EPackage> loadedEPackages = this.findEPackagesInGenPackages(usedEPackages.keySet(), workingResourceSet);
final Map<EObject, EObject> eNamedElementMapping = this.createENamedElementMapping(usedEPackages, loadedEPackages);
this.replaceReferencesInGeneratedPackages(generatedPackages, eNamedElementMapping);
final Resource ePackageResource = this.createResourceForEPackages(clonedGrammar, generatedPackages, workingResourceSet);
if ((!this.skipGenerate)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Generating EMF model");
{
if (this.generateEdit) {
{
if (this.generateEditor) {
_builder.append(", edit");
} else {
_builder.append(" and edit");
}
}
}
}
{
if (this.generateEditor) {
_builder.append(" and editor");
}
}
_builder.append(" code");
EMFGeneratorFragment2.LOG.info(_builder);
final GenModel genModel = this.getSaveAndReconcileGenModel(clonedGrammar, generatedPackages, workingResourceSet);
genModel.reconcile();
this.doGenerate(genModel);
this.addProjectContributions(clonedGrammar, generatedPackages, workingResourceSet);
if (this.bindEPackageAndEFactory) {
for (final EPackage pkg : generatedPackages) {
{
final GenPackage genPkg = GenModelUtil2.getGenPackage(pkg, genModel.eResource().getResourceSet());
GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
TypeReference _typeRef = TypeReference.typeRef(genPkg.getQualifiedPackageInterfaceName());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _packageInterfaceName = genPkg.getPackageInterfaceName();
_builder.append(_packageInterfaceName);
_builder.append(".eINSTANCE");
}
};
GuiceModuleAccess.BindingFactory _addTypeToInstance = _bindingFactory.addTypeToInstance(_typeRef, _client);
TypeReference _typeRef_1 = TypeReference.typeRef(genPkg.getQualifiedFactoryInterfaceName());
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _factoryInterfaceName = genPkg.getFactoryInterfaceName();
_builder.append(_factoryInterfaceName);
_builder.append(".eINSTANCE");
}
};
_addTypeToInstance.addTypeToInstance(_typeRef_1, _client_1).contributeTo(this.getLanguage().getRuntimeGenModule());
}
}
}
}
this.saveResource(ePackageResource);
}
this.updateBuildProperties();
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception) _t;
EMFGeneratorFragment2.LOG.error("Failed to execute EMF generator", e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class Formatter2Fragment2 method doGenerateStubFile.
protected void doGenerateStubFile() {
boolean _isGenerateStub = this.isGenerateStub();
boolean _not = (!_isGenerateStub);
if (_not) {
return;
}
boolean _isGenerateXtendStub = this.isGenerateXtendStub();
if (_isGenerateXtendStub) {
final XtendFileAccess xtendFile = this.fileAccessFactory.createXtendFile(this.getFormatter2Stub(this.getGrammar()));
xtendFile.setResourceSet(this.getLanguage().getResourceSet());
final LinkedHashMultimap<EClass, EReference> type2ref = LinkedHashMultimap.<EClass, EReference>create();
this.getLocallyAssignedContainmentReferences(this.getLanguage().getGrammar(), type2ref);
final LinkedHashMultimap<EClass, EReference> inheritedTypes = LinkedHashMultimap.<EClass, EReference>create();
this.getInheritedContainmentReferences(this.getLanguage().getGrammar(), inheritedTypes, CollectionLiterals.<Grammar>newHashSet());
final Set<EClass> types = type2ref.keySet();
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("class ");
String _simpleName = Formatter2Fragment2.this.getFormatter2Stub(Formatter2Fragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _stubSuperClass = Formatter2Fragment2.this.getStubSuperClass();
_builder.append(_stubSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.append(" extension ");
TypeReference _grammarAccess = Formatter2Fragment2.this._grammarAccessExtensions.getGrammarAccess(Formatter2Fragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.newLineIfNotEmpty();
{
Iterable<EClass> _take = IterableExtensions.<EClass>take(types, 2);
for (final EClass type : _take) {
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _generateFormatMethod = Formatter2Fragment2.this.generateFormatMethod(type, type2ref.get(type), inheritedTypes.containsKey(type));
_builder.append(_generateFormatMethod, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("// TODO: implement for ");
final Function1<EClass, String> _function = (EClass it) -> {
return it.getName();
};
String _join = IterableExtensions.join(IterableExtensions.<EClass, String>map(IterableExtensions.<EClass>drop(types, 2), _function), ", ");
_builder.append(_join, "\t");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
}
};
xtendFile.setContent(_client);
xtendFile.writeTo(this.getProjectConfig().getRuntime().getSrc());
} else {
String _name = this.getClass().getName();
String _plus = (_name + " has been configured to generate a Java stub, but that\'s not yet supported. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=481563");
Formatter2Fragment2.LOG.error(_plus);
}
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class Formatter2Fragment2 method generate.
@Override
public void generate() {
boolean _isGenerateStub = this.isGenerateStub();
boolean _not = (!_isGenerateStub);
if (_not) {
return;
}
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("binder.bind(");
_builder.append(IPreferenceValuesProvider.class);
_builder.append(".class).annotatedWith(");
_builder.append(FormatterPreferences.class);
_builder.append(".class).to(");
_builder.append(FormatterPreferenceValuesProvider.class);
_builder.append(".class);");
}
};
final StringConcatenationClient statement = _client;
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef(IFormatter2.class), this.getFormatter2Stub(this.getLanguage().getGrammar())).addConfiguredBinding(FormatterPreferences.class.getSimpleName(), statement).contributeTo(this.getLanguage().getRuntimeGenModule());
new GuiceModuleAccess.BindingFactory().addTypeToType(TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting.IContentFormatterFactory"), TypeReference.typeRef("org.eclipse.xtext.ui.editor.formatting2.ContentFormatterFactory")).contributeTo(this.getLanguage().getEclipsePluginGenModule());
ManifestAccess _manifest = this.getProjectConfig().getRuntime().getManifest();
boolean _tripleNotEquals = (_manifest != null);
if (_tripleNotEquals) {
Set<String> _exportedPackages = this.getProjectConfig().getRuntime().getManifest().getExportedPackages();
String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
String _plus = (_runtimeBasePackage + ".formatting2");
_exportedPackages.add(_plus);
}
this.doGenerateStubFile();
}
Aggregations