You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-12-03 09:25:22 +02:00
#936 исправление регистрации проверки
- реакция на все свойства от которых зависит код - улучшение точности регистрации ошибки
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
- Падение NPE в проверке ql-using-for-update, корректный учет зависимых проектов (обработки, расширения)
|
||||
- Клиентский глобальный модуль: ошибочное предупреждение о некорректном типе
|
||||
- Отключено создание модуля менеджера при создании перечисления
|
||||
- Для проверки md-standard-attribute-synonym-empty исправлена регистрация и улучшена точность позиции ошибки
|
||||
|
||||
## 0.1.0
|
||||
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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<EStructuralFeature> 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MdPropertySynonymInNotSetForStandartAttributeOwner</name>
|
||||
<name>MdStandardAttributeSynonymEmpty</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
|
||||
@@ -17,25 +17,6 @@
|
||||
<inputByString>Catalog.NegativeOwnerTest.StandardAttribute.Code</inputByString>
|
||||
<inputByString>Catalog.NegativeOwnerTest.StandardAttribute.Description</inputByString>
|
||||
<fullTextSearchOnInputByString>DontUse</fullTextSearchOnInputByString>
|
||||
<standardAttributes>
|
||||
<dataHistory>Use</dataHistory>
|
||||
<name>Owner</name>
|
||||
<comment></comment>
|
||||
<fillFromFillingValue>true</fillFromFillingValue>
|
||||
<fillChecking>ShowError</fillChecking>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
</standardAttributes>
|
||||
<standardAttributes>
|
||||
<dataHistory>Use</dataHistory>
|
||||
<name>Parent</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>This is parrent</value>
|
||||
</synonym>
|
||||
<comment></comment>
|
||||
<fillFromFillingValue>true</fillFromFillingValue>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
</standardAttributes>
|
||||
<createOnInput>Use</createOnInput>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
|
||||
@@ -17,13 +17,6 @@
|
||||
<inputByString>Catalog.NegativeParentTest.StandardAttribute.Code</inputByString>
|
||||
<inputByString>Catalog.NegativeParentTest.StandardAttribute.Description</inputByString>
|
||||
<fullTextSearchOnInputByString>DontUse</fullTextSearchOnInputByString>
|
||||
<standardAttributes>
|
||||
<dataHistory>Use</dataHistory>
|
||||
<name>Parent</name>
|
||||
<comment>Простой комметарий</comment>
|
||||
<fillFromFillingValue>true</fillFromFillingValue>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
</standardAttributes>
|
||||
<createOnInput>Use</createOnInput>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
|
||||
@@ -17,6 +17,13 @@
|
||||
<inputByString>Catalog.NegativeParentTestWithComment.StandardAttribute.Code</inputByString>
|
||||
<inputByString>Catalog.NegativeParentTestWithComment.StandardAttribute.Description</inputByString>
|
||||
<fullTextSearchOnInputByString>DontUse</fullTextSearchOnInputByString>
|
||||
<standardAttributes>
|
||||
<dataHistory>Use</dataHistory>
|
||||
<name>Parent</name>
|
||||
<comment>Простой комметарий</comment>
|
||||
<fillFromFillingValue>true</fillFromFillingValue>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
</standardAttributes>
|
||||
<createOnInput>Use</createOnInput>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<fullTextSearch>Use</fullTextSearch>
|
||||
|
||||
Reference in New Issue
Block a user