Search in sources :

Example 1 with Event

use of org.eclipse.xtext.example.fowlerdsl.statemachine.Event in project xtext-eclipse by eclipse.

the class StatemachineSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == StatemachinePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case StatemachinePackage.COMMAND:
                sequence_Command(context, (Command) semanticObject);
                return;
            case StatemachinePackage.EVENT:
                sequence_Event(context, (Event) semanticObject);
                return;
            case StatemachinePackage.STATE:
                sequence_State(context, (State) semanticObject);
                return;
            case StatemachinePackage.STATEMACHINE:
                sequence_Statemachine(context, (Statemachine) semanticObject);
                return;
            case StatemachinePackage.TRANSITION:
                sequence_Transition(context, (Transition) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Statemachine(org.eclipse.xtext.example.fowlerdsl.statemachine.Statemachine) Action(org.eclipse.xtext.Action) Command(org.eclipse.xtext.example.fowlerdsl.statemachine.Command) State(org.eclipse.xtext.example.fowlerdsl.statemachine.State) Transition(org.eclipse.xtext.example.fowlerdsl.statemachine.Transition) Parameter(org.eclipse.xtext.Parameter) Event(org.eclipse.xtext.example.fowlerdsl.statemachine.Event) EPackage(org.eclipse.emf.ecore.EPackage)

Example 2 with Event

use of org.eclipse.xtext.example.fowlerdsl.statemachine.Event in project xtext-eclipse by eclipse.

the class StatemachineGenerator method toJavaCode.

public CharSequence toJavaCode(final Statemachine sm) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.io.BufferedReader;");
    _builder.newLine();
    _builder.append("import java.io.IOException;");
    _builder.newLine();
    _builder.append("import java.io.InputStreamReader;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _className = this.className(sm.eResource());
    _builder.append(_className);
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static void main(String[] args) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new ");
    String _className_1 = this.className(sm.eResource());
    _builder.append(_className_1, "\t\t");
    _builder.append("().run();");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    {
        EList<Command> _commands = sm.getCommands();
        for (final Command c : _commands) {
            _builder.append("\t");
            CharSequence _declareCommand = this.declareCommand(c);
            _builder.append(_declareCommand, "\t");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected void run() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("boolean executeActions = true;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("String currentState = \"");
    State _head = IterableExtensions.<State>head(sm.getStates());
    String _name = null;
    if (_head != null) {
        _name = _head.getName();
    }
    _builder.append(_name, "\t\t");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("String lastEvent = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("while (true) {");
    _builder.newLine();
    {
        EList<State> _states = sm.getStates();
        for (final State state : _states) {
            _builder.append("\t\t\t");
            CharSequence _generateCode = this.generateCode(state);
            _builder.append(_generateCode, "\t\t\t");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        EList<Event> _resetEvents = sm.getResetEvents();
        for (final Event resetEvent : _resetEvents) {
            _builder.append("\t\t\t");
            _builder.append("if (\"");
            String _name_1 = resetEvent.getName();
            _builder.append(_name_1, "\t\t\t");
            _builder.append("\".equals(lastEvent)) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("System.out.println(\"Resetting state machine.\");");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("currentState = \"");
            State _head_1 = IterableExtensions.<State>head(sm.getStates());
            String _name_2 = null;
            if (_head_1 != null) {
                _name_2 = _head_1.getName();
            }
            _builder.append(_name_2, "\t\t\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("executeActions = true;");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    _builder.append("\t\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private String receiveEvent() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("System.out.flush();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("BufferedReader br = new BufferedReader(new InputStreamReader(System.in));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return br.readLine();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch (IOException ioe) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("System.out.println(\"Problem reading input\");");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return \"\";");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : EList(org.eclipse.emf.common.util.EList) Command(org.eclipse.xtext.example.fowlerdsl.statemachine.Command) State(org.eclipse.xtext.example.fowlerdsl.statemachine.State) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Event(org.eclipse.xtext.example.fowlerdsl.statemachine.Event)

Example 3 with Event

use of org.eclipse.xtext.example.fowlerdsl.statemachine.Event in project xtext-eclipse by eclipse.

the class TransitionImpl method setEvent.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setEvent(Event newEvent) {
    Event oldEvent = event;
    event = newEvent;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, StatemachinePackage.TRANSITION__EVENT, oldEvent, event));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) Event(org.eclipse.xtext.example.fowlerdsl.statemachine.Event)

Aggregations

Event (org.eclipse.xtext.example.fowlerdsl.statemachine.Event)3 Command (org.eclipse.xtext.example.fowlerdsl.statemachine.Command)2 State (org.eclipse.xtext.example.fowlerdsl.statemachine.State)2 EList (org.eclipse.emf.common.util.EList)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 Statemachine (org.eclipse.xtext.example.fowlerdsl.statemachine.Statemachine)1 Transition (org.eclipse.xtext.example.fowlerdsl.statemachine.Transition)1