15
15
16
16
import com .ca .lsp .core .cobol .params .CobolDialect ;
17
17
import com .ca .lsp .core .cobol .preprocessor .CobolSourceFormat ;
18
- import com .ca .lsp .core .cobol .preprocessor .ProcessingConstants ;
19
- import com .google .common .base .Strings ;
20
-
21
- import static com .ca .lsp .core .cobol .preprocessor .CobolSourceFormat .TANDEM ;
18
+ import com .ca .lsp .core .cobol .preprocessor .sub .util .CobolLineUtils ;
19
+ import lombok .Data ;
20
+ import lombok .NoArgsConstructor ;
22
21
22
+ /**
23
+ * This class represents a structure for a COBOL code line that is used for parsing. The exact line
24
+ * structure depends on the format, see {@link CobolSourceFormat}
25
+ */
26
+ @ Data
27
+ @ NoArgsConstructor
23
28
public class CobolLine {
24
- protected String commentArea = "" ;
25
- protected String commentAreaOriginal = "" ;
26
- protected String contentAreaA = "" ;
27
- protected String contentAreaAOriginal = "" ;
28
- protected String contentAreaB = "" ;
29
- protected String contentAreaBOriginal = "" ;
30
- protected CobolDialect dialect ;
31
- protected CobolSourceFormat format ;
32
- protected String indicatorArea = " " ;
33
- protected String indicatorAreaOriginal = "" ;
34
- protected int number ;
35
- protected CobolLine predecessor ;
36
- protected String sequenceArea = "" ;
37
- protected String sequenceAreaOriginal = "" ;
38
- protected CobolLine successor ;
39
- protected CobolLineTypeEnum type = CobolLineTypeEnum .NORMAL ;
29
+ private String commentArea = "" ;
30
+ private String contentAreaA = "" ;
31
+ private String contentAreaB = "" ;
32
+ private CobolDialect dialect ;
33
+ private CobolSourceFormat format ;
34
+ private String indicatorArea = " " ;
35
+ private int number ;
36
+ private CobolLine predecessor ;
37
+ private String sequenceArea = "" ;
38
+ private CobolLine successor ;
39
+ private CobolLineTypeEnum type = CobolLineTypeEnum .NORMAL ;
40
40
41
- // getter & setter
41
+ /**
42
+ * Create and return a blank sequence area depended on the type of the line
43
+ *
44
+ * @return an empty String or a String with white spaces
45
+ */
42
46
public String getBlankSequenceArea () {
43
- return createBlankSequenceArea (format );
44
- }
45
-
46
- public String getCommentArea () {
47
- return commentArea ;
48
- }
49
-
50
- public String getCommentAreaOriginal () {
51
- return commentAreaOriginal ;
47
+ return CobolLineUtils .createBlankSequenceArea (format );
52
48
}
53
49
50
+ /**
51
+ * Build and return a significant for syntax parsing content line
52
+ *
53
+ * @return a String with combined content areas
54
+ */
54
55
public String getContentArea () {
55
56
return contentAreaA + contentAreaB ;
56
57
}
57
58
58
- public String getContentAreaA () {
59
- return contentAreaA ;
60
- }
61
-
62
- public String getContentAreaAOriginal () {
63
- return contentAreaAOriginal ;
64
- }
65
-
66
- public String getContentAreaB () {
67
- return contentAreaB ;
68
- }
69
-
70
- public String getContentAreaBOriginal () {
71
- return contentAreaBOriginal ;
72
- }
73
-
74
- public String getContentAreaOriginal () {
75
- return contentAreaAOriginal + contentAreaBOriginal ;
76
- }
77
-
78
- public CobolDialect getDialect () {
79
- return dialect ;
80
- }
81
-
82
- public CobolSourceFormat getFormat () {
83
- return format ;
84
- }
85
-
86
- public String getIndicatorArea () {
87
- return indicatorArea ;
88
- }
89
-
90
- public String getIndicatorAreaOriginal () {
91
- return indicatorAreaOriginal ;
92
- }
93
-
94
- public int getNumber () {
95
- return number ;
96
- }
97
-
98
- public CobolLine getPredecessor () {
99
- return predecessor ;
100
- }
101
-
102
- public String getSequenceArea () {
103
- return sequenceArea ;
104
- }
105
-
106
- public String getSequenceAreaOriginal () {
107
- return sequenceAreaOriginal ;
108
- }
109
-
110
- public CobolLine getSuccessor () {
111
- return successor ;
112
- }
113
-
114
- public CobolLineTypeEnum getType () {
115
- return type ;
116
- }
117
-
118
- public void setCommentArea (String commentArea ) {
119
- this .commentArea = commentArea ;
120
- }
121
-
122
- public void setCommentAreaOriginal (String commentAreaOriginal ) {
123
- this .commentAreaOriginal = commentAreaOriginal ;
124
- }
125
-
126
- public void setContentAreaA (String contentAreaA ) {
127
- this .contentAreaA = contentAreaA ;
128
- }
129
-
130
- public void setContentAreaAOriginal (String contentAreaAOriginal ) {
131
- this .contentAreaAOriginal = contentAreaAOriginal ;
132
- }
133
-
134
- public void setContentAreaB (String contentAreaB ) {
135
- this .contentAreaB = contentAreaB ;
136
- }
137
-
138
- public void setContentAreaBOriginal (String contentAreaBOriginal ) {
139
- this .contentAreaBOriginal = contentAreaBOriginal ;
140
- }
141
-
142
- public void setDialect (CobolDialect dialect ) {
143
- this .dialect = dialect ;
144
- }
145
-
146
- public void setFormat (CobolSourceFormat format ) {
147
- this .format = format ;
148
- }
149
-
150
- public void setIndicatorArea (String indicatorArea ) {
151
- this .indicatorArea = indicatorArea ;
152
- }
153
-
154
- public void setIndicatorAreaOriginal (String indicatorAreaOriginal ) {
155
- this .indicatorAreaOriginal = indicatorAreaOriginal ;
156
- }
157
-
158
- public void setNumber (int number ) {
159
- this .number = number ;
160
- }
161
-
162
- public void setSequenceArea (String sequenceArea ) {
163
- this .sequenceArea = sequenceArea ;
164
- }
165
-
166
- public void setSequenceAreaOriginal (String sequenceAreaOriginal ) {
167
- this .sequenceAreaOriginal = sequenceAreaOriginal ;
168
- }
169
-
170
- public void setType (CobolLineTypeEnum type ) {
171
- this .type = type ;
172
- }
173
-
59
+ /**
60
+ * Set previous line and bind this lines together
61
+ *
62
+ * @param predecessor - the previous line in a document
63
+ */
174
64
public void setPredecessor (final CobolLine predecessor ) {
175
65
this .predecessor = predecessor ;
176
66
@@ -179,6 +69,11 @@ public void setPredecessor(final CobolLine predecessor) {
179
69
}
180
70
}
181
71
72
+ /**
73
+ * Set following line and bind this lines together
74
+ *
75
+ * @param successor - the previous line in a document
76
+ */
182
77
public void setSuccessor (final CobolLine successor ) {
183
78
this .successor = successor ;
184
79
@@ -187,91 +82,13 @@ public void setSuccessor(final CobolLine successor) {
187
82
}
188
83
}
189
84
190
- public static CobolLine copyCobolLineWithContentArea (
191
- final String contentArea , final CobolLine line ) {
192
- CobolLine cobolLine = copyCobolLine (line );
193
- cobolLine .setContentAreaA (extractContentAreaA (contentArea ));
194
- cobolLine .setContentAreaB (extractContentAreaB (contentArea ));
195
- return cobolLine ;
196
- }
197
-
198
85
/**
199
- * @param indicatorArea
200
- * @param contentArea
201
- * @param line
202
- * @return new CobolLine
86
+ * Serialize the line and combine the fields that are significant for parsing
87
+ *
88
+ * @return combination of string parts of the COBOL line
203
89
*/
204
- public static CobolLine copyCobolLineWithIndicatorAndContentArea (
205
- final String indicatorArea , final String contentArea , final CobolLine line ) {
206
-
207
- CobolLine cobolLine = copyCobolLine (line );
208
- cobolLine .setIndicatorArea (indicatorArea );
209
- cobolLine .setContentAreaA (extractContentAreaA (contentArea ));
210
- cobolLine .setContentAreaB (extractContentAreaB (contentArea ));
211
- return cobolLine ;
212
- }
213
-
214
- public static CobolLine copyCobolLineWithIndicatorArea (
215
- final String indicatorArea , final CobolLine line ) {
216
- CobolLine cobolLine = copyCobolLine (line );
217
- cobolLine .setIndicatorArea (indicatorArea );
218
- return cobolLine ;
219
- }
220
-
221
- public static CobolLine copyCobolLineWithEmptyContent (final CobolLine line ) {
222
- CobolLine cobolLine = new CobolLine ();
223
- cobolLine .setFormat (line .format );
224
- cobolLine .setDialect (line .dialect );
225
- cobolLine .setNumber (line .number );
226
- cobolLine .setType (line .type );
227
- cobolLine .setPredecessor (line .predecessor );
228
- cobolLine .setSuccessor (line .successor );
229
- return cobolLine ;
230
- }
231
-
232
- private static CobolLine copyCobolLine (final CobolLine line ) {
233
- CobolLine cobolLine = new CobolLine ();
234
- cobolLine .setSequenceArea (line .getSequenceArea ());
235
- cobolLine .setSequenceAreaOriginal (line .getSequenceAreaOriginal ());
236
- cobolLine .setIndicatorArea (line .indicatorArea );
237
- cobolLine .setIndicatorAreaOriginal (line .indicatorAreaOriginal );
238
- cobolLine .setContentAreaA (line .contentAreaA );
239
- cobolLine .setContentAreaAOriginal (line .contentAreaAOriginal );
240
- cobolLine .setContentAreaB (line .contentAreaB );
241
- cobolLine .setContentAreaBOriginal (line .contentAreaBOriginal );
242
- cobolLine .setCommentArea (line .commentArea );
243
- cobolLine .setCommentAreaOriginal (line .commentAreaOriginal );
244
- cobolLine .setFormat (line .format );
245
- cobolLine .setDialect (line .dialect );
246
- cobolLine .setNumber (line .number );
247
- cobolLine .setType (line .type );
248
- cobolLine .setPredecessor (line .predecessor );
249
- cobolLine .setSuccessor (line .successor );
250
- return cobolLine ;
251
- }
252
-
253
- public static String createBlankSequenceArea (final CobolSourceFormat format ) {
254
- return TANDEM .equals (format ) ? "" : Strings .repeat (ProcessingConstants .WS , 6 );
255
- }
256
-
257
- protected static String extractContentAreaA (final String contentArea ) {
258
- return contentArea .length () > 4 ? contentArea .substring (0 , 4 ) : contentArea ;
259
- }
260
-
261
- protected static String extractContentAreaB (final String contentArea ) {
262
- return contentArea .length () > 4 ? contentArea .substring (4 ) : "" ;
263
- }
264
-
265
- public String serialize () {
266
- return sequenceArea + indicatorArea + contentAreaA + contentAreaB + commentArea ;
267
- }
268
-
269
- public String serializeWithoutCommentArea () {
270
- return sequenceArea + indicatorArea + contentAreaA + contentAreaB ;
271
- }
272
-
273
90
@ Override
274
91
public String toString () {
275
- return serialize () ;
92
+ return sequenceArea + indicatorArea + contentAreaA + contentAreaB + commentArea ;
276
93
}
277
94
}
0 commit comments