Skip to content

Commit

Permalink
Проверки корня конфигурации
Browse files Browse the repository at this point in the history
  • Loading branch information
marmyshev committed Jan 16, 2024
1 parent 1d3e0b5 commit b008da6
Show file tree
Hide file tree
Showing 41 changed files with 1,351 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
*
*/
package com.e1c.v8codestyle.md.check;

import java.text.MessageFormat;
import java.util.regex.Pattern;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;

import com._1c.g5.v8.dt.common.StringUtils;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com.e1c.g5.v8.dt.check.CheckComplexity;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.components.BasicCheck;
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
import com.e1c.g5.v8.dt.check.settings.IssueType;

/**
* The abstract class to check UI feature of EMF object that is not empty or match pattern.
*
* @author Dmitriy Marmyshev
*/
public abstract class AbstractUiStringCheck
extends BasicCheck
{
protected static final String PARAM_UI_STRING_PATTERN = "uiStringPattern"; //$NON-NLS-1$

protected final EReference uiStringRef;

private final IV8ProjectManager v8ProjectManager;

protected AbstractUiStringCheck(EReference uiStringRef, IV8ProjectManager v8ProjectManager)
{
this.uiStringRef = uiStringRef;
this.v8ProjectManager = v8ProjectManager;
}

@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.MINOR)
.issueType(IssueType.UI_STYLE)
.extension(new MdUiStringExtension())
.parameter(PARAM_UI_STRING_PATTERN, String.class, getUiStringPatternDefaultValue(),
getUiStringPatternTitle());
}

protected String getUiStringPatternDefaultValue()
{
return StringUtils.EMPTY;
}

protected String getUiStringPatternTitle()
{
return "UI string pattern";
}

@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
EObject eObject = (EObject)object;
Object rawValue = eObject.eGet(uiStringRef);
if (!(rawValue instanceof EMap))
{
return;
}

@SuppressWarnings("unchecked")
EMap<String, String> uiString = (EMap<String, String>)rawValue;

if (uiString.isEmpty())
{
resultAceptor.addIssue(getUiStringIsEmptyForAll(), uiStringRef);
}
else
{
String uiStringPatternText = parameters.getString(PARAM_UI_STRING_PATTERN);
Pattern uiStringPattern = StringUtils.isBlank(uiStringPatternText) ? null
: Pattern.compile(uiStringPatternText, Pattern.UNICODE_CHARACTER_CLASS);

for (String languageCode : MdUiStringExtension.getLanguageCodes(parameters, eObject, v8ProjectManager))
{
String value = uiString.get(languageCode);
if (StringUtils.isBlank(value))
{
resultAceptor.addIssue(getUiStringIsEmpty(languageCode), uiStringRef);
}
else
{
if (uiStringPattern != null && !uiStringPattern.matcher(value).matches())
{
resultAceptor.addIssue(getUiStringShouldMatchPattern(languageCode, uiStringPatternText),
uiStringRef);
}
}
}
}
}

protected String getUiStringIsEmptyForAll()
{
return "UI string is empty for all languages";
}

protected String getUiStringIsEmpty(String languageCode)
{
return MessageFormat.format("UI string for language \"{0}\" is empty", languageCode);
}

protected String getUiStringShouldMatchPattern(String languageCode, String patternText)
{
return MessageFormat.format("UI string for language \"{0}\" should match pattern: \"{1}\"", languageCode,
patternText);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected void configureCheck(CheckConfigurer builder)
.severity(IssueSeverity.MAJOR)
.issueType(IssueType.PERFORMANCE)
.extension(new StandardCheckExtension(728, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.topObject(BASIC_DB_OBJECT)
.containment(TYPE_DESCRIPTION)
.features(TYPE_DESCRIPTION__TYPES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected void configureCheck(CheckConfigurer builder)
.severity(IssueSeverity.MAJOR)
.issueType(IssueType.PORTABILITY)
.extension(new StandardCheckExtension(467, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.parameter(MAX_LENGTH, Integer.class, MAX_LENGTH_DEFAULT, Messages.DbObjectMaxNumberLengthCheck_parameter);

builder.topObject(BASIC_DB_OBJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void configureCheck(CheckConfigurer builder)
.severity(IssueSeverity.MAJOR)
.issueType(IssueType.PERFORMANCE)
.extension(new StandardCheckExtension(728, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.topObject(BASIC_DB_OBJECT)
.containment(TYPE_DESCRIPTION)
.features(TYPE_DESCRIPTION__TYPES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void configureCheck(CheckConfigurer builder)
.extension(new TopObjectFilterExtension())
.issueType(IssueType.UI_STYLE)
.extension(new StandardCheckExtension(468, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension());
.extension(SkipAdoptedInExtensionMdObjectExtension.instance());

builder.topObject(BASIC_DB_OBJECT)
.checkTop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected void configureCheck(CheckConfigurer builder)
.severity(IssueSeverity.MINOR)
.issueType(IssueType.UI_STYLE)
.extension(new StandardCheckExtension(531, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.extension(new TopObjectFilterExtension())
.parameter(PARAM_ATTRIBUTES_LIST, String.class, DEFAULT_ATTRIBUTES_LIST,
Messages.MdObjectAttributeCommentCheck_Attribute_list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void configureCheck(CheckConfigurer builder)
.severity(IssueSeverity.MINOR)
.issueType(IssueType.UI_STYLE)
.extension(new StandardCheckExtension(531, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.extension(new TopObjectFilterExtension())
.parameter(PARAM_ATTRIBUTE_NAMES_LIST, String.class, DEFAULT_ATTRIBUTE_NAMES_LIST,
Messages.MdObjectAttributeCommentNotExist_Param_Attribute_name_list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void configureCheck(CheckConfigurer builder)
.extension(new TopObjectFilterExtension())
.issueType(IssueType.PORTABILITY)
.extension(new CommonSenseCheckExtension(getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.topObject(MD_OBJECT)
.checkTop()
.features(MD_OBJECT__NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected void configureCheck(CheckConfigurer builder)
.extension(new TopObjectFilterExtension())
.issueType(IssueType.UI_STYLE)
.extension(new StandardCheckExtension(474, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.topObject(MD_OBJECT)
.features(MD_OBJECT__NAME, MD_OBJECT__SYNONYM, MD_OBJECT__COMMENT);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*******************************************************************************
* Copyright (C) 2021, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.md.check;

import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.MD_OBJECT;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.MD_OBJECT__SYNONYM;

import java.text.MessageFormat;

import org.eclipse.core.runtime.IProgressMonitor;

import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.v8codestyle.check.StandardCheckExtension;
import com.e1c.v8codestyle.internal.md.CorePlugin;
import com.google.inject.Inject;

/**
* Check MD object synonym should not be empty or should match a pattern
*
* @author Dmitriy Marmyshev
*/
public final class MdObjectSynonymCheck
extends AbstractUiStringCheck
{
private static final String CHECK_ID = "mdo-synonym"; //$NON-NLS-1$

@Inject
public MdObjectSynonymCheck(IV8ProjectManager v8ProjectManager)
{
super(MD_OBJECT__SYNONYM, v8ProjectManager);
}
@Override
public String getCheckId()
{
return CHECK_ID;
}

@Override
protected void configureCheck(CheckConfigurer builder)
{
super.configureCheck(builder);
builder.title("Metada object synonym")
.description("Metada object synonym")
.extension(new StandardCheckExtension(474, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.topObject(MD_OBJECT)
.checkTop()
.features(MD_OBJECT__SYNONYM);
}

@Override
protected String getUiStringPatternTitle()
{
return "Synonym pattern";
}

@Override
protected String getUiStringIsEmptyForAll()
{
return "Synonym is empty for all languages";
}

@Override
protected String getUiStringIsEmpty(String languageCode)
{
return MessageFormat.format("Synonym for language \"{0}\" is empty", languageCode);
}

@Override
protected String getUiStringShouldMatchPattern(String languageCode, String patternText)
{
return MessageFormat.format("Synonym for language \"{0}\" should match pattern: \"{1}\"", languageCode,
patternText);
}

@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
if (object instanceof Configuration)
{
// Skip here, there is another synonym check for Configuration
return;
}
super.check(object, resultAceptor, parameters, monitor);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected void configureCheck(CheckConfigurer builder)
.issueType(IssueType.UI_STYLE)
.extension(new TopObjectFilterExtension())
.extension(new StandardCheckExtension(474, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.extension(SkipAdoptedInExtensionMdObjectExtension.instance())
.extension(new CatalogChangeExtension());

builder.topObject(CATALOG).containment(STANDARD_ATTRIBUTE).features(STANDARD_ATTRIBUTE__SYNONYM);
Expand Down
Loading

0 comments on commit b008da6

Please sign in to comment.