Skip to content

Implementation of REMOVE statement in CICS #2629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ cics_release: RELEASE cics_release_option;
cics_release_option: (PROGRAM cics_name | cics_handle_response)+;

/** REMOVE SUBEVENT */
cics_remove: REMOVE (SUBEVENT cics_data_value | EVENT cics_data_value | cics_handle_response)+;
cics_remove: REMOVE cics_remove_option;
cics_remove_option: ((SUBEVENT | EVENT) cics_data_value | cics_handle_response)+;

/** RESET ACQPROCESS / RESET ACTIVITY */
cics_reset: RESET (cics_reset_acqprocess | cics_reset_activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
optionsMap.put(
CICSPostOptionsCheckUtility.RULE_INDEX,
new CICSPostOptionsCheckUtility(context, errors));
optionsMap.put(
CICSRemoveOptionsCheckUtility.RULE_INDEX,
new CICSRemoveOptionsCheckUtility(context, errors));
spOptionsMap.put(
CICSInquireSPOptionsCheckUtility.RULE_INDEX,
new CICSInquireSPOptionsCheckUtility(context, errors));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.implicitDialects.cics.utility;

import org.antlr.v4.runtime.ParserRuleContext;
import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext;
import org.eclipse.lsp.cobol.common.error.ErrorSeverity;
import org.eclipse.lsp.cobol.common.error.SyntaxError;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_remove;

/** Checks CICS REMOVE SUBEVENT rules for required and invalid options */
public class CICSRemoveOptionsCheckUtility extends CICSOptionsCheckBaseUtility {
public static final int RULE_INDEX = RULE_cics_remove;

private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
new HashMap<Integer, ErrorSeverity>() {
{
put(CICSLexer.SUBEVENT, ErrorSeverity.ERROR);
put(CICSLexer.EVENT, ErrorSeverity.ERROR);
}
};

public CICSRemoveOptionsCheckUtility(DialectProcessingContext context, List<SyntaxError> errors) {
super(context, errors, DUPLICATE_CHECK_OPTIONS);
}

/**
* Entrypoint to check CICS REMOVE SUBEVENT rule options
*
* @param ctx ParserRuleContext subclass containing options
* @param <E> A subclass of ParserRuleContext
*/
public <E extends ParserRuleContext> void checkOptions(E ctx) {
if (ctx instanceof CICSParser.Cics_remove_optionContext) {
checkRemoveSubevent((CICSParser.Cics_remove_optionContext) ctx);
}
checkDuplicates(ctx);
}

private void checkRemoveSubevent(CICSParser.Cics_remove_optionContext ctx) {
checkHasMandatoryOptions(ctx.SUBEVENT(), ctx, "SUBEVENT");
checkHasMandatoryOptions(ctx.EVENT(), ctx, "EVENT");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.usecases;

import com.google.common.collect.ImmutableMap;
import org.eclipse.lsp.cobol.common.error.ErrorSource;
import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

/**
* Test CICS REMOVE SUBEVENT command. Documentation link: <a
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-remove-subevent">REMOVE SUBEVENT Command</a>
*
* <p>This class tests the REMOVE SUBEVENT command.
*/
public class TestCICSRemove {
private static final String REMOVE_SUBEVENT_VALID =
"REMOVE SUBEVENT({$varOne}) EVENT({$varTwo})";

private static final String REMOVE_SUBEVENT_INVALID_NO_SUBEVENT =
"REMOVE {_EVENT({$varOne})|errorOne_}";

private static final String REMOVE_SUBEVENT_INVALID_NO_EVENT =
"REMOVE {_SUBEVENT({$varOne})|errorOne_}";

private static final String REMOVE_SUBEVENT_INVALID_DUPLICATE_EVENT =
"REMOVE SUBEVENT({$varOne}) EVENT({$varTwo}) {EVENT|errorOne}({$varTwo})";

@Test
void testRemoveSubeventValid() {
CICSTestUtils.noErrorTest(REMOVE_SUBEVENT_VALID);
}

@Test
void testRemoveSubeventInvalidNoSubevent() {
CICSTestUtils.errorTest(
REMOVE_SUBEVENT_INVALID_NO_SUBEVENT,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Missing required option: SUBEVENT",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testRemoveSubeventInvalidNoEvent() {
CICSTestUtils.errorTest(
REMOVE_SUBEVENT_INVALID_NO_EVENT,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Missing required option: EVENT",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testRemoveSubeventInvalidExtraOption() {
CICSTestUtils.errorTest(
REMOVE_SUBEVENT_INVALID_DUPLICATE_EVENT,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Excessive options provided for: EVENT",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}
}
Loading