Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@
<fix class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.UndefinedMethodFix"/>
<fix class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.UndefinedFunctionFix"/>
<fix class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.UndefinedVariableFix"/>
<fix class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.MethodSemicolonExtraFix"/>
<fix class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.SemicolonMissingFix"/>
<fix
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.SelfReferenceFix">
</fix>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ final class Messages

public static String OpenBslDocCommentViewFix_Details;

public static String MethodSemicolonExtraFix_Details;
public static String MethodSemicolonExtraFix_Description;

public static String SemicolonMissngFix_Details;
public static String SemicolonMissingFix_Description;

public static String SelfReferenceFix_description;

public static String SelfReferenceFix_details;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (C) 2025, 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.ui.qfix;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.TextEdit;
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.model.EmptyStatement;
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.qfix.components.QuickFix;

/**
* Removes extra semicolon
*
* @author Ivan Sergeev
*/
@QuickFix(checkId = "method-semicolon-extra", supplierId = "com.e1c.v8codestyle.bsl")
public class MethodSemicolonExtraFix
extends SingleVariantXtextBslModuleFix
{

@Override
protected void configureFix(FixConfigurer configurer)
{
configurer.interactive(true)
.description(Messages.MethodSemicolonExtraFix_Description)
.details(Messages.MethodSemicolonExtraFix_Description);
}

@Override
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException
{
EObject eobject = model.getElement();

if (!(eobject instanceof EmptyStatement))
{
return null;
}

INode node = NodeModelUtils.findActualNodeFor(eobject);

if (node == null)
{
return null;
}
INode checkNode = node.getNextSibling();
if (checkNode == null)
{
return null;
}
String checkText = checkNode.getText();
INode checkNextNode = checkNode.getNextSibling();
if (checkText.contains(";")) //$NON-NLS-1$
{
return new DeleteEdit(checkNode.getTotalOffset(), checkNode.getTotalLength());
}
else if (checkNextNode.getText().contains(";") && !(checkNextNode == null)) //$NON-NLS-1$
{
return new DeleteEdit(checkNextNode.getTotalOffset(), checkNextNode.getTotalLength());
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (C) 2025, 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.ui.qfix;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.InsertEdit;
import org.eclipse.text.edits.TextEdit;
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.model.Conditional;
import com._1c.g5.v8.dt.bsl.model.Statement;
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.qfix.components.QuickFix;

/**
* Add missing semicolon
*
* @author Ivan Sergeev
*/
@QuickFix(checkId = "semicolon-missing", supplierId = "com.e1c.v8codestyle.bsl")
public class SemicolonMissingFix
extends SingleVariantXtextBslModuleFix
{

@Override
protected void configureFix(FixConfigurer configurer)
{
configurer.interactive(true)
.description(Messages.SemicolonMissingFix_Description)
.details(Messages.SemicolonMissngFix_Details);
}

@Override
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException
{
EObject eobject = model.getElement();
if (!(eobject instanceof Statement) & !(eobject instanceof Conditional))
{
return null;
}

INode node = NodeModelUtils.findActualNodeFor(eobject);
if (node == null)
{
return null;
}
return new InsertEdit(node.getEndOffset(), ";"); //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ManagerModuleNamedSelfReferenceFix_description=Remove excessive named self refer
ManagerModuleNamedSelfReferenceFix_details=Remove excessive named self reference from manager module
OpenBslDocCommentViewFix_Details=Open documentation comment data structure view and show current probleme object.
OpenBslDocCommentViewFix_Description=Open documentation comment structure view
MethodSemicolonExtraFix_Details = Remove extra semicolon
MethodSemicolonExtraFix_Description = Remove extra semicolon
SemicolonMissingFix_Details = Add missing semicolon
SemicolonMissingFix_Description = Add missing semicolon
SelfReferenceFix_description=Remove excessive self reference
SelfReferenceFix_details=Remove excessive self reference
ServerExecutionSafeModeFix_description = Enable safe mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ ServerExecutionSafeModeFix_description = Включить безопасный

ServerExecutionSafeModeFix_details = Добавить включение безопасного режима перед вызовом метода "Выполнить" или "Вычислить"

MethodSemicolonExtraFix_Details = Удалить лишнюю точку с запятой

MethodSemicolonExtraFix_Description = Удалить лишнюю точку с запятой

SemicolonMissingFix_Details = Добавить пропущенную точку с запятой

SemicolonMissingFix_Description = Добавить пропущенную точку с запятой

UndefinedMethodFix_func_desc = Создать новую функцию в модуле

UndefinedMethodFix_func_title = Создать функцию
Expand Down
8 changes: 8 additions & 0 deletions bundles/com.e1c.v8codestyle.bsl/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.internal.bsl.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.comment.check.ExportProcedureCommentDescriptionCheck">
</check>
<check
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.bsl.check.MethodSemicolonExtraCheck">
</check>
<check
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.bsl.check.SemicolonMissingCheck">
</check>
<check
category="com.e1c.v8codestyle.bsl"
class="com.e1c.v8codestyle.bsl.check.OptionalFormParameterAccessCheck">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ final class Messages
public static String QueryInLoop_Loop_has_query;
public static String QueryInLoop_title;

public static String SemicolonMissingCheck_Description;

public static String SemicolonMissingCheck_Title;

public static String SemicolonMissingCheck_Issue;

public static String SelfReferenceCheck_check_object_module;

public static String SelfReferenceCheck_check_only_existing_form_properties;
Expand Down Expand Up @@ -394,6 +400,12 @@ final class Messages

public static String MethodTooManyPramsCheck_title;

public static String MethodSemicolonExtraCheck_Description;

public static String MethodSemicolonExtraCheck_Title;

public static String MethodSemicolonExtraCheck_Issue;

public static String MissingTemporaryFileDeletionCheck_Delete_File_Methods;

public static String MissingTemporaryFileDeletionCheck_description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (C) 2025, 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.METHOD;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;

import com._1c.g5.v8.dt.bsl.model.EmptyStatement;
import com._1c.g5.v8.dt.bsl.model.Method;
import com._1c.g5.v8.dt.bsl.model.Statement;
import com._1c.g5.v8.dt.bsl.model.util.BslUtil;
import com.e1c.g5.v8.dt.check.BslDirectLocationIssue;
import com.e1c.g5.v8.dt.check.CheckComplexity;
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.ModuleTopObjectNameFilterExtension;
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
import com.e1c.g5.v8.dt.check.settings.IssueType;
import com.e1c.v8codestyle.check.CommonSenseCheckExtension;
import com.e1c.v8codestyle.internal.bsl.BslPlugin;

/**
* Checks method declaration contain extra semicolon
*
* @author Ivan Sergeev
*/
public class MethodSemicolonExtraCheck
extends AbstractModuleStructureCheck
{
private static final String CHECK_ID = "method-semicolon-extra"; //$NON-NLS-1$

@Override
public String getCheckId()
{
return CHECK_ID;
}

@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.title(Messages.MethodSemicolonExtraCheck_Title)
.description(Messages.MethodSemicolonExtraCheck_Description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.MINOR)
.issueType(IssueType.CODE_STYLE)
.extension(new ModuleTopObjectNameFilterExtension())
.extension(new CommonSenseCheckExtension(getCheckId(), BslPlugin.PLUGIN_ID))
.module()
.checkedObjectType(METHOD);
}

@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
Method method = (Method)object;
List<Statement> allItems = BslUtil.allStatements(method);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я понимаю, что жаловались толкьо на ; в начале методов, но чисто по общности вот такой вариант тоже не очень хорош, можно отдельно со всеми обсудить будет ли править

Uploading image.png…

if (allItems.isEmpty())
{
return;
}

if (allItems.get(0) instanceof EmptyStatement)
{
INode node = NodeModelUtils.findActualNodeFor(allItems.get(0));

if (node == null)
{
return;
}
INode checkNode = node.getNextSibling();

if (checkNode == null)
{
return;
}
String checkText = checkNode.getText();
INode checkNodeNext = checkNode.getNextSibling();
if (checkText.contains(";")) //$NON-NLS-1$
{

DirectLocation directLocation = new DirectLocation(checkNode.getOffset(), checkNode.getLength(),
checkNode.getStartLine(), allItems.get(0));

Issue issue = new BslDirectLocationIssue(Messages.MethodSemicolonExtraCheck_Issue, directLocation);

resultAceptor.addIssue(issue);
}
else if (checkNodeNext.getText().contains(";") && !(checkNodeNext == null)) //$NON-NLS-1$
{
DirectLocation directLocation = new DirectLocation(checkNodeNext.getOffset(), checkNodeNext.getLength(),
checkNodeNext.getStartLine(), allItems.get(0));

Issue issue = new BslDirectLocationIssue(Messages.MethodSemicolonExtraCheck_Issue, directLocation);

resultAceptor.addIssue(issue);
}
}
}
}
Loading
Loading