Skip to content

Commit c852454

Browse files
authored
#84 Добавлена проверка длины ресурса регистра накопления или бухгалтерии (#1139)
1 parent 1e4f144 commit c852454

File tree

18 files changed

+431
-2
lines changed

18 files changed

+431
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#### Метаданные
1212

13+
- Превышена максимальная длина ресурса регистра накопления или бухгалтерии (25 знаков)
1314

1415
#### Формы
1516

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Accumulation or accounting register resource precision
2+
3+
Accumulation or accounting register resource precision must be no more than 25
4+
5+
6+
## Noncompliant Code Example
7+
8+
## Compliant Solution
9+
10+
## See
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Длина ресурса регистра накопления или бухгалтерии
2+
3+
Длина ресурса регистра накопления или бухгалтерии должна быть не больше 25 знаков
4+
5+
6+
## Неправильно
7+
8+
## Правильно
9+
10+
## См.
11+

bundles/com.e1c.v8codestyle.md/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
category="com.e1c.v8codestyle.md"
6363
class="com.e1c.v8codestyle.md.check.MdScheduledJobPeriodicityCheck">
6464
</check>
65+
<check
66+
category="com.e1c.v8codestyle.md"
67+
class="com.e1c.v8codestyle.md.check.RegisterResourcePrecisionCheck">
68+
</check>
6569
<check
6670
category="com.e1c.v8codestyle.md"
6771
class="com.e1c.v8codestyle.internal.md.ExecutableExtensionFactory:com.e1c.v8codestyle.md.check.CommonModuleNameServerCallCheck">

bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ final class Messages
6868
public static String UnsafePasswordStorageCheck_Avoid_storing_password_in_infobase;
6969
public static String UnsafePasswordStorageCheck_Avoid_storing_password_in_infobase_description;
7070
public static String UnsafePasswordStorageCheck_Avoid_storing_password_in_infobase_error;
71+
public static String RegisterResourcePrecisionCheck_description;
72+
public static String RegisterResourcePrecisionCheck_message;
73+
public static String RegisterResourcePrecisionCheck_title;
7174
public static String SubsystemSynonymTooLongCheck_description;
7275
public static String SubsystemSynonymTooLongCheck_Exclude_languages_comma_separated;
7376
public static String SubsystemSynonymTooLongCheck_Length_of_section_name_more_than_symbols_for_language;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2022, 1C-Soft LLC and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* 1C-Soft LLC - initial API and implementation
12+
*******************************************************************************/
13+
package com.e1c.v8codestyle.md.check;
14+
15+
import static com._1c.g5.v8.dt.mcore.McorePackage.Literals.TYPE_DESCRIPTION;
16+
import static com._1c.g5.v8.dt.mcore.McorePackage.Literals.TYPE_DESCRIPTION__NUMBER_QUALIFIERS;
17+
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ACCOUNTING_REGISTER;
18+
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ACCUMULATION_REGISTER;
19+
20+
import java.text.MessageFormat;
21+
22+
import org.eclipse.core.runtime.IProgressMonitor;
23+
24+
import com._1c.g5.v8.dt.mcore.TypeDescription;
25+
import com._1c.g5.v8.dt.metadata.mdclass.RegisterResource;
26+
import com.e1c.g5.v8.dt.check.CheckComplexity;
27+
import com.e1c.g5.v8.dt.check.ICheckParameters;
28+
import com.e1c.g5.v8.dt.check.components.BasicCheck;
29+
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
30+
import com.e1c.g5.v8.dt.check.settings.IssueType;
31+
import com.e1c.v8codestyle.check.StandardCheckExtension;
32+
import com.e1c.v8codestyle.internal.md.CorePlugin;
33+
34+
/**
35+
* Check accounting or accumulation register resource precision that should be no more than 25.
36+
*
37+
* @author Timur Mukhamedishin
38+
*/
39+
public final class RegisterResourcePrecisionCheck
40+
extends BasicCheck
41+
{
42+
43+
private static final String CHECK_ID = "register-resource-precision"; //$NON-NLS-1$
44+
45+
public static final String MAX_PRECISION = "max-precision"; //$NON-NLS-1$
46+
47+
public static final String MAX_PRECISION_DEFAULT = "25"; //$NON-NLS-1$
48+
49+
@Override
50+
public String getCheckId()
51+
{
52+
return CHECK_ID;
53+
}
54+
55+
@Override
56+
protected void configureCheck(CheckConfigurer builder)
57+
{
58+
builder.title(Messages.RegisterResourcePrecisionCheck_title)
59+
.description(Messages.RegisterResourcePrecisionCheck_description)
60+
.complexity(CheckComplexity.NORMAL)
61+
.severity(IssueSeverity.MINOR)
62+
.issueType(IssueType.PORTABILITY)
63+
.extension(new StandardCheckExtension(getCheckId(), CorePlugin.PLUGIN_ID))
64+
.parameter(MAX_PRECISION, Integer.class, MAX_PRECISION_DEFAULT,
65+
Messages.RegisterResourcePrecisionCheck_message);
66+
67+
builder.topObject(ACCUMULATION_REGISTER)
68+
.checkTop()
69+
.containment(TYPE_DESCRIPTION)
70+
.features(TYPE_DESCRIPTION__NUMBER_QUALIFIERS);
71+
72+
builder.topObject(ACCOUNTING_REGISTER)
73+
.checkTop()
74+
.containment(TYPE_DESCRIPTION)
75+
.features(TYPE_DESCRIPTION__NUMBER_QUALIFIERS);
76+
}
77+
78+
@Override
79+
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
80+
IProgressMonitor monitor)
81+
{
82+
if (!(object instanceof TypeDescription))
83+
{
84+
return;
85+
}
86+
87+
TypeDescription td = (TypeDescription)object;
88+
if (!(td.eContainer() instanceof RegisterResource))
89+
{
90+
return;
91+
}
92+
93+
int maxPrecision = parameters.getInt(MAX_PRECISION);
94+
int precision = td.getNumberQualifiers().getPrecision();
95+
96+
if (precision > maxPrecision)
97+
{
98+
RegisterResource resource = (RegisterResource)(td.eContainer());
99+
resultAceptor.addIssue(
100+
MessageFormat.format(Messages.RegisterResourcePrecisionCheck_message, resource.getName(), maxPrecision),
101+
td);
102+
}
103+
}
104+
}

bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages.properties

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ UnsafePasswordStorageCheck_Avoid_storing_password_in_infobase_description=To min
9797

9898
UnsafePasswordStorageCheck_Avoid_storing_password_in_infobase_error=Avoid storing passwords in the infobase
9999

100+
RegisterResourcePrecisionCheck_description = Accumulation or accounting register resource precision is more than 25
101+
102+
RegisterResourcePrecisionCheck_message = Accumulation or accounting register resource "{0}" precision is more than {1}
103+
104+
RegisterResourcePrecisionCheck_title = Accumulation or accounting register resource precision is more than 25
105+
100106
SubsystemSynonymTooLongCheck_Exclude_languages_comma_separated = Exclude languages (codes, comma-separated)
101107

102108
SubsystemSynonymTooLongCheck_Length_of_section_name_more_than_symbols_for_language = Length of section synonym "{0}" more than {1} symbols for language {2}
103109

104110
SubsystemSynonymTooLongCheck_Maximum_section_name_length = Maximum section name length
105111

106-
SubsystemSynonymTooLongCheck_description = Section name is more then 35 characters long
112+
SubsystemSynonymTooLongCheck_description = Section name is more than 35 characters long
107113

108-
SubsystemSynonymTooLongCheck_title = Section name is more then 35 characters long
114+
SubsystemSynonymTooLongCheck_title = Section name is more than 35 characters long

bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/messages_ru.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ MdScheduledJobPeriodicityCheck_description = Периодичность выпо
9292

9393
MdScheduledJobPeriodicityCheck_title = Периодичность выполнения регламентного задания меньше {0}сек
9494

95+
RegisterResourcePrecisionCheck_description = Превышена максимальная длина ресурса регистра накопления или бухгалтерии (25 знаков)
96+
97+
RegisterResourcePrecisionCheck_message = Длина ресурса регистра "{0}" превышает {1}
98+
99+
RegisterResourcePrecisionCheck_title = Превышена максимальная длина ресурса регистра накопления или бухгалтерии (25 знаков)
100+
95101
SubsystemSynonymTooLongCheck_Exclude_languages_comma_separated = Исключить языки (коды, разделенных запятыми)
96102

97103
SubsystemSynonymTooLongCheck_Length_of_section_name_more_than_symbols_for_language = Длина синонима раздела "{0}" превышает {1} символов для языка {2}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021, 1C-Soft LLC and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* 1C-Soft LLC - initial API and implementation
12+
*******************************************************************************/
13+
package com.e1c.v8codestyle.md.check.itests;
14+
15+
import static org.junit.Assert.assertNotNull;
16+
17+
import org.junit.Test;
18+
19+
import com._1c.g5.v8.bm.core.IBmObject;
20+
import com._1c.g5.v8.dt.core.platform.IDtProject;
21+
import com._1c.g5.v8.dt.validation.marker.Marker;
22+
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
23+
24+
/**
25+
* Tests for {@link RegisterResourcePrecision} check
26+
*
27+
* @author Timur Mukhamedishin
28+
*
29+
*/
30+
public class RegisterResourcePrecisionTest
31+
extends CheckTestBase
32+
{
33+
34+
private static final String CHECK_ID = "register-resource-precision"; //$NON-NLS-1$
35+
36+
private static final String PROJECT_NAME = "RegisterResourcePrecision";
37+
38+
/**
39+
* Test that accounting register resource precision longer than maximal length.
40+
*
41+
* @throws Exception the exception
42+
*/
43+
@Test
44+
public void testAccountingRegisterResourcePrecision() throws Exception
45+
{
46+
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
47+
assertNotNull(dtProject);
48+
49+
IBmObject object =
50+
getTopObjectByFqn("AccountingRegister.AccountingRegisterTest", dtProject);
51+
assertNotNull(object);
52+
53+
Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
54+
assertNotNull(marker);
55+
}
56+
57+
/**
58+
* Test that accumulation register resource precision longer than maximal length.
59+
*
60+
* @throws Exception the exception
61+
*/
62+
@Test
63+
public void testAccumulationRegisterResourcePrecision() throws Exception
64+
{
65+
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
66+
assertNotNull(dtProject);
67+
68+
IBmObject object = getTopObjectByFqn("AccumulationRegister.AccumulationRegisterTest", dtProject);
69+
assertNotNull(object);
70+
71+
Marker marker = getFirstNestedMarker(CHECK_ID, object.bmGetId(), dtProject);
72+
assertNotNull(marker);
73+
}
74+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>RegisterResourcePrecision</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
16+
<nature>com._1c.g5.v8.dt.core.V8ConfigurationNature</nature>
17+
</natures>
18+
</projectDescription>

0 commit comments

Comments
 (0)