mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-04-09 17:34:02 +02:00
* Очистка пустых строк (quick-fix)
This commit is contained in:
parent
df38125544
commit
8acd5a4efc
@ -20,6 +20,7 @@
|
||||
#### Код модулей
|
||||
|
||||
- Добавление типизированного значения в не типизированную коллекцию
|
||||
- Проверка максимального количества допустимых пустых строк
|
||||
- Чтение отдельных реквизитов объекта из базы данных
|
||||
- Использование экспортных переменных в модулях объекта
|
||||
- Использование конструкции "Новый Шрифт"
|
||||
@ -35,6 +36,7 @@
|
||||
|
||||
|
||||
### Новые быстрые исправления (Quick-fix)
|
||||
- Исправление превышения максимального количества допустимых пустых строк
|
||||
|
||||
|
||||
### Исправленные ошибки
|
||||
|
@ -0,0 +1,29 @@
|
||||
# Checking the maximum number of empty rows
|
||||
|
||||
## Noncompliant Code Example
|
||||
|
||||
```bsl
|
||||
Procedure Test()
|
||||
|
||||
A1 = 1;
|
||||
|
||||
|
||||
A2 = 2;
|
||||
|
||||
EndProcedure
|
||||
```
|
||||
|
||||
## Compliant Solution
|
||||
|
||||
```bsl
|
||||
Procedure Test()
|
||||
|
||||
A1 = 1;
|
||||
|
||||
A2 = 2;
|
||||
|
||||
EndProcedure
|
||||
```
|
||||
|
||||
## See
|
||||
|
@ -0,0 +1,28 @@
|
||||
# Проверка максимального количства пустых строк
|
||||
|
||||
## Неправильно
|
||||
|
||||
```bsl
|
||||
Процедура Тест()
|
||||
|
||||
А1 = 1;
|
||||
|
||||
|
||||
A2 = 2;
|
||||
|
||||
КонецПроцедуры
|
||||
```
|
||||
|
||||
## Правильно
|
||||
|
||||
```bsl
|
||||
Процедура Тест()
|
||||
|
||||
А1 = 1;
|
||||
|
||||
A2 = 2;
|
||||
|
||||
КонецПроцедуры
|
||||
```
|
||||
|
||||
## См.
|
@ -311,6 +311,10 @@
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ModuleStructureVariablesInRegionCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ConsecutiveEmptyLinesCheck">
|
||||
</check>
|
||||
<check
|
||||
category="com.e1c.v8codestyle.bsl"
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.check.ReadingAttributesFromDataBaseCheck">
|
||||
@ -351,5 +355,11 @@
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.internal.bsl.StrictTypesProjectOptionProvider">
|
||||
</provider>
|
||||
</extension>
|
||||
<extension
|
||||
point="com.e1c.g5.v8.dt.check.fixes">
|
||||
<fix
|
||||
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.qfix.ConsecutiveEmptyLinesFix">
|
||||
</fix>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
@ -0,0 +1,142 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2022, 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.bsl.check;
|
||||
|
||||
import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.MODULE;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.TerminalRule;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.model.Module;
|
||||
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
|
||||
import com.e1c.g5.v8.dt.check.BslDirectLocationIssue;
|
||||
import com.e1c.g5.v8.dt.check.DirectLocation;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
import com.e1c.g5.v8.dt.check.Issue;
|
||||
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;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Checks consecutive empty lines
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public class ConsecutiveEmptyLinesCheck
|
||||
extends BasicCheck
|
||||
{
|
||||
|
||||
private static final String PATTERN = "(?<=\\n)"; //$NON-NLS-1$
|
||||
private static final String DEFAULT_NUMBER_OF_EMPTY_LINES = "1"; //$NON-NLS-1$
|
||||
private static final String NUMBER_OF_EMPTY_LINES = "numberOfEmptyLines"; //$NON-NLS-1$
|
||||
private static final String CHECK_ID = "module-consecutive-blank-lines"; //$NON-NLS-1$
|
||||
|
||||
private final BslGrammarAccess grammarAccess;
|
||||
|
||||
/**
|
||||
* Instantiates a new consecutive empty lines check.
|
||||
*
|
||||
* @param grammarAccess the grammar access
|
||||
*/
|
||||
@Inject
|
||||
public ConsecutiveEmptyLinesCheck(BslGrammarAccess grammarAccess)
|
||||
{
|
||||
super();
|
||||
this.grammarAccess = grammarAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCheckId()
|
||||
{
|
||||
return CHECK_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCheck(CheckConfigurer builder)
|
||||
{
|
||||
builder.title(Messages.ConsecutiveEmptyLines_Title)
|
||||
.description(Messages.ConsecutiveEmptyLines_Description)
|
||||
.issueType(IssueType.CODE_STYLE)
|
||||
.severity(IssueSeverity.TRIVIAL)
|
||||
.disable()
|
||||
.module()
|
||||
.checkedObjectType(MODULE)
|
||||
.parameter(NUMBER_OF_EMPTY_LINES, Integer.class, DEFAULT_NUMBER_OF_EMPTY_LINES,
|
||||
Messages.ConsecutiveEmptyLines_Parameter_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
|
||||
IProgressMonitor progressMonitor)
|
||||
{
|
||||
Module module = (Module)object;
|
||||
INode node = NodeModelUtils.findActualNodeFor(module);
|
||||
Iterator<ILeafNode> iterator = node.getLeafNodes().iterator();
|
||||
|
||||
int numberAllowedLines = parameters.getInt(NUMBER_OF_EMPTY_LINES);
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
ILeafNode leafNode = iterator.next();
|
||||
if (leafNode.isHidden())
|
||||
{
|
||||
EObject grammarElement = leafNode.getGrammarElement();
|
||||
int startLine = leafNode.getStartLine();
|
||||
int endLine = leafNode.getEndLine();
|
||||
if (grammarElement instanceof TerminalRule && grammarAccess.getWSRule().equals(grammarElement)
|
||||
&& (endLine - startLine - 1) > numberAllowedLines)
|
||||
{
|
||||
String message = MessageFormat.format(
|
||||
Messages.ConsecutiveEmptyLines_Sequence_of_empty_lines_between__0__and__1__is_greator_than__2,
|
||||
startLine, endLine, numberAllowedLines);
|
||||
|
||||
String[] lines = leafNode.getText().split(PATTERN);
|
||||
int headLength = getAllowedHeadLength(numberAllowedLines, lines);
|
||||
|
||||
DirectLocation directLocation =
|
||||
new DirectLocation(
|
||||
leafNode.getOffset() + headLength,
|
||||
leafNode.getLength() - (headLength + getAllowedTailLength(lines)),
|
||||
startLine + numberAllowedLines + 1, module);
|
||||
|
||||
Issue issue = new BslDirectLocationIssue(message, directLocation);
|
||||
|
||||
resultAceptor.addIssue(issue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getAllowedHeadLength(int number, String[] lines)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i <= number; i++)
|
||||
{
|
||||
sum += lines[i].length();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
private int getAllowedTailLength(String[] lines)
|
||||
{
|
||||
return lines[lines.length - 1].length();
|
||||
}
|
||||
}
|
@ -88,6 +88,14 @@ final class Messages
|
||||
|
||||
public static String CommonModuleNamedSelfReferenceCheck_title;
|
||||
|
||||
public static String ConsecutiveEmptyLines_Description;
|
||||
|
||||
public static String ConsecutiveEmptyLines_Parameter_title;
|
||||
|
||||
public static String ConsecutiveEmptyLines_Sequence_of_empty_lines_between__0__and__1__is_greator_than__2;
|
||||
|
||||
public static String ConsecutiveEmptyLines_Title;
|
||||
|
||||
public static String DeprecatedProcedureOutsideDeprecatedRegionCheck_Deprecated_function_out_of_deprecated_area;
|
||||
|
||||
public static String DeprecatedProcedureOutsideDeprecatedRegionCheck_description;
|
||||
|
@ -82,6 +82,14 @@ CommonModuleNamedSelfReferenceCheck_issue=Excessive named self reference
|
||||
|
||||
CommonModuleNamedSelfReferenceCheck_title=Excessive named self reference in common module
|
||||
|
||||
ConsecutiveEmptyLines_Description=Consecutive empty lines
|
||||
|
||||
ConsecutiveEmptyLines_Parameter_title=Maximum number of empty lines
|
||||
|
||||
ConsecutiveEmptyLines_Sequence_of_empty_lines_between__0__and__1__is_greator_than__2=The sequence of empty lines between lines {0} and {1} is more than {2}
|
||||
|
||||
ConsecutiveEmptyLines_Title=Consecutive empty lines
|
||||
|
||||
DeprecatedProcedureOutsideDeprecatedRegionCheck_Deprecated_function_out_of_deprecated_area=The deprecated procedure (function) "{0}" should be placed in the Deprecated region of the Public region in a common module area
|
||||
|
||||
DeprecatedProcedureOutsideDeprecatedRegionCheck_description=Deprecated procedure (function) should be placed in the Deprecated region of the Public region in a common module area
|
||||
|
@ -88,6 +88,14 @@ CommonModuleNamedSelfReferenceCheck_issue=Избыточное обращени
|
||||
|
||||
CommonModuleNamedSelfReferenceCheck_title=Избыточное обращение по собственному имени в общем модуле
|
||||
|
||||
ConsecutiveEmptyLines_Description=Последовательно расположенные пустые строки
|
||||
|
||||
ConsecutiveEmptyLines_Parameter_title=Максимальное количество последовательно расположенных пустых строк
|
||||
|
||||
ConsecutiveEmptyLines_Sequence_of_empty_lines_between__0__and__1__is_greator_than__2=Между строками {0} и {1} расположено больше {2} пустых строк
|
||||
|
||||
ConsecutiveEmptyLines_Title=Последовательность пустых строк
|
||||
|
||||
DeprecatedProcedureOutsideDeprecatedRegionCheck_Deprecated_function_out_of_deprecated_area = Устаревшую процедуру (функцию) "{0}" следует перенести в область общего модуля УстаревшиеПроцедурыИФункции, размещенную внутри области ПрограммныйИнтерфейс
|
||||
|
||||
DeprecatedProcedureOutsideDeprecatedRegionCheck_description = Устаревшую процедуру (функцию) следует перенести в область общего модуля УстаревшиеПроцедурыИФункции, размещенную внутри области ПрограммныйИнтерфейс
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2022, 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.bsl.qfix;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.text.edits.DeleteEdit;
|
||||
import org.eclipse.text.edits.MultiTextEdit;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.xtext.TerminalRule;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
|
||||
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel;
|
||||
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;
|
||||
import com.e1c.g5.v8.dt.check.settings.ICheckRepository;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Removes extra empty lines
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
@QuickFix(checkId = "module-consecutive-blank-lines", supplierId = BslPlugin.PLUGIN_ID)
|
||||
public class ConsecutiveEmptyLinesFix
|
||||
extends SingleVariantXtextBslModuleFix
|
||||
{
|
||||
private static final String PATTERN = "(?<=\\n)"; //$NON-NLS-1$
|
||||
|
||||
private static final String NUMBER_OF_EMPTY_LINES = "numberOfEmptyLines"; //$NON-NLS-1$
|
||||
|
||||
private final BslGrammarAccess grammarAccess;
|
||||
|
||||
private final ICheckRepository checkRepository;
|
||||
|
||||
private final IV8ProjectManager v8ProjectManager;
|
||||
|
||||
/**
|
||||
* Instantiates a new consecutive empty lines fix.
|
||||
*
|
||||
* @param grammarAccess the grammar access
|
||||
* @param checkRepository the check repository
|
||||
* @param v8ProjectManager the v 8 project manager
|
||||
*/
|
||||
@Inject
|
||||
public ConsecutiveEmptyLinesFix(BslGrammarAccess grammarAccess, ICheckRepository checkRepository,
|
||||
IV8ProjectManager v8ProjectManager)
|
||||
{
|
||||
super();
|
||||
this.grammarAccess = grammarAccess;
|
||||
this.checkRepository = checkRepository;
|
||||
this.v8ProjectManager = v8ProjectManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureFix(FixConfigurer configurer)
|
||||
{
|
||||
configurer.interactive(true)
|
||||
.description(Messages.ConsecutiveEmptyLinesFix_Description)
|
||||
.details(Messages.ConsecutiveEmptyLinesFix_Details);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException
|
||||
{
|
||||
EObject element = model.getElement();
|
||||
INode node = NodeModelUtils.findActualNodeFor(element);
|
||||
Iterator<ILeafNode> iterator = node.getLeafNodes().iterator();
|
||||
|
||||
IV8Project project = v8ProjectManager.getProject(element);
|
||||
ICheckParameters parameters = checkRepository.getCheckParameters(getCheckId(), project.getProject());
|
||||
int numberOfEmtyLines = parameters.getInt(NUMBER_OF_EMPTY_LINES);
|
||||
|
||||
MultiTextEdit result = new MultiTextEdit();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
ILeafNode leafNode = iterator.next();
|
||||
EObject grammarElement = leafNode.getGrammarElement();
|
||||
int startLine = leafNode.getStartLine();
|
||||
int endLine = leafNode.getEndLine();
|
||||
|
||||
if (grammarElement instanceof TerminalRule && grammarAccess.getWSRule().equals(grammarElement)
|
||||
&& (endLine - startLine - 1) > numberOfEmtyLines)
|
||||
{
|
||||
String[] lines = leafNode.getText().split(PATTERN);
|
||||
int headLength = getAllowedHeadLength(numberOfEmtyLines, lines);
|
||||
|
||||
int tailLength = leafNode.getLength() - getAllowedTailLength(headLength, lines);
|
||||
result.addChild(new DeleteEdit(leafNode.getOffset() + headLength, tailLength == 0 ? 1 : tailLength));
|
||||
}
|
||||
}
|
||||
|
||||
if (result.getChildrenSize() > 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getAllowedHeadLength(int number, String[] lines)
|
||||
{
|
||||
int sum = 0;
|
||||
for (int i = 0; i <= number; i++)
|
||||
{
|
||||
sum += lines[i].length();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
private int getAllowedTailLength(int sum, String[] lines)
|
||||
{
|
||||
return sum + lines[lines.length - 1].length();
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@ final class Messages
|
||||
extends NLS
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.bsl.qfix.messages"; //$NON-NLS-1$
|
||||
public static String ConsecutiveEmptyLinesFix_Description;
|
||||
public static String ConsecutiveEmptyLinesFix_Details;
|
||||
public static String RemoveExportFix_Remove_export_keyword_des;
|
||||
public static String RemoveExportFix_Remove_export_keyword_det;
|
||||
static
|
||||
|
@ -12,3 +12,6 @@
|
||||
###############################################################################
|
||||
RemoveExportFix_Remove_export_keyword_des=Remove Export keyword
|
||||
RemoveExportFix_Remove_export_keyword_det=Remove Export keyword
|
||||
|
||||
ConsecutiveEmptyLinesFix_Details=Clear extra empty lines
|
||||
ConsecutiveEmptyLinesFix_Description=Clear extra empty lines
|
||||
|
@ -12,3 +12,6 @@
|
||||
###############################################################################
|
||||
RemoveExportFix_Remove_export_keyword_des=Удалить ключевое слово Экспорт
|
||||
RemoveExportFix_Remove_export_keyword_det=Удалить ключевое слово Экспорт
|
||||
|
||||
ConsecutiveEmptyLinesFix_Details=Очистить пустые строки
|
||||
ConsecutiveEmptyLinesFix_Description=Очистить лишние пустые строки
|
||||
|
@ -33,6 +33,7 @@ import com._1c.g5.v8.dt.bsl.resource.BslEventsService;
|
||||
import com._1c.g5.v8.dt.bsl.resource.DynamicFeatureAccessComputer;
|
||||
import com._1c.g5.v8.dt.bsl.resource.ExportMethodProvider;
|
||||
import com._1c.g5.v8.dt.bsl.resource.TypesComputer;
|
||||
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
|
||||
import com._1c.g5.v8.dt.bsl.typesystem.ExportMethodTypeProvider;
|
||||
import com._1c.g5.v8.dt.core.platform.IConfigurationProvider;
|
||||
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
@ -89,5 +90,6 @@ class ExternalDependenciesModule
|
||||
bind(IResourceAccess.class).toService();
|
||||
bind(ResourceDescriptionsProvider.class).toService();
|
||||
bind(IConfigurationProvider.class).toService();
|
||||
bind(BslGrammarAccess.class).toProvider(() -> rsp.get(BslGrammarAccess.class));
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,13 @@ Fragment-Host: com.e1c.v8codestyle.bsl;bundle-version="[0.4.0,0.5.0)"
|
||||
Automatic-Module-Name: com.e1c.v8codestyle.md.itests
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Bundle-Localization: fragment
|
||||
Import-Package: com._1c.g5.v8.dt.core.platform;version="[10.0.0,11.0.0)",
|
||||
Import-Package: com._1c.g5.v8.dt.core.naming;version="[6.0.0,7.0.0)",
|
||||
com._1c.g5.v8.dt.core.platform;version="[10.0.0,11.0.0)",
|
||||
com._1c.g5.v8.dt.form.model;version="[10.0.0,11.0.0)",
|
||||
com._1c.g5.v8.dt.md.naming;version="[5.1.0,6.0.0)",
|
||||
com._1c.g5.v8.dt.testing;version="[3.1.0,4.0.0)",
|
||||
com._1c.g5.v8.dt.ui.util;version="[6.0.0,7.0.0)",
|
||||
com._1c.g5.v8.dt.ui.validation;version="[5.0.0,6.0.0)",
|
||||
com._1c.g5.v8.dt.validation.marker;version="[5.0.0,6.0.0)",
|
||||
com.e1c.g5.v8.dt.testing.check;version="[1.0.0,2.0.0)",
|
||||
org.junit;version="[4.13.0,5.0.0)"
|
||||
|
@ -0,0 +1,10 @@
|
||||
Procedure MyCorrectProcedureBeforeAfter(Param) Export
|
||||
|
||||
|
||||
If Param > 10 Then
|
||||
|
||||
Param = 0;
|
||||
|
||||
EndIf
|
||||
|
||||
EndProcedure
|
@ -0,0 +1,9 @@
|
||||
Procedure MyCorrectProcedureBeforeAfter(Param) Export
|
||||
|
||||
If Param > 10 Then
|
||||
|
||||
Param = 0;
|
||||
|
||||
EndIf
|
||||
|
||||
EndProcedure
|
@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (C) 2022, 1C
|
||||
*/
|
||||
package com.e1c.v8codestyle.bsl.check.itests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com._1c.g5.v8.dt.validation.marker.IExtraInfoKeys;
|
||||
import com._1c.g5.v8.dt.validation.marker.Marker;
|
||||
import com.e1c.v8codestyle.bsl.check.ConsecutiveEmptyLinesCheck;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConsecutiveEmptyLinesCheck} check.
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public class ConsecutiveEmptyLinesCheckTest
|
||||
extends AbstractSingleModuleTestBase
|
||||
{
|
||||
|
||||
public ConsecutiveEmptyLinesCheckTest()
|
||||
{
|
||||
super(ConsecutiveEmptyLinesCheck.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithManyEmptyLines() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "empty-lines.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertFalse(markers.isEmpty());
|
||||
assertEquals("3", markers.get(0).getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithOneEmptyLine() throws Exception
|
||||
{
|
||||
updateModule(FOLDER_RESOURCE + "one-empty-line.bsl");
|
||||
|
||||
List<Marker> markers = getModuleMarkers();
|
||||
assertTrue(markers.isEmpty());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright (C) 2022, 1C
|
||||
*/
|
||||
package com.e1c.v8codestyle.bsl.fix.itests;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.junit.Test;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.dt.core.naming.ISymbolicLinkLocalizer;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProject;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.md.naming.MdSymbolicLinkLocalizer;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.CommonModule;
|
||||
import com._1c.g5.v8.dt.ui.util.OpenHelper;
|
||||
import com._1c.g5.v8.dt.ui.validation.BmMarkerWrapper;
|
||||
import com._1c.g5.v8.dt.validation.marker.IMarkerWrapper;
|
||||
import com._1c.g5.v8.dt.validation.marker.Marker;
|
||||
import com._1c.g5.wiring.ServiceAccess;
|
||||
import com.e1c.g5.v8.dt.check.qfix.FixProcessHandle;
|
||||
import com.e1c.g5.v8.dt.check.qfix.FixVariantDescriptor;
|
||||
import com.e1c.g5.v8.dt.check.qfix.IFixManager;
|
||||
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
|
||||
import com.e1c.v8codestyle.bsl.qfix.ConsecutiveEmptyLinesFix;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConsecutiveEmptyLinesFix} fix.
|
||||
*
|
||||
* @author Artem Iliukhin
|
||||
*/
|
||||
public class ConsecutiveEmptyLinesFixTest
|
||||
extends CheckTestBase
|
||||
{
|
||||
|
||||
private static final String PROJECT_NAME = "ConsecutiveEmptyLines";
|
||||
private static final String FQN_COMMON_MODULE = "CommonModule.CommonModule";
|
||||
private static final String CHECK_ID = "module-consecutive-blank-lines";
|
||||
private static final String DESCRIPTION = "Clear extra empty lines";
|
||||
private static final String COMMON_MODULE_FILE_NAME = "/src/CommonModules/CommonModule/Module.bsl";
|
||||
private IFixManager fixManager = ServiceAccess.get(IFixManager.class);
|
||||
private IV8ProjectManager projectManager = ServiceAccess.get(IV8ProjectManager.class);
|
||||
private ISymbolicLinkLocalizer symbolicLinkLocalizer = new MdSymbolicLinkLocalizer();
|
||||
private final OpenHelper openHelper = new OpenHelper();
|
||||
|
||||
@Test
|
||||
public void testApplyFix() throws Exception
|
||||
{
|
||||
|
||||
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME);
|
||||
assertNotNull(dtProject);
|
||||
|
||||
IBmObject object = getTopObjectByFqn(FQN_COMMON_MODULE, dtProject);
|
||||
assertTrue(object instanceof CommonModule);
|
||||
CommonModule module = (CommonModule)object;
|
||||
|
||||
Marker marker = getFirstMarker(CHECK_ID, module.getModule(), dtProject);
|
||||
assertNotNull(marker);
|
||||
|
||||
applyFix(marker, dtProject);
|
||||
|
||||
IFile file = dtProject.getWorkspaceProject().getFile(COMMON_MODULE_FILE_NAME);
|
||||
try (InputStream in = file.getContents())
|
||||
{
|
||||
file.setContents(in, true, true, new NullProgressMonitor());
|
||||
}
|
||||
|
||||
waitForDD(dtProject);
|
||||
|
||||
object = getTopObjectByFqn(FQN_COMMON_MODULE, dtProject);
|
||||
assertTrue(object instanceof CommonModule);
|
||||
module = (CommonModule)object;
|
||||
|
||||
waitForDD(dtProject);
|
||||
|
||||
marker = getFirstMarker(CHECK_ID, module.getModule(), dtProject);
|
||||
assertNull(marker);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply fix for the marker.
|
||||
*
|
||||
* @param marker the marker
|
||||
* @param dtProject the DT project of the marker
|
||||
*/
|
||||
private void applyFix(Marker marker, IDtProject dtProject)
|
||||
{
|
||||
IMarkerWrapper markerWrapper = new BmMarkerWrapper(marker, dtProject.getWorkspaceProject(), bmModelManager,
|
||||
projectManager, symbolicLinkLocalizer, openHelper);
|
||||
|
||||
FixProcessHandle handle = fixManager.prepareFix(markerWrapper, dtProject);
|
||||
|
||||
FixVariantDescriptor variantDescr = null;
|
||||
|
||||
Collection<FixVariantDescriptor> variants = fixManager.getApplicableFixVariants(handle);
|
||||
for (FixVariantDescriptor variant : variants)
|
||||
{
|
||||
if (variant.getDescription().matches(DESCRIPTION))
|
||||
{
|
||||
variantDescr = variant;
|
||||
}
|
||||
}
|
||||
|
||||
fixManager.selectFixVariant(variantDescr, handle);
|
||||
fixManager.executeFix(handle, new NullProgressMonitor());
|
||||
fixManager.finishFix(handle);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ConsecutiveEmptyLines</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
<nature>com._1c.g5.v8.dt.core.V8ConfigurationNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"version": 1,
|
||||
"settings": {
|
||||
"module-consecutive-blank-lines": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Runtime-Version: 8.3.19
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="95f19c60-97f4-4bb7-931b-efe6de87dd13">
|
||||
<name>CommonModule</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Common module</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,8 @@
|
||||
Procedure Test()
|
||||
|
||||
A1 = 1;
|
||||
|
||||
|
||||
A2 = 2;
|
||||
|
||||
EndProcedure
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="9d8f8016-ae99-449f-8d99-ed17661cd97a">
|
||||
<name>ConsecutiveEmptyLines</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Consecutive empty lines</value>
|
||||
</synonym>
|
||||
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="f892fa7b-c598-4028-89d6-127ece6f5a7a"/>
|
||||
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="2b616abd-7e14-4a60-9b9b-8946e682cdbe"/>
|
||||
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="50c919bc-bc73-406c-ac9f-8fc416737452"/>
|
||||
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="fe99a0d6-e31f-433b-83d4-515219fc433d"/>
|
||||
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="403efeb9-d75b-4f8e-82d4-6a619a0ec6d4"/>
|
||||
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="8de95119-3c48-44ef-8f8f-2a5e1ccc45ec"/>
|
||||
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="00b5c590-680e-4465-8c9a-75caf8114588"/>
|
||||
<configurationExtensionCompatibilityMode>8.3.19</configurationExtensionCompatibilityMode>
|
||||
<defaultRunMode>ManagedApplication</defaultRunMode>
|
||||
<usePurposes>PersonalComputer</usePurposes>
|
||||
<usedMobileApplicationFunctionalities>
|
||||
<functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
<functionality>
|
||||
<functionality>OSBackup</functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
</usedMobileApplicationFunctionalities>
|
||||
<defaultLanguage>Language.English</defaultLanguage>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<objectAutonumerationMode>NotAutoFree</objectAutonumerationMode>
|
||||
<modalityUseMode>DontUse</modalityUseMode>
|
||||
<synchronousPlatformExtensionAndAddInCallUseMode>DontUse</synchronousPlatformExtensionAndAddInCallUseMode>
|
||||
<compatibilityMode>8.3.19</compatibilityMode>
|
||||
<languages uuid="11695685-8cd5-4e80-ace7-3c114a76df34">
|
||||
<name>English</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>English</value>
|
||||
</synonym>
|
||||
<languageCode>en</languageCode>
|
||||
</languages>
|
||||
<commonModules>CommonModule.CommonModule</commonModules>
|
||||
</mdclass:Configuration>
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
Loading…
x
Reference in New Issue
Block a user