|
| 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.implicitDialects.cics.utility; |
| 16 | + |
| 17 | +import org.antlr.v4.runtime.ParserRuleContext; |
| 18 | +import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext; |
| 19 | +import org.eclipse.lsp.cobol.common.error.ErrorSeverity; |
| 20 | +import org.eclipse.lsp.cobol.common.error.SyntaxError; |
| 21 | +import org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer; |
| 22 | +import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser; |
| 23 | + |
| 24 | +import java.util.*; |
| 25 | + |
| 26 | +import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.*; |
| 27 | + |
| 28 | +/** Checks CICS SOAPFAULT rules for required and invalid options */ |
| 29 | +public class CICSSoapfaultOptionsCheckUtility extends CICSOptionsCheckBaseUtility { |
| 30 | + |
| 31 | + public static final int RULE_INDEX = RULE_cics_soapfault; |
| 32 | + |
| 33 | + private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS = |
| 34 | + new HashMap<Integer, ErrorSeverity>() { |
| 35 | + { |
| 36 | + put(CICSLexer.FAULTCODE, ErrorSeverity.ERROR); |
| 37 | + put(CICSLexer.CLIENT, ErrorSeverity.ERROR); |
| 38 | + put(CICSLexer.SERVER, ErrorSeverity.ERROR); |
| 39 | + put(CICSLexer.SENDER, ErrorSeverity.ERROR); |
| 40 | + put(CICSLexer.RECEIVER, ErrorSeverity.ERROR); |
| 41 | + put(CICSLexer.FAULTCODESTR, ErrorSeverity.ERROR); |
| 42 | + put(CICSLexer.FAULTCODELEN, ErrorSeverity.ERROR); |
| 43 | + put(CICSLexer.FAULTSTRING, ErrorSeverity.ERROR); |
| 44 | + put(CICSLexer.FAULTSTRLEN, ErrorSeverity.ERROR); |
| 45 | + put(CICSLexer.NATLANG, ErrorSeverity.ERROR); |
| 46 | + put(CICSLexer.ROLE, ErrorSeverity.ERROR); |
| 47 | + put(CICSLexer.ROLELENGTH, ErrorSeverity.ERROR); |
| 48 | + put(CICSLexer.FAULTACTOR, ErrorSeverity.ERROR); |
| 49 | + put(CICSLexer.FAULTACTLEN, ErrorSeverity.ERROR); |
| 50 | + put(CICSLexer.DETAIL, ErrorSeverity.ERROR); |
| 51 | + put(CICSLexer.DETAILLENGTH, ErrorSeverity.ERROR); |
| 52 | + put(CICSLexer.FROMCCSID, ErrorSeverity.ERROR); |
| 53 | + |
| 54 | + put(CICSLexer.DELETE, ErrorSeverity.WARNING); |
| 55 | + put(CICSLexer.CREATE, ErrorSeverity.WARNING); |
| 56 | + put(CICSLexer.ADD, ErrorSeverity.WARNING); |
| 57 | + } |
| 58 | + }; |
| 59 | + |
| 60 | + public CICSSoapfaultOptionsCheckUtility(DialectProcessingContext context, List<SyntaxError> errors) { |
| 61 | + super(context, errors, DUPLICATE_CHECK_OPTIONS); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Entrypoint to check CICS SOAPFAULT CREATE rules for required and invalid options |
| 66 | + * @param ctx ParserRuleContext subclass containing options |
| 67 | + * @param <E> A subclass of ParserRuleContext |
| 68 | + */ |
| 69 | + public <E extends ParserRuleContext> void checkOptions(E ctx) { |
| 70 | + switch (ctx.getRuleIndex()) { |
| 71 | + case RULE_cics_soapfault_create: |
| 72 | + checkCreate((CICSParser.Cics_soapfault_createContext) ctx); |
| 73 | + break; |
| 74 | + case RULE_cics_soapfault_add: |
| 75 | + checkAdd((CICSParser.Cics_soapfault_addContext) ctx); |
| 76 | + break; |
| 77 | + case RULE_cics_soapfault_delete: |
| 78 | + checkDelete((CICSParser.Cics_soapfault_deleteContext) ctx); |
| 79 | + break; |
| 80 | + default: |
| 81 | + break; |
| 82 | + } |
| 83 | + |
| 84 | + checkDuplicates(ctx); |
| 85 | + } |
| 86 | + |
| 87 | + private void checkCreate(CICSParser.Cics_soapfault_createContext ctx) { |
| 88 | + checkHasExactlyOneOption("FAULTCODE, FAULTCODESTR, CLIENT, SERVER, SENDER or RECEIVER", ctx, ctx.FAULTCODE(), ctx.FAULTCODESTR(), ctx.CLIENT(), ctx.SERVER(), ctx.SENDER(), ctx.RECEIVER()); |
| 89 | + |
| 90 | + checkHasMandatoryOptions(ctx.FAULTSTRING(), ctx, "FAULTSTRING"); |
| 91 | + |
| 92 | + checkPrerequisiteIsMet(ctx.FAULTCODESTR(), ctx.FAULTCODELEN(), ctx, "FAULTCODELEN without FAULTCODESTR"); |
| 93 | + |
| 94 | + checkPrerequisiteIsMet(ctx.ROLE(), ctx.ROLELENGTH(), ctx, "ROLELENGTH without ROLE"); |
| 95 | + |
| 96 | + checkPrerequisiteIsMet(ctx.FAULTACTOR(), ctx.FAULTACTLEN(), ctx, "FAULTACTLEN without FAULTACTOR"); |
| 97 | + |
| 98 | + checkPrerequisiteIsMet(ctx.DETAIL(), ctx.DETAILLENGTH(), ctx, "DETAILLENGTH without DETAIL"); |
| 99 | + |
| 100 | + checkPrerequisiteIsMet(ctx.FAULTCODE(), ctx.FAULTCODELEN(), ctx, "FAULTCODELEN without FAULTCODE"); |
| 101 | + |
| 102 | + checkPrerequisiteIsMet(ctx.FAULTSTRING(), ctx.FAULTSTRLEN(), ctx, "FAULTSTRLEN without FAULTSTRING"); |
| 103 | + } |
| 104 | + |
| 105 | + private void checkAdd(CICSParser.Cics_soapfault_addContext ctx) { |
| 106 | + checkPrerequisiteIsMet(ctx.FAULTSTRING(), ctx.FAULTSTRLEN(), ctx, "FAULTSTRLEN without FAULTSTRING"); |
| 107 | + |
| 108 | + checkPrerequisiteIsMet(ctx.SUBCODESTR(), ctx.SUBCODELEN(), ctx, "SUBCODELEN without SUBCODESTR"); |
| 109 | + |
| 110 | + checkHasExactlyOneOption("FAULTSTRING or SUBCODESTR", ctx, ctx.FAULTSTRING(), ctx.SUBCODESTR()); |
| 111 | + } |
| 112 | + |
| 113 | + private void checkDelete(CICSParser.Cics_soapfault_deleteContext ctx) { |
| 114 | + checkHasMandatoryOptions(ctx.DELETE(), ctx, "DELETE"); |
| 115 | + } |
| 116 | + |
| 117 | +} |
0 commit comments