Repository: workcraft/workcraft
Issue: Incorrect reparent of FST signals

On copy-paste of FST events their associated Signal labels are incorrectly interpreted as Symbol of FSM model. As a result the type of signal (input/output/internal) may be lost if no such signal exists in the destination FST.

To reproduce:
* Create an FST model with two states and an event arc between them.
* Copy the whole model and paste it in a new (empty) FST model.

Expected behaviour:
An exact replica of the source FST should be pasted into the destination FST.

Observed behaviour:
Exception that a Symbol cannot be cast to Signal.


Changed files:
workcraft/FstPlugin/src/org/workcraft/plugins/fst/Fst.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualFst.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToStgConverter.java
workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/FsmPropertyHelper.java
workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/VisualFsm.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/SignalEvent.java
workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/Fsm.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToFsmConverter.java
workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/observers/InitialStateSupervisor.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualSignalEvent.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/FstPropertyHelper.java
workcraft/FstPlugin/src/org/workcraft/plugins/fst/serialisation/SgSerialiser.java

diff --git a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/Fsm.java b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/Fsm.java
index fae5decda..20cfe7407 100644
--- a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/Fsm.java
+++ b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/Fsm.java
@@ -5,7 +5,6 @@ import org.workcraft.dom.Model;
 import org.workcraft.dom.Node;
 import org.workcraft.dom.math.AbstractMathModel;
 import org.workcraft.dom.math.MathNode;
-import org.workcraft.dom.references.HierarchyReferenceManager;
 import org.workcraft.dom.references.NameManager;
 import org.workcraft.exceptions.ArgumentException;
 import org.workcraft.plugins.fsm.observers.InitialStateSupervisor;
@@ -104,29 +103,36 @@ public class Fsm extends AbstractMathModel {
         if (srcModel == null) {
             srcModel = this;
         }
-        HierarchyReferenceManager refManager = getReferenceManager();
-        NameManager nameManager = refManager.getNameManager(null);
+        reparentDependencies(srcModel, srcChildren);
+        return super.reparent(dstContainer, srcModel, srcRoot, srcChildren);
+    }
+
+    public void reparentDependencies(Model srcModel, Collection<? extends MathNode> srcChildren) {
         for (MathNode srcNode: srcChildren) {
             if (srcNode instanceof Event) {
                 Event srcEvent = (Event) srcNode;
-                Symbol dstSymbol = null;
-                Symbol srcSymbol = srcEvent.getSymbol();
-                if (srcSymbol != null) {
-                    String symbolName = srcModel.getNodeReference(srcSymbol);
-                    Node dstNode = getNodeByReference(symbolName);
-                    if (dstNode instanceof Symbol) {
-                        dstSymbol = (Symbol) dstNode;
-                    } else {
-                        if (dstNode != null) {
-                            symbolName = nameManager.getDerivedName(null, symbolName);
-                        }
-                        dstSymbol = createSymbol(symbolName);
-                    }
-                }
+                Symbol dstSymbol = reparentSymbol(srcModel, srcEvent.getSymbol());
                 srcEvent.setSymbol(dstSymbol);
             }
         }
-        return super.reparent(dstContainer, srcModel, srcRoot, srcChildren);
+    }
+
+    private Symbol reparentSymbol(Model srcModel, Symbol srcSymbol) {
+        Symbol dstSymbol = null;
+        if (srcSymbol != null) {
+            String symbolName = srcModel.getNodeReference(srcSymbol);
+            Node dstNode = getNodeByReference(symbolName);
+            if (dstNode instanceof Symbol) {
+                dstSymbol = (Symbol) dstNode;
+            } else {
+                if (dstNode != null) {
+                    NameManager nameManager = getReferenceManager().getNameManager(null);
+                    symbolName = nameManager.getDerivedName(null, symbolName);
+                }
+                dstSymbol = createSymbol(symbolName);
+            }
+        }
+        return dstSymbol;
     }
 
 }
diff --git a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/FsmPropertyHelper.java b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/FsmPropertyHelper.java
index 3ba99857a..f88c02c98 100644
--- a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/FsmPropertyHelper.java
+++ b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/FsmPropertyHelper.java
@@ -61,11 +61,7 @@ public class FsmPropertyHelper {
                 },
                 () -> {
                     Symbol symbol = event.getSymbol();
-                    String symbolName = "";
-                    if (symbol != null) {
-                        symbolName = fsm.getName(symbol);
-                    }
-                    return symbolName;
+                    return symbol == null ? "" : fsm.getName(symbol);
                 })
                 .setCombinable().setTemplatable();
     }
diff --git a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/VisualFsm.java b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/VisualFsm.java
index e8442af20..cfad6d5a8 100644
--- a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/VisualFsm.java
+++ b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/VisualFsm.java
@@ -93,19 +93,16 @@ public class VisualFsm extends AbstractVisualModel {
     @Override
     public ModelProperties getProperties(VisualNode node) {
         ModelProperties properties = super.getProperties(node);
-        Fsm mathFsm = getMathModel();
         if (node == null) {
             properties.add(PropertyHelper.createSeparatorProperty("Symbols"));
-            List<Symbol> symbols = new ArrayList<>(mathFsm.getSymbols());
-            symbols.sort((s1, s2) -> SortUtils.compareNatural(
-                    mathFsm.getNodeReference(s1), mathFsm.getNodeReference(s2)));
-
+            List<Symbol> symbols = new ArrayList<>(getMathModel().getSymbols());
+            symbols.sort((s1, s2) -> SortUtils.compareNatural(getMathReference(s1), getMathReference(s2)));
             for (final Symbol symbol : symbols) {
                 properties.add(FsmPropertyHelper.getSymbolProperty(this, symbol));
             }
         } else if (node instanceof VisualEvent) {
-            Event event = ((VisualEvent) node).getReferencedConnection();
-            properties.add(FsmPropertyHelper.getEventSymbolProperty(mathFsm, event));
+            VisualEvent event = (VisualEvent) node;
+            properties.add(FsmPropertyHelper.getEventSymbolProperty(getMathModel(), event.getReferencedConnection()));
         }
         return properties;
     }
diff --git a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/observers/InitialStateSupervisor.java b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/observers/InitialStateSupervisor.java
index 40e3210dc..a162552dd 100644
--- a/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/observers/InitialStateSupervisor.java
+++ b/workcraft/FsmPlugin/src/org/workcraft/plugins/fsm/observers/InitialStateSupervisor.java
@@ -1,12 +1,7 @@
 package org.workcraft.plugins.fsm.observers;
 
 import org.workcraft.dom.Node;
-import org.workcraft.observation.HierarchyEvent;
-import org.workcraft.observation.NodesAddingEvent;
-import org.workcraft.observation.NodesDeletingEvent;
-import org.workcraft.observation.PropertyChangedEvent;
-import org.workcraft.observation.StateEvent;
-import org.workcraft.observation.StateSupervisor;
+import org.workcraft.observation.*;
 import org.workcraft.plugins.fsm.Fsm;
 import org.workcraft.plugins.fsm.State;
 import org.workcraft.utils.Hierarchy;
@@ -34,14 +29,14 @@ public class InitialStateSupervisor extends StateSupervisor {
     @Override
     public void handleHierarchyEvent(HierarchyEvent e) {
         if (e instanceof NodesDeletingEvent) {
-            for (Node node: e.getAffectedNodes()) {
+            for (Node node : e.getAffectedNodes()) {
                 if (node instanceof State) {
                     // Move the initial property to another state on state removal
                     handleStateRemoval((State) node);
                 }
             }
         } else if (e instanceof NodesAddingEvent) {
-            for (Node node: e.getAffectedNodes()) {
+            for (Node node : e.getAffectedNodes()) {
                 if (node instanceof State) {
                     // Make pasted states non-initial
                     ((State) node).setInitialQuiet(false);
@@ -51,25 +46,23 @@ public class InitialStateSupervisor extends StateSupervisor {
     }
 
     private void handleInitialStateChange(State state) {
-        for (State s: Hierarchy.getChildrenOfType(state.getParent(), State.class)) {
-            if (!s.equals(state)) {
-                if (state.isInitial()) {
-                    s.setInitialQuiet(false);
-                } else {
-                    s.setInitialQuiet(true);
-                    break;
-                }
+        for (State otherState : Hierarchy.getChildrenOfType(state.getParent(), State.class)) {
+            if (otherState == state) continue;
+            if (state.isInitial()) {
+                otherState.setInitialQuiet(false);
+            } else {
+                otherState.setInitialQuiet(true);
+                break;
             }
         }
     }
 
     private void handleStateRemoval(State state) {
         if (state.isInitial()) {
-            for (State s: fsm.getStates()) {
-                if (!s.equals(state)) {
-                    s.setInitial(true);
-                    break;
-                }
+            for (State otherState : fsm.getStates()) {
+                if (otherState == state) continue;
+                otherState.setInitial(true);
+                break;
             }
         }
     }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/Fst.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/Fst.java
index 1bbc1ec77..671e07815 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/Fst.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/Fst.java
@@ -1,7 +1,10 @@
 package org.workcraft.plugins.fst;
 
 import org.workcraft.dom.Container;
+import org.workcraft.dom.Model;
 import org.workcraft.dom.Node;
+import org.workcraft.dom.math.MathNode;
+import org.workcraft.dom.references.NameManager;
 import org.workcraft.exceptions.ArgumentException;
 import org.workcraft.plugins.fsm.Fsm;
 import org.workcraft.plugins.fsm.State;
@@ -79,7 +82,36 @@ public class Fst extends Fsm {
     }
 
     public final Collection<SignalEvent> getSignalEvents(Signal signal) {
-        return Hierarchy.getDescendantsOfType(getRoot(), SignalEvent.class, event -> event.getSignal() == signal);
+        return Hierarchy.getDescendantsOfType(getRoot(), SignalEvent.class, event -> event.getSymbol() == signal);
+    }
+
+    @Override
+    public void reparentDependencies(Model srcModel, Collection<? extends MathNode> srcChildren) {
+        for (MathNode srcNode: srcChildren) {
+            if (srcNode instanceof SignalEvent) {
+                SignalEvent srcSignalEvent = (SignalEvent) srcNode;
+                Signal dstSignal = reparentSignal(srcModel, srcSignalEvent.getSymbol());
+                srcSignalEvent.setSymbol(dstSignal);
+            }
+        }
+    }
+
+    private Signal reparentSignal(Model srcModel, Signal srcSignal) {
+        Signal dstSignal = null;
+        if (srcSignal != null) {
+            String signalName = srcModel.getNodeReference(srcSignal);
+            Node dstNode = getNodeByReference(signalName);
+            if (dstNode instanceof Signal) {
+                dstSignal = (Signal) dstNode;
+            } else {
+                if (dstNode != null) {
+                    NameManager nameManager = getReferenceManager().getNameManager(null);
+                    signalName = nameManager.getDerivedName(null, signalName);
+                }
+                dstSignal = createSignal(signalName, srcSignal.getType());
+            }
+        }
+        return dstSignal;
     }
 
 }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/FstPropertyHelper.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/FstPropertyHelper.java
index 76c519ce2..793e1f685 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/FstPropertyHelper.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/FstPropertyHelper.java
@@ -91,7 +91,7 @@ public class FstPropertyHelper {
                         if (node instanceof Signal) {
                             signal = (Signal) node;
                         } else {
-                            Signal oldSignal = signalEvent.getSignal();
+                            Signal oldSignal = signalEvent.getSymbol();
                             Signal.Type type = oldSignal.getType();
                             signal = fst.createSignal(value, type);
                         }
@@ -101,26 +101,20 @@ public class FstPropertyHelper {
                     }
                 },
                 () -> {
-                    Signal signal = signalEvent.getSignal();
-                    if (signal != null) {
-                        return fst.getName(signal);
-                    }
-                    return null;
+                    Signal signal = signalEvent.getSymbol();
+                    return signal == null ? null : fst.getName(signal);
                 })
                 .setCombinable().setTemplatable();
     }
 
     public static PropertyDescriptor getSignalTypeProperty(Signal signal, String description) {
         return new PropertyDeclaration<>(Signal.Type.class, description,
-                value -> signal.setType(value), () -> signal.getType())
-                .setCombinable().setTemplatable();
+                signal::setType, signal::getType).setCombinable().setTemplatable();
     }
 
-    public static PropertyDescriptor getEventDrectionProperty(SignalEvent signalEvent) {
+    public static PropertyDescriptor getEventDirectionProperty(SignalEvent signalEvent) {
         return new PropertyDeclaration<>(SignalEvent.Direction.class, SignalEvent.PROPERTY_DIRECTION,
-                value -> signalEvent.setDirection(value),
-                () -> signalEvent.getDirection())
-                .setCombinable().setTemplatable();
+                signalEvent::setDirection, signalEvent::getDirection).setCombinable().setTemplatable();
     }
 
 }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/SignalEvent.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/SignalEvent.java
index 4dbb3845f..370c66b98 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/SignalEvent.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/SignalEvent.java
@@ -49,8 +49,9 @@ public class SignalEvent extends Event {
         }
     }
 
-    public Signal getSignal() {
-        return (Signal) getSymbol();
+    @Override
+    public Signal getSymbol() {
+        return (Signal) super.getSymbol();
     }
 
 }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualFst.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualFst.java
index 9a5cd402d..2831ca518 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualFst.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualFst.java
@@ -81,11 +81,12 @@ public class VisualFst extends VisualFsm {
             properties.addAll(FstPropertyHelper.getSignalProperties(this));
         } else if (node instanceof VisualSignalEvent) {
             VisualSignalEvent signalEvent = (VisualSignalEvent) node;
-            Signal signal = signalEvent.getReferencedConnection().getSignal();
             properties.add(FstPropertyHelper.getEventSignalProperty(getMathModel(), signalEvent.getReferencedConnection()));
+
+            Signal signal = signalEvent.getReferencedConnection().getSymbol();
             properties.add(FstPropertyHelper.getSignalTypeProperty(signal, Signal.PROPERTY_TYPE));
             if (signal.hasDirection()) {
-                properties.add(FstPropertyHelper.getEventDrectionProperty(signalEvent.getReferencedConnection()));
+                properties.add(FstPropertyHelper.getEventDirectionProperty(signalEvent.getReferencedConnection()));
             }
             properties.removeByName(Event.PROPERTY_SYMBOL);
         }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualSignalEvent.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualSignalEvent.java
index 610f28a47..5485890a3 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualSignalEvent.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/VisualSignalEvent.java
@@ -1,15 +1,15 @@
 package org.workcraft.plugins.fst;
 
-import java.awt.Color;
-
 import org.workcraft.dom.visual.DrawRequest;
 import org.workcraft.dom.visual.Stylable;
+import org.workcraft.plugins.builtin.settings.SignalCommonSettings;
 import org.workcraft.plugins.fsm.VisualEvent;
 import org.workcraft.plugins.fsm.VisualState;
 import org.workcraft.plugins.fst.SignalEvent.Direction;
-import org.workcraft.plugins.builtin.settings.SignalCommonSettings;
 import org.workcraft.plugins.fst.utils.FstUtils;
 
+import java.awt.*;
+
 public class VisualSignalEvent extends VisualEvent {
 
     public VisualSignalEvent() {
@@ -27,7 +27,7 @@ public class VisualSignalEvent extends VisualEvent {
 
     @Override
     public Color getLabelColor() {
-        Signal signal = getReferencedSignal();
+        Signal signal = getReferencedConnection().getSymbol();
         if (signal != null) {
             return FstUtils.getTypeColor(signal.getType());
         }
@@ -39,14 +39,11 @@ public class VisualSignalEvent extends VisualEvent {
         return (SignalEvent) super.getReferencedConnection();
     }
 
-    private Signal getReferencedSignal() {
-        return getReferencedConnection().getSignal();
-    }
-
     @Override
     public String getLabel(DrawRequest r) {
         String result = super.getLabel(r);
-        if (getReferencedSignal().hasDirection()) {
+        Signal signal = getReferencedConnection().getSymbol();
+        if ((signal != null) && signal.hasDirection()) {
             if (SignalCommonSettings.getShowToggle() || (getReferencedConnection().getDirection() != Direction.TOGGLE)) {
                 result += getReferencedConnection().getDirection();
             }
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToFsmConverter.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToFsmConverter.java
index 7fb387182..ee9203df5 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToFsmConverter.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToFsmConverter.java
@@ -1,22 +1,12 @@
 package org.workcraft.plugins.fst.converters;
 
-import java.util.Map;
-
+import org.workcraft.dom.converters.DefaultModelConverter;
 import org.workcraft.dom.math.MathNode;
 import org.workcraft.dom.visual.connections.VisualConnection;
-import org.workcraft.dom.converters.DefaultModelConverter;
-import org.workcraft.plugins.fsm.Event;
-import org.workcraft.plugins.fsm.Fsm;
-import org.workcraft.plugins.fsm.State;
-import org.workcraft.plugins.fsm.Symbol;
-import org.workcraft.plugins.fsm.VisualEvent;
-import org.workcraft.plugins.fsm.VisualFsm;
-import org.workcraft.plugins.fsm.VisualState;
-import org.workcraft.plugins.fst.Fst;
-import org.workcraft.plugins.fst.Signal;
-import org.workcraft.plugins.fst.SignalEvent;
-import org.workcraft.plugins.fst.VisualFst;
-import org.workcraft.plugins.fst.VisualSignalEvent;
+import org.workcraft.plugins.fsm.*;
+import org.workcraft.plugins.fst.*;
+
+import java.util.Map;
 
 public class FstToFsmConverter extends DefaultModelConverter<VisualFst, VisualFsm> {
 
@@ -35,15 +25,25 @@ public class FstToFsmConverter extends DefaultModelConverter<VisualFst, VisualFs
     public VisualConnection convertConnection(VisualConnection srcConnection) {
         VisualConnection dstConnection = super.convertConnection(srcConnection);
         if ((srcConnection instanceof VisualSignalEvent) && (dstConnection instanceof VisualEvent)) {
-            Fst fst = (Fst) getSrcModel().getMathModel();
+            Fst fst = getSrcModel().getMathModel();
             SignalEvent srcSignalEvent = (SignalEvent) srcConnection.getReferencedConnection();
-            Signal srcSignal = srcSignalEvent.getSignal();
-            String name = fst.getName(srcSignal);
+            Signal srcSignal = srcSignalEvent.getSymbol();
+            String directionSuffix = "";
             if (srcSignal.hasDirection()) {
-                name += srcSignalEvent.getDirection();
-                name = name.replace("+", "_PLUS").replace("-", "_MINUS").replace("~", "_TOGGLE");
+                switch (srcSignalEvent.getDirection()) {
+                case PLUS:
+                    directionSuffix = "_PLUS";
+                    break;
+                case MINUS:
+                    directionSuffix = "_MINUS";
+                    break;
+                case TOGGLE:
+                    directionSuffix = "_TOGGLE";
+                    break;
+                }
             }
-            Fsm fsm = (Fsm) getDstModel().getMathModel();
+            String name = fst.getName(srcSignal) + directionSuffix;
+            Fsm fsm = getDstModel().getMathModel();
             Event dstEvent = (Event) dstConnection.getReferencedConnection();
             Symbol symbol = fsm.getOrCreateSymbol(name);
             dstEvent.setSymbol(symbol);
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToStgConverter.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToStgConverter.java
index a12374424..c79833700 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToStgConverter.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/converters/FstToStgConverter.java
@@ -50,7 +50,7 @@ public class FstToStgConverter {
         for (Entry<VisualSignalEvent, VisualNamedTransition> entry: eventToTransitionMap.entrySet()) {
             VisualSignalEvent signalEvent = entry.getKey();
             VisualNamedTransition transition = entry.getValue();
-            Signal signal = signalEvent.getReferencedConnection().getSignal();
+            Signal signal = signalEvent.getReferencedConnection().getSymbol();
             String dstName = dstModel.getMathName(transition);
             String srcName = srcModel.getMathName(signal);
             if (signal.hasDirection()) {
@@ -98,7 +98,7 @@ public class FstToStgConverter {
         Map<VisualSignalEvent, VisualNamedTransition> result = new HashMap<>();
         for (VisualSignalEvent signalEvent : srcModel.getVisualSignalEvents()) {
             VisualNamedTransition transition = null;
-            Signal signal = signalEvent.getReferencedConnection().getSignal();
+            Signal signal = signalEvent.getReferencedConnection().getSymbol();
             String name = srcModel.getMathName(signal);
             if (signal.hasDirection()) {
                 Signal.Type srcType = signal.getType();
diff --git a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/serialisation/SgSerialiser.java b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/serialisation/SgSerialiser.java
index 28fbdea41..1eeac3938 100644
--- a/workcraft/FstPlugin/src/org/workcraft/plugins/fst/serialisation/SgSerialiser.java
+++ b/workcraft/FstPlugin/src/org/workcraft/plugins/fst/serialisation/SgSerialiser.java
@@ -48,15 +48,15 @@ public class SgSerialiser implements ModelSerialiser {
         return SgFormat.getInstance().getUuid();
     }
 
-    private String getSrialisedNodeName(Fsm fsm, Node node) {
+    private String getSerialisedNodeName(Fsm fsm, Node node) {
         return fsm.getNodeReference(node);
     }
 
-    private String getSrialisedEventName(Fsm fsm, Event event) {
+    private String getSerialisedEventName(Fsm fsm, Event event) {
         String result = null;
         if (event instanceof SignalEvent) {
             SignalEvent signalEvent = (SignalEvent) event;
-            Signal signal = signalEvent.getSignal();
+            Signal signal = signalEvent.getSymbol();
             result = fsm.getNodeReference(signal);
             if (signal.hasDirection()) {
                 result += signalEvent.getDirection();
@@ -75,7 +75,7 @@ public class SgSerialiser implements ModelSerialiser {
     private void writeSignalHeader(PrintWriter out, Fst fst, Signal.Type type) {
         HashSet<String> names = new HashSet<>();
         for (Signal signal: fst.getSignals(type)) {
-            String name = getSrialisedNodeName(fst, signal);
+            String name = getSerialisedNodeName(fst, signal);
             names.add(name);
         }
         if (!names.isEmpty()) {
@@ -103,7 +103,7 @@ public class SgSerialiser implements ModelSerialiser {
     private void writeSymbolHeader(PrintWriter out, Fsm fsm) {
         HashSet<String> names = new HashSet<>();
         for (Event event: fsm.getEvents()) {
-            String name = getSrialisedEventName(fsm, event);
+            String name = getSerialisedEventName(fsm, event);
             names.add(name);
         }
         if (!names.isEmpty()) {
@@ -120,9 +120,9 @@ public class SgSerialiser implements ModelSerialiser {
             State firstState = (State) event.getFirst();
             State secondState = (State) event.getSecond();
             if ((firstState != null) && (secondState != null)) {
-                String eventName = getSrialisedEventName(fsm, event);
-                String firstStateName = getSrialisedNodeName(fsm, firstState);
-                String secondStateName = getSrialisedNodeName(fsm, secondState);
+                String eventName = getSerialisedEventName(fsm, event);
+                String firstStateName = getSerialisedNodeName(fsm, firstState);
+                String secondStateName = getSerialisedNodeName(fsm, secondState);
                 out.write(firstStateName + " " + eventName + " " + secondStateName + "\\n");
             }
         }
@@ -130,7 +130,7 @@ public class SgSerialiser implements ModelSerialiser {
 
     private void writeMarking(PrintWriter out, Fsm fsm, State state) {
         if (state != null) {
-            String stateStr = getSrialisedNodeName(fsm, state);
+            String stateStr = getSerialisedNodeName(fsm, state);
             out.write(".marking {" + stateStr + "}\\n");
         }
     }