-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,351 additions
and
39 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/AbstractUiStringCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
bundles/com.e1c.v8codestyle.md/src/com/e1c/v8codestyle/md/check/MdObjectSynonymCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.