use of org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation in project xtext-core by eclipse.
the class SerializerFragment2 method generateAbstractSyntacticSequencer.
protected void generateAbstractSyntacticSequencer() {
TypeReference _xifexpression = null;
boolean _isGenerateStub = this.isGenerateStub();
if (_isGenerateStub) {
_xifexpression = this.getAbstractSyntacticSequencerClass(this.getGrammar());
} else {
_xifexpression = this.getSyntacticSequencerClass(this.getGrammar());
}
final TypeReference clazz = _xifexpression;
final GeneratedJavaFileAccess javaFile = this.fileAccessFactory.createGeneratedJavaFile(clazz);
javaFile.setResourceSet(this.getLanguage().getResourceSet());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public ");
{
boolean _isGenerateStub = SerializerFragment2.this.isGenerateStub();
if (_isGenerateStub) {
_builder.append("abstract ");
}
}
_builder.append("class ");
String _simpleName = clazz.getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(AbstractSyntacticSequencer.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("protected ");
TypeReference _grammarAccess = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
_builder.append(_grammarAccess, "\t");
_builder.append(" grammarAccess;");
_builder.newLineIfNotEmpty();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group : _allAmbiguousTransitionsBySyntax) {
_builder.append("\t");
_builder.append("protected ");
TypeReference _typeReference = new TypeReference("org.eclipse.xtext.serializer.analysis", "GrammarAlias.AbstractElementAlias");
_builder.append(_typeReference, "\t");
_builder.append(" match_");
String _identifier = group.getIdentifier();
_builder.append(_identifier, "\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@");
_builder.append(Inject.class, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("protected void init(");
_builder.append(IGrammarAccess.class, "\t");
_builder.append(" access) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("grammarAccess = (");
TypeReference _grammarAccess_1 = SerializerFragment2.this._grammarAccessExtensions.getGrammarAccess(SerializerFragment2.this.getGrammar());
_builder.append(_grammarAccess_1, "\t\t");
_builder.append(") access;");
_builder.newLineIfNotEmpty();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_1 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group_1 : _allAmbiguousTransitionsBySyntax_1) {
_builder.append("\t\t");
_builder.append("match_");
String _identifier_1 = group_1.getIdentifier();
_builder.append(_identifier_1, "\t\t");
_builder.append(" = ");
StringConcatenationClient _elementAliasToConstructor = SerializerFragment2.this._syntacticSequencerExtensions.elementAliasToConstructor(group_1.getElementAlias());
_builder.append(_elementAliasToConstructor, "\t\t");
_builder.append(";");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _genGetUnassignedRuleCallTokens = SerializerFragment2.this.genGetUnassignedRuleCallTokens();
_builder.append(_genGetUnassignedRuleCallTokens, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.newLine();
{
List<AbstractRule> _unassignedCalledTokenRules = SerializerFragment2.this.unassignedCalledTokenRules();
boolean _hasElements = false;
for (final AbstractRule rule : _unassignedCalledTokenRules) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate("\n", "\t");
}
_builder.append("\t");
StringConcatenationClient _genGetUnassignedRuleCallToken = SerializerFragment2.this.genGetUnassignedRuleCallToken(rule);
_builder.append(_genGetUnassignedRuleCallToken, "\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
StringConcatenationClient _genEmitUnassignedTokens = SerializerFragment2.this.genEmitUnassignedTokens();
_builder.append(_genEmitUnassignedTokens, "\t");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
List<EqualAmbiguousTransitions> _allAmbiguousTransitionsBySyntax_2 = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax();
for (final EqualAmbiguousTransitions group_2 : _allAmbiguousTransitionsBySyntax_2) {
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Ambiguous syntax:");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* ");
String _replace = group_2.getElementAlias().toString().replace("\n", "\n * ");
_builder.append(_replace, "\t ");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append(" ");
_builder.append("*");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* This ambiguous syntax occurs at:");
_builder.newLine();
{
final Function1<ISyntacticSequencerPDAProvider.ISynTransition, String> _function = (ISyntacticSequencerPDAProvider.ISynTransition it) -> {
return group_2.ambiguityInsideTransition(it).trim();
};
List<String> _sort = IterableExtensions.<String>sort(IterableExtensions.<String>toSet(ListExtensions.<ISyntacticSequencerPDAProvider.ISynTransition, String>map(group_2.getTransitions(), _function)));
for (final String trans : _sort) {
_builder.append("\t");
_builder.append(" ");
_builder.append("* ");
String _replace_1 = trans.toString().replace("\n", "\n* ");
_builder.append(_replace_1, "\t ");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void emit_");
String _identifier_2 = group_2.getIdentifier();
_builder.append(_identifier_2, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" semanticObject, ");
_builder.append(ISyntacticSequencerPDAProvider.ISynNavigable.class, "\t");
_builder.append(" transition, ");
_builder.append(List.class, "\t");
_builder.append("<");
_builder.append(INode.class, "\t");
_builder.append("> nodes) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("acceptNodes(transition, nodes);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
}
};
javaFile.setContent(_client);
List<IClassAnnotation> _annotations = javaFile.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
javaFile.writeTo(this.getProjectConfig().getRuntime().getSrcGen());
}
use of org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation in project xtext-core by eclipse.
the class GeneratedJavaFileAccess method getInternalContent.
@Override
public CharSequence getInternalContent() {
StringConcatenation _builder = new StringConcatenation();
_builder.append(this.typeComment);
_builder.newLineIfNotEmpty();
{
Set<IClassAnnotation> _classAnnotations = this.getClassAnnotations();
for (final IClassAnnotation annot : _classAnnotations) {
CharSequence _generate = annot.generate();
_builder.append(_generate);
_builder.newLineIfNotEmpty();
}
}
CharSequence _internalContent = super.getInternalContent();
_builder.append(_internalContent);
_builder.newLineIfNotEmpty();
return _builder;
}
use of org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation in project xtext-core by eclipse.
the class CodeConfig method getAnnotationImportsAsString.
public String getAnnotationImportsAsString() {
boolean _isEmpty = this.classAnnotations.isEmpty();
if (_isEmpty) {
return null;
}
final StringBuilder stringBuilder = new StringBuilder();
for (final IClassAnnotation annotation : this.classAnnotations) {
{
final TypeReference importString = annotation.getAnnotationImport();
if ((importString != null)) {
stringBuilder.append("import ").append(importString).append(";").append(Strings.newLine());
}
}
}
return stringBuilder.toString();
}
use of org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createRuntimeGenSetup.
public JavaFileAccess createRuntimeGenSetup(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getRuntimeGenSetup(it));
XtextGeneratorTemplates.addBackwardsCompabibleImportsTo(langConfig, file);
List<IClassAnnotation> _annotations = file.getAnnotations();
SuppressWarningsAnnotation _suppressWarningsAnnotation = new SuppressWarningsAnnotation();
_annotations.add(_suppressWarningsAnnotation);
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = XtextGeneratorTemplates.this.naming.getRuntimeGenSetup(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" implements ");
_builder.append(ISetup.class);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(Injector.class, "\t");
_builder.append(" createInjectorAndDoEMFRegistration() {");
_builder.newLineIfNotEmpty();
{
EList<Grammar> _usedGrammars = langConfig.getGrammar().getUsedGrammars();
for (final Grammar usedGrammar : _usedGrammars) {
_builder.append("\t\t");
TypeReference _runtimeSetup = XtextGeneratorTemplates.this.naming.getRuntimeSetup(usedGrammar);
_builder.append(_runtimeSetup, "\t\t");
_builder.append(".doSetup();");
_builder.newLineIfNotEmpty();
}
}
{
boolean _isEmpty = langConfig.getGrammar().getUsedGrammars().isEmpty();
if (_isEmpty) {
_builder.append("\t\t");
_builder.append("// register default ePackages");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"ecore\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_1 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_1, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"ecore\", new ");
TypeReference _typeRef_2 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl");
_builder.append(_typeRef_2, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_3 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_3, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xmi\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_4 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_4, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"xmi\", new ");
TypeReference _typeRef_5 = TypeReference.typeRef("org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl");
_builder.append(_typeRef_5, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_6 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_6, "\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(\"xtextbin\"))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_7 = TypeReference.typeRef("org.eclipse.emf.ecore.resource.Resource");
_builder.append(_typeRef_7, "\t\t\t");
_builder.append(".Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t\t");
_builder.append("\"xtextbin\", new ");
_builder.append(BinaryGrammarResourceFactoryImpl.class, "\t\t\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("if (!");
TypeReference _typeRef_8 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
_builder.append(_typeRef_8, "\t\t");
_builder.append(".Registry.INSTANCE.containsKey(");
_builder.append(XtextPackage.class, "\t\t");
_builder.append(".eNS_URI))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
TypeReference _typeRef_9 = TypeReference.typeRef("org.eclipse.emf.ecore.EPackage");
_builder.append(_typeRef_9, "\t\t\t");
_builder.append(".Registry.INSTANCE.put(");
_builder.append(XtextPackage.class, "\t\t\t");
_builder.append(".eNS_URI, ");
_builder.append(XtextPackage.class, "\t\t\t");
_builder.append(".eINSTANCE);");
_builder.newLineIfNotEmpty();
}
}
_builder.newLine();
_builder.append("\t\t");
_builder.append(Injector.class, "\t\t");
_builder.append(" injector = createInjector();");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("register(injector);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return injector;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public ");
_builder.append(Injector.class, "\t");
_builder.append(" createInjector() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return ");
_builder.append(Guice.class, "\t\t");
_builder.append(".createInjector(new ");
TypeReference _runtimeModule = XtextGeneratorTemplates.this.naming.getRuntimeModule(it);
_builder.append(_runtimeModule, "\t\t");
_builder.append("());");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public void register(");
_builder.append(Injector.class, "\t");
_builder.append(" injector) {");
_builder.newLineIfNotEmpty();
{
List<StringConcatenationClient> _registrations = langConfig.getRuntimeGenSetup().getRegistrations();
for (final StringConcatenationClient reg : _registrations) {
_builder.append("\t\t");
_builder.append(reg, "\t\t");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
file.setContent(_client);
return file;
}
use of org.eclipse.xtext.xtext.generator.model.annotations.IClassAnnotation in project xtext-core by eclipse.
the class XtextGeneratorTemplates method createIdeGenModule.
public JavaFileAccess createIdeGenModule(final IXtextGeneratorLanguage langConfig) {
final Grammar it = langConfig.getGrammar();
TypeReference _elvis = null;
TypeReference _superClass = langConfig.getIdeGenModule().getSuperClass();
if (_superClass != null) {
_elvis = _superClass;
} else {
TypeReference _genericIdeDefaultModule = this.naming.getGenericIdeDefaultModule(it);
_elvis = _genericIdeDefaultModule;
}
final TypeReference superClass = _elvis;
final GeneratedJavaFileAccess file = this.fileAccessFactory.createGeneratedJavaFile(this.naming.getGenericIdeGenModule(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.getGenericIdeModule(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.getGenericIdeGenModule(it).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
_builder.append(superClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.newLine();
{
Set<GuiceModuleAccess.Binding> _bindings = langConfig.getIdeGenModule().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;
}
Aggregations