use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class SerializerFragment2 method generateSyntacticSequencer.
protected void generateSyntacticSequencer() {
boolean _isGenerateXtendStub = this.isGenerateXtendStub();
if (_isGenerateXtendStub) {
TypeReference _syntacticSequencerClass = this.getSyntacticSequencerClass(this.getGrammar());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("class ");
String _simpleName = SerializerFragment2.this.getSyntacticSequencerClass(SerializerFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _abstractSyntacticSequencerClass = SerializerFragment2.this.getAbstractSyntacticSequencerClass(SerializerFragment2.this.getGrammar());
_builder.append(_abstractSyntacticSequencerClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
if (SerializerFragment2.this.detectSyntheticTerminals) {
{
final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
return Boolean.valueOf(SerializerFragment2.this.syntheticTerminalDetector.isSyntheticTerminalRule(it));
};
Iterable<TerminalRule> _filter = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(SerializerFragment2.this.getGrammar()), _function);
for (final TerminalRule rule : _filter) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Stub implementation for a synthetic terminal rule. Defaults to the empty string.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("// TODO review the concrete syntax for the terminal");
_builder.newLine();
_builder.append("\t");
_builder.append("override ");
CharSequence _unassignedCalledTokenRuleName = SerializerFragment2.this.unassignedCalledTokenRuleName(rule);
_builder.append(_unassignedCalledTokenRuleName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" semanticObject, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
_builder.append(INode.class, "\t");
_builder.append(" node) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return \'\'");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createXtendFile(_syntacticSequencerClass, _client).writeTo(this.getProjectConfig().getRuntime().getSrc());
} else {
TypeReference _syntacticSequencerClass_1 = this.getSyntacticSequencerClass(this.getGrammar());
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("public class ");
String _simpleName = SerializerFragment2.this.getSyntacticSequencerClass(SerializerFragment2.this.getGrammar()).getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _abstractSyntacticSequencerClass = SerializerFragment2.this.getAbstractSyntacticSequencerClass(SerializerFragment2.this.getGrammar());
_builder.append(_abstractSyntacticSequencerClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
{
if (SerializerFragment2.this.detectSyntheticTerminals) {
{
final Function1<TerminalRule, Boolean> _function = (TerminalRule it) -> {
return Boolean.valueOf(SerializerFragment2.this.syntheticTerminalDetector.isSyntheticTerminalRule(it));
};
Iterable<TerminalRule> _filter = IterableExtensions.<TerminalRule>filter(GrammarUtil.allTerminalRules(SerializerFragment2.this.getGrammar()), _function);
for (final TerminalRule rule : _filter) {
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("/**");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("* Stub implementation for a synthetic terminal rule. Defaults to the empty string.");
_builder.newLine();
_builder.append("\t");
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("\t");
_builder.append("// TODO review the concrete syntax for the terminal");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public String ");
CharSequence _unassignedCalledTokenRuleName = SerializerFragment2.this.unassignedCalledTokenRuleName(rule);
_builder.append(_unassignedCalledTokenRuleName, "\t");
_builder.append("(");
_builder.append(EObject.class, "\t");
_builder.append(" semanticObject, ");
_builder.append(RuleCall.class, "\t");
_builder.append(" ruleCall, ");
_builder.append(INode.class, "\t");
_builder.append(" node) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("return \"\";");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
}
}
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createJavaFile(_syntacticSequencerClass_1, _client_1).writeTo(this.getProjectConfig().getRuntime().getSrc());
}
}
use of org.eclipse.xtend2.lib.StringConcatenationClient 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.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class SerializerFragment2 method genEmitUnassignedTokens.
private StringConcatenationClient genEmitUnassignedTokens() {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("@Override");
_builder.newLine();
_builder.append("protected void emitUnassignedTokens(");
_builder.append(EObject.class);
_builder.append(" semanticObject, ");
_builder.append(ISyntacticSequencerPDAProvider.ISynTransition.class);
_builder.append(" transition, ");
_builder.append(INode.class);
_builder.append(" fromNode, ");
_builder.append(INode.class);
_builder.append(" toNode) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (transition.getAmbiguousSyntaxes().isEmpty()) return;");
_builder.newLine();
_builder.append("\t");
_builder.append(List.class, "\t");
_builder.append("<");
_builder.append(INode.class, "\t");
_builder.append("> transitionNodes = collectNodes(fromNode, toNode);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("for (");
_builder.append(GrammarAlias.AbstractElementAlias.class, "\t");
_builder.append(" syntax : transition.getAmbiguousSyntaxes()) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append(List.class, "\t\t");
_builder.append("<");
_builder.append(INode.class, "\t\t");
_builder.append("> syntaxNodes = getNodesFor(transitionNodes, syntax);");
_builder.newLineIfNotEmpty();
{
Iterable<Pair<Integer, EqualAmbiguousTransitions>> _indexed = IterableExtensions.<EqualAmbiguousTransitions>indexed(SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax());
for (final Pair<Integer, EqualAmbiguousTransitions> group : _indexed) {
_builder.append("\t\t");
{
Integer _key = group.getKey();
boolean _greaterThan = ((_key).intValue() > 0);
if (_greaterThan) {
_builder.append("else ");
}
}
_builder.append("if (match_");
String _identifier = group.getValue().getIdentifier();
_builder.append(_identifier, "\t\t");
_builder.append(".equals(syntax))");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("\t");
_builder.append("emit_");
String _identifier_1 = group.getValue().getIdentifier();
_builder.append(_identifier_1, "\t\t\t");
_builder.append("(semanticObject, getLastNavigableState(), syntaxNodes);");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
{
boolean _isEmpty = SerializerFragment2.this._syntacticSequencerExtensions.getAllAmbiguousTransitionsBySyntax().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
_builder.append("else ");
}
}
_builder.append("acceptNodes(getLastNavigableState(), syntaxNodes);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
return _client;
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class SyntacticSequencerExtensions method elementAliasToConstructor.
public StringConcatenationClient elementAliasToConstructor(final GrammarAlias.AbstractElementAlias alias) {
final String many = String.valueOf(alias.isMany());
final String optional = String.valueOf(alias.isOptional());
if ((alias instanceof GrammarAlias.TokenAlias)) {
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("new ");
_builder.append(GrammarAlias.TokenAlias.class);
_builder.append("(");
_builder.append(many);
_builder.append(", ");
_builder.append(optional);
_builder.append(", grammarAccess.");
String _gaAccessor = SyntacticSequencerExtensions.this._grammarAccessExtensions.gaAccessor(((GrammarAlias.TokenAlias) alias).getToken());
_builder.append(_gaAccessor);
_builder.append(")");
}
};
return _client;
} else {
if ((alias instanceof GrammarAlias.GroupAlias)) {
final List<StringConcatenationClient> children = CollectionLiterals.<StringConcatenationClient>newArrayList();
List<GrammarAlias.AbstractElementAlias> _children = ((GrammarAlias.GroupAlias) alias).getChildren();
for (final GrammarAlias.AbstractElementAlias child : _children) {
children.add(this.elementAliasToConstructor(child));
}
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("new ");
_builder.append(GrammarAlias.GroupAlias.class);
_builder.append("(");
_builder.append(many);
_builder.append(", ");
_builder.append(optional);
_builder.append(", ");
{
boolean _hasElements = false;
for (final StringConcatenationClient c : children) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "");
}
_builder.append(c);
}
}
_builder.append(")");
}
};
return _client_1;
} else {
if ((alias instanceof GrammarAlias.AlternativeAlias)) {
final List<StringConcatenationClient> children_1 = CollectionLiterals.<StringConcatenationClient>newArrayList();
Set<GrammarAlias.AbstractElementAlias> _children_1 = ((GrammarAlias.AlternativeAlias) alias).getChildren();
for (final GrammarAlias.AbstractElementAlias child_1 : _children_1) {
children_1.add(this.elementAliasToConstructor(child_1));
}
final Function1<StringConcatenationClient, String> _function = (StringConcatenationClient it) -> {
StringConcatenation _builder = new StringConcatenation();
_builder.append(it);
return _builder.toString();
};
ListExtensions.<StringConcatenationClient, String>sortInplaceBy(children_1, _function);
StringConcatenationClient _client_2 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("new ");
_builder.append(GrammarAlias.AlternativeAlias.class);
_builder.append("(");
_builder.append(many);
_builder.append(", ");
_builder.append(optional);
_builder.append(", ");
{
boolean _hasElements = false;
for (final StringConcatenationClient c : children_1) {
if (!_hasElements) {
_hasElements = true;
} else {
_builder.appendImmediate(", ", "");
}
_builder.append(c);
}
}
_builder.append(")");
}
};
return _client_2;
}
}
}
throw new RuntimeException("unknown element");
}
use of org.eclipse.xtend2.lib.StringConcatenationClient in project xtext-core by eclipse.
the class CodeMiningFragment method generateXtendCodeMiningProvider.
protected void generateXtendCodeMiningProvider() {
TypeReference _typeRef = TypeReference.typeRef(this.getCodeMiningProviderClass().toString());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
_builder.append("class ");
String _simpleName = CodeMiningFragment.this.getCodeMiningProviderClass().getSimpleName();
_builder.append(_simpleName);
_builder.append(" extends ");
TypeReference _codeMiningProviderSuperClass = CodeMiningFragment.this.getCodeMiningProviderSuperClass();
_builder.append(_codeMiningProviderSuperClass);
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("override void createCodeMinings(");
TypeReference _iDocument = CodeMiningFragment.this.getIDocument();
_builder.append(_iDocument, "\t");
_builder.append(" document, ");
TypeReference _xtextResource = CodeMiningFragment.this.getXtextResource();
_builder.append(_xtextResource, "\t");
_builder.append(" resource, ");
TypeReference _cancelIndicator = CodeMiningFragment.this.getCancelIndicator();
_builder.append(_cancelIndicator, "\t");
_builder.append(" indicator,");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
TypeReference _iAcceptor = CodeMiningFragment.this.getIAcceptor();
_builder.append(_iAcceptor, "\t\t");
_builder.append("<? super ");
TypeReference _iCodeMining = CodeMiningFragment.this.getICodeMining();
_builder.append(_iCodeMining, "\t\t");
_builder.append("> acceptor) throws ");
TypeReference _badLocationException = CodeMiningFragment.this.getBadLocationException();
_builder.append(_badLocationException, "\t\t");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// TODO: implement me");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// use acceptor.accept(super.createNewLineHeaderCodeMining(...)) to add a new code mining to the final list");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// example:");
_builder.newLine();
_builder.append("\t\t");
_builder.append("// acceptor.accept(createNewLineHeaderCodeMining(1, document, \"Header annotation\"))");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
}
};
this.fileAccessFactory.createXtendFile(_typeRef, _client).writeTo(this.getProjectConfig().getEclipsePlugin().getSrc());
}
Aggregations