|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (C) 2022, 1C-Soft LLC and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made |
| 5 | + * available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * 1C-Soft LLC - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package com.e1c.v8codestyle.bsl.check; |
| 14 | + |
| 15 | +import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.INVOCATION; |
| 16 | + |
| 17 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 18 | + |
| 19 | +import com._1c.g5.v8.dt.bsl.model.FeatureAccess; |
| 20 | +import com._1c.g5.v8.dt.bsl.model.Invocation; |
| 21 | +import com._1c.g5.v8.dt.bsl.model.Statement; |
| 22 | +import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; |
| 23 | +import com._1c.g5.v8.dt.bsl.model.TryExceptStatement; |
| 24 | +import com.e1c.g5.v8.dt.check.CheckComplexity; |
| 25 | +import com.e1c.g5.v8.dt.check.ICheckParameters; |
| 26 | +import com.e1c.g5.v8.dt.check.settings.IssueSeverity; |
| 27 | +import com.e1c.g5.v8.dt.check.settings.IssueType; |
| 28 | + |
| 29 | +/** |
| 30 | + * The try operator was not found after calling begin transaction, |
| 31 | + * there should be no executable code between begin transaction and try, |
| 32 | + * |
| 33 | + * @author Artem Iliukhin |
| 34 | + */ |
| 35 | +public final class BeginTransactionCheck |
| 36 | + extends AbstractTransactionCheck |
| 37 | +{ |
| 38 | + |
| 39 | + private static final String CHECK_ID = "begin-transaction"; //$NON-NLS-1$ |
| 40 | + |
| 41 | + @Override |
| 42 | + public String getCheckId() |
| 43 | + { |
| 44 | + return CHECK_ID; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected void configureCheck(CheckConfigurer builder) |
| 49 | + { |
| 50 | + builder.title(Messages.BeginTransactionCheck_Begin_transaction_is_incorrect) |
| 51 | + .description(Messages.BeginTransactionCheck_Try_must_be_after_begin) |
| 52 | + .complexity(CheckComplexity.NORMAL) |
| 53 | + .severity(IssueSeverity.MINOR) |
| 54 | + .issueType(IssueType.WARNING) |
| 55 | + .disable() |
| 56 | + .module() |
| 57 | + .checkedObjectType(INVOCATION); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters, |
| 62 | + IProgressMonitor monitor) |
| 63 | + { |
| 64 | + Invocation inv = (Invocation)object; |
| 65 | + FeatureAccess featureAccess = inv.getMethodAccess(); |
| 66 | + if (featureAccess instanceof StaticFeatureAccess) |
| 67 | + { |
| 68 | + if (monitor.isCanceled()) |
| 69 | + { |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + String nameFeature = featureAccess.getName(); |
| 74 | + if (!(BEGIN_TRANSACTION_RU.equalsIgnoreCase(nameFeature) |
| 75 | + || BEGIN_TRANSACTION.equalsIgnoreCase(nameFeature))) |
| 76 | + { |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + Statement statement = getStatementFromInvoc(inv); |
| 81 | + if (statement != null) |
| 82 | + { |
| 83 | + statement = getNextStatement(statement); |
| 84 | + if (statement == null) |
| 85 | + { |
| 86 | + resultAceptor.addIssue(Messages.BeginTransactionCheck_Try_was_not_found_after_calling_begin, inv); |
| 87 | + } |
| 88 | + else if (!(statement instanceof TryExceptStatement)) |
| 89 | + { |
| 90 | + resultAceptor.addIssue( |
| 91 | + Messages.BeginTransactionCheck_Executable_code_between_begin_transaction_and_try, inv); |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
0 commit comments