1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-07-17 13:07:50 +02:00

Исправление NPE при работе проверки #1146

This commit is contained in:
Dmitriy Marmyshev
2022-09-15 16:20:57 +03:00
parent 1084572fc0
commit c1388f72e3
2 changed files with 17 additions and 15 deletions

View File

@ -102,6 +102,7 @@
- Ложное срабатывание проверки: new-color при сбрасывании цвета в значение Авто можно использовать Новый Цвет #1123
- Ложное срабатывание проверки: ql-constants-in-binary-operation #1142
- Не понятно в какой бинарной операции ошибка ql-constants-in-binary-operation #1143
- Возникает NPE при работе проверки form-list-ref-user-visibility-enabled #1146
## 0.2.0

View File

@ -13,15 +13,14 @@
package com.e1c.v8codestyle.form.check;
import static com._1c.g5.v8.dt.form.model.FormPackage.Literals.FORM;
import static com._1c.g5.v8.dt.form.model.FormPackage.Literals.VISIBLE__USER_VISIBLE;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ADJUSTABLE_BOOLEAN;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.ADJUSTABLE_BOOLEAN__COMMON;
import java.text.MessageFormat;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.EcoreUtil2;
import com._1c.g5.v8.dt.form.model.AbstractDataPath;
@ -46,8 +45,10 @@ public class FormListRefUserVisibilityEnabledCheck
{
private static final String CHECK_ID = "form-list-ref-user-visibility-enabled"; //$NON-NLS-1$
private static final String FEATURE_NAME = "userVisible"; //$NON-NLS-1$
private static final List<String> REF_SEGMENT = List.of("Ref", "Ссылка"); //$NON-NLS-1$ //$NON-NLS-2$
private static final String REF_SEGMENT = "Ref"; //$NON-NLS-1$
private static final String REF_SEGMENT_RU = "Ссылка"; //$NON-NLS-1$
@Override
public String getCheckId()
@ -77,11 +78,16 @@ public class FormListRefUserVisibilityEnabledCheck
{
AdjustableBoolean adjBoolean = (AdjustableBoolean)object;
if (adjBoolean.isCommon() && adjBoolean.eContainer() instanceof FormField
&& adjBoolean.eContainmentFeature().getName().equals(FEATURE_NAME)
&& pathCheck(adjBoolean.eContainer().eContents()))
&& adjBoolean.eContainmentFeature().equals(VISIBLE__USER_VISIBLE)
&& isRefPath(((FormField)adjBoolean.eContainer()).getDataPath()))
{
Table table = EcoreUtil2.getContainerOfType(adjBoolean, Table.class);
if (table == null)
{
return;
}
FormField formField = (FormField)(adjBoolean.eContainer());
Table table = EcoreUtil2.getContainerOfType(formField.eContainer(), Table.class);
resultAceptor.addIssue(
MessageFormat.format(
Messages.FormListRefUserVisibilityEnabledCheck_User_visibility_is_not_disabled_for_the_Ref_field,
@ -91,15 +97,10 @@ public class FormListRefUserVisibilityEnabledCheck
}
private boolean pathCheck(EList<EObject> eContents)
private boolean isRefPath(AbstractDataPath dataPath)
{
if (eContents.size() < 2 || !(eContents.get(1) instanceof AbstractDataPath))
{
return false;
}
EList<String> segments = ((AbstractDataPath)eContents.get(1)).getSegments();
EList<String> segments = dataPath.getSegments();
return segments.size() == 2
&& (segments.get(1).equals(REF_SEGMENT.get(0)) || segments.get(1).equals(REF_SEGMENT.get(1)));
&& (REF_SEGMENT.equalsIgnoreCase(segments.get(1)) || REF_SEGMENT_RU.equalsIgnoreCase(segments.get(1)));
}
}