From 07340f36a40df458294eb7467a704011639b04d5 Mon Sep 17 00:00:00 2001 From: Dmitriy Marmyshev Date: Wed, 26 Jan 2022 21:48:20 +0200 Subject: [PATCH] =?UTF-8?q?#936=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - реакция на все свойства от которых зависит код - улучшение точности регистрации ошибки --- CHANGELOG.md | 1 + .../META-INF/MANIFEST.MF | 2 + .../MdStandardAttributeSynonymEmpty.java | 117 ++++++++++++++---- .../MdStandardAttributeSynonymEmptyTest.java | 44 ++++--- .../MdStandardAttributeSynonymEmpty/.project | 2 +- .../NegativeOwnerTest/NegativeOwnerTest.mdo | 19 --- .../NegativeParentTest/NegativeParentTest.mdo | 7 -- .../NegativeParentTestWithComment.mdo | 7 ++ 8 files changed, 131 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4b9a3d6..559592f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - Падение NPE в проверке ql-using-for-update, корректный учет зависимых проектов (обработки, расширения) - Клиентский глобальный модуль: ошибочное предупреждение о некорректном типе - Отключено создание модуля менеджера при создании перечисления +- Для проверки md-standard-attribute-synonym-empty исправлена регистрация и улучшена точность позиции ошибки ## 0.1.0 diff --git a/bundles/com.e1c.v8codestyle.md/META-INF/MANIFEST.MF b/bundles/com.e1c.v8codestyle.md/META-INF/MANIFEST.MF index a0193cf8..304b213c 100644 --- a/bundles/com.e1c.v8codestyle.md/META-INF/MANIFEST.MF +++ b/bundles/com.e1c.v8codestyle.md/META-INF/MANIFEST.MF @@ -13,6 +13,7 @@ Automatic-Module-Name: com.e1c.v8codestyle.md Bundle-ActivationPolicy: lazy Bundle-Localization: plugin Import-Package: com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)", + com._1c.g5.v8.bm.core.event;version="[2.1.0,3.0.0)", com._1c.g5.v8.dt.common;version="[6.0.0,7.0.0)", com._1c.g5.v8.dt.core.platform;version="[10.0.0,11.0.0)", com._1c.g5.v8.dt.metadata.mdclass;version="[8.0.0,9.0.0)", @@ -22,6 +23,7 @@ Import-Package: com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)", com._1c.g5.wiring.binder;version="[1.1.0,2.0.0)", com.e1c.g5.v8.dt.check;version="[2.0.0,3.0.0)", com.e1c.g5.v8.dt.check.components;version="[2.0.0,3.0.0)", + com.e1c.g5.v8.dt.check.context;version="[2.0.0,3.0.0)", com.e1c.g5.v8.dt.check.ext;version="[1.0.0,2.0.0)", com.e1c.g5.v8.dt.check.settings;version="[2.0.0,3.0.0)", com.e1c.v8codestyle.check;version="[0.2.0,0.3.0)", diff --git a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/MdStandardAttributeSynonymEmpty.java b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/MdStandardAttributeSynonymEmpty.java index 07b18b6a..1ae70bf8 100644 --- a/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/MdStandardAttributeSynonymEmpty.java +++ b/bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/MdStandardAttributeSynonymEmpty.java @@ -16,21 +16,33 @@ package com.e1c.v8codestyle.md.check; import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.BASIC_DB_OBJECT__STANDARD_ATTRIBUTES; import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG; +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__HIERARCHICAL; +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__OWNERS; +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.STANDARD_ATTRIBUTE; import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.STANDARD_ATTRIBUTE__SYNONYM; -import org.eclipse.core.runtime.IProgressMonitor; +import java.util.Set; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; + +import com._1c.g5.v8.bm.core.IBmObject; +import com._1c.g5.v8.bm.core.event.BmSubEvent; import com._1c.g5.v8.dt.common.StringUtils; 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.Catalog; -import com._1c.g5.v8.dt.metadata.mdclass.MdObject; import com._1c.g5.v8.dt.metadata.mdclass.ObjectBelonging; import com._1c.g5.v8.dt.metadata.mdclass.StandardAttribute; import com.e1c.g5.v8.dt.check.CheckComplexity; +import com.e1c.g5.v8.dt.check.ICheckDefinition; import com.e1c.g5.v8.dt.check.ICheckParameters; import com.e1c.g5.v8.dt.check.components.BasicCheck; +import com.e1c.g5.v8.dt.check.components.IBasicCheckExtension; import com.e1c.g5.v8.dt.check.components.TopObjectFilterExtension; +import com.e1c.g5.v8.dt.check.context.CheckContextCollectingSession; +import com.e1c.g5.v8.dt.check.context.OnModelFeatureChangeContextCollector; import com.e1c.g5.v8.dt.check.settings.IssueSeverity; import com.e1c.g5.v8.dt.check.settings.IssueType; import com.e1c.v8codestyle.check.StandardCheckExtension; @@ -38,19 +50,24 @@ import com.e1c.v8codestyle.internal.md.CorePlugin; import com.google.inject.Inject; /** - * The check the {@link MdObject} has specified synonyms for owner and parent + * The check the {@link Catalog} has specified synonyms for owner and parent * for default language of the project. * * @author Bombin Valentin - * + * @author Dmitriy Marmyshev */ public class MdStandardAttributeSynonymEmpty extends BasicCheck { private static final String CHECK_ID = "md-standard-attribute-synonym-empty"; //$NON-NLS-1$ + private static final String OWNER_NAME = "Owner"; //$NON-NLS-1$ + private static final String PARENT_NAME = "Parent"; //$NON-NLS-1$ + private static final Set FEATURES = + Set.of(BASIC_DB_OBJECT__STANDARD_ATTRIBUTES, CATALOG__HIERARCHICAL, CATALOG__OWNERS); + private final IV8ProjectManager v8ProjectManager; @Inject @@ -76,9 +93,11 @@ public class MdStandardAttributeSynonymEmpty .issueType(IssueType.UI_STYLE) .extension(new TopObjectFilterExtension()) .extension(new StandardCheckExtension(getCheckId(), CorePlugin.PLUGIN_ID)) - .topObject(CATALOG) - .checkTop() - .features(BASIC_DB_OBJECT__STANDARD_ATTRIBUTES, STANDARD_ATTRIBUTE__SYNONYM); + .extension(new CatalogChangeExtension()); + + builder.topObject(CATALOG).containment(STANDARD_ATTRIBUTE).features(STANDARD_ATTRIBUTE__SYNONYM); + builder.topObject(CATALOG).checkTop().features(FEATURES.toArray(new EStructuralFeature[0])); + } @Override @@ -86,19 +105,53 @@ public class MdStandardAttributeSynonymEmpty IProgressMonitor monitor) { - MdObject mdObject = (MdObject)object; - if (mdObject.getObjectBelonging() != ObjectBelonging.NATIVE) - { - return; - } - IV8Project project = v8ProjectManager.getProject(mdObject); + EObject eObject = (EObject)object; + IV8Project project = v8ProjectManager.getProject(eObject); String languageCode = project.getDefaultLanguage().getLanguageCode(); if (monitor.isCanceled()) { return; } - checkParent((Catalog)object, resultAceptor, languageCode); - checkOwner((Catalog)object, resultAceptor, languageCode); + + if (object instanceof StandardAttribute) + { + StandardAttribute attribute = (StandardAttribute)object; + EObject parent = attribute.eContainer(); + if (!isValidCatalog(parent)) + { + return; + } + Catalog catalog = (Catalog)parent; + if (PARENT_NAME.equalsIgnoreCase(attribute.getName()) && hasParent(catalog) + && isSynonymEmpty(attribute, languageCode)) + { + resultAceptor.addIssue(Messages.MdOwnerAttributeSynonymEmpty_parent_ErrorMessage, + STANDARD_ATTRIBUTE__SYNONYM); + } + else if (OWNER_NAME.equalsIgnoreCase(attribute.getName()) && hasAnyOwner(catalog) + && isSynonymEmpty(attribute, languageCode)) + { + resultAceptor.addIssue(Messages.MdOwnerAttributeSynonymEmpty_owner_ErrorMessage, + STANDARD_ATTRIBUTE__SYNONYM); + } + } + else if (isValidCatalog(object)) + { + Catalog catalog = (Catalog)object; + + checkParent(catalog, resultAceptor); + checkOwner(catalog, resultAceptor); + } + } + + private boolean isValidCatalog(Object object) + { + if (object instanceof Catalog) + { + Catalog catalog = (Catalog)object; + return catalog.getObjectBelonging() == ObjectBelonging.NATIVE; + } + return false; } private boolean hasAnyOwner(Catalog catalog) @@ -115,7 +168,7 @@ public class MdStandardAttributeSynonymEmpty { for (StandardAttribute attribute : catalog.getStandardAttributes()) { - if (attribute.getName().compareTo(attributeName) == 0) + if (attributeName.equalsIgnoreCase(attribute.getName())) { return attribute; } @@ -123,12 +176,12 @@ public class MdStandardAttributeSynonymEmpty return null; } - private String getSynonym(StandardAttribute attribute, String languageCode) + private boolean isSynonymEmpty(StandardAttribute attribute, String languageCode) { - return attribute.getSynonym().get(languageCode); + return StringUtils.isBlank(attribute.getSynonym().get(languageCode)); } - private void checkParent(Catalog catalog, ResultAcceptor resultAceptor, String languageCode) + private void checkParent(Catalog catalog, ResultAcceptor resultAceptor) { if (!hasParent(catalog)) { @@ -137,14 +190,14 @@ public class MdStandardAttributeSynonymEmpty StandardAttribute attribute = getStandardAttributeByName(catalog, PARENT_NAME); - if (attribute == null || StringUtils.isBlank(getSynonym(attribute, languageCode))) + if (attribute == null) { resultAceptor.addIssue(Messages.MdOwnerAttributeSynonymEmpty_parent_ErrorMessage, BASIC_DB_OBJECT__STANDARD_ATTRIBUTES); } } - private void checkOwner(Catalog catalog, ResultAcceptor resultAceptor, String languageCode) + private void checkOwner(Catalog catalog, ResultAcceptor resultAceptor) { if (!hasAnyOwner(catalog)) { @@ -153,10 +206,30 @@ public class MdStandardAttributeSynonymEmpty StandardAttribute attribute = getStandardAttributeByName(catalog, OWNER_NAME); - if (attribute == null || StringUtils.isBlank(getSynonym(attribute, languageCode))) + if (attribute == null) { resultAceptor.addIssue(Messages.MdOwnerAttributeSynonymEmpty_owner_ErrorMessage, BASIC_DB_OBJECT__STANDARD_ATTRIBUTES); } } + + private class CatalogChangeExtension + implements IBasicCheckExtension + { + + @Override + public void configureContextCollector(final ICheckDefinition definition) + { + OnModelFeatureChangeContextCollector collector = (IBmObject bmObject, EStructuralFeature feature, + BmSubEvent bmEvent, CheckContextCollectingSession contextSession) -> { + + if (bmObject instanceof Catalog && FEATURES.contains(feature)) + { + contextSession.addFullCheck(bmObject); + } + }; + definition.addModelFeatureChangeContextCollector(collector, CATALOG); + } + + } } diff --git a/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/MdStandardAttributeSynonymEmptyTest.java b/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/MdStandardAttributeSynonymEmptyTest.java index b979260e..e2f90826 100644 --- a/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/MdStandardAttributeSynonymEmptyTest.java +++ b/tests/com.e1c.v8codestyle.md.itests/src/com/e1c/v8codestyle/md/check/itests/MdStandardAttributeSynonymEmptyTest.java @@ -19,20 +19,23 @@ import static org.junit.Assert.assertNull; import org.junit.Test; import com._1c.g5.v8.dt.core.platform.IDtProject; +import com._1c.g5.v8.dt.metadata.mdclass.Catalog; +import com._1c.g5.v8.dt.metadata.mdclass.StandardAttribute; import com._1c.g5.v8.dt.validation.marker.Marker; -import com.e1c.g5.v8.dt.testing.check.CheckTestBase; -import com.e1c.v8codestyle.md.check.MdStandardAttributeSynonymEmpty; +import com.e1c.g5.v8.dt.testing.check.SingleProjectReadOnlyCheckTestBase; /** * The test for class {@link MdStandardAttributeSynonymEmpty}. * * @author Bombin Valentin + * @author Dmitriy Marmyshev */ public class MdStandardAttributeSynonymEmptyTest - extends CheckTestBase + extends SingleProjectReadOnlyCheckTestBase { private static final String CHECK_ID = "md-standard-attribute-synonym-empty"; //$NON-NLS-1$ + private static final String PROJECT_NAME = "MdStandardAttributeSynonymEmpty"; /** @@ -43,8 +46,7 @@ public class MdStandardAttributeSynonymEmptyTest @Test public void testPositiveTest() throws Exception { - IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME); - assertNotNull(dtProject); + IDtProject dtProject = getProject(); long id = getTopObjectIdByFqn("Catalog.PositiveParentTest", dtProject); Marker marker = getFirstMarker(CHECK_ID, id, dtProject); @@ -57,36 +59,40 @@ public class MdStandardAttributeSynonymEmptyTest } @Test - public void testNegativeParent() throws Exception + public void testNegativeOwner() throws Exception { + IDtProject dtProject = getProject(); - IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME); - assertNotNull(dtProject); - - long id = getTopObjectIdByFqn("Catalog.NegativeOwnerTest", dtProject); + Long id = getTopObjectIdByFqn("Catalog.NegativeOwnerTest", dtProject); Marker marker = getFirstMarker(CHECK_ID, id, dtProject); assertNotNull(marker); - id = getTopObjectIdByFqn("Catalog.NegativeOwnerTestWithComment", dtProject); - marker = getFirstMarker(CHECK_ID, id, dtProject); + Catalog catalog = (Catalog)getTopObjectByFqn("Catalog.NegativeOwnerTestWithComment", dtProject); + StandardAttribute attribute = catalog.getStandardAttributes().get(0); + marker = getFirstMarker(CHECK_ID, attribute, dtProject); assertNotNull(marker); + } @Test - public void testNegativeOwner() throws Exception + public void testNegativeParent() throws Exception { + IDtProject dtProject = getProject(); - IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME); - assertNotNull(dtProject); - - long id = getTopObjectIdByFqn("Catalog.NegativeParentTest", dtProject); + Long id = getTopObjectIdByFqn("Catalog.NegativeParentTest", dtProject); Marker marker = getFirstMarker(CHECK_ID, id, dtProject); assertNotNull(marker); - id = getTopObjectIdByFqn("Catalog.NegativeParentTestWithComment", dtProject); - marker = getFirstMarker(CHECK_ID, id, dtProject); + Catalog catalog = (Catalog)getTopObjectByFqn("Catalog.NegativeParentTestWithComment", dtProject); + StandardAttribute attribute = catalog.getStandardAttributes().get(0); + marker = getFirstMarker(CHECK_ID, attribute, dtProject); assertNotNull(marker); + } + @Override + protected String getTestConfigurationName() + { + return PROJECT_NAME; } } diff --git a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/.project b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/.project index b513c875..62c351f4 100644 --- a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/.project +++ b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/.project @@ -1,6 +1,6 @@ - MdPropertySynonymInNotSetForStandartAttributeOwner + MdStandardAttributeSynonymEmpty diff --git a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeOwnerTest/NegativeOwnerTest.mdo b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeOwnerTest/NegativeOwnerTest.mdo index 522c01f8..9628786d 100644 --- a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeOwnerTest/NegativeOwnerTest.mdo +++ b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeOwnerTest/NegativeOwnerTest.mdo @@ -17,25 +17,6 @@ Catalog.NegativeOwnerTest.StandardAttribute.Code Catalog.NegativeOwnerTest.StandardAttribute.Description DontUse - - Use - Owner - - true - ShowError - Use - - - Use - Parent - - en - This is parrent - - - true - Use - Use Managed Use diff --git a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTest/NegativeParentTest.mdo b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTest/NegativeParentTest.mdo index 7dbffc9b..06932856 100644 --- a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTest/NegativeParentTest.mdo +++ b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTest/NegativeParentTest.mdo @@ -17,13 +17,6 @@ Catalog.NegativeParentTest.StandardAttribute.Code Catalog.NegativeParentTest.StandardAttribute.Description DontUse - - Use - Parent - Простой комметарий - true - Use - Use Managed Use diff --git a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTestWithComment/NegativeParentTestWithComment.mdo b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTestWithComment/NegativeParentTestWithComment.mdo index b7d9edf7..e87211f4 100644 --- a/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTestWithComment/NegativeParentTestWithComment.mdo +++ b/tests/com.e1c.v8codestyle.md.itests/workspace/MdStandardAttributeSynonymEmpty/src/Catalogs/NegativeParentTestWithComment/NegativeParentTestWithComment.mdo @@ -17,6 +17,13 @@ Catalog.NegativeParentTestWithComment.StandardAttribute.Code Catalog.NegativeParentTestWithComment.StandardAttribute.Description DontUse + + Use + Parent + Простой комметарий + true + Use + Use Managed Use