Search in sources :

Example 36 with ISerializationContext

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

the class SerializerFragment2 method genCondition.

private StringConcatenationClient genCondition(final List<ISerializationContext> contexts, final IGrammarConstraintProvider.IConstraint constraint, final Multimap<EObject, IGrammarConstraintProvider.IConstraint> ctx2ctr) {
    StringConcatenationClient _xblockexpression = null;
    {
        final List<ISerializationContext> sorted = IterableExtensions.<ISerializationContext>sort(contexts);
        final LinkedHashMultimap<EObject, ISerializationContext> index = LinkedHashMultimap.<EObject, ISerializationContext>create();
        final Consumer<ISerializationContext> _function = (ISerializationContext it) -> {
            index.put(this.getContextObject(it), it);
        };
        sorted.forEach(_function);
        StringConcatenationClient _client = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                {
                    Set<EObject> _keySet = index.keySet();
                    boolean _hasElements = false;
                    for (final EObject obj : _keySet) {
                        if (!_hasElements) {
                            _hasElements = true;
                        } else {
                            _builder.appendImmediate("\n\t\t|| ", "");
                        }
                        StringConcatenationClient _genObjectSelector = SerializerFragment2.this.genObjectSelector(obj);
                        _builder.append(_genObjectSelector);
                        {
                            int _size = ctx2ctr.get(obj).size();
                            boolean _greaterThan = (_size > 1);
                            if (_greaterThan) {
                                StringConcatenationClient _genParameterSelector = SerializerFragment2.this.genParameterSelector(obj, index.get(obj), constraint);
                                _builder.append(_genParameterSelector);
                            }
                        }
                    }
                }
            }
        };
        _xblockexpression = _client;
    }
    return _xblockexpression;
}
Also used : LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Consumer(java.util.function.Consumer) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List)

Example 37 with ISerializationContext

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

the class SerializerFragment2 method genMethodSequence.

private StringConcatenationClient genMethodSequence(final IGrammarConstraintProvider.IConstraint c) {
    StringConcatenationClient _xblockexpression = null;
    {
        final ResourceSet rs = this.getLanguage().getResourceSet();
        StringConcatenationClient _xifexpression = null;
        boolean _isEObjectExtension = GenModelUtil2.getGenClass(c.getType(), rs).isEObjectExtension();
        if (_isEObjectExtension) {
            StringConcatenationClient _client = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                }
            };
            _xifexpression = _client;
        } else {
            StringConcatenationClient _client_1 = new StringConcatenationClient() {

                @Override
                protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                    _builder.append("(");
                    _builder.append(EObject.class);
                    _builder.append(") ");
                }
            };
            _xifexpression = _client_1;
        }
        final StringConcatenationClient cast = _xifexpression;
        final List<ISemanticSequencerNfaProvider.ISemState> states = this._semanticSequencerExtensions.getLinearListOfMandatoryAssignments(c);
        StringConcatenationClient _client_2 = new StringConcatenationClient() {

            @Override
            protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
                _builder.append("/**");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Contexts:");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*     ");
                String _replaceAll = IterableExtensions.join(IterableExtensions.<ISerializationContext>sort(c.getContexts()), "\n").replaceAll("\\n", "\n*     ");
                _builder.append(_replaceAll, " ");
                _builder.newLineIfNotEmpty();
                _builder.append(" ");
                _builder.append("*");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("* Constraint:");
                _builder.newLine();
                _builder.append(" ");
                _builder.append("*     ");
                {
                    IGrammarConstraintProvider.IConstraintElement _body = c.getBody();
                    boolean _tripleEquals = (_body == null);
                    if (_tripleEquals) {
                        _builder.append("{");
                        String _name = c.getType().getName();
                        _builder.append(_name, " ");
                        _builder.append("}");
                    } else {
                        String _replaceAll_1 = c.getBody().toString().replaceAll("\\n", "\n*     ");
                        _builder.append(_replaceAll_1, " ");
                    }
                }
                _builder.newLineIfNotEmpty();
                _builder.append(" ");
                _builder.append("*/");
                _builder.newLine();
                _builder.append("protected void sequence_");
                String _simpleName = c.getSimpleName();
                _builder.append(_simpleName);
                _builder.append("(");
                _builder.append(ISerializationContext.class);
                _builder.append(" context, ");
                EClass _type = c.getType();
                _builder.append(_type);
                _builder.append(" semanticObject) {");
                _builder.newLineIfNotEmpty();
                {
                    if ((states != null)) {
                        _builder.append("\t");
                        _builder.append("if (errorAcceptor != null) {");
                        _builder.newLine();
                        {
                            for (final ISemanticSequencerNfaProvider.ISemState s : states) {
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("if (transientValues.isValueTransient(");
                                _builder.append(cast, "\t\t");
                                _builder.append("semanticObject, ");
                                EPackage _ePackage = s.getFeature().getEContainingClass().getEPackage();
                                _builder.append(_ePackage, "\t\t");
                                _builder.append(".");
                                String _featureLiteral = GenModelUtil2.getFeatureLiteral(s.getFeature(), rs);
                                _builder.append(_featureLiteral, "\t\t");
                                _builder.append(") == ");
                                _builder.append(ITransientValueService.ValueTransient.class, "\t\t");
                                _builder.append(".YES)");
                                _builder.newLineIfNotEmpty();
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("\t");
                                _builder.append("errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(");
                                _builder.append(cast, "\t\t\t");
                                _builder.append("semanticObject, ");
                                EPackage _ePackage_1 = s.getFeature().getEContainingClass().getEPackage();
                                _builder.append(_ePackage_1, "\t\t\t");
                                _builder.append(".");
                                String _featureLiteral_1 = GenModelUtil2.getFeatureLiteral(s.getFeature(), rs);
                                _builder.append(_featureLiteral_1, "\t\t\t");
                                _builder.append("));");
                                _builder.newLineIfNotEmpty();
                            }
                        }
                        _builder.append("\t");
                        _builder.append("}");
                        _builder.newLine();
                        _builder.append("\t");
                        _builder.append(SequenceFeeder.class, "\t");
                        _builder.append(" feeder = createSequencerFeeder(context, ");
                        _builder.append(cast, "\t");
                        _builder.append("semanticObject);");
                        _builder.newLineIfNotEmpty();
                        {
                            for (final ISemanticSequencerNfaProvider.ISemState f : states) {
                                _builder.append("\t");
                                _builder.append("feeder.accept(grammarAccess.");
                                String _gaAccessor = SerializerFragment2.this._grammarAccessExtensions.gaAccessor(f.getAssignedGrammarElement());
                                _builder.append(_gaAccessor, "\t");
                                _builder.append(", semanticObject.");
                                StringConcatenationClient _unresolvingGetAccessor = SerializerFragment2.this.getUnresolvingGetAccessor(f.getFeature(), rs);
                                _builder.append(_unresolvingGetAccessor, "\t");
                                _builder.append(");");
                                _builder.newLineIfNotEmpty();
                            }
                        }
                        _builder.append("\t");
                        _builder.append("feeder.finish();");
                        _builder.newLine();
                    } else {
                        _builder.append("\t");
                        _builder.append("genericSequencer.createSequence(context, ");
                        _builder.append(cast, "\t");
                        _builder.append("semanticObject);");
                        _builder.newLineIfNotEmpty();
                    }
                }
                _builder.append("}");
                _builder.newLine();
                _builder.newLine();
                {
                    if (SerializerFragment2.this.generateSupportForDeprecatedContextEObject) {
                        _builder.append("@Deprecated");
                        _builder.newLine();
                        _builder.append("protected void sequence_");
                        String _simpleName_1 = c.getSimpleName();
                        _builder.append(_simpleName_1);
                        _builder.append("(");
                        _builder.append(EObject.class);
                        _builder.append(" context, ");
                        EClass _type_1 = c.getType();
                        _builder.append(_type_1);
                        _builder.append(" semanticObject) {");
                        _builder.newLineIfNotEmpty();
                        _builder.append("\t");
                        _builder.append("sequence_");
                        String _simpleName_2 = c.getSimpleName();
                        _builder.append(_simpleName_2, "\t");
                        _builder.append("(createContext(context, semanticObject), semanticObject);");
                        _builder.newLineIfNotEmpty();
                        _builder.append("}");
                        _builder.newLine();
                    }
                }
            }
        };
        _xblockexpression = _client_2;
    }
    return _xblockexpression;
}
Also used : StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EPackage(org.eclipse.emf.ecore.EPackage) EClass(org.eclipse.emf.ecore.EClass) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) ISemanticSequencerNfaProvider(org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider) IGrammarConstraintProvider(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider) List(java.util.List)

Example 38 with ISerializationContext

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

the class SerializerFragment2 method genParameterSelector.

private StringConcatenationClient genParameterSelector(final EObject obj, final Set<ISerializationContext> contexts, final IGrammarConstraintProvider.IConstraint constraint) {
    StringConcatenationClient _client = new StringConcatenationClient() {

        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
            _builder.append(" ");
            _builder.append("&& (");
            {
                boolean _hasElements = false;
                for (final ISerializationContext context : contexts) {
                    if (!_hasElements) {
                        _hasElements = true;
                    } else {
                        _builder.appendImmediate("\n\t\t\t|| ", " ");
                    }
                    StringConcatenationClient _genParameterCondition = SerializerFragment2.this.genParameterCondition(context, constraint);
                    _builder.append(_genParameterCondition, " ");
                }
            }
            _builder.append(")");
        }
    };
    return _client;
}
Also used : ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient)

Example 39 with ISerializationContext

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

the class FormatterTest method serializeToTokenBuffer.

protected void serializeToTokenBuffer(String model, ITokenStream out) throws Exception {
    EObject semanticObject = get(ParseHelper.class).parse(model);
    ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
    ISemanticSequencer semantic = get(ISemanticSequencer.class);
    ISyntacticSequencer syntactic = get(ISyntacticSequencer.class);
    IHiddenTokenSequencer hidden = get(IHiddenTokenSequencer.class);
    TokenStreamSequenceAdapter tokenstream = new TokenStreamSequenceAdapter(out, getGrammarAccess().getGrammar(), errors);
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    ISerializationContext context = new SerializationContext.RuleContext(null, (ParserRule) get(IGrammarAccess.class).getGrammar().getRules().get(0));
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokenstream, errors);
    tokenstream.init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ParseHelper(org.eclipse.xtext.testing.util.ParseHelper) ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Aggregations

ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)39 EClass (org.eclipse.emf.ecore.EClass)12 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)8 EObject (org.eclipse.emf.ecore.EObject)7 RuleCall (org.eclipse.xtext.RuleCall)7 Parameter (org.eclipse.xtext.Parameter)6 List (java.util.List)5 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)5 AbstractElement (org.eclipse.xtext.AbstractElement)5 ParserRule (org.eclipse.xtext.ParserRule)5 Pda (org.eclipse.xtext.util.formallang.Pda)5 Collection (java.util.Collection)4 ISerializationDiagnostic (org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic)4 Map (java.util.Map)3 Action (org.eclipse.xtext.Action)3 ISynAbsorberState (org.eclipse.xtext.serializer.analysis.ISyntacticSequencerPDAProvider.ISynAbsorberState)3 SerializationContextMap (org.eclipse.xtext.serializer.analysis.SerializationContextMap)3 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)2 EReference (org.eclipse.emf.ecore.EReference)2 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)2