Skip to content

Commit 575c27b

Browse files
authored
fix: CICS suspend improvements (#2655)
1 parent d0a4f9d commit 575c27b

File tree

4 files changed

+176
-1
lines changed

4 files changed

+176
-1
lines changed

server/engine/src/main/antlr4/org/eclipse/lsp/cobol/implicitDialects/cics/CICSParser.g4

+2-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ cics_startbrowse_event: EVENT (BROWSETOKEN cics_data_area | ACTIVITYID cics_data
790790
cics_startbrowse_process: PROCESS (PROCESSTYPE cics_data_value | BROWSETOKEN cics_data_area | cics_handle_response)+;
791791

792792
/** SUSPEND (both) */
793-
cics_suspend: SUSPEND (ACQACTIVITY | ACQPROCESS | ACTIVITY cics_data_value | cics_handle_response)*;
793+
cics_suspend: SUSPEND cics_suspend_body;
794+
cics_suspend_body: (ACQACTIVITY | ACQPROCESS | ACTIVITY cics_data_value | cics_handle_response)*;
794795

795796
/** SYNCPOINT / SYNCPOINT ROLLBACK */
796797
cics_syncpoint: SYNCPOINT (cics_handle_response | ROLLBACK)*;

server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSOptionsCheckUtility.java

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
189189
optionsMap.put(
190190
CICSXctlOptionsUtility.RULE_INDEX,
191191
new CICSXctlOptionsUtility(context, errors));
192+
optionsMap.put(
193+
CICSSuspendOptionsUtility.RULE_INDEX,
194+
new CICSSuspendOptionsUtility(context, errors));
192195
optionsMap.put(
193196
CICSGetMainOptionsUtility.RULE_INDEX,
194197
new CICSGetMainOptionsUtility(context, errors));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2024 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
16+
package org.eclipse.lsp.cobol.implicitDialects.cics.utility;
17+
18+
import org.antlr.v4.runtime.ParserRuleContext;
19+
import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext;
20+
import org.eclipse.lsp.cobol.common.error.ErrorSeverity;
21+
import org.eclipse.lsp.cobol.common.error.SyntaxError;
22+
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer;
23+
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser;
24+
25+
import java.util.HashMap;
26+
import java.util.List;
27+
import java.util.Map;
28+
29+
import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_suspend;
30+
import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_suspend_body;
31+
32+
/** Checks CICS Suspend rules for required and invalid options */
33+
public class CICSSuspendOptionsUtility extends CICSOptionsCheckBaseUtility {
34+
35+
public static final int RULE_INDEX = RULE_cics_suspend;
36+
37+
private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
38+
new HashMap<Integer, ErrorSeverity>() {
39+
{
40+
put(CICSLexer.ACQACTIVITY, ErrorSeverity.WARNING);
41+
put(CICSLexer.ACQPROCESS, ErrorSeverity.WARNING);
42+
put(CICSLexer.ACTIVITY, ErrorSeverity.ERROR);
43+
}
44+
};
45+
46+
public CICSSuspendOptionsUtility(DialectProcessingContext context, List<SyntaxError> errors) {
47+
super(context, errors, DUPLICATE_CHECK_OPTIONS);
48+
}
49+
50+
/**
51+
* Entrypoint to check CICS SUSPEND rule options
52+
*
53+
* @param ctx ParserRuleContext subclass containing options
54+
* @param <E> A subclass of ParserRuleContext
55+
*/
56+
public <E extends ParserRuleContext> void checkOptions(E ctx) {
57+
if (ctx.getRuleIndex() == RULE_cics_suspend_body) {
58+
checkSuspend((CICSParser.Cics_suspend_bodyContext) ctx);
59+
}
60+
checkDuplicates(ctx);
61+
}
62+
63+
@SuppressWarnings("unchecked")
64+
private void checkSuspend(CICSParser.Cics_suspend_bodyContext ctx) {
65+
checkHasMutuallyExclusiveOptions("ACQACTIVITY or ACQPROCESS or ACTIVITY",
66+
ctx.ACQACTIVITY(), ctx.ACQPROCESS(), ctx.ACTIVITY());
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2024 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
package org.eclipse.lsp.cobol.usecases;
16+
17+
import com.google.common.collect.ImmutableMap;
18+
import org.eclipse.lsp.cobol.common.error.ErrorSource;
19+
import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils;
20+
import org.eclipse.lsp4j.Diagnostic;
21+
import org.eclipse.lsp4j.DiagnosticSeverity;
22+
import org.eclipse.lsp4j.Range;
23+
import org.junit.jupiter.api.Test;
24+
25+
import java.util.Map;
26+
27+
/**
28+
* Test CICS SUSPEND command. Documentation link: <a
29+
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-suspend">SUSPEND
30+
* Command</a>
31+
*
32+
* <p>This class tests all variations of the SUSPEND command found in the link above.
33+
*/
34+
public class TestCicsSuspend {
35+
private static final String SUSPEND_BARE = "SUSPEND";
36+
private static final String SUSPEND_ACTIVITY = "SUSPEND ACTIVITY({$varOne})";
37+
private static final String SUSPEND_ACQACTIVITY = "SUSPEND ACQACTIVITY";
38+
private static final String SUSPEND_ACQPROCESS = "SUSPEND ACQPROCESS";
39+
40+
private static final String SUSPEND_INVALID_ONE = "SUSPEND {ACQACTIVITY|error1} {ACQPROCESS|error1}";
41+
private static final String SUSPEND_INVALID_TWO = "SUSPEND {ACTIVITY|error1}({$varOne}) {ACQPROCESS|error1}";
42+
private static final String SUSPEND_INVALID_THREE = "SUSPEND {ACQACTIVITY|error1} {ACTIVITY|error1}({$varOne})";
43+
44+
@Test
45+
void testSuspend() {
46+
CICSTestUtils.noErrorTest(SUSPEND_BARE);
47+
}
48+
49+
@Test
50+
void testSuspendActivity() {
51+
CICSTestUtils.noErrorTest(SUSPEND_ACTIVITY);
52+
}
53+
54+
@Test
55+
void testSuspendAcqActivity() {
56+
CICSTestUtils.noErrorTest(SUSPEND_ACQACTIVITY);
57+
}
58+
59+
@Test
60+
void testSuspendAcqProcess() {
61+
CICSTestUtils.noErrorTest(SUSPEND_ACQPROCESS);
62+
}
63+
64+
@Test
65+
void testSuspendInvalidOne() {
66+
Map<String, Diagnostic> expectedDiagnostic =
67+
ImmutableMap.of(
68+
"error1",
69+
new Diagnostic(
70+
new Range(),
71+
"Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY",
72+
DiagnosticSeverity.Error,
73+
ErrorSource.PARSING.getText()));
74+
CICSTestUtils.errorTest(SUSPEND_INVALID_ONE, expectedDiagnostic);
75+
}
76+
77+
@Test
78+
void testSuspendInvalidTwo() {
79+
Map<String, Diagnostic> expectedDiagnostic =
80+
ImmutableMap.of(
81+
"error1",
82+
new Diagnostic(
83+
new Range(),
84+
"Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY",
85+
DiagnosticSeverity.Error,
86+
ErrorSource.PARSING.getText()));
87+
CICSTestUtils.errorTest(SUSPEND_INVALID_TWO, expectedDiagnostic);
88+
}
89+
90+
@Test
91+
void testSuspendInvalidThree() {
92+
Map<String, Diagnostic> expectedDiagnostic =
93+
ImmutableMap.of(
94+
"error1",
95+
new Diagnostic(
96+
new Range(),
97+
"Exactly one option required, options are mutually exclusive: ACQACTIVITY or ACQPROCESS or ACTIVITY",
98+
DiagnosticSeverity.Error,
99+
ErrorSource.PARSING.getText()));
100+
CICSTestUtils.errorTest(SUSPEND_INVALID_THREE, expectedDiagnostic);
101+
}
102+
103+
}

0 commit comments

Comments
 (0)