1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2024-11-28 09:33:06 +02:00

Исправление области обработчики в общих модулях

This commit is contained in:
Artem Iliukhin 2022-08-06 22:53:28 +03:00
parent 1059cb64df
commit b60077fd7a
7 changed files with 85 additions and 40 deletions

View File

@ -91,6 +91,7 @@
- Проверка: right-... не находит ошибку для роли с включением по умолчанию #815
- Отключение проверок для заимствованных объектов в расширении #1076
- Проверка: form-self-reference не находит ошибку #1086
- Ложное срабатывание проверки: module-structure-event-regions для обработчиков событий расположенных в общем модуле #1102
## 0.2.0

View File

@ -106,7 +106,7 @@ public class ModuleStructureEventRegionsCheck
MessageFormat.format(Messages.ModuleStructureEventRegionsCheck_Only_event_methods__0, name),
McorePackage.Literals.NAMED_ELEMENT__NAME);
}
else if (!eventHandlersName.equals(name) && method.isEvent())
else if (!ModuleType.COMMON_MODULE.equals(moduleType) && !eventHandlersName.equals(name) && method.isEvent())
{
resultAceptor.addIssue(
MessageFormat.format(Messages.ModuleStructureEventRegionsCheck_Event_handler__0__not_region__1,

View File

@ -12,16 +12,15 @@
*******************************************************************************/
package com.e1c.v8codestyle.bsl.check.itests;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.core.runtime.Path;
import org.junit.Test;
import com._1c.g5.v8.bm.core.IBmObject;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.metadata.mdclass.Catalog;
import com._1c.g5.v8.dt.validation.marker.IExtraInfoKeys;
import com._1c.g5.v8.dt.validation.marker.Marker;
import com.e1c.g5.v8.dt.testing.check.SingleProjectReadOnlyCheckTestBase;
import com.e1c.v8codestyle.bsl.check.ModuleStructureEventRegionsCheck;
@ -38,9 +37,13 @@ public class ModuleStructureEventRegionsCheckTest
private static final String CHECK_ID = "module-structure-event-regions"; //$NON-NLS-1$
private static final String PROJECT_NAME = "StructureModule";
private static final String FQN_CATALOG_MODULE_MANAGER_EVENT = "Catalog.CatalogInRegion";
private static final String FQN_CATALOG_MODULE_MANAGER_EVENT_WRONG_REGION = "Catalog.CatalogInWrongRegion";
private static final String FQN_CATALOG_MODULE_MANAGER_EVENT_WRONG_METHOD = "Catalog.CatalogInRegionWrongMethod";
private static final String CATALOG_MODULE_MANAGER_EVENT_FILE_NAME =
"/src/Catalogs/CatalogInRegion/ManagerModule.bsl";
private static final String CATALOG_MODULE_MANAGER_EVENT_WRONG_REGION_FILE_NAME =
"/src/Catalogs/CatalogInWrongRegion/ManagerModule.bsl";
private static final String CATALOG_MODULE_MANAGER_EVENT_WRONG_METHOD_FILE_NAME =
"/src/Catalogs/CatalogInRegionWrongMethod/ManagerModule.bsl";
private static final String COMMON_MODULE_EVENT_FILE_NAME = "/src/CommonModules/CommonModule/Module.bsl";
@Override
protected String getTestConfigurationName()
@ -51,49 +54,43 @@ public class ModuleStructureEventRegionsCheckTest
@Test
public void testEventModuleManagerInWrongRegion() throws Exception
{
IDtProject dtProject = dtProjectManager.getDtProject(PROJECT_NAME);
assertNotNull(dtProject);
List<Marker> markers = getMarkers(CATALOG_MODULE_MANAGER_EVENT_WRONG_REGION_FILE_NAME);
assertEquals(1, markers.size());
IBmObject mdObject = getTopObjectByFqn(FQN_CATALOG_MODULE_MANAGER_EVENT_WRONG_REGION, dtProject);
assertTrue(mdObject instanceof Catalog);
Module module = ((Catalog)mdObject).getManagerModule();
assertNotNull(module);
Marker marker = getFirstMarker(CHECK_ID, module.eResource().getURI(), getProject());
assertNotNull(marker);
assertEquals("16", markers.get(0).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
@Test
public void testEventModuleManagerInRegion() throws Exception
{
IDtProject dtProject = dtProjectManager.getDtProject(PROJECT_NAME);
assertNotNull(dtProject);
IBmObject mdObject = getTopObjectByFqn(FQN_CATALOG_MODULE_MANAGER_EVENT, dtProject);
assertTrue(mdObject instanceof Catalog);
Module module = ((Catalog)mdObject).getManagerModule();
assertNotNull(module);
Marker marker = getFirstMarker(CHECK_ID, module.eResource().getURI(), getProject());
assertNull(marker);
List<Marker> markers = getMarkers(CATALOG_MODULE_MANAGER_EVENT_FILE_NAME);
assertEquals(0, markers.size());
}
@Test
public void testEventModuleManagerInRegionWrongMethod() throws Exception
{
IDtProject dtProject = dtProjectManager.getDtProject(PROJECT_NAME);
assertNotNull(dtProject);
List<Marker> markers = getMarkers(CATALOG_MODULE_MANAGER_EVENT_WRONG_METHOD_FILE_NAME);
assertEquals(1, markers.size());
IBmObject mdObject = getTopObjectByFqn(FQN_CATALOG_MODULE_MANAGER_EVENT_WRONG_METHOD, dtProject);
assertTrue(mdObject instanceof Catalog);
assertEquals("8", markers.get(0).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
Module module = ((Catalog)mdObject).getManagerModule();
assertNotNull(module);
@Test
public void testEventCommonModuleInRegion() throws Exception
{
List<Marker> markers = getMarkers(COMMON_MODULE_EVENT_FILE_NAME);
assertEquals(0, markers.size());
}
Marker marker = getFirstMarker(CHECK_ID, module.eResource().getURI(), getProject());
assertNotNull(marker);
private List<Marker> getMarkers(String moduleFileName)
{
String moduleId = Path.ROOT.append(getTestConfigurationName()).append(moduleFileName).toString();
List<Marker> markers = List.of(markerManager.getMarkers(getProject().getWorkspaceProject(), moduleId));
return markers.stream()
.filter(marker -> CHECK_ID.equals(getCheckIdFromMarker(marker, getProject())))
.collect(Collectors.toList());
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="6cbbf814-18db-453c-92ed-054a8f310cdc">
<name>CommonModule</name>
<synonym>
<key>en</key>
<value>Common module</value>
</synonym>
<server>true</server>
<externalConnection>true</externalConnection>
<clientOrdinaryApplication>true</clientOrdinaryApplication>
</mdclass:CommonModule>

View File

@ -0,0 +1,21 @@
#Region Public
// Enter code here.
#Region EventHandlers
Procedure EventSubscriptionAfterWriteDataHistoryVersionsProcessing(Source, WriteVersionsInformation) Export
// TODO: Insert handler code.
EndProcedure
#EndRegion
#EndRegion
#Region Internal
// Enter code here.
#EndRegion
#Region Private
// Enter code here.
#EndRegion

View File

@ -38,6 +38,8 @@
</synonym>
<languageCode>en</languageCode>
</languages>
<commonModules>CommonModule.CommonModule</commonModules>
<eventSubscriptions>EventSubscription.EventSubscription</eventSubscriptions>
<catalogs>Catalog.CatalogInRegion</catalogs>
<catalogs>Catalog.CatalogInRegionWrongMethod</catalogs>
<catalogs>Catalog.CatalogInWrongRegion</catalogs>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:EventSubscription xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="6467eda5-af3d-4c58-8abf-396d2433a1a1">
<name>EventSubscription</name>
<synonym>
<key>en</key>
<value>Event subscription</value>
</synonym>
<source>
<types>CatalogManager</types>
</source>
<event>AfterWriteDataHistoryVersionsProcessing</event>
<handler>CommonModule.CommonModule.EventSubscriptionAfterWriteDataHistoryVersionsProcessing</handler>
</mdclass:EventSubscription>