mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-03-27 07:41:27 +02:00
Merge pull request #967 from 1C-Company/feature/941-qfix-remove-strict-types
#941 Квик-фикс для удаления аннотации строгой типизации
This commit is contained in:
commit
9b7b2c9fdf
@ -54,6 +54,10 @@
|
||||
|
||||
#### Права ролей
|
||||
|
||||
### Новые быстрые исправления (Quick-fix)
|
||||
|
||||
- Удаление аннотации строгой типизации из модуля
|
||||
|
||||
### Исправленные ошибки
|
||||
|
||||
- Падение NPE в проверке ql-using-for-update, корректный учет зависимых проектов (обработки, расширения)
|
||||
|
@ -14,13 +14,11 @@ Require-Bundle: org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)",
|
||||
org.eclipse.xtext.builder;bundle-version="[2.18.0,3.0.0)",
|
||||
org.eclipse.xtext.ui;bundle-version="[2.24.0,3.0.0)",
|
||||
org.eclipse.handly;bundle-version="[1.5.0,2.0.0)",
|
||||
org.eclipse.xtext.ui.shared;bundle-version="[2.19.0,3.0.0)",
|
||||
org.eclipse.jface.text;bundle-version="[3.17.0,4.0.0)"
|
||||
org.eclipse.xtext.ui.shared;bundle-version="[2.19.0,3.0.0)"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Automatic-Module-Name: com.e1c.v8codestyle.bsl
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[5.0.0,6.0.0)",
|
||||
com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)",
|
||||
Import-Package: com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)",
|
||||
com._1c.g5.v8.dt.bsl;version="[4.4.0,5.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.comment;version="[3.0.0,4.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.common;version="[6.0.0,7.0.0)",
|
||||
@ -35,7 +33,6 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[5.0.0,6.0
|
||||
com._1c.g5.v8.dt.bsl.typesystem;version="[9.0.0,10.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.typesystem.util;version="[9.0.0,10.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.ui;version="[8.2.0,9.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.ui.contentassist;version="[8.0.0,9.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.ui.quickfix;version="[4.1.0,5.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.util;version="[7.0.0,8.0.0)",
|
||||
com._1c.g5.v8.dt.bsl.validation;version="[16.0.0,17.0.0)",
|
||||
|
@ -157,22 +157,34 @@ public final class StrictTypeUtil
|
||||
* @return true, if module has annotation in header
|
||||
*/
|
||||
public static boolean hasStrictTypeAnnotation(INode root)
|
||||
{
|
||||
return getStrictTypeAnnotationNode(root) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Gets the {@link ILeafNode} of the {@code @strict-types} annotation in module description.
|
||||
*
|
||||
* @param root the root, cannot be {@code null}.
|
||||
* @return leaf node, if module has annotation in header, or {@code null} if not found
|
||||
*/
|
||||
public static ILeafNode getStrictTypeAnnotationNode(INode root)
|
||||
{
|
||||
for (ILeafNode node : root.getLeafNodes())
|
||||
{
|
||||
if (!node.isHidden())
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (BslCommentUtils.isCommentNode(node)
|
||||
&& node.getText().substring(COMMENT_LENGTH).trim().startsWith(STRICT_TYPE_ANNOTATION))
|
||||
{
|
||||
return true;
|
||||
return node;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* 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.strict.fix;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
final class Messages
|
||||
extends NLS
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.bsl.strict.fix.messages"; //$NON-NLS-1$
|
||||
public static String RemoveStrictTypesAnnotationFix_Description;
|
||||
public static String RemoveStrictTypesAnnotationFix_Details;
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
/*******************************************************************************
|
||||
* 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.strict.fix;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.text.edits.DeleteEdit;
|
||||
import org.eclipse.text.edits.TextEdit;
|
||||
import org.eclipse.xtext.nodemodel.ICompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.ILeafNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
|
||||
import com.e1c.g5.v8.dt.check.settings.CheckUid;
|
||||
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
|
||||
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
|
||||
import com.e1c.v8codestyle.bsl.strict.StrictTypeUtil;
|
||||
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
|
||||
|
||||
/**
|
||||
* The fix for all strict types checks that allows to remove annotation.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class RemoveStrictTypesAnnotationFix
|
||||
extends SingleVariantXtextBslModuleFix
|
||||
{
|
||||
|
||||
public static Collection<String> getCheckIds()
|
||||
{
|
||||
return Set.of("property-return-type", "doc-comment-field-type-strict", "dynamic-access-method-not-found", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"constructor-function-return-section", "function-return-value-type", "invocation-parameter-type-intersect", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"method-param-value-type", "statement-type-change", "structure-consructor-value-type", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
"variable-value-type"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private final CheckUid checkUid;
|
||||
|
||||
/**
|
||||
* Instantiates a new removes the strict types annotation fix.
|
||||
*
|
||||
* @param checkId the check id, cannot be {@code null}.
|
||||
*/
|
||||
public RemoveStrictTypesAnnotationFix(CheckUid checkId)
|
||||
{
|
||||
this.checkUid = checkId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckUid getCheckId()
|
||||
{
|
||||
return checkUid;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureFix(FixConfigurer configurer)
|
||||
{
|
||||
configurer.description(Messages.RemoveStrictTypesAnnotationFix_Description)
|
||||
.details(Messages.RemoveStrictTypesAnnotationFix_Details);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException
|
||||
{
|
||||
if (model.getElement() != null)
|
||||
{
|
||||
ICompositeNode node = NodeModelUtils.getNode(model.getElement());
|
||||
if (node == null)
|
||||
{
|
||||
IStatus status =
|
||||
BslPlugin.createErrorStatus("RemoveStrictTypesAnnotationFix: cannot get node for module object: " //$NON-NLS-1$
|
||||
+ EcoreUtil.getURI(model.getElement()), null);
|
||||
BslPlugin.log(status);
|
||||
return null;
|
||||
}
|
||||
node = node.getRootNode();
|
||||
ILeafNode annotatioNode = StrictTypeUtil.getStrictTypeAnnotationNode(node);
|
||||
if (annotatioNode != null)
|
||||
{
|
||||
return new DeleteEdit(annotatioNode.getTotalOffset(), annotatioNode.getTotalLength());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
###############################################################################
|
||||
# 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
|
||||
###############################################################################
|
||||
RemoveStrictTypesAnnotationFix_Description=Remove @strict-types annotation from module
|
||||
RemoveStrictTypesAnnotationFix_Details=Comment in module header that contains annotation "// @strict-types" will be removed
|
@ -0,0 +1,5 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
RemoveStrictTypesAnnotationFix_Description = Удалить аннотацию @strict-types из модуля
|
||||
|
||||
RemoveStrictTypesAnnotationFix_Details = Комментарий в заголовке модуля которой содержит аннотацию "// @strict-types" будет удален
|
@ -137,6 +137,7 @@ public class BslPlugin
|
||||
// register services from injector
|
||||
registrator.service(IModuleStructureProvider.class).registerInjected();
|
||||
registrator.managedService(BslCheckFixBoostrap.class).activateBeforeRegistration().registerInjected();
|
||||
registrator.managedService(MultiCheckFixRegistrator.class).activateBeforeRegistration().registerInjected();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* 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.internal.bsl;
|
||||
|
||||
import com._1c.g5.wiring.IManagedService;
|
||||
import com.e1c.g5.v8.dt.check.qfix.IFix;
|
||||
import com.e1c.g5.v8.dt.check.qfix.IFixContext;
|
||||
import com.e1c.g5.v8.dt.check.qfix.IFixRepository;
|
||||
import com.e1c.g5.v8.dt.check.settings.CheckUid;
|
||||
import com.e1c.v8codestyle.bsl.strict.fix.RemoveStrictTypesAnnotationFix;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* The registrar of quick-fix instance that applicable for several checks.
|
||||
* The registering quick-fix should accept {@link CheckUid} as parameter in public constructor.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class MultiCheckFixRegistrator
|
||||
implements IManagedService
|
||||
{
|
||||
|
||||
@Inject
|
||||
private IFixRepository fixRepository;
|
||||
|
||||
/**
|
||||
* Multi-check fix should be added here
|
||||
*/
|
||||
@Override
|
||||
public void activate()
|
||||
{
|
||||
registerRemoveStrictTypesAnnotationFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private void registerRemoveStrictTypesAnnotationFix()
|
||||
{
|
||||
for (String checkId : RemoveStrictTypesAnnotationFix.getCheckIds())
|
||||
{
|
||||
CheckUid id = new CheckUid(checkId, BslPlugin.PLUGIN_ID);
|
||||
|
||||
IFix<? extends IFixContext> instance = new RemoveStrictTypesAnnotationFix(id);
|
||||
fixRepository.registerFix(instance);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user