Search in sources :

Example 26 with INodesForEObjectProvider

use of org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider in project applause by applause.

the class ApplauseDslSemanticSequencer method sequence_RESTMethodCall.

/**
	 * Constraint:
	 *     (datasource=[DataSourceCall|ID] restMethod=[DataSourceAccessMethod|ID])
	 */
protected void sequence_RESTMethodCall(EObject context, RESTMethodCall semanticObject) {
    if (errorAcceptor != null) {
        if (transientValues.isValueTransient(semanticObject, ApplauseDslPackage.Literals.REST_METHOD_CALL__DATASOURCE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, ApplauseDslPackage.Literals.REST_METHOD_CALL__DATASOURCE));
        if (transientValues.isValueTransient(semanticObject, ApplauseDslPackage.Literals.REST_METHOD_CALL__REST_METHOD) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, ApplauseDslPackage.Literals.REST_METHOD_CALL__REST_METHOD));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getRESTMethodCallAccess().getDatasourceDataSourceCallIDTerminalRuleCall_0_0_1(), semanticObject.getDatasource());
    feeder.accept(grammarAccess.getRESTMethodCallAccess().getRestMethodDataSourceAccessMethodIDTerminalRuleCall_2_0_1(), semanticObject.getRestMethod());
    feeder.finish();
}
Also used : SequenceFeeder(org.eclipse.xtext.serializer.acceptor.SequenceFeeder) INodesForEObjectProvider(org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider)

Example 27 with INodesForEObjectProvider

use of org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider in project applause by applause.

the class ApplauseDslSemanticSequencer method sequence_DataType.

/**
	 * Constraint:
	 *     name=KeywordedID
	 */
protected void sequence_DataType(EObject context, DataType semanticObject) {
    if (errorAcceptor != null) {
        if (transientValues.isValueTransient(semanticObject, ApplauseDslPackage.Literals.NAMED_ELEMENT__NAME) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, ApplauseDslPackage.Literals.NAMED_ELEMENT__NAME));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getDataTypeAccess().getNameKeywordedIDParserRuleCall_1_0(), semanticObject.getName());
    feeder.finish();
}
Also used : SequenceFeeder(org.eclipse.xtext.serializer.acceptor.SequenceFeeder) INodesForEObjectProvider(org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider)

Example 28 with INodesForEObjectProvider

use of org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider in project xtext-core by eclipse.

the class BacktrackingSemanticSequencer method createSequence.

@Override
public void createSequence(ISerializationContext context, EObject obj) {
    INodesForEObjectProvider nodes = nodeProvider.getNodesForSemanticObject(obj, null);
    SerializationContextMap<IConstraint> constraints = constraintProvider.getConstraints(grammar.getGrammar());
    IConstraint constraint = constraints.get(context);
    if (constraint == null)
        throw new IllegalStateException("Invalid context: " + context);
    Nfa<ISemState> nfa = constraint.getNfa();
    final SerializableObject object = new SerializableObject(context, obj, nodes);
    TraceItem co = new TraceItem(object);
    List<TraceItem> trace = new NfaUtil().backtrack(nfa, co, new NfaUtil.BacktrackHandler<ISemState, TraceItem>() {

        @Override
        public TraceItem handle(ISemState state, TraceItem previous) {
            if (!previous.canEnter(state))
                return null;
            if (state.getFeature() != null) {
                return previous.cloneAndConsume(state);
            } else
                return previous.clone(state);
        }

        @Override
        public boolean isSolution(TraceItem result) {
            return result.isConsumed();
        }

        @Override
        public Iterable<ISemState> sortFollowers(TraceItem result, Iterable<ISemState> followers) {
            AbstractElement next = result.getNextGrammarElement();
            List<ISemState> r = Lists.newArrayList(followers);
            Collections.sort(r, createFollowerSorter(object, next));
            return r;
        }
    });
    SequenceFeeder feeder = feederProvider.create(context, obj, nodes, masterSequencer, sequenceAcceptor, errorAcceptor);
    if (trace != null) {
        for (TraceItem ti : trace) if (ti.getState() != null && ti.getState().getFeature() != null)
            accept(ti, feeder);
    } else if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createBacktrackingFailedDiagnostic(object, context, constraint));
    feeder.finish();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) SequenceFeeder(org.eclipse.xtext.serializer.acceptor.SequenceFeeder) INodesForEObjectProvider(org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider) NfaUtil(org.eclipse.xtext.util.formallang.NfaUtil) InternalEList(org.eclipse.emf.ecore.util.InternalEList) List(java.util.List) ISemState(org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider.ISemState)

Example 29 with INodesForEObjectProvider

use of org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider in project xtext-core by eclipse.

the class ContextFinder method findAssignedElements.

protected Set<AbstractElement> findAssignedElements(EObject obj, EStructuralFeature feature, Multimap<AbstractElement, ISerializationContext> assignments) {
    if (feature.isMany()) {
        Set<AbstractElement> r = Sets.newLinkedHashSet();
        INodesForEObjectProvider nodes = nodesProvider.getNodesForSemanticObject(obj, null);
        switch(transientValues.isListTransient(obj, feature)) {
            case SOME:
                List<?> values1 = (List<?>) obj.eGet(feature);
                int j = 0;
                for (int i = 0; i < values1.size(); i++) if (!transientValues.isValueInListTransient(obj, i, feature)) {
                    Object value = values1.get(i);
                    INode node = nodes.getNodeForMultiValue(feature, i, j, value);
                    r.addAll(assignmentFinder.findAssignmentsByValue(obj, assignments, value, node));
                    j++;
                }
                return r;
            case NO:
                List<?> values2 = (List<?>) obj.eGet(feature);
                for (int i = 0; i < values2.size(); i++) {
                    Object value = values2.get(i);
                    INode node = nodes.getNodeForMultiValue(feature, i, i, value);
                    r.addAll(assignmentFinder.findAssignmentsByValue(obj, assignments, value, node));
                }
                return r;
            default:
                return Collections.emptySet();
        }
    } else {
        if (transientValues.isValueTransient(obj, feature) == ValueTransient.YES)
            return Collections.emptySet();
        Object value = obj.eGet(feature);
        INode node = nodesProvider.getNodesForSemanticObject(obj, null).getNodeForSingelValue(feature, value);
        return assignmentFinder.findAssignmentsByValue(obj, assignments, value, node);
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) AbstractElement(org.eclipse.xtext.AbstractElement) List(java.util.List) EObject(org.eclipse.emf.ecore.EObject) IConstraint(org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint) INodesForEObjectProvider(org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider)

Example 30 with INodesForEObjectProvider

use of org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider in project mechanoid by robotoworks.

the class NetModelSemanticSequencer method sequence_LongType.

/**
	 * Constraint:
	 *     id='long'
	 */
protected void sequence_LongType(EObject context, LongType semanticObject) {
    if (errorAcceptor != null) {
        if (transientValues.isValueTransient(semanticObject, NetModelPackage.Literals.INTRINSIC_TYPE__ID) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, NetModelPackage.Literals.INTRINSIC_TYPE__ID));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getLongTypeAccess().getIdLongKeyword_0(), semanticObject.getId());
    feeder.finish();
}
Also used : SequenceFeeder(org.eclipse.xtext.serializer.acceptor.SequenceFeeder) INodesForEObjectProvider(org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider)

Aggregations

INodesForEObjectProvider (org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider)65 SequenceFeeder (org.eclipse.xtext.serializer.acceptor.SequenceFeeder)64 List (java.util.List)2 AbstractElement (org.eclipse.xtext.AbstractElement)2 IConstraint (org.eclipse.xtext.serializer.analysis.IGrammarConstraintProvider.IConstraint)2 EObject (org.eclipse.emf.ecore.EObject)1 InternalEList (org.eclipse.emf.ecore.util.InternalEList)1 INode (org.eclipse.xtext.nodemodel.INode)1 ISemState (org.eclipse.xtext.serializer.analysis.ISemanticSequencerNfaProvider.ISemState)1 NfaUtil (org.eclipse.xtext.util.formallang.NfaUtil)1