~cpn-gui/tapaal/SrcDestPair

« back to all changes in this revision

Viewing changes to src/pipe/gui/widgets/TypeCheckingPanel.java

  • Committer: Mark Glavind
  • Date: 2019-06-15 14:26:46 UTC
  • mfrom: (1066.1.4 finalbugfixing)
  • Revision ID: mglavi14@student.aau.dk-20190615142646-7nsviy24aj11y2t6
 merge to add transport arcs to typchecking analysis

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
package pipe.gui.widgets;
2
2
 
3
3
import dk.aau.cs.gui.Context;
 
4
import dk.aau.cs.model.tapn.*;
4
5
import dk.aau.cs.model.tapn.Colored.*;
5
6
import dk.aau.cs.model.tapn.Colored.Color;
6
7
import dk.aau.cs.model.tapn.Colored.ExpressionSupport.ExprValues;
7
 
import dk.aau.cs.model.tapn.TimedInputArc;
8
 
import dk.aau.cs.model.tapn.TimedOutputArc;
9
 
import dk.aau.cs.model.tapn.TimedPlace;
10
 
import dk.aau.cs.model.tapn.TimedTransition;
11
8
 
12
9
import javax.swing.*;
13
 
import javax.swing.border.TitledBorder;
14
10
import java.awt.*;
15
11
import java.awt.event.ActionEvent;
16
12
import java.awt.event.ActionListener;
23
19
    List<ColoredInputArc> inputArcs = new ArrayList();
24
20
    List<ColoredOutputArc> outputArcs = new ArrayList();
25
21
    List<ColoredTransition> transitions = new ArrayList();
 
22
    List<ColoredTransportArc> transportArcs = new ArrayList<ColoredTransportArc>();
26
23
    List<TimedPlace> places = new ArrayList();
27
24
    List<String> errorMsgs = new ArrayList<String>();
28
25
 
42
39
 
43
40
    private void runTypeCheckingAnalysis() {
44
41
        loadExpressions();
 
42
        for (ColoredTransportArc transportArc : transportArcs) {
 
43
            if (transportArc.getInputExpression() != null) {
 
44
                getColorTypeMismatchErrors(transportArc.getInputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to transition " + transportArc.transition().name() );
 
45
 
 
46
                ColorType ct;
 
47
                if (transportArc.source() instanceof LocalColoredPlace)
 
48
                    ct = ((LocalColoredPlace) transportArc.source()).getColorType();
 
49
                else
 
50
                    ct = ((SharedColoredPlace)transportArc.source()).getColorType();
 
51
 
 
52
                getConnectedPlaceErrors(ct, transportArc.getInputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to transition " + transportArc.transition().name());
 
53
            }
 
54
            if (transportArc.getOutputExpression() != null) {
 
55
                getColorTypeMismatchErrors(transportArc.getOutputExpression().getValues(new ExprValues()), "Transport arc from transition " + transportArc.transition().name() + " to place " + transportArc.destination().name());
 
56
 
 
57
                ColorType ct;
 
58
                if (transportArc.source() instanceof LocalColoredPlace)
 
59
                    ct = ((LocalColoredPlace) transportArc.source()).getColorType();
 
60
                else
 
61
                    ct = ((SharedColoredPlace)transportArc.source()).getColorType();
 
62
 
 
63
                getConnectedPlaceErrors(ct, transportArc.getOutputExpression().getValues(new ExprValues()), "Transport arc from place " + transportArc.source().name() + " to place " + transportArc.destination().name());
 
64
            }
 
65
        }
 
66
 
45
67
        for (ColoredInputArc inputArc : inputArcs) {
46
68
            if (inputArc.getArcExpression() != null) {
47
69
                getColorTypeMismatchErrors(inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name() );
48
 
                getConnectedPlaceErrorsInput(inputArc, inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name());
 
70
 
 
71
                ColorType ct;
 
72
                if (inputArc.source() instanceof LocalColoredPlace)
 
73
                    ct = ((LocalColoredPlace) inputArc.source()).getColorType();
 
74
                else
 
75
                    ct = ((SharedColoredPlace)inputArc.source()).getColorType();
 
76
 
 
77
                getConnectedPlaceErrors(ct, inputArc.getArcExpression().getValues(new ExprValues()), "Input arc from place " + inputArc.source().name() + " to transition " + inputArc.destination().name());
49
78
            }
50
79
        }
51
80
        for (ColoredOutputArc outputArc : outputArcs) {
52
81
            if (outputArc.getExpression() != null) {
53
82
                getColorTypeMismatchErrors(outputArc.getExpression().getValues(new ExprValues()), "Output arc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
54
 
                getConnectedPlaceErrosOutput(outputArc, outputArc.getExpression().getValues(new ExprValues()), "outputArc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
 
83
 
 
84
                ColorType ct;
 
85
                if (outputArc.destination() instanceof LocalColoredPlace)
 
86
                    ct = ((LocalColoredPlace) outputArc.destination()).getColorType();
 
87
                else
 
88
                    ct = ((SharedColoredPlace)outputArc.destination()).getColorType();
 
89
 
 
90
                getConnectedPlaceErrors(ct, outputArc.getExpression().getValues(new ExprValues()), "outputArc from transition " + outputArc.source().name() + " to place " + outputArc.destination().name());
55
91
            }
56
92
        }
57
93
 
63
99
 
64
100
    }
65
101
 
66
 
    private void getConnectedPlaceErrosOutput(ColoredOutputArc outputArc, ExprValues exprValues, String identifier) {
67
 
        ColorType colorType;
68
 
        if (outputArc.destination() instanceof LocalColoredPlace)
69
 
         colorType = ((LocalColoredPlace)outputArc.destination()).getColorType();
70
 
        else
71
 
            colorType =  ((SharedColoredPlace)outputArc.destination()).getColorType();
72
 
 
 
102
 
 
103
 
 
104
    private void getConnectedPlaceErrors(ColorType colorType, ExprValues exprValues, String identifier) {
73
105
        for (Variable variable : exprValues.getVariables()) {
74
106
            if (variable.getColorType().getName().equals(colorType.getName())) {
75
107
                errorMsgs.add("<html>" + identifier + ": The Variable <b>" + variable.getName() + "</b> does not have the same color type as the connecting place.");
94
126
        }
95
127
    }
96
128
 
97
 
    private void getConnectedPlaceErrorsInput(ColoredInputArc inputArc, ExprValues exprValues, String identifier) {
98
 
        ColorType colorType;
99
 
        if (inputArc.source() instanceof  LocalColoredPlace)
100
 
            colorType = ((LocalColoredPlace)inputArc.source()).getColorType();
101
 
        else
102
 
            colorType = ((SharedColoredPlace)inputArc.source()).getColorType();
103
 
 
104
 
        for (Variable variable : exprValues.getVariables()) {
105
 
            if (variable.getColorType().getName().equals(colorType.getName())) {
106
 
                errorMsgs.add("<html>" + identifier + ": The Variable <b>" + variable.getName() + "</b> does not have the same color type as the connecting place.");
107
 
            }
108
 
        }
109
 
        for (Color color : exprValues.getColors()) {
110
 
            boolean colorExists = false;
111
 
            for (Color color1 : colorType) {
112
 
                if (color.equals(color1)) {
113
 
                    colorExists = true;
114
 
                }
115
 
            }
116
 
            if (colorExists != true) {
117
 
                errorMsgs.add("<html>" + identifier + ": color types do not match");
118
 
            }
119
 
        }
120
 
 
121
 
        for (ColorType type : exprValues.getColorTypes()) {
122
 
            if (!type.getName().equals(colorType.getName())) {
123
 
                errorMsgs.add("<html>" + identifier + ": The color type <b>" + colorType.getName() + "</b> does not have the same color type as the connecting place.");
124
 
            }
125
 
        }
126
 
    }
127
129
 
128
130
    private void getColorTypeMismatchErrors(ExprValues exprValues, String identifier) {
129
131
        for (Color color : exprValues.getColors()) {
183
185
    }
184
186
 
185
187
    private void loadExpressions() {
 
188
        transportArcs.clear();
186
189
        inputArcs.clear();
187
190
        outputArcs.clear();
188
191
        transitions.clear();
189
192
        places.clear();
 
193
        for (TransportArc transportArc : context.activeModel().transportArcs()) {
 
194
            transportArcs.add((ColoredTransportArc) transportArc);
 
195
        }
190
196
 
191
197
        for (TimedInputArc arc : context.activeModel().inputArcs()) {
192
198
            inputArcs.add((ColoredInputArc) arc);