Search in sources :

Example 1 with SerializationContext

use of org.eclipse.xtext.serializer.analysis.SerializationContext in project xtext-core by eclipse.

the class SerializerFragment2 method genMethodCreateSequenceCaseBody.

private StringConcatenationClient genMethodCreateSequenceCaseBody(final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints, final EClass type) {
    StringConcatenationClient _xblockexpression = null;
    {
        final Function1<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String> _function = (Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> it) -> {
            return it.getKey().getName();
        };
        final List<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> contexts = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>, String>sortBy(this._semanticSequencerExtensions.getGrammarConstraints(this.getGrammar(), type).entrySet(), _function);
        final LinkedHashMultimap<EObject, IGrammarConstraintProvider.IConstraint> context2constraint = LinkedHashMultimap.<EObject, IGrammarConstraintProvider.IConstraint>create();
        for (final Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>> e : contexts) {
            List<ISerializationContext> _value = e.getValue();
            for (final ISerializationContext ctx : _value) {
                context2constraint.put(((SerializationContext) ctx).getActionOrRule(), e.getKey());
            }
        }
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    int _size = contexts.size();
                    boolean _greaterThan = (_size > 1);
                    if (_greaterThan) {
                        {
                            Iterable<Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>> _indexed = IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>indexed(contexts);
                            for (final Pair<Integer, Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>> ctx : _indexed) {
                                {
                                    Integer _key = ctx.getKey();
                                    boolean _greaterThan_1 = ((_key).intValue() > 0);
                                    if (_greaterThan_1) {
                                        _builder.append("else ");
                                    }
                                }
                                _builder.append("if (");
                                StringConcatenationClient _genCondition = SerializerFragment2.this.genCondition(ctx.getValue().getValue(), ctx.getValue().getKey(), context2constraint);
                                _builder.append(_genCondition);
                                _builder.append(") {");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                StringConcatenationClient _genMethodCreateSequenceCall = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, ctx.getValue().getKey());
                                _builder.append(_genMethodCreateSequenceCall, "\t");
                                _builder.newLineIfNotEmpty();
                                _builder.append("}");
                                _builder.newLine();
                            }
                        }
                        _builder.append("else break;");
                        _builder.newLine();
                    } else {
                        int _size_1 = contexts.size();
                        boolean _equals = (_size_1 == 1);
                        if (_equals) {
                            StringConcatenationClient _genMethodCreateSequenceCall_1 = SerializerFragment2.this.genMethodCreateSequenceCall(superConstraints, type, IterableExtensions.<Map.Entry<IGrammarConstraintProvider.IConstraint, List<ISerializationContext>>>head(contexts).getKey());
                            _builder.append(_genMethodCreateSequenceCall_1);
                            _builder.newLineIfNotEmpty();
                        } else {
                            _builder.append("// error, no contexts. ");
                            _builder.newLine();
                        }
                    }
                }
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) SerializationContext(org.eclipse.xtext.serializer.analysis.SerializationContext) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) List(java.util.List) SerializationContextMap(org.eclipse.xtext.serializer.analysis.SerializationContextMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)1 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 IGrammarConstraintProvider (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider)1 SerializationContext (org.eclipse.xtext.serializer.analysis.SerializationContext)1 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1