You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-17 13:07:50 +02:00
committed by
GitHub
parent
0b73e5fd28
commit
0b6c5d0319
@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
### Новые быстрые исправления (Quick-fix)
|
### Новые быстрые исправления (Quick-fix)
|
||||||
|
|
||||||
|
- Конвертация функции в процедуру
|
||||||
|
|
||||||
### Исправленные ошибки
|
### Исправленные ошибки
|
||||||
|
|
||||||
|
@ -361,6 +361,9 @@
|
|||||||
<fix
|
<fix
|
||||||
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.ManagerModuleNamedSelfReferenceFix">
|
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.ManagerModuleNamedSelfReferenceFix">
|
||||||
</fix>
|
</fix>
|
||||||
|
<fix
|
||||||
|
class="com.e1c.v8codestyle.internal.bsl.ui.ExecutableExtensionFactory:com.e1c.v8codestyle.bsl.ui.qfix.ConvertFunctionToProcedureFix">
|
||||||
|
</fix>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -0,0 +1,158 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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.ui.qfix;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import org.eclipse.emf.ecore.EObject;
|
||||||
|
import org.eclipse.text.edits.MultiTextEdit;
|
||||||
|
import org.eclipse.text.edits.ReplaceEdit;
|
||||||
|
import org.eclipse.text.edits.TextEdit;
|
||||||
|
import org.eclipse.xtext.Keyword;
|
||||||
|
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.model.Function;
|
||||||
|
import com._1c.g5.v8.dt.common.Pair;
|
||||||
|
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick fix for check com.e1c.v8codestyle.bsl.strict.check:function-return-value-type
|
||||||
|
* Replaces Function and EndFunction keywords with Procedure and EndProcedure
|
||||||
|
*
|
||||||
|
* @author Timur Mukhamedishin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@QuickFix(checkId = "function-return-value-type", supplierId = "com.e1c.v8codestyle.bsl")
|
||||||
|
public class ConvertFunctionToProcedureFix
|
||||||
|
extends SingleVariantXtextBslModuleFix
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void configureFix(FixConfigurer configurer)
|
||||||
|
{
|
||||||
|
configurer.interactive(true)
|
||||||
|
.description((context, session) -> {
|
||||||
|
String name = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
|
IXtextBslModuleFixModel model = context.getModel(session, false);
|
||||||
|
EObject element = model.getElement();
|
||||||
|
|
||||||
|
if (element instanceof Function)
|
||||||
|
{
|
||||||
|
name = ((Function)element).getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
String description = MessageFormat.format(Messages.ConvertFunctionToProcedureFix_description, name);
|
||||||
|
String details = MessageFormat.format(Messages.ConvertFunctionToProcedureFix_details, name);
|
||||||
|
|
||||||
|
return Pair.newPair(description, details);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model)
|
||||||
|
{
|
||||||
|
EObject element = model.getElement();
|
||||||
|
|
||||||
|
if (!(element instanceof Function))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isRussian = model.getScriptVariant() == ScriptVariant.RUSSIAN;
|
||||||
|
|
||||||
|
Keyword functionKeyword = getFunctionKeyword(model, isRussian);
|
||||||
|
Keyword endFunctionKeyword = getEndFunctionKeyword(model, isRussian);
|
||||||
|
Keyword procedureKeyword = getProcedureKeyword(model, isRussian);
|
||||||
|
Keyword endProcedureKeyword = getEndProcedureKeyword(model, isRussian);
|
||||||
|
|
||||||
|
INode node = NodeModelUtils.findActualNodeFor(element);
|
||||||
|
|
||||||
|
LinkedList<ILeafNode> allLeafNodes = new LinkedList<>();
|
||||||
|
node.getLeafNodes().forEach(allLeafNodes::add);
|
||||||
|
|
||||||
|
MultiTextEdit result = new MultiTextEdit();
|
||||||
|
|
||||||
|
for (int i = 0; i < allLeafNodes.size(); ++i)
|
||||||
|
{
|
||||||
|
ILeafNode firstNode = allLeafNodes.pollFirst();
|
||||||
|
|
||||||
|
if (firstNode.getGrammarElement().equals(functionKeyword))
|
||||||
|
{
|
||||||
|
result.addChild(new ReplaceEdit(firstNode.getOffset(), firstNode.getLength(),
|
||||||
|
procedureKeyword.getValue()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < allLeafNodes.size(); ++i)
|
||||||
|
{
|
||||||
|
ILeafNode lastNode = allLeafNodes.pollLast();
|
||||||
|
|
||||||
|
if (lastNode.getGrammarElement().equals(endFunctionKeyword))
|
||||||
|
{
|
||||||
|
result.addChild(new ReplaceEdit(lastNode.getOffset(), lastNode.getLength(),
|
||||||
|
endProcedureKeyword.getValue()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.getChildrenSize() == 2)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CHECKSTYLE.OFF: LineLength
|
||||||
|
private Keyword getFunctionKeyword(IXtextBslModuleFixModel model, boolean isRussian)
|
||||||
|
{
|
||||||
|
return !isRussian ? model.getBslGrammar().getFunctionAccess().getFunctionKeyword_2_0()
|
||||||
|
: model.getBslGrammar()
|
||||||
|
.getFunctionAccess()
|
||||||
|
.getCyrillicCapitalLetterEfCyrillicSmallLetterUCyrillicSmallLetterEnCyrillicSmallLetterKaCyrillicSmallLetterTseCyrillicSmallLetterICyrillicSmallLetterYaKeyword_2_1();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Keyword getEndFunctionKeyword(IXtextBslModuleFixModel model, boolean isRussian)
|
||||||
|
{
|
||||||
|
return !isRussian ? model.getBslGrammar().getFunctionAccess().getEndFunctionKeyword_9_0() : model
|
||||||
|
.getBslGrammar()
|
||||||
|
.getFunctionAccess()
|
||||||
|
.getCyrillicCapitalLetterKaCyrillicSmallLetterOCyrillicSmallLetterEnCyrillicSmallLetterIeCyrillicSmallLetterTseCyrillicCapitalLetterEfCyrillicSmallLetterUCyrillicSmallLetterEnCyrillicSmallLetterKaCyrillicSmallLetterTseCyrillicSmallLetterICyrillicSmallLetterIKeyword_9_1();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Keyword getProcedureKeyword(IXtextBslModuleFixModel model, boolean isRussian)
|
||||||
|
{
|
||||||
|
return !isRussian ? model.getBslGrammar().getProcedureAccess().getProcedureKeyword_2_0() : model
|
||||||
|
.getBslGrammar()
|
||||||
|
.getProcedureAccess()
|
||||||
|
.getCyrillicCapitalLetterPeCyrillicSmallLetterErCyrillicSmallLetterOCyrillicSmallLetterTseCyrillicSmallLetterIeCyrillicSmallLetterDeCyrillicSmallLetterUCyrillicSmallLetterErCyrillicSmallLetterAKeyword_2_1();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Keyword getEndProcedureKeyword(IXtextBslModuleFixModel model, boolean isRussian)
|
||||||
|
{
|
||||||
|
return !isRussian ? model.getBslGrammar().getProcedureAccess().getEndProcedureKeyword_9_0() : model
|
||||||
|
.getBslGrammar()
|
||||||
|
.getProcedureAccess()
|
||||||
|
.getCyrillicCapitalLetterKaCyrillicSmallLetterOCyrillicSmallLetterEnCyrillicSmallLetterIeCyrillicSmallLetterTseCyrillicCapitalLetterPeCyrillicSmallLetterErCyrillicSmallLetterOCyrillicSmallLetterTseCyrillicSmallLetterIeCyrillicSmallLetterDeCyrillicSmallLetterUCyrillicSmallLetterErCyrillicSmallLetterYeruKeyword_9_1();
|
||||||
|
}
|
||||||
|
//CHECKSTYLE.ON: LineLength
|
||||||
|
}
|
@ -24,6 +24,10 @@ final class Messages
|
|||||||
{
|
{
|
||||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.bsl.ui.qfix.messages"; //$NON-NLS-1$
|
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.bsl.ui.qfix.messages"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
public static String ConvertFunctionToProcedureFix_description;
|
||||||
|
|
||||||
|
public static String ConvertFunctionToProcedureFix_details;
|
||||||
|
|
||||||
public static String CommonModuleNamedSelfReferenceFix_description;
|
public static String CommonModuleNamedSelfReferenceFix_description;
|
||||||
|
|
||||||
public static String CommonModuleNamedSelfReferenceFix_details;
|
public static String CommonModuleNamedSelfReferenceFix_details;
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
# Vadim Geraskin - initial contibution
|
# Vadim Geraskin - initial contibution
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
ConvertFunctionToProcedureFix_description=Convert function "{0}" to procedure
|
||||||
|
ConvertFunctionToProcedureFix_details=Convert function "{0}" to procedure
|
||||||
CommonModuleNamedSelfReferenceFix_details=Remove excessive named self reference in common module
|
CommonModuleNamedSelfReferenceFix_details=Remove excessive named self reference in common module
|
||||||
CommonModuleNamedSelfReferenceFix_description=Remove excessive named self reference
|
CommonModuleNamedSelfReferenceFix_description=Remove excessive named self reference
|
||||||
FormSelfReferenceOutdatedFix_description=Replace outdated self reference
|
FormSelfReferenceOutdatedFix_description=Replace outdated self reference
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
# Vadim Geraskin - initial contibution
|
# Vadim Geraskin - initial contibution
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
ConvertFunctionToProcedureFix_details=Конвертировать функцию "{0}" в процедуру
|
||||||
|
|
||||||
|
ConvertFunctionToProcedureFix_description=Конвертировать функцию "{0}" в процедуру
|
||||||
|
|
||||||
CommonModuleNamedSelfReferenceFix_details=Удалить избыточное обращение внутри общего модуля по имени
|
CommonModuleNamedSelfReferenceFix_details=Удалить избыточное обращение внутри общего модуля по имени
|
||||||
|
|
||||||
CommonModuleNamedSelfReferenceFix_description=Удалить избыточное обращение внутри модуля по имени
|
CommonModuleNamedSelfReferenceFix_description=Удалить избыточное обращение внутри модуля по имени
|
||||||
|
Reference in New Issue
Block a user