use of org.eclipse.xtext.example.fowlerdsl.statemachine.Transition 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));
}
use of org.eclipse.xtext.example.fowlerdsl.statemachine.Transition in project xtext-eclipse by eclipse.
the class StatemachineGenerator method generateCode.
public CharSequence generateCode(final State state) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("if (currentState.equals(\"");
String _name = state.getName();
_builder.append(_name);
_builder.append("\")) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("if (executeActions) {");
_builder.newLine();
{
EList<Command> _actions = state.getActions();
for (final Command c : _actions) {
_builder.append("\t\t");
_builder.append("do");
String _firstUpper = StringExtensions.toFirstUpper(c.getName());
_builder.append(_firstUpper, "\t\t");
_builder.append("();");
_builder.newLineIfNotEmpty();
}
}
_builder.append("\t\t");
_builder.append("executeActions = false;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("System.out.println(\"Your are now in state \'");
String _name_1 = state.getName();
_builder.append(_name_1, "\t");
_builder.append("\'. Possible events are [");
final Function1<Transition, String> _function = (Transition t) -> {
return t.getEvent().getName();
};
String _join = IterableExtensions.join(ListExtensions.<Transition, String>map(state.getTransitions(), _function), ", ");
_builder.append(_join, "\t");
_builder.append("].\");");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("lastEvent = receiveEvent();");
_builder.newLine();
{
EList<Transition> _transitions = state.getTransitions();
for (final Transition t : _transitions) {
_builder.append("\t");
_builder.append("if (\"");
String _name_2 = t.getEvent().getName();
_builder.append(_name_2, "\t");
_builder.append("\".equals(lastEvent)) {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("currentState = \"");
String _name_3 = t.getState().getName();
_builder.append(_name_3, "\t\t");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\t");
_builder.append("executeActions = true;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
}
}
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations