Examples of Transition


Examples of org.antlr.v4.runtime.atn.Transition

//      }

      // make a DOT edge for each transition
      ST edgeST;
      for (int i = 0; i < s.getNumberOfTransitions(); i++) {
        Transition edge = s.transition(i);
        if ( edge instanceof RuleTransition ) {
          RuleTransition rr = ((RuleTransition)edge);
          // don't jump to other rules, but display edge to follow node
          edgeST = stlib.getInstanceOf("edge");

          String label = "<" + ruleNames[rr.ruleIndex];
          if (((RuleStartState)rr.target).isPrecedenceRule) {
            label += "[" + rr.precedence + "]";
          }
          label += ">";

          edgeST.add("label", label);
          edgeST.add("src", "s"+s.stateNumber);
          edgeST.add("target", "s"+rr.followState.stateNumber);
          edgeST.add("arrowhead", arrowhead);
          dot.add("edges", edgeST);
          work.add(rr.followState);
          continue;
        }
        if ( edge instanceof ActionTransition) {
          edgeST = stlib.getInstanceOf("action-edge");
          edgeST.add("label", getEdgeLabel(edge.toString()));
        }
        else if ( edge instanceof AbstractPredicateTransition ) {
          edgeST = stlib.getInstanceOf("edge");
          edgeST.add("label", getEdgeLabel(edge.toString()));
        }
        else if ( edge.isEpsilon() ) {
          edgeST = stlib.getInstanceOf("epsilon-edge");
          edgeST.add("label", getEdgeLabel(edge.toString()));
          boolean loopback = false;
          if (edge.target instanceof PlusBlockStartState) {
            loopback = s.equals(((PlusBlockStartState)edge.target).loopBackState);
          }
          else if (edge.target instanceof StarLoopEntryState) {
            loopback = s.equals(((StarLoopEntryState)edge.target).loopBackState);
          }
          edgeST.add("loopback", loopback);
        }
        else if ( edge instanceof AtomTransition ) {
          edgeST = stlib.getInstanceOf("edge");
          AtomTransition atom = (AtomTransition)edge;
          String label = String.valueOf(atom.label);
          if ( isLexer ) label = "'"+getEdgeLabel(String.valueOf((char)atom.label))+"'";
          else if ( grammar!=null ) label = grammar.getTokenDisplayName(atom.label);
          edgeST.add("label", getEdgeLabel(label));
        }
        else if ( edge instanceof SetTransition ) {
          edgeST = stlib.getInstanceOf("edge");
          SetTransition set = (SetTransition)edge;
          String label = set.label().toString();
          if ( isLexer ) label = set.label().toString(true);
          else if ( grammar!=null ) label = set.label().toString(grammar.getVocabulary());
          if ( edge instanceof NotSetTransition ) label = "~"+label;
          edgeST.add("label", getEdgeLabel(label));
        }
        else if ( edge instanceof RangeTransition ) {
          edgeST = stlib.getInstanceOf("edge");
          RangeTransition range = (RangeTransition)edge;
          String label = range.label().toString();
          if ( isLexer ) label = range.toString();
          else if ( grammar!=null ) label = range.label().toString(grammar.getVocabulary());
          edgeST.add("label", getEdgeLabel(label));
        }
        else {
          edgeST = stlib.getInstanceOf("edge");
          edgeST.add("label", getEdgeLabel(edge.toString()));
        }
        edgeST.add("src", "s"+s.stateNumber);
        edgeST.add("target", "s"+edge.target.stateNumber);
        edgeST.add("arrowhead", arrowhead);
        if (s.getNumberOfTransitions() > 1) {
View Full Code Here

Examples of org.antlr.v4.runtime.atn.Transition

        }
      }

      IntervalSet setTransitions = new IntervalSet();
      for (int i = 0; i < decision.getNumberOfTransitions(); i++) {
        Transition epsTransition = decision.transition(i);
        if (!(epsTransition instanceof EpsilonTransition)) {
          continue;
        }

        if (epsTransition.target.getNumberOfTransitions() != 1) {
          continue;
        }

        Transition transition = epsTransition.target.transition(0);
        if (!(transition.target instanceof BlockEndState)) {
          continue;
        }

        if (transition instanceof NotSetTransition) {
          // TODO: not yet implemented
          continue;
        }

        if (transition instanceof AtomTransition
          || transition instanceof RangeTransition
          || transition instanceof SetTransition)
        {
          setTransitions.add(i);
        }
      }

      // due to min alt resolution policies, can only collapse sequential alts
      for (int i = setTransitions.getIntervals().size() - 1; i >= 0; i--) {
        Interval interval = setTransitions.getIntervals().get(i);
        if (interval.length() <= 1) {
          continue;
        }

        ATNState blockEndState = decision.transition(interval.a).target.transition(0).target;
        IntervalSet matchSet = new IntervalSet();
        for (int j = interval.a; j <= interval.b; j++) {
          Transition matchTransition = decision.transition(j).target.transition(0);
          if (matchTransition instanceof NotSetTransition) {
            throw new UnsupportedOperationException("Not yet implemented.");
          } else {
            matchSet.addAll(matchTransition.label());
          }
        }

        Transition newTransition;
        if (matchSet.getIntervals().size() == 1) {
          if (matchSet.size() == 1) {
            newTransition = new AtomTransition(blockEndState, matchSet.getMinElement());
          } else {
            Interval matchInterval = matchSet.getIntervals().get(0);
            newTransition = new RangeTransition(blockEndState, matchInterval.a, matchInterval.b);
          }
        } else {
          newTransition = new SetTransition(blockEndState, matchSet);
        }

        decision.transition(interval.a).target.setTransition(0, newTransition);
        for (int j = interval.a + 1; j <= interval.b; j++) {
          Transition removed = decision.removeTransition(interval.a + 1);
          atn.removeState(removed.target);
          removedStates++;
        }
      }
    }
View Full Code Here

Examples of org.apache.commons.scxml.model.Transition

        if (!c.isEmpty()) {
            if (ini == null) {
                logAndThrowModelError(ERR_STATE_NO_INIT,
                    new Object[] {getStateName(s)});
            }
            Transition initialTransition = ini.getTransition();
            updateTransition(initialTransition, targets);
            initialStates = initialTransition.getTargets();
            // we have to allow for an indirect descendant initial (targets)
            //check that initialState is a descendant of s
            if (initialStates.size() == 0) {
                logAndThrowModelError(ERR_STATE_BAD_INIT,
                    new Object[] {getStateName(s)});
            } else {
                for (int i = 0; i < initialStates.size(); i++) {
                    TransitionTarget initialState = (TransitionTarget)
                        initialStates.get(i);
                    if (!SCXMLHelper.isDescendant(initialState, s)) {
                        logAndThrowModelError(ERR_STATE_BAD_INIT,
                            new Object[] {getStateName(s)});
                    }
                }
            }
        }
        List histories = s.getHistory();
        Iterator histIter = histories.iterator();
        while (histIter.hasNext()) {
            if (s.isSimple()) {
                logAndThrowModelError(ERR_HISTORY_SIMPLE_STATE,
                    new Object[] {getStateName(s)});
            }
            History h = (History) histIter.next();
            Transition historyTransition = h.getTransition();
            if (historyTransition == null) {
                // try to assign initial as default
                if (initialStates != null && initialStates.size() > 0) {
                    for (int i = 0; i < initialStates.size(); i++) {
                        if (initialStates.get(i) instanceof History) {
                            logAndThrowModelError(ERR_HISTORY_BAD_DEFAULT,
                                new Object[] {h.getId(), getStateName(s)});
                        }
                    }
                    historyTransition = new Transition();
                    historyTransition.getTargets().addAll(initialStates);
                    h.setTransition(historyTransition);
                } else {
                    logAndThrowModelError(ERR_HISTORY_NO_DEFAULT,
                        new Object[] {h.getId(), getStateName(s)});
                }
            }
            updateTransition(historyTransition, targets);
            List historyStates = historyTransition.getTargets();
            if (historyStates.size() == 0) {
                logAndThrowModelError(ERR_STATE_NO_HIST,
                    new Object[] {getStateName(s)});
            }
            for (int i = 0; i < historyStates.size(); i++) {
                TransitionTarget historyState = (TransitionTarget)
                    historyStates.get(i);
                if (!h.isDeep()) {
                    if (!c.containsValue(historyState)) {
                        logAndThrowModelError(ERR_STATE_BAD_SHALLOW_HIST,
                            new Object[] {getStateName(s)});
                    }
                } else {
                    if (!SCXMLHelper.isDescendant(historyState, s)) {
                        logAndThrowModelError(ERR_STATE_BAD_DEEP_HIST,
                            new Object[] {getStateName(s)});
                    }
                }
            }
        }
        List t = s.getTransitionsList();
        for (int i = 0; i < t.size(); i++) {
            Transition trn = (Transition) t.get(i);
            updateTransition(trn, targets);
        }
        Parallel p = s.getParallel(); //TODO: Remove in v1.0
        Invoke inv = s.getInvoke();
        if ((inv != null && p != null)
View Full Code Here

Examples of org.apache.commons.scxml.model.Transition

        // Add <exit> custom action rule in Commons SCXML namespace
        scxmlRules.setNamespaceURI(NAMESPACE_COMMONS_SCXML);
        scxmlRules.add(xp + XPF_EXT, new Rule() {
            public void end(final String namespace, final String name) {
                Transition t = (Transition) getDigester().peek(1);
                State exitState = new State();
                exitState.setFinal(true);
                t.getTargets().add(exitState);
            }
        });
        scxmlRules.setNamespaceURI(NAMESPACE_SCXML);

        scxmlRules.add(xp, new SetNextRule(setNextMethod));
View Full Code Here

Examples of org.apache.commons.scxml.model.Transition

            }
            State s = (State) digester.peek();
            if (fragment == null) {
                // All targets pulled in since its not a src fragment
                Initial ini = new Initial();
                Transition t = new Transition();
                t.setNext(externalSCXML.getInitialstate());
                ini.setTransition(t);
                s.setInitial(ini);
                Map children = externalSCXML.getChildren();
                Iterator childIter = children.values().iterator();
                while (childIter.hasNext()) {
View Full Code Here

Examples of org.apache.commons.scxml.model.Transition

        scxmlRules.add(xp, new SetCurrentNamespacesRule());
        scxmlRules.add(xp + XPF_TAR, new SetPropertiesRule());
        addActionRules(xp, scxmlRules, pr, customActions);
        scxmlRules.add(xp + XPF_EXT, new Rule() {
            public void end(final String namespace, final String name) {
                Transition t = (Transition) getDigester().peek(1);
                State exitState = new State();
                exitState.setFinal(true);
                t.getTargets().add(exitState);
            }
        });
        scxmlRules.add(xp, new SetNextRule(setNextMethod));
    }
View Full Code Here

Examples of org.apache.commons.scxml.model.Transition

            }
            State s = (State) digester.peek();
            if (fragment == null) {
                // All targets pulled in since its not a src fragment
                Initial ini = new Initial();
                Transition t = new Transition();
                t.setNext(externalSCXML.getInitialstate());
                ini.setTransition(t);
                s.setInitial(ini);
                Map children = externalSCXML.getChildren();
                Iterator childIter = children.values().iterator();
                while (childIter.hasNext()) {
View Full Code Here

Examples of org.apache.commons.scxml2.model.Transition

     *                        errors in the SCXML document that may not be identified by the schema).
     */
    private static Transition readTransition(final XMLStreamReader reader, final Configuration configuration)
            throws XMLStreamException, ModelException {

        Transition transition = new Transition();
        transition.setCond(readAV(reader, ATTR_COND));
        transition.setEvent(readAV(reader, ATTR_EVENT));
        transition.setNext(readAV(reader, ATTR_TARGET));
        String type = readAV(reader, ATTR_TYPE);
        if (type != null) {
            try {
                transition.setType(TransitionType.valueOf(type));
            }
            catch (IllegalArgumentException e) {
                MessageFormat msgFormat = new MessageFormat(ERR_UNSUPPORTED_TRANSITION_TYPE);
                String errMsg = msgFormat.format(new Object[] {type, reader.getLocation()});
                throw new ModelException(errMsg);
View Full Code Here

Examples of org.apache.helix.model.Transition

    states.add("DROPPED");
    states.add("OFFLINE");


    List<Transition> transitions = new ArrayList<Transition>();
    transitions.add(new Transition("SLAVE", "OFFLINE"));
    transitions.add(new Transition("OFFLINE", "SLAVE"));
    transitions.add(new Transition("SLAVE", "MASTER"));
    transitions.add(new Transition("OFFLINE", "DROPPED"));
    transitions.add(new Transition("MASTER", "SLAVE"));

    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);
    System.out.println(next);
    printPath(states, next);
View Full Code Here

Examples of org.apache.helix.model.Transition

    states.add("COMPLETED");
    states.add("DROPPED");
    states.add("OFFLINE");

    List<Transition> transitions = new ArrayList<Transition>();
    transitions.add(new Transition("OFFLINE", "COMPLETED"));
    transitions.add(new Transition("OFFLINE", "DROPPED"));
    transitions.add(new Transition("COMPLETED", "DROPPED"));

    StateTransitionTableBuilder builder = new StateTransitionTableBuilder();
    Map<String, Map<String, String>> next = builder.buildTransitionTable(states, transitions);

    for (String state : statePriorityList) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.