From 23a97a89d5d9d777ada86fd5a39abbb8c35e1315 Mon Sep 17 00:00:00 2001 From: Dmitriy Marmyshev Date: Mon, 11 Jul 2022 20:06:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=202022.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../META-INF/MANIFEST.MF | 1 - .../CommonModuleNamedSelfReferenceFix.java | 4 +- .../ui/qfix/FormSelfReferenceOutdatedFix.java | 4 +- .../ManagerModuleNamedSelfReferenceFix.java | 4 +- .../bsl/ui/qfix/OpenBslDocCommentViewFix.java | 6 +- .../bsl/ui/qfix/QuickFixMethodsHelper.java | 4 +- .../bsl/ui/qfix/SelfReferenceFix.java | 4 +- .../bsl/ui/qfix/UndefinedFunctionFix.java | 6 +- .../bsl/ui/qfix/UndefinedMethodFix.java | 4 +- .../bsl/ui/qfix/UndefinedVariableFix.java | 6 +- .../META-INF/MANIFEST.MF | 1 - .../v8codestyle/bsl/qfix/RemoveExportFix.java | 4 +- .../qfix/external/BslCheckFixBoostrap.java | 43 --- .../external/BslIssueModificationContext.java | 109 ------- ...tiVariantXtextModuleFixChangeDelegate.java | 35 --- ...leVariantXtextModuleFixChangeDelegate.java | 30 -- .../external/IXtextBslModuleFixModel.java | 83 ----- .../external/IXtextBslModuleFixProvider.java | 37 --- .../IXtextInteractiveBslModuleFixModel.java | 92 ------ .../MultiVariantXtextBslModuleFix.java | 257 ---------------- .../SingleVariantXtextBslModuleFix.java | 287 ------------------ ...SingleVariantXtextBslModuleFixContext.java | 79 ----- ...ariantXtextBslModuleFixContextFactory.java | 54 ---- .../qfix/external/XtextBslModuleFixModel.java | 158 ---------- .../external/XtextBslModuleFixProvider.java | 79 ----- .../XtextInteractiveBslModuleFixModel.java | 186 ------------ .../bsl/strict/check/AbstractTypeCheck.java | 81 +---- .../fix/RemoveStrictTypesAnnotationFix.java | 4 +- .../v8codestyle/internal/bsl/BslPlugin.java | 2 - .../bsl/ExternalDependenciesModule.java | 7 - .../internal/bsl/ServiceModule.java | 5 - 31 files changed, 28 insertions(+), 1648 deletions(-) delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslCheckFixBoostrap.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslIssueModificationContext.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IMultiVariantXtextModuleFixChangeDelegate.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/ISingleVariantXtextModuleFixChangeDelegate.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixModel.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixProvider.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextInteractiveBslModuleFixModel.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/MultiVariantXtextBslModuleFix.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFix.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContext.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContextFactory.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixModel.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixProvider.java delete mode 100644 bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextInteractiveBslModuleFixModel.java diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF b/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF index c60872b4..a36581c0 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF +++ b/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF @@ -51,5 +51,4 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[5.0.0,6.0 com.e1c.g5.v8.dt.check.qfix.components;version="[1.0.0,2.0.0)", com.e1c.g5.v8.dt.check.settings;version="[3.0.0,4.0.0)", com.e1c.v8codestyle.bsl;version="[0.3.0,0.4.0)", - com.e1c.v8codestyle.bsl.qfix.external;version="[0.3.0,0.4.0)", com.e1c.v8codestyle.bsl.strict;version="[0.3.0,0.4.0)" diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/CommonModuleNamedSelfReferenceFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/CommonModuleNamedSelfReferenceFix.java index 15e3378d..d1452f30 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/CommonModuleNamedSelfReferenceFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/CommonModuleNamedSelfReferenceFix.java @@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** * Quick fix for check com.e1c.v8codestyle.bsl.check:common-module-named-self-reference diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/FormSelfReferenceOutdatedFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/FormSelfReferenceOutdatedFix.java index 9af570c3..f2322257 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/FormSelfReferenceOutdatedFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/FormSelfReferenceOutdatedFix.java @@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** * Quick fix for check com.e1c.v8codestyle.bsl.check:form-self-reference-outdated diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/ManagerModuleNamedSelfReferenceFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/ManagerModuleNamedSelfReferenceFix.java index 7b199ad7..414bfe47 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/ManagerModuleNamedSelfReferenceFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/ManagerModuleNamedSelfReferenceFix.java @@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.model.DynamicFeatureAccess; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** * Quick fix for check com.e1c.v8codestyle.bsl.check:common-module-named-self-reference diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/OpenBslDocCommentViewFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/OpenBslDocCommentViewFix.java index eec6dfca..f64cedb0 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/OpenBslDocCommentViewFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/OpenBslDocCommentViewFix.java @@ -24,10 +24,10 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.settings.CheckUid; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin; import com.e1c.v8codestyle.internal.bsl.ui.views.BslDocCommentView; diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/QuickFixMethodsHelper.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/QuickFixMethodsHelper.java index e3bfee7f..63846f23 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/QuickFixMethodsHelper.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/QuickFixMethodsHelper.java @@ -28,8 +28,8 @@ import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; import com._1c.g5.v8.dt.bsl.ui.contentassist.BslProposalProvider; import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil; import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel; import com.google.common.base.Strings; /** diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/SelfReferenceFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/SelfReferenceFix.java index a02812b6..4987f98b 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/SelfReferenceFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/SelfReferenceFix.java @@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** * Quick fix for check com.e1c.v8codestyle.bsl.check:self-reference diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedFunctionFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedFunctionFix.java index 76bee21a..e556e9f6 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedFunctionFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedFunctionFix.java @@ -16,10 +16,10 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.text.edits.TextEdit; import org.eclipse.xtext.resource.XtextResource; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedMethodFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedMethodFix.java index 2be4e38a..e5eb2882 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedMethodFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedMethodFix.java @@ -14,9 +14,9 @@ package com.e1c.v8codestyle.bsl.ui.qfix; import org.eclipse.jface.text.BadLocationException; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.MultiVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.MultiVariantXtextBslModuleFix; import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin; /** diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedVariableFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedVariableFix.java index 110fffda..af744448 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedVariableFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/UndefinedVariableFix.java @@ -28,10 +28,10 @@ import com._1c.g5.v8.dt.bsl.model.Method; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil; import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; /** * Quick fix for check com.e1c.v8codestyle.bsl.check:undefined-variable diff --git a/bundles/com.e1c.v8codestyle.bsl/META-INF/MANIFEST.MF b/bundles/com.e1c.v8codestyle.bsl/META-INF/MANIFEST.MF index da2e9046..d1e59ff7 100644 --- a/bundles/com.e1c.v8codestyle.bsl/META-INF/MANIFEST.MF +++ b/bundles/com.e1c.v8codestyle.bsl/META-INF/MANIFEST.MF @@ -60,5 +60,4 @@ Import-Package: com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)", com.e1c.v8codestyle;version="[0.3.0,0.4.0)", com.e1c.v8codestyle.check;version="[0.3.0,0.4.0)" Export-Package: com.e1c.v8codestyle.bsl;version="0.3.0", - com.e1c.v8codestyle.bsl.qfix.external;version="0.3.0", com.e1c.v8codestyle.bsl.strict;version="0.3.0" diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/RemoveExportFix.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/RemoveExportFix.java index b6fad354..7ba09f93 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/RemoveExportFix.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/RemoveExportFix.java @@ -26,9 +26,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; import com._1c.g5.v8.dt.bsl.model.Method; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.qfix.components.QuickFix; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; import com.e1c.v8codestyle.internal.bsl.BslPlugin; /** diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslCheckFixBoostrap.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslCheckFixBoostrap.java deleted file mode 100644 index 28bf7cec..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslCheckFixBoostrap.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import com._1c.g5.wiring.IManagedService; -import com.e1c.g5.v8.dt.check.qfix.IFixRepository; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * Java-based registrar of BSL quick fix components - * - * @author Alexander Tretyakevich - */ -@Singleton -public class BslCheckFixBoostrap - implements IManagedService -{ - @Inject - private IFixRepository fixRepository; - - @Inject - private SingleVariantXtextBslModuleFixContextFactory singleVariantXtextBslModuleFixContextFactory; - - @Override - public void activate() - { - fixRepository.registerContextFactory(singleVariantXtextBslModuleFixContextFactory); - } - - @Override - public void deactivate() - { - // Not necessary at the moment - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslIssueModificationContext.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslIssueModificationContext.java deleted file mode 100644 index 1f1b6399..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/BslIssueModificationContext.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.ui.IEditorPart; -import org.eclipse.xtext.ui.editor.IURIEditorOpener; -import org.eclipse.xtext.ui.editor.XtextEditor; -import org.eclipse.xtext.ui.editor.model.IXtextDocument; -import org.eclipse.xtext.ui.editor.model.edit.IssueModificationContext; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.lcore.ui.editor.ViewerAwareIssueModificationContext; -import com.google.common.base.Preconditions; - -/** - * Extension of {@link IssueModificationContext} to be used by quick fixes and suppressions - * - * @author Vadim Geraskin - */ -public class BslIssueModificationContext - extends ViewerAwareIssueModificationContext -{ - private final AtomicReference viewerRef = new AtomicReference<>(); - private final Issue issue; - private final IURIEditorOpener editorOpener; - - private IXtextDocument document; - - /** - * Instantiates modification context - * - * @param issue the issue, cannot be {@code null} - * @param editorOpener the editor opener, cannot be {@code null} - */ - public BslIssueModificationContext(Issue issue, IURIEditorOpener editorOpener) - { - this.issue = Preconditions.checkNotNull(issue); - this.editorOpener = Preconditions.checkNotNull(editorOpener); - } - - @Override - public IXtextDocument getXtextDocument() - { - return getXtextDocument(issue.getUriToProblem()); - } - - @Override - public IXtextDocument getXtextDocument(URI uri) - { - if (document != null) - { - return document; - } - - document = getXtextDocument(uri, editorOpener, editor -> viewerRef.set(extractLocalTextViewer(editor))); - setTextViewer(viewerRef.get()); - - return document; - } - - /* - * Extract text viewer from editor. Can return {@code null} - */ - private static ITextViewer extractLocalTextViewer(IEditorPart editor) - { - ITextOperationTarget target = editor.getAdapter(ITextOperationTarget.class); - if (target instanceof ITextViewer) - { - return (ITextViewer)target; - } - return null; - } - - private static IXtextDocument getXtextDocument(URI uri, IURIEditorOpener editorOpener, - Consumer editorConsumer) - { - for (int trial = 0; trial < 2; trial++) - { - IEditorPart editor = editorOpener.open(uri, false); - if (editor == null) - { - return null; - } - if (editorConsumer != null) - { - editorConsumer.accept(editor); - } - if (editor instanceof XtextEditor) - { - XtextEditor xtextEditor = (XtextEditor)editor; - return xtextEditor.getDocument(); - } - } - return null; - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IMultiVariantXtextModuleFixChangeDelegate.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IMultiVariantXtextModuleFixChangeDelegate.java deleted file mode 100644 index a1e6e15a..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IMultiVariantXtextModuleFixChangeDelegate.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import org.eclipse.xtext.resource.XtextResource; - -import com.e1c.g5.v8.dt.check.qfix.IFixSession; - -/** - * Functional delegate that allows to specify the matching method as a change execution logic for multi-variant - * quick fixes - * - * @author Vadim Geraskin - */ -@FunctionalInterface -public interface IMultiVariantXtextModuleFixChangeDelegate -{ - /** - * Performs the fix application - * - * @param context the quick fix context, cannot be {@code null} - * @param session the fix session, cannot be {@code null} - * @param state the xtext resource, cannot be {@code null} - * @param model the quick fix model, cannot be {@code null} - */ - void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session, XtextResource state, - IXtextBslModuleFixModel model); -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/ISingleVariantXtextModuleFixChangeDelegate.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/ISingleVariantXtextModuleFixChangeDelegate.java deleted file mode 100644 index 2adb5fc6..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/ISingleVariantXtextModuleFixChangeDelegate.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import com.e1c.g5.v8.dt.check.qfix.IFixSession; - -/** - * Functional delegate that allows to specify the matching method as a change execution logic for multi-variant - * quick fixes - * - * @author Vadim Geraskin - */ -@FunctionalInterface -public interface ISingleVariantXtextModuleFixChangeDelegate -{ - /** - * Perfoms apply of the fix - * - * @param context the quick fix context, cannot be {@code null} - * @param session the session, cannot be {@code null} - */ - void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session); -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixModel.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixModel.java deleted file mode 100644 index d24e3236..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixModel.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.IDocument; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess; -import com._1c.g5.v8.dt.core.platform.IResourceLookup; -import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; - -/** - * Contract for xtext BSL quick fix model - * - * @author Vadim Geraskin - */ -public interface IXtextBslModuleFixModel -{ - /** - * Provides {@link IDocument} - * - * @return {@link IDocument}, never {@code null} - */ - IDocument getDocument(); - - /** - * Provides module {@link IResourceLookup} - * - * @return {link IResourceLookup}, never {@code null} - */ - IResourceLookup getResourceLookup(); - - /** - * Provides the element which is used to create a quick fix - * - * @return the element, can be {@code null} - */ - EObject getElement(); - - /** - * xtext validation issue reference - * - * @return {@link Issue}, never {@code null} - */ - Issue getIssue(); - - /** - * The associated user data. May be {@code null} or empty but may not contain {@code null} entries. - * - * @return user data, can be {@code null} - */ - String[] getIssueData(); - - /** - * Provides {@link BslGrammarAccess} - * - * @return {@link BslGrammarAccess}, never {@code null} - */ - BslGrammarAccess getBslGrammar(); - - /** - * Returns {@code ScriptVariant} for current project - * - * @return {@code ScriptVariant}, never {@code null} - */ - ScriptVariant getScriptVariant(); - - /** - * Gets line separator preference set for current project. If the preference is not set for the project then - * the canonical lookup order is used (instance, configuration, default). - * - * @return the line separator preference. Never {@code null}. - */ - String getLineSeparator(); -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixProvider.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixProvider.java deleted file mode 100644 index 1b55fb22..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextBslModuleFixProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.core.platform.IDtProject; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; - -/** - * Contract for {@link XtextBslModuleFixProvider} - * - * @author Vadim Geraskin - */ -public interface IXtextBslModuleFixProvider -{ - /** - * Returns xtext quick fix model - * - * @param dtProject the {@IDtProject}, cannot be {@code null} - * @param issue instance of the {@link Issue}, cannot be {@code null} - * @param session the {@code IFixSession}, cannot be {@code null} - * @param targetModuleUri the target module Uri, cannot be {@code null} - * @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise - * @return the quick fix model, never {@code null} - */ - IXtextBslModuleFixModel getXtextFixModel(IDtProject dtProject, Issue issue, IFixSession session, - URI targetModuleUri, boolean isInteractive); -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextInteractiveBslModuleFixModel.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextInteractiveBslModuleFixModel.java deleted file mode 100644 index c914aa60..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/IXtextInteractiveBslModuleFixModel.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.Optional; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.link.LinkedModeModel; -import org.eclipse.xtext.ui.editor.model.edit.IModificationContext; - -import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals; -import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider; - -/** - * Contract for xtext BSL interactive quick fix model - * - * @author Vadim Geraskin - */ -public interface IXtextInteractiveBslModuleFixModel - extends IXtextBslModuleFixModel -{ - /** - * Provides {@link IndentTextEditorProvider} - * - * @return {@link IndentTextEditorProvider}, never {@code null} - */ - IndentTextEditorProvider getIndentProvider(); - - /** - * Multilanguage proposals for quick-fix and content-assist for Bsl - * - * @return reference to {@link BslGeneratorMultiLangProposals}, never {@code null} - */ - BslGeneratorMultiLangProposals getBslGeneratorMultiLangProposals(); - - /** - * Provides modification context - * - * @return {@link IModificationContext}, never {@code null} - */ - IModificationContext getModificationContext(); - - /** - * Provides the format string for the given {@code EObject} which is the semantic object whose node should - * be provided {@code NodeModelUtils.findActualNodeFor()} - * - * @param eObject the object, cannot be {@code null} - * @return format string, never {@code null} - * @throws BadLocationException - */ - Optional getFormatString(EObject eObject) throws BadLocationException; - - /** - * Provides {@code LinkedModeModel} - * - * @return {@code LinkedModeModel}, never {@code null} - */ - LinkedModeModel getLinkedModeModel(); - - /** - * Returns a description of the line at the given offset.The description contains the offset and the length of the - * line excluding the line's delimiter. - * - * @param offset the offset whose line should be described - * @return a region describing the line, never {@code null} - * @throws BadLocationException - */ - IRegion getLineInformationOfOffset(int offset) throws BadLocationException; - - /** - * Connects the ui mode for linked mode and starts UI on the first position - * Should be called write after installation of linkedModeModel: {@code linkedModeModel.forceInstall()} - */ - void enterUiMode(); - - /** - * Sets the selected range and reveals it - * - * @param posStart the start position - * @param length the length of selection - */ - void selectAndRevealForLinkedModeModel(int posStart, int length); -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/MultiVariantXtextBslModuleFix.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/MultiVariantXtextBslModuleFix.java deleted file mode 100644 index 5ca20a58..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/MultiVariantXtextBslModuleFix.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; - -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.ui.editor.model.IXtextDocument; -import org.eclipse.xtext.util.concurrent.IUnitOfWork; - -import com.e1c.g5.v8.dt.check.qfix.FixDescriptor; -import com.e1c.g5.v8.dt.check.qfix.FixVariantDescriptor; -import com.e1c.g5.v8.dt.check.qfix.IFix; -import com.e1c.g5.v8.dt.check.qfix.IFixChange; -import com.e1c.g5.v8.dt.check.qfix.IFixChangeProcessor; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; -import com.e1c.g5.v8.dt.check.qfix.IFixVariant; -import com.e1c.g5.v8.dt.check.qfix.components.BasicFix; - -/** - * Multi-variant xtext module fix definition - * - * @author Alexander Tretyakevich - Initial contribution - * @author Vadim Geraskin - Additional features - */ -public abstract class MultiVariantXtextBslModuleFix - extends BasicFix - implements IFix -{ - private Collection> fixVariants = new HashSet<>(); - - @Override - public Class getRequiredContextType() - { - return SingleVariantXtextBslModuleFixContext.class; - } - - @Override - public Collection> getVariants( - SingleVariantXtextBslModuleFixContext context, IFixSession session) - { - return fixVariants; - } - - @Override - public void onRegistration(FixDescriptor registrationContext) - { - VariantXtextBslModuleFixChangeProcessor changeProcessor = new VariantXtextBslModuleFixChangeProcessor(); - registrationContext.setChangeProcessor(changeProcessor); - buildVariants(); - } - - /** - * Creates and sets up fix variants - */ - protected abstract void buildVariants(); - - /** - * Provides a builder of the quick fix variant - * - * @author Vadim Geraskin - */ - protected static class VariantBuilder - { - private final MultiVariantXtextBslModuleFix fix; - private IMultiVariantXtextModuleFixChangeDelegate delegate; - private String description; - private String details; - private boolean isInteractive; - - /** - * Creates variant builder instance - * - * @param fix the reference to the model fix, cannot be {@code null} - */ - public VariantBuilder(MultiVariantXtextBslModuleFix fix) - { - this.fix = fix; - } - - /** - * Static variant builder creator - * - * @param fix the reference to the model fix, cannot be {@code null} - * @return the instance of the variant builder, never {@code null} - */ - public static VariantBuilder create(MultiVariantXtextBslModuleFix fix) - { - return new VariantBuilder(fix); - } - - /** - * Creates code change delegate - * - * @param delegate change delegate, cannot be {@code null} - * @return the instance of the variant builder, never {@code null} - */ - public VariantBuilder change(IMultiVariantXtextModuleFixChangeDelegate delegate) - { - this.delegate = delegate; - return this; - } - - /** - * Sets the modification model type - either interactive (UI) or not - * - * @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise - * @return the instance of the variant builder, never {@code null} - */ - public VariantBuilder interactive(boolean isInteractive) - { - this.isInteractive = isInteractive; - return this; - } - - /** - * Creates variant description and details messages - * - * @param description the short description, cannot be {@code null} - * @param details the detailed message, can be {@code null} - * @return the instance of the variant builder, never {@code null} - */ - public VariantBuilder description(String description, String details) - { - this.description = description; - this.details = details; - return this; - } - - /** - * Finalizes the variant builder, registers the variant - */ - public void build() - { - IFixVariant variant = - new MultiVariantXtextBslModuleVariant<>(delegate, description, details, isInteractive); - fix.fixVariants.add(variant); - } - } - - private static class MultiVariantXtextBslModuleVariant - implements IFixVariant - { - private final IMultiVariantXtextModuleFixChangeDelegate delegate; - private final String description; - private final String details; - private final boolean isInteractive; - - /** - * Creates {@link MultiVariantXtextBslModuleVariant} instance - * - * @param delegate the delegate to be executed, cannot be {@code null} - * @param description the fix variant short description, cannot be {@code null} - * @param details the fix variant detailed description, can be {@code null} - * @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise - */ - MultiVariantXtextBslModuleVariant(IMultiVariantXtextModuleFixChangeDelegate delegate, String description, - String details, boolean isInteractive) - { - this.delegate = delegate; - this.description = description; - this.details = details; - this.isInteractive = true; - } - - @Override - public Collection prepareChanges(C context, IFixSession session) - { - if (context.getTargetModuleUri() == null) - { - return Collections.emptyList(); - } - - return Collections.singleton(new VariantXtextBslModuleFixChange(delegate, isInteractive)); - } - - @Override - public FixVariantDescriptor describeChanges(C context, IFixSession session) - { - return new FixVariantDescriptor(description, details); - } - } - - private static final class VariantXtextBslModuleFixChange - implements IFixChange - { - private final IMultiVariantXtextModuleFixChangeDelegate delegate; - private final boolean isInteractive; - - /** - * Creates {@link VariantXtextBslModuleFixChange} instance - * - * @param delegate the delegate to be executed, cannot be {@code null} - * @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise - */ - VariantXtextBslModuleFixChange(IMultiVariantXtextModuleFixChangeDelegate delegate, boolean isInteractive) - { - this.delegate = delegate; - this.isInteractive = isInteractive; - } - - /** - * Executes the quick fix resolution code - * - * @param context the quick fix context, cannot be {@code null} - * @param session the quick fix session, cannot be {@code null} - */ - public void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session) - { - IXtextBslModuleFixModel fixModel = context.getModel(session, isInteractive); - if (fixModel instanceof IXtextInteractiveBslModuleFixModel) - { - ((IXtextDocument)fixModel.getDocument()).readOnly(new IUnitOfWork.Void() - { - @Override - public void process(XtextResource state) throws Exception - { - delegate.applyFix(context, session, state, fixModel); - } - }); - } - else - { - // Nothing at the moment - } - } - } - - /* - * Variant fix change processor - */ - private static final class VariantXtextBslModuleFixChangeProcessor - implements IFixChangeProcessor - { - @Override - public void applyFix(VariantXtextBslModuleFixChange fixChange, SingleVariantXtextBslModuleFixContext context, - IFixSession session) - { - fixChange.applyFix(context, session); - } - - @Override - public Class getProcessedFixType() - { - return VariantXtextBslModuleFixChange.class; - } - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFix.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFix.java deleted file mode 100644 index 02c75fae..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFix.java +++ /dev/null @@ -1,287 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.Collection; -import java.util.Collections; -import java.util.function.BiFunction; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.xtext.resource.XtextResource; -import org.eclipse.xtext.ui.editor.model.IXtextDocument; -import org.eclipse.xtext.ui.editor.model.edit.IModificationContext; -import org.eclipse.xtext.util.concurrent.IUnitOfWork; -import org.eclipse.xtext.validation.Issue; -import org.eclipse.xtext.validation.Issue.IssueImpl; - -import com._1c.g5.v8.dt.bsl.model.Module; -import com._1c.g5.v8.dt.common.Pair; -import com._1c.g5.v8.dt.common.StringUtils; -import com.e1c.g5.v8.dt.bsl.check.qfix.ExternalQuickfixModification; -import com.e1c.g5.v8.dt.check.qfix.FixDescriptor; -import com.e1c.g5.v8.dt.check.qfix.FixVariantDescriptor; -import com.e1c.g5.v8.dt.check.qfix.IFixChange; -import com.e1c.g5.v8.dt.check.qfix.IFixChangeProcessor; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; -import com.e1c.g5.v8.dt.check.qfix.components.SingleVariantBasicFix; -import com.e1c.v8codestyle.internal.bsl.BslPlugin; - -/** - * Single variant xtext bsl module fix common class for multi-variant quick fixes - * - * @author Vadim Geraskin - */ -public abstract class SingleVariantXtextBslModuleFix - extends SingleVariantBasicFix -{ - private BiFunction> descriptionSupplier; - private boolean isInteractive; - - @Override - public Collection prepareChanges(SingleVariantXtextBslModuleFixContext context, IFixSession session) - { - Module module = session.getModule(context.getTargetModuleUri()); - if (module == null) - { - return Collections.emptyList(); - } - - return prepareChanges(this::applyChanges); - } - - @Override - public final FixVariantDescriptor describeChanges(SingleVariantXtextBslModuleFixContext context, - IFixSession session) - { - Pair description = descriptionSupplier.apply(context, session); - return new FixVariantDescriptor(description.first, description.second); - } - - @Override - public final void onRegistration(FixDescriptor registrationContext) - { - registrationContext.setChangeProcessor(new SingleVariantModuleFixChangeProcessor()); - - FixConfigurer configurer = new FixConfigurer(); - configureFix(configurer); - applyConfiguration(configurer); - } - - @Override - public Class getRequiredContextType() - { - return SingleVariantXtextBslModuleFixContext.class; - } - - /** - * Configures the fix. The developer could provide descreptive/filtering information for the fix here - * - * @param configurer The configurer of the fix. May not be {@code null} - */ - protected void configureFix(FixConfigurer configurer) - { - // Nothing by default - } - - /** - * Modification of code to be overriden by clients - * - * @param state the xtext resource, cannot be {@code null} - * @param model xtext bsl module fix model facade, cannot be {@code null} - * @return {@link TextEdit}, can be {@code null} - * @throws BadLocationException - */ - protected abstract TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) - throws BadLocationException; - - protected void applyChanges(SingleVariantXtextBslModuleFixContext context, IFixSession session) - { - IssueImpl issue = context.getIssue(); - - IXtextBslModuleFixModel fixModel = context.getModel(session, isInteractive); - if (fixModel instanceof IXtextInteractiveBslModuleFixModel) - { - IModificationContext modificationContext = - ((XtextInteractiveBslModuleFixModel)fixModel).getModificationContext(); - - IXtextDocument document = (IXtextDocument)fixModel.getDocument(); - XtextResource xtextResource = document.readOnly(new IUnitOfWork() - { - @Override - public XtextResource exec(XtextResource state) throws Exception - { - return state; - } - }); - - ExternalQuickfixModification quickFixModification = new ExternalQuickfixModification<>(issue, - EObject.class, element -> fixIssue((IXtextInteractiveBslModuleFixModel)fixModel, xtextResource)); - - try - { - quickFixModification.apply(modificationContext); - } - catch (Exception e) - { - BslPlugin.log(BslPlugin.createErrorStatus("Error occured when applying quick fix", e)); //$NON-NLS-1$ - } - } - else - { - // Nothing at the moment - } - } - - private TextEdit fixIssue(IXtextInteractiveBslModuleFixModel fixModel, XtextResource xtextResource) - { - Issue issue = fixModel.getIssue(); - if (issue.getOffset() == null) - { - return null; - } - - try - { - return fixIssue(xtextResource, fixModel); - } - catch (Exception e) - { - BslPlugin.log(BslPlugin.createErrorStatus("Error occured when applying quick fix", e)); //$NON-NLS-1$ - } - - return null; - } - - private Collection prepareChanges(ISingleVariantXtextModuleFixChangeDelegate changeDelegate) - { - return Collections.singleton(new SingleVariantModuleFixChange(changeDelegate)); - } - - /* - * Applies configuration provided by the fix developer - */ - private void applyConfiguration(FixConfigurer configurer) - { - this.descriptionSupplier = configurer.descriptionSupplier; - if (this.descriptionSupplier == null) - { - // Description isn't specified - adding the safety loopback - this.descriptionSupplier = (context, session) -> Pair.newPair(StringUtils.EMPTY, StringUtils.EMPTY); - } - this.isInteractive = configurer.isInteractive; - } - - /* - * Single variant fix change unique for the SingleVariantModelBasicFix - */ - private static final class SingleVariantModuleFixChange - implements IFixChange - { - private final ISingleVariantXtextModuleFixChangeDelegate delegate; - - SingleVariantModuleFixChange(ISingleVariantXtextModuleFixChangeDelegate delegate) - { - this.delegate = delegate; - } - - public void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session) - { - delegate.applyFix(context, session); - } - } - - /* - * Single variant fix change processor unique for the SingleVariantModelBasicFix - */ - private static final class SingleVariantModuleFixChangeProcessor - implements IFixChangeProcessor - { - @Override - public void applyFix(SingleVariantModuleFixChange fixChange, SingleVariantXtextBslModuleFixContext context, - IFixSession session) - { - fixChange.applyFix(context, session); - } - - @Override - public Class getProcessedFixType() - { - return SingleVariantModuleFixChange.class; - } - } - - /** - * Configuration container for the {@link SingleVariantXtextBslModuleFixContext} descendants allowing them to - * specify fix parameters via the pure Java API - * - * @author Alexander Tretyakevich - */ - protected static final class FixConfigurer - { - private BiFunction> descriptionSupplier; //CHECKSTYLE.OFF: LineLength - private boolean isInteractive = true; - private String description = StringUtils.EMPTY; - private String details = StringUtils.EMPTY; - - /** - * Sets the dynamic description supplier for the fix. The description may be formed using the data from - * the {@link SingleVariantXtextBslModuleFixContext} - * - * @param descriptionSupplier The supplier to set. May not be {@code null} - * @return the instance of the fix configurer, never {@code null} - */ - public FixConfigurer description( - BiFunction> descriptionSupplier) - { - this.descriptionSupplier = descriptionSupplier; - return this; - } - - /** - * Sets the static description for the fix - * - * @param description The description to set. May not be {@code null} - * @return the instance of the fix configurer, never {@code null} - */ - public FixConfigurer description(String description) - { - this.description = description; - descriptionSupplier = (context, session) -> Pair.newPair(description, details); - return this; - } - - /** - * Sets the static details for the fix - * - * @param description The description to set. May not be {@code null} - * @return the instance of the fix configurer, never {@code null} - */ - public FixConfigurer details(String details) - { - this.details = details; - descriptionSupplier = (context, session) -> Pair.newPair(description, details); - return this; - } - - /** - * Sets the modification model type - either interactive (UI) or not - * - * @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise - * @return the instance of the fix configurer, never {@code null} - */ - public FixConfigurer interactive(boolean isInteractive) - { - this.isInteractive = isInteractive; - return this; - } - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContext.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContext.java deleted file mode 100644 index 12c53f4d..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContext.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.validation.Issue.IssueImpl; - -import com._1c.g5.v8.dt.core.platform.IDtProject; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; -import com.e1c.g5.v8.dt.check.qfix.components.BasicFixContext; - -/** - * Single-variant xtext module quick fix context - * - * @author Vadim Geraskin - */ -public class SingleVariantXtextBslModuleFixContext - extends BasicFixContext -{ - private final URI targetModuleUri; - private final IssueImpl issue; - private final IXtextBslModuleFixProvider provider; - - /** - * Creates quick fix context - * - * @param targetModuleUri the module {@code URI}, cannot be {@code null} - * @param issue the {@code IssueImpl} instance, cannot be {@code null} - * @param provider the {@code IXtextBslModuleFixProvider} instance, cannot be {@code null} - * @param dtProject the DT project, cannot be {@code null} - */ - public SingleVariantXtextBslModuleFixContext(URI targetModuleUri, IssueImpl issue, - IXtextBslModuleFixProvider provider, IDtProject dtProject) - { - super(dtProject); - this.targetModuleUri = targetModuleUri; - this.issue = issue; - this.provider = provider; - } - - /** - * Provides the target module URI - * - * @return the targetModuleUri, never {@code null} - */ - public URI getTargetModuleUri() - { - return targetModuleUri; - } - - /** - * Provides the {@code IssueImpl} for quick fix - * - * @return xtext issue, never {@code null} - */ - public IssueImpl getIssue() - { - return issue; - } - - /** - * Provides the model {@code IXtextBslModuleFixModel} for quick fix - * - * @param session {@link IFixSession}, cannot be {@code null} - * @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise - * @return model {@code IXtextBslModuleFixModel}, never {@code null} - */ - public IXtextBslModuleFixModel getModel(IFixSession session, boolean isInteractive) - { - return provider.getXtextFixModel(getDtProject(), issue, session, targetModuleUri, isInteractive); - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContextFactory.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContextFactory.java deleted file mode 100644 index 5594caa9..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/SingleVariantXtextBslModuleFixContextFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.validation.CheckType; -import org.eclipse.xtext.validation.Issue.IssueImpl; - -import com._1c.g5.v8.dt.bsl.validation.BslValidationUtil; -import com._1c.g5.v8.dt.validation.marker.IMarkerWrapper; -import com._1c.g5.v8.dt.validation.marker.PlainEObjectMarker; -import com.e1c.g5.v8.dt.check.qfix.IFixContextFactory; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * Context factory for {@link SingleVariantXtextBslModuleFixContext} - * - * @author Vadim Geraskin - */ -@Singleton -public class SingleVariantXtextBslModuleFixContextFactory - implements IFixContextFactory -{ - @Inject - private IXtextBslModuleFixProvider provider; - - @Override - public final SingleVariantXtextBslModuleFixContext createContext(IMarkerWrapper marker, IFixSession session) - { - if (marker.getMarker() instanceof PlainEObjectMarker) - { - PlainEObjectMarker plainObjectMarker = (PlainEObjectMarker)marker.getMarker(); - URI uri = plainObjectMarker.getURI(); - IssueImpl issue = BslValidationUtil.createIssue(plainObjectMarker, CheckType.EXPENSIVE); - return new SingleVariantXtextBslModuleFixContext(uri, issue, provider, session.getDtProject()); - } - return null; - } - - @Override - public final Class getProvidedContextType() - { - return SingleVariantXtextBslModuleFixContext.class; - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixModel.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixModel.java deleted file mode 100644 index 2c683588..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixModel.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.Locale; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.URIConverter; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.bsl.model.Module; -import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess; -import com._1c.g5.v8.dt.common.PreferenceUtils; -import com._1c.g5.v8.dt.core.platform.IDtProject; -import com._1c.g5.v8.dt.core.platform.IResourceLookup; -import com._1c.g5.v8.dt.core.platform.IV8Project; -import com._1c.g5.v8.dt.core.platform.IV8ProjectManager; -import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; -import com.e1c.v8codestyle.internal.bsl.BslPlugin; -import com.google.common.base.Preconditions; - -/** - * The xtext module quick fix model - * - * @author Vadim Geraskin - */ -public class XtextBslModuleFixModel - implements IXtextBslModuleFixModel -{ - protected final IV8Project v8project; - private final Supplier moduleSupp; - private final BslGrammarAccess bslGrammar; - private final IResourceLookup resourceLookup; - private final Issue issue; - private IDocument document; - - /** - * Creates module quick fix model - * - * @param moduleSupp supplier for {@link Module}, cannot be {@code null} - * @param v8projectManager V8 project manager, cannot be {@code null} - * @param bslGrammar BSL grammar, cannot be {@code null} - * @param resourceLookup resource lookup service, cannot be {@code null} - * @param issue issue, cannot be {@code null} - * @param dtProject {@code IDtProject}, cannot be {@code null} - */ - public XtextBslModuleFixModel(Supplier moduleSupp, IV8ProjectManager v8projectManager, - BslGrammarAccess bslGrammar, IResourceLookup resourceLookup, Issue issue, IDtProject dtProject) - { - this.moduleSupp = Preconditions.checkNotNull(moduleSupp); - this.bslGrammar = Preconditions.checkNotNull(bslGrammar); - this.resourceLookup = Preconditions.checkNotNull(resourceLookup); - this.issue = Preconditions.checkNotNull(issue); - this.v8project = v8projectManager.getProject(dtProject); - } - - @Override - public IDocument getDocument() - { - if (document == null) - { - Module module = moduleSupp.get(); - if (module != null) - { - URI uri = EcoreUtil.getURI(module).trimFragment(); - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(URIConverter.INSTANCE.createInputStream(uri), StandardCharsets.UTF_8))) - { - Stream lines = reader.lines(); - String content = lines.collect(Collectors.joining(System.lineSeparator())); - document = new Document(content); - } - catch (IOException e) - { - BslPlugin.log(BslPlugin.createErrorStatus("Unable to read bsl module file", e)); //$NON-NLS-1$ - } - } - } - return document; - } - - @Override - public IResourceLookup getResourceLookup() - { - return resourceLookup; - } - - @Override - public EObject getElement() - { - URI uriToProblem = issue.getUriToProblem(); - String fragment = uriToProblem != null ? uriToProblem.fragment() : null; - if (fragment != null) - { - Module module = moduleSupp.get(); - return module != null ? module.eResource().getEObject(fragment) : null; - } - return null; - } - - @Override - public Issue getIssue() - { - return issue; - } - - @Override - public String[] getIssueData() - { - return issue.getData(); - } - - @Override - public BslGrammarAccess getBslGrammar() - { - return bslGrammar; - } - - @Override - public ScriptVariant getScriptVariant() - { - return getScriptVariant(v8project); - } - - @Override - public String getLineSeparator() - { - return PreferenceUtils.getLineSeparator(v8project.getProject()); - } - - protected static ScriptVariant getScriptVariant(IV8Project v8project) - { - if (v8project != null) - { - return v8project.getScriptVariant(); - } - return Locale.getDefault().getLanguage().equals(new Locale("ru").getLanguage()) ? ScriptVariant.RUSSIAN //$NON-NLS-1$ - : ScriptVariant.ENGLISH; - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixProvider.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixProvider.java deleted file mode 100644 index b3d13a66..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextBslModuleFixProvider.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.function.Supplier; - -import org.eclipse.emf.common.util.URI; -import org.eclipse.xtext.ui.editor.IURIEditorOpener; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.bsl.model.Module; -import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess; -import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals; -import com._1c.g5.v8.dt.core.platform.IDtProject; -import com._1c.g5.v8.dt.core.platform.IResourceLookup; -import com._1c.g5.v8.dt.core.platform.IV8ProjectManager; -import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider; -import com.e1c.g5.v8.dt.check.qfix.IFixSession; -import com.google.common.base.Preconditions; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * Xtext BSl module quick fix provider - * - * @author Vadim Geraskin - */ -@Singleton -public class XtextBslModuleFixProvider - implements IXtextBslModuleFixProvider -{ - private final IV8ProjectManager v8projectManager; - private final BslGrammarAccess bslGrammar; - private final IResourceLookup resourceLookup; - private final IndentTextEditorProvider indentProvider; - private final BslGeneratorMultiLangProposals bslGenProp; - private final IURIEditorOpener editorOpener; - - @Inject - /** - * @param v8projectManager V8 project manager, cannot be {@code null} - * @param bslGrammar BSl grammar, cannot be {@code null} - * @param resourceLookup resource lookup, cannot be {@code null} - * @param indentProvider indent provider, cannot be {@code null} - * @param bslGenProp BSL multi-language proposals generator, cannot be {@code null} - * @param editorOpener editor opener, cannot be {@code null} - */ - public XtextBslModuleFixProvider(IV8ProjectManager v8projectManager, BslGrammarAccess bslGrammar, - IResourceLookup resourceLookup, IndentTextEditorProvider indentProvider, - BslGeneratorMultiLangProposals bslGenProp, IURIEditorOpener editorOpener) - { - this.v8projectManager = Preconditions.checkNotNull(v8projectManager); - this.bslGrammar = Preconditions.checkNotNull(bslGrammar); - this.resourceLookup = Preconditions.checkNotNull(resourceLookup); - this.indentProvider = Preconditions.checkNotNull(indentProvider); - this.bslGenProp = Preconditions.checkNotNull(bslGenProp); - this.editorOpener = Preconditions.checkNotNull(editorOpener); - } - - @Override - public IXtextBslModuleFixModel getXtextFixModel(IDtProject dtProject, Issue issue, IFixSession session, - URI targetModuleUri, boolean isInteractive) - { - Supplier moduleSupp = () -> session.getModule(targetModuleUri); - if (isInteractive) - { - return new XtextInteractiveBslModuleFixModel(moduleSupp, v8projectManager, bslGrammar, resourceLookup, - indentProvider, bslGenProp, issue, dtProject, editorOpener); - } - return new XtextBslModuleFixModel(moduleSupp, v8projectManager, bslGrammar, resourceLookup, issue, dtProject); - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextInteractiveBslModuleFixModel.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextInteractiveBslModuleFixModel.java deleted file mode 100644 index 0f4b2ec7..00000000 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/qfix/external/XtextInteractiveBslModuleFixModel.java +++ /dev/null @@ -1,186 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2022, 1C-Soft LLC and others. - * - * 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 - *******************************************************************************/ -package com.e1c.v8codestyle.bsl.qfix.external; - -import java.util.Optional; -import java.util.function.Supplier; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.link.LinkedModeModel; -import org.eclipse.jface.text.link.LinkedModeUI; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.xtext.nodemodel.INode; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; -import org.eclipse.xtext.ui.editor.IURIEditorOpener; -import org.eclipse.xtext.ui.editor.model.IXtextDocument; -import org.eclipse.xtext.ui.editor.model.edit.IModificationContext; -import org.eclipse.xtext.validation.Issue; - -import com._1c.g5.v8.dt.bsl.model.Module; -import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess; -import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals; -import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil; -import com._1c.g5.v8.dt.common.PreferenceUtils; -import com._1c.g5.v8.dt.core.platform.IDtProject; -import com._1c.g5.v8.dt.core.platform.IResourceLookup; -import com._1c.g5.v8.dt.core.platform.IV8ProjectManager; -import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider; -import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant; -import com.google.common.base.Preconditions; - -/** - * The xtext module quick fix model - * - * @author Vadim Geraskin - */ -public class XtextInteractiveBslModuleFixModel - extends XtextBslModuleFixModel - implements IXtextInteractiveBslModuleFixModel -{ - private final IndentTextEditorProvider indentProvider; - private final BslGeneratorMultiLangProposals bslGenProp; - private final IModificationContext modificationContext; - private final IXtextDocument document; - private final LinkedModeModel linkedModeModel; - - /** - /** - * Creates module quick fix model - * - * @param moduleSupp supplier for {@link Module}, cannot be {@code null} - * @param v8projectManager V8 project manager, cannot be {@code null} - * @param bslGrammar BSL grammar, cannot be {@code null} - * @param resourceLookup resource lookup service, cannot be {@code null} - * @param indentProvider indent provider, cannot be {@code null} - * @param bslGenProp Multi-lang BSL proposals generator, cannot be {@code null} - * @param issue issue, cannot be {@code null} - * @param dtProject {@code IDtProject}, cannot be {@code null} - * @param editorOpener {@code IURIEditorOpener}, cannot be {@code null} - */ - public XtextInteractiveBslModuleFixModel(Supplier moduleSupp, IV8ProjectManager v8projectManager, - BslGrammarAccess bslGrammar, IResourceLookup resourceLookup, IndentTextEditorProvider indentProvider, - BslGeneratorMultiLangProposals bslGenProp, Issue issue, IDtProject dtProject, IURIEditorOpener editorOpener) - { - super(moduleSupp, v8projectManager, bslGrammar, resourceLookup, issue, dtProject); - this.indentProvider = Preconditions.checkNotNull(indentProvider); - this.bslGenProp = Preconditions.checkNotNull(bslGenProp); - this.modificationContext = new BslIssueModificationContext(issue, Preconditions.checkNotNull(editorOpener)); - this.document = modificationContext.getXtextDocument(issue.getUriToProblem()); - - linkedModeModel = new LinkedModeModel(); - boolean isRussian = getScriptVariant(v8project) == ScriptVariant.RUSSIAN; - bslGenProp.setRussianLang(isRussian); - } - - @Override - public IXtextDocument getDocument() - { - return document; - } - - @Override - public IndentTextEditorProvider getIndentProvider() - { - return indentProvider; - } - - @Override - public BslGeneratorMultiLangProposals getBslGeneratorMultiLangProposals() - { - return bslGenProp; - } - - @Override - public IModificationContext getModificationContext() - { - return modificationContext; - } - - @Override - public IRegion getLineInformationOfOffset(int offset) throws BadLocationException - { - return document.getLineInformationOfOffset(offset); - } - - @Override - public String getLineSeparator() - { - return PreferenceUtils.getLineSeparator(getResourceLookup().getProject(document.getResourceURI())); - } - - @Override - public Optional getFormatString(EObject eObject) throws BadLocationException - { - INode node = NodeModelUtils.findActualNodeFor(eObject); - if (node == null) - { - return Optional.empty(); - } - IRegion lineInformation = getLineInformationOfOffset(node.getOffset()); - String indent = computeFormatLine(document, lineInformation).toString(); - return Optional.ofNullable(indent); - } - - @Override - public LinkedModeModel getLinkedModeModel() - { - return linkedModeModel; - } - - @Override - public void enterUiMode() - { - LinkedModeUI ui = new LinkedModeUI(linkedModeModel, BslQuickFixUtil.getTextViewer(modificationContext)); - ui.enter(); - } - - @Override - public void selectAndRevealForLinkedModeModel(int posStart, int length) - { - selectAndRevealForLinkedModeModel(BslQuickFixUtil.getTextViewer(modificationContext), posStart, length); - } - - private static StringBuilder computeFormatLine(IDocument doc, IRegion lineInformation) throws BadLocationException - { - String lineContent = doc.get(lineInformation.getOffset(), lineInformation.getLength()); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < lineContent.length(); ++i) - { - if (Character.isWhitespace(lineContent.charAt(i))) - { - builder.append(lineContent.charAt(i)); - } - else - { - break; - } - } - return builder; - } - - private static void selectAndRevealForLinkedModeModel(ITextViewer viewer, int posStart, int length) - { - viewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() - { - @Override - public void selectionChanged(SelectionChangedEvent event) - { - viewer.getSelectionProvider().removeSelectionChangedListener(this); - viewer.revealRange(posStart, length); - viewer.setSelectedRange(posStart, length); - } - }); - } -} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/AbstractTypeCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/AbstractTypeCheck.java index c532cfa8..2158e780 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/AbstractTypeCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/AbstractTypeCheck.java @@ -30,7 +30,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.naming.IQualifiedNameConverter; import org.eclipse.xtext.naming.QualifiedName; -import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.IEObjectDescription; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.scoping.IScope; @@ -38,21 +37,13 @@ import org.eclipse.xtext.scoping.IScopeProvider; import com._1c.g5.v8.dt.bsl.common.IBslPreferences; import com._1c.g5.v8.dt.bsl.documentation.comment.BslMultiLineCommentDocumentationProvider; -import com._1c.g5.v8.dt.bsl.model.BslPackage; import com._1c.g5.v8.dt.bsl.model.DynamicFeatureAccess; import com._1c.g5.v8.dt.bsl.model.ExplicitVariable; import com._1c.g5.v8.dt.bsl.model.FeatureAccess; -import com._1c.g5.v8.dt.bsl.model.ForEachStatement; -import com._1c.g5.v8.dt.bsl.model.ForToStatement; -import com._1c.g5.v8.dt.bsl.model.FormalParam; import com._1c.g5.v8.dt.bsl.model.Invocation; import com._1c.g5.v8.dt.bsl.model.SimpleStatement; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; import com._1c.g5.v8.dt.bsl.model.Variable; -import com._1c.g5.v8.dt.bsl.model.typesytem.TypeSystemMode; -import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTreeTypeState; -import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTreeTypeStateWithSubStates; -import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTypeState; import com._1c.g5.v8.dt.bsl.resource.DynamicFeatureAccessComputer; import com._1c.g5.v8.dt.bsl.resource.TypesComputer; import com._1c.g5.v8.dt.bsl.typesystem.util.TypeSystemUtil; @@ -179,11 +170,12 @@ public abstract class AbstractTypeCheck { if (object instanceof Variable && object.eContainer() instanceof FeatureAccess) { - return getActualTypesForFeatureVariable((Variable)object, object.eContainer(), envs); + return TypeSystemUtil.getVariableTypesAfterModelObject((Variable)object, object.eContainer()); } else if (object instanceof StaticFeatureAccess && ((StaticFeatureAccess)object).getImplicitVariable() != null) { - return getActualTypesForFeatureVariable(((StaticFeatureAccess)object).getImplicitVariable(), object, envs); + return TypeSystemUtil.getVariableTypesAfterModelObject(((StaticFeatureAccess)object).getImplicitVariable(), + object); } List types = typeComputer.computeTypes(object, envs); @@ -389,71 +381,4 @@ public abstract class AbstractTypeCheck } } - // TODO replace this with utility com._1c.g5.v8.dt.bsl.typesystem.util.TypeSystemUtil after 2022.1 - private List getActualTypesForFeatureVariable(Variable variable, EObject featureObject, Environments envs) - { - SimpleStatement statement = EcoreUtil2.getContainerOfType(featureObject, SimpleStatement.class); - Invocation inv = EcoreUtil2.getContainerOfType(featureObject, Invocation.class); - List allTypes = null; - int actualOffset = -1; - if (statement != null && statement.getRight() != null && statement.getLeft() == featureObject) - { - actualOffset = NodeModelUtils.findActualNodeFor(statement).getTotalEndOffset(); - } - else if (inv != null && inv.getParams().contains(featureObject)) - { - actualOffset = NodeModelUtils.findActualNodeFor(featureObject).getTotalEndOffset(); - } - else if (inv == null && statement == null && variable instanceof FormalParam) - { - actualOffset = NodeModelUtils.findActualNodeFor(featureObject).getTotalEndOffset(); - } - else if (featureObject.eContainingFeature() == BslPackage.Literals.FOR_STATEMENT__VARIABLE_ACCESS) - { - if (featureObject.eContainer() instanceof ForEachStatement - && ((ForEachStatement)featureObject.eContainer()).getCollection() != null) - { - actualOffset = - NodeModelUtils.findActualNodeFor(((ForEachStatement)featureObject.eContainer()).getCollection()) - .getTotalEndOffset() + 1; - } - else if (featureObject.eContainer() instanceof ForToStatement - && ((ForToStatement)featureObject.eContainer()).getInitializer() != null) - { - actualOffset = - NodeModelUtils.findActualNodeFor(((ForToStatement)featureObject.eContainer()).getInitializer()) - .getTotalEndOffset() + 1; - } - } - if (actualOffset != -1 && variable.getTypeStateProvider() != null) - { - allTypes = new ArrayList<>(); - List nearestStates = - variable.getTypeStateProvider().get(TypeSystemMode.NORMAL).getNearestByOffset(envs, actualOffset); - for (VariableTypeState nearestState : nearestStates) - { - if (nearestState != null) - { - if (nearestState instanceof VariableTreeTypeStateWithSubStates) - { - for (VariableTreeTypeState subState : ((VariableTreeTypeStateWithSubStates)nearestState) - .getSubStates(envs)) - { - subState.getTypes().forEach(allTypes::add); - } - } - else - { - nearestState.getTypes().forEach(allTypes::add); - } - } - } - } - else - { - allTypes = typeComputer.computeTypes(featureObject, envs); - } - return allTypes; - } - } diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/fix/RemoveStrictTypesAnnotationFix.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/fix/RemoveStrictTypesAnnotationFix.java index c75f3052..31eb3041 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/fix/RemoveStrictTypesAnnotationFix.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/fix/RemoveStrictTypesAnnotationFix.java @@ -25,9 +25,9 @@ import org.eclipse.xtext.nodemodel.ILeafNode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; +import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; +import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; import com.e1c.g5.v8.dt.check.settings.CheckUid; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel; -import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix; import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil; import com.e1c.v8codestyle.internal.bsl.BslPlugin; diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/BslPlugin.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/BslPlugin.java index f80af702..74df5ee6 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/BslPlugin.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/BslPlugin.java @@ -21,7 +21,6 @@ import com._1c.g5.v8.dt.bsl.model.BslPackage; import com._1c.g5.wiring.InjectorAwareServiceRegistrator; import com._1c.g5.wiring.ServiceInitialization; import com.e1c.v8codestyle.bsl.IModuleStructureProvider; -import com.e1c.v8codestyle.bsl.qfix.external.BslCheckFixBoostrap; import com.google.inject.Guice; import com.google.inject.Injector; @@ -132,7 +131,6 @@ public class BslPlugin ServiceInitialization.schedule(() -> { // register services from injector registrator.service(IModuleStructureProvider.class).registerInjected(); - registrator.managedService(BslCheckFixBoostrap.class).activateBeforeRegistration().registerInjected(); registrator.managedService(MultiCheckFixRegistrator.class).activateBeforeRegistration().registerInjected(); }); } diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ExternalDependenciesModule.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ExternalDependenciesModule.java index 3e6a15fd..2bfb5e85 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ExternalDependenciesModule.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ExternalDependenciesModule.java @@ -20,7 +20,6 @@ import org.eclipse.xtext.naming.IQualifiedNameProvider; import org.eclipse.xtext.resource.IResourceDescription; import org.eclipse.xtext.resource.IResourceServiceProvider; import org.eclipse.xtext.scoping.IScopeProvider; -import org.eclipse.xtext.ui.editor.IURIEditorOpener; import com._1c.g5.v8.dt.bsl.common.IBslPreferences; import com._1c.g5.v8.dt.bsl.contextdef.IBslModuleContextDefService; @@ -30,7 +29,6 @@ import com._1c.g5.v8.dt.bsl.resource.BslEventsService; import com._1c.g5.v8.dt.bsl.resource.DynamicFeatureAccessComputer; import com._1c.g5.v8.dt.bsl.resource.ExportMethodProvider; import com._1c.g5.v8.dt.bsl.resource.TypesComputer; -import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess; import com._1c.g5.v8.dt.bsl.typesystem.ExportMethodTypeProvider; import com._1c.g5.v8.dt.core.platform.IResourceLookup; import com._1c.g5.v8.dt.core.platform.IV8ProjectManager; @@ -80,10 +78,5 @@ class ExternalDependenciesModule bind(IBslOwnerComputerService.class).toProvider(() -> rsp.get(IBslOwnerComputerService.class)); bind(IScopeProvider.class).toProvider(() -> rsp.get(IScopeProvider.class)); bind(IQualifiedNameProvider.class).toProvider(() -> rsp.get(IQualifiedNameProvider.class)); - - // Remove this after 2021.1 - bind(BslGrammarAccess.class).toProvider(() -> rsp.get(BslGrammarAccess.class)); - bind(IURIEditorOpener.class).toProvider(() -> rsp.get(IURIEditorOpener.class)); - } } diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ServiceModule.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ServiceModule.java index 9e79295a..fa7b056f 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ServiceModule.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/internal/bsl/ServiceModule.java @@ -13,8 +13,6 @@ package com.e1c.v8codestyle.internal.bsl; import com.e1c.v8codestyle.bsl.IModuleStructureProvider; -import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixProvider; -import com.e1c.v8codestyle.bsl.qfix.external.XtextBslModuleFixProvider; import com.google.inject.AbstractModule; import com.google.inject.Singleton; @@ -31,9 +29,6 @@ public class ServiceModule protected void configure() { bind(IModuleStructureProvider.class).to(ModuleStructureProvider.class).in(Singleton.class); - - // Remove this after 2022.1 - bind(IXtextBslModuleFixProvider.class).to(XtextBslModuleFixProvider.class).in(Singleton.class); } }