1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2025-02-07 19:40:08 +02:00

Merge pull request #1064 from 1C-Company/move-to-2022-1

Переход на 2022.1
This commit is contained in:
Dmitriy Marmyshev 2022-07-12 17:30:05 +03:00 committed by GitHub
commit 33668db3a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 28 additions and 1648 deletions

View File

@ -51,5 +51,4 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[5.0.0,6.0
com.e1c.g5.v8.dt.check.qfix.components;version="[1.0.0,2.0.0)",
com.e1c.g5.v8.dt.check.settings;version="[3.0.0,4.0.0)",
com.e1c.v8codestyle.bsl;version="[0.3.0,0.4.0)",
com.e1c.v8codestyle.bsl.qfix.external;version="[0.3.0,0.4.0)",
com.e1c.v8codestyle.bsl.strict;version="[0.3.0,0.4.0)"

View File

@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
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;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**
* Quick fix for check com.e1c.v8codestyle.bsl.check:common-module-named-self-reference

View File

@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
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;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**
* Quick fix for check com.e1c.v8codestyle.bsl.check:form-self-reference-outdated

View File

@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.model.DynamicFeatureAccess;
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;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**
* Quick fix for check com.e1c.v8codestyle.bsl.check:common-module-named-self-reference

View File

@ -24,10 +24,10 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
import com.e1c.g5.v8.dt.check.settings.CheckUid;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
import com.e1c.v8codestyle.internal.bsl.ui.views.BslDocCommentView;

View File

@ -28,8 +28,8 @@ import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
import com._1c.g5.v8.dt.bsl.ui.contentassist.BslProposalProvider;
import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel;
import com.google.common.base.Strings;
/**

View File

@ -21,9 +21,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
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;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**
* Quick fix for check com.e1c.v8codestyle.bsl.check:self-reference

View File

@ -16,10 +16,10 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.xtext.resource.XtextResource;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**

View File

@ -14,9 +14,9 @@ package com.e1c.v8codestyle.bsl.ui.qfix;
import org.eclipse.jface.text.BadLocationException;
import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextInteractiveBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.MultiVariantXtextBslModuleFix;
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.MultiVariantXtextBslModuleFix;
import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin;
/**

View File

@ -28,10 +28,10 @@ import com._1c.g5.v8.dt.bsl.model.Method;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil;
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.IXtextInteractiveBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
import com.e1c.g5.v8.dt.check.qfix.components.QuickFix;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextInteractiveBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
/**
* Quick fix for check com.e1c.v8codestyle.bsl.check:undefined-variable

View File

@ -60,5 +60,4 @@ Import-Package: com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)",
com.e1c.v8codestyle;version="[0.3.0,0.4.0)",
com.e1c.v8codestyle.check;version="[0.3.0,0.4.0)"
Export-Package: com.e1c.v8codestyle.bsl;version="0.3.0",
com.e1c.v8codestyle.bsl.qfix.external;version="0.3.0",
com.e1c.v8codestyle.bsl.strict;version="0.3.0"

View File

@ -26,9 +26,9 @@ import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.XtextResource;
import com._1c.g5.v8.dt.bsl.model.Method;
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;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixModel;
import com.e1c.v8codestyle.bsl.qfix.external.SingleVariantXtextBslModuleFix;
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
/**

View File

@ -1,43 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import com._1c.g5.wiring.IManagedService;
import com.e1c.g5.v8.dt.check.qfix.IFixRepository;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* Java-based registrar of BSL quick fix components
*
* @author Alexander Tretyakevich
*/
@Singleton
public class BslCheckFixBoostrap
implements IManagedService
{
@Inject
private IFixRepository fixRepository;
@Inject
private SingleVariantXtextBslModuleFixContextFactory singleVariantXtextBslModuleFixContextFactory;
@Override
public void activate()
{
fixRepository.registerContextFactory(singleVariantXtextBslModuleFixContextFactory);
}
@Override
public void deactivate()
{
// Not necessary at the moment
}
}

View File

@ -1,109 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.model.edit.IssueModificationContext;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.lcore.ui.editor.ViewerAwareIssueModificationContext;
import com.google.common.base.Preconditions;
/**
* Extension of {@link IssueModificationContext} to be used by quick fixes and suppressions
*
* @author Vadim Geraskin
*/
public class BslIssueModificationContext
extends ViewerAwareIssueModificationContext
{
private final AtomicReference<ITextViewer> viewerRef = new AtomicReference<>();
private final Issue issue;
private final IURIEditorOpener editorOpener;
private IXtextDocument document;
/**
* Instantiates modification context
*
* @param issue the issue, cannot be {@code null}
* @param editorOpener the editor opener, cannot be {@code null}
*/
public BslIssueModificationContext(Issue issue, IURIEditorOpener editorOpener)
{
this.issue = Preconditions.checkNotNull(issue);
this.editorOpener = Preconditions.checkNotNull(editorOpener);
}
@Override
public IXtextDocument getXtextDocument()
{
return getXtextDocument(issue.getUriToProblem());
}
@Override
public IXtextDocument getXtextDocument(URI uri)
{
if (document != null)
{
return document;
}
document = getXtextDocument(uri, editorOpener, editor -> viewerRef.set(extractLocalTextViewer(editor)));
setTextViewer(viewerRef.get());
return document;
}
/*
* Extract text viewer from editor. Can return {@code null}
*/
private static ITextViewer extractLocalTextViewer(IEditorPart editor)
{
ITextOperationTarget target = editor.getAdapter(ITextOperationTarget.class);
if (target instanceof ITextViewer)
{
return (ITextViewer)target;
}
return null;
}
private static IXtextDocument getXtextDocument(URI uri, IURIEditorOpener editorOpener,
Consumer<IEditorPart> editorConsumer)
{
for (int trial = 0; trial < 2; trial++)
{
IEditorPart editor = editorOpener.open(uri, false);
if (editor == null)
{
return null;
}
if (editorConsumer != null)
{
editorConsumer.accept(editor);
}
if (editor instanceof XtextEditor)
{
XtextEditor xtextEditor = (XtextEditor)editor;
return xtextEditor.getDocument();
}
}
return null;
}
}

View File

@ -1,35 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import org.eclipse.xtext.resource.XtextResource;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
/**
* Functional delegate that allows to specify the matching method as a change execution logic for multi-variant
* quick fixes
*
* @author Vadim Geraskin
*/
@FunctionalInterface
public interface IMultiVariantXtextModuleFixChangeDelegate
{
/**
* Performs the fix application
*
* @param context the quick fix context, cannot be {@code null}
* @param session the fix session, cannot be {@code null}
* @param state the xtext resource, cannot be {@code null}
* @param model the quick fix model, cannot be {@code null}
*/
void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session, XtextResource state,
IXtextBslModuleFixModel model);
}

View File

@ -1,30 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
/**
* Functional delegate that allows to specify the matching method as a change execution logic for multi-variant
* quick fixes
*
* @author Vadim Geraskin
*/
@FunctionalInterface
public interface ISingleVariantXtextModuleFixChangeDelegate
{
/**
* Perfoms apply of the fix
*
* @param context the quick fix context, cannot be {@code null}
* @param session the session, cannot be {@code null}
*/
void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session);
}

View File

@ -1,83 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.IDocument;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
/**
* Contract for xtext BSL quick fix model
*
* @author Vadim Geraskin
*/
public interface IXtextBslModuleFixModel
{
/**
* Provides {@link IDocument}
*
* @return {@link IDocument}, never {@code null}
*/
IDocument getDocument();
/**
* Provides module {@link IResourceLookup}
*
* @return {link IResourceLookup}, never {@code null}
*/
IResourceLookup getResourceLookup();
/**
* Provides the element which is used to create a quick fix
*
* @return the element, can be {@code null}
*/
EObject getElement();
/**
* xtext validation issue reference
*
* @return {@link Issue}, never {@code null}
*/
Issue getIssue();
/**
* The associated user data. May be {@code null} or empty but may not contain {@code null} entries.
*
* @return user data, can be {@code null}
*/
String[] getIssueData();
/**
* Provides {@link BslGrammarAccess}
*
* @return {@link BslGrammarAccess}, never {@code null}
*/
BslGrammarAccess getBslGrammar();
/**
* Returns {@code ScriptVariant} for current project
*
* @return {@code ScriptVariant}, never {@code null}
*/
ScriptVariant getScriptVariant();
/**
* Gets line separator preference set for current project. If the preference is not set for the project then
* the canonical lookup order is used (instance, configuration, default).
*
* @return the line separator preference. Never {@code null}.
*/
String getLineSeparator();
}

View File

@ -1,37 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
/**
* Contract for {@link XtextBslModuleFixProvider}
*
* @author Vadim Geraskin
*/
public interface IXtextBslModuleFixProvider
{
/**
* Returns xtext quick fix model
*
* @param dtProject the {@IDtProject}, cannot be {@code null}
* @param issue instance of the {@link Issue}, cannot be {@code null}
* @param session the {@code IFixSession}, cannot be {@code null}
* @param targetModuleUri the target module Uri, cannot be {@code null}
* @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise
* @return the quick fix model, never {@code null}
*/
IXtextBslModuleFixModel getXtextFixModel(IDtProject dtProject, Issue issue, IFixSession session,
URI targetModuleUri, boolean isInteractive);
}

View File

@ -1,92 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.link.LinkedModeModel;
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals;
import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider;
/**
* Contract for xtext BSL interactive quick fix model
*
* @author Vadim Geraskin
*/
public interface IXtextInteractiveBslModuleFixModel
extends IXtextBslModuleFixModel
{
/**
* Provides {@link IndentTextEditorProvider}
*
* @return {@link IndentTextEditorProvider}, never {@code null}
*/
IndentTextEditorProvider getIndentProvider();
/**
* Multilanguage proposals for quick-fix and content-assist for Bsl
*
* @return reference to {@link BslGeneratorMultiLangProposals}, never {@code null}
*/
BslGeneratorMultiLangProposals getBslGeneratorMultiLangProposals();
/**
* Provides modification context
*
* @return {@link IModificationContext}, never {@code null}
*/
IModificationContext getModificationContext();
/**
* Provides the format string for the given {@code EObject} which is the semantic object whose node should
* be provided {@code NodeModelUtils.findActualNodeFor()}
*
* @param eObject the object, cannot be {@code null}
* @return format string, never {@code null}
* @throws BadLocationException
*/
Optional<String> getFormatString(EObject eObject) throws BadLocationException;
/**
* Provides {@code LinkedModeModel}
*
* @return {@code LinkedModeModel}, never {@code null}
*/
LinkedModeModel getLinkedModeModel();
/**
* Returns a description of the line at the given offset.The description contains the offset and the length of the
* line excluding the line's delimiter.
*
* @param offset the offset whose line should be described
* @return a region describing the line, never {@code null}
* @throws BadLocationException
*/
IRegion getLineInformationOfOffset(int offset) throws BadLocationException;
/**
* Connects the ui mode for linked mode and starts UI on the first position
* Should be called write after installation of linkedModeModel: {@code linkedModeModel.forceInstall()}
*/
void enterUiMode();
/**
* Sets the selected range and reveals it
*
* @param posStart the start position
* @param length the length of selection
*/
void selectAndRevealForLinkedModeModel(int posStart, int length);
}

View File

@ -1,257 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import com.e1c.g5.v8.dt.check.qfix.FixDescriptor;
import com.e1c.g5.v8.dt.check.qfix.FixVariantDescriptor;
import com.e1c.g5.v8.dt.check.qfix.IFix;
import com.e1c.g5.v8.dt.check.qfix.IFixChange;
import com.e1c.g5.v8.dt.check.qfix.IFixChangeProcessor;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.e1c.g5.v8.dt.check.qfix.IFixVariant;
import com.e1c.g5.v8.dt.check.qfix.components.BasicFix;
/**
* Multi-variant xtext module fix definition
*
* @author Alexander Tretyakevich - Initial contribution
* @author Vadim Geraskin - Additional features
*/
public abstract class MultiVariantXtextBslModuleFix
extends BasicFix<SingleVariantXtextBslModuleFixContext>
implements IFix<SingleVariantXtextBslModuleFixContext>
{
private Collection<IFixVariant<SingleVariantXtextBslModuleFixContext>> fixVariants = new HashSet<>();
@Override
public Class<SingleVariantXtextBslModuleFixContext> getRequiredContextType()
{
return SingleVariantXtextBslModuleFixContext.class;
}
@Override
public Collection<IFixVariant<SingleVariantXtextBslModuleFixContext>> getVariants(
SingleVariantXtextBslModuleFixContext context, IFixSession session)
{
return fixVariants;
}
@Override
public void onRegistration(FixDescriptor registrationContext)
{
VariantXtextBslModuleFixChangeProcessor changeProcessor = new VariantXtextBslModuleFixChangeProcessor();
registrationContext.setChangeProcessor(changeProcessor);
buildVariants();
}
/**
* Creates and sets up fix variants
*/
protected abstract void buildVariants();
/**
* Provides a builder of the quick fix variant
*
* @author Vadim Geraskin
*/
protected static class VariantBuilder
{
private final MultiVariantXtextBslModuleFix fix;
private IMultiVariantXtextModuleFixChangeDelegate delegate;
private String description;
private String details;
private boolean isInteractive;
/**
* Creates variant builder instance
*
* @param fix the reference to the model fix, cannot be {@code null}
*/
public VariantBuilder(MultiVariantXtextBslModuleFix fix)
{
this.fix = fix;
}
/**
* Static variant builder creator
*
* @param fix the reference to the model fix, cannot be {@code null}
* @return the instance of the variant builder, never {@code null}
*/
public static VariantBuilder create(MultiVariantXtextBslModuleFix fix)
{
return new VariantBuilder(fix);
}
/**
* Creates code change delegate
*
* @param delegate change delegate, cannot be {@code null}
* @return the instance of the variant builder, never {@code null}
*/
public VariantBuilder change(IMultiVariantXtextModuleFixChangeDelegate delegate)
{
this.delegate = delegate;
return this;
}
/**
* Sets the modification model type - either interactive (UI) or not
*
* @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise
* @return the instance of the variant builder, never {@code null}
*/
public VariantBuilder interactive(boolean isInteractive)
{
this.isInteractive = isInteractive;
return this;
}
/**
* Creates variant description and details messages
*
* @param description the short description, cannot be {@code null}
* @param details the detailed message, can be {@code null}
* @return the instance of the variant builder, never {@code null}
*/
public VariantBuilder description(String description, String details)
{
this.description = description;
this.details = details;
return this;
}
/**
* Finalizes the variant builder, registers the variant
*/
public void build()
{
IFixVariant<SingleVariantXtextBslModuleFixContext> variant =
new MultiVariantXtextBslModuleVariant<>(delegate, description, details, isInteractive);
fix.fixVariants.add(variant);
}
}
private static class MultiVariantXtextBslModuleVariant<C extends SingleVariantXtextBslModuleFixContext>
implements IFixVariant<C>
{
private final IMultiVariantXtextModuleFixChangeDelegate delegate;
private final String description;
private final String details;
private final boolean isInteractive;
/**
* Creates {@link MultiVariantXtextBslModuleVariant} instance
*
* @param delegate the delegate to be executed, cannot be {@code null}
* @param description the fix variant short description, cannot be {@code null}
* @param details the fix variant detailed description, can be {@code null}
* @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise
*/
MultiVariantXtextBslModuleVariant(IMultiVariantXtextModuleFixChangeDelegate delegate, String description,
String details, boolean isInteractive)
{
this.delegate = delegate;
this.description = description;
this.details = details;
this.isInteractive = true;
}
@Override
public Collection<IFixChange> prepareChanges(C context, IFixSession session)
{
if (context.getTargetModuleUri() == null)
{
return Collections.emptyList();
}
return Collections.singleton(new VariantXtextBslModuleFixChange(delegate, isInteractive));
}
@Override
public FixVariantDescriptor describeChanges(C context, IFixSession session)
{
return new FixVariantDescriptor(description, details);
}
}
private static final class VariantXtextBslModuleFixChange
implements IFixChange
{
private final IMultiVariantXtextModuleFixChangeDelegate delegate;
private final boolean isInteractive;
/**
* Creates {@link VariantXtextBslModuleFixChange} instance
*
* @param delegate the delegate to be executed, cannot be {@code null}
* @param isInteractive {@code true} if quick fix supports interactive (UI) model, {@code false} otherwise
*/
VariantXtextBslModuleFixChange(IMultiVariantXtextModuleFixChangeDelegate delegate, boolean isInteractive)
{
this.delegate = delegate;
this.isInteractive = isInteractive;
}
/**
* Executes the quick fix resolution code
*
* @param context the quick fix context, cannot be {@code null}
* @param session the quick fix session, cannot be {@code null}
*/
public void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session)
{
IXtextBslModuleFixModel fixModel = context.getModel(session, isInteractive);
if (fixModel instanceof IXtextInteractiveBslModuleFixModel)
{
((IXtextDocument)fixModel.getDocument()).readOnly(new IUnitOfWork.Void<XtextResource>()
{
@Override
public void process(XtextResource state) throws Exception
{
delegate.applyFix(context, session, state, fixModel);
}
});
}
else
{
// Nothing at the moment
}
}
}
/*
* Variant fix change processor
*/
private static final class VariantXtextBslModuleFixChangeProcessor
implements IFixChangeProcessor<VariantXtextBslModuleFixChange, SingleVariantXtextBslModuleFixContext>
{
@Override
public void applyFix(VariantXtextBslModuleFixChange fixChange, SingleVariantXtextBslModuleFixContext context,
IFixSession session)
{
fixChange.applyFix(context, session);
}
@Override
public Class<VariantXtextBslModuleFixChange> getProcessedFixType()
{
return VariantXtextBslModuleFixChange.class;
}
}
}

View File

@ -1,287 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.Collection;
import java.util.Collections;
import java.util.function.BiFunction;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.eclipse.xtext.validation.Issue;
import org.eclipse.xtext.validation.Issue.IssueImpl;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.common.Pair;
import com._1c.g5.v8.dt.common.StringUtils;
import com.e1c.g5.v8.dt.bsl.check.qfix.ExternalQuickfixModification;
import com.e1c.g5.v8.dt.check.qfix.FixDescriptor;
import com.e1c.g5.v8.dt.check.qfix.FixVariantDescriptor;
import com.e1c.g5.v8.dt.check.qfix.IFixChange;
import com.e1c.g5.v8.dt.check.qfix.IFixChangeProcessor;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.e1c.g5.v8.dt.check.qfix.components.SingleVariantBasicFix;
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
/**
* Single variant xtext bsl module fix common class for multi-variant quick fixes
*
* @author Vadim Geraskin
*/
public abstract class SingleVariantXtextBslModuleFix
extends SingleVariantBasicFix<SingleVariantXtextBslModuleFixContext>
{
private BiFunction<SingleVariantXtextBslModuleFixContext, IFixSession, Pair<String, String>> descriptionSupplier;
private boolean isInteractive;
@Override
public Collection<IFixChange> prepareChanges(SingleVariantXtextBslModuleFixContext context, IFixSession session)
{
Module module = session.getModule(context.getTargetModuleUri());
if (module == null)
{
return Collections.emptyList();
}
return prepareChanges(this::applyChanges);
}
@Override
public final FixVariantDescriptor describeChanges(SingleVariantXtextBslModuleFixContext context,
IFixSession session)
{
Pair<String, String> description = descriptionSupplier.apply(context, session);
return new FixVariantDescriptor(description.first, description.second);
}
@Override
public final void onRegistration(FixDescriptor registrationContext)
{
registrationContext.setChangeProcessor(new SingleVariantModuleFixChangeProcessor());
FixConfigurer configurer = new FixConfigurer();
configureFix(configurer);
applyConfiguration(configurer);
}
@Override
public Class<SingleVariantXtextBslModuleFixContext> getRequiredContextType()
{
return SingleVariantXtextBslModuleFixContext.class;
}
/**
* Configures the fix. The developer could provide descreptive/filtering information for the fix here
*
* @param configurer The configurer of the fix. May not be {@code null}
*/
protected void configureFix(FixConfigurer configurer)
{
// Nothing by default
}
/**
* Modification of code to be overriden by clients
*
* @param state the xtext resource, cannot be {@code null}
* @param model xtext bsl module fix model facade, cannot be {@code null}
* @return {@link TextEdit}, can be {@code null}
* @throws BadLocationException
*/
protected abstract TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model)
throws BadLocationException;
protected void applyChanges(SingleVariantXtextBslModuleFixContext context, IFixSession session)
{
IssueImpl issue = context.getIssue();
IXtextBslModuleFixModel fixModel = context.getModel(session, isInteractive);
if (fixModel instanceof IXtextInteractiveBslModuleFixModel)
{
IModificationContext modificationContext =
((XtextInteractiveBslModuleFixModel)fixModel).getModificationContext();
IXtextDocument document = (IXtextDocument)fixModel.getDocument();
XtextResource xtextResource = document.readOnly(new IUnitOfWork<XtextResource, XtextResource>()
{
@Override
public XtextResource exec(XtextResource state) throws Exception
{
return state;
}
});
ExternalQuickfixModification<EObject> quickFixModification = new ExternalQuickfixModification<>(issue,
EObject.class, element -> fixIssue((IXtextInteractiveBslModuleFixModel)fixModel, xtextResource));
try
{
quickFixModification.apply(modificationContext);
}
catch (Exception e)
{
BslPlugin.log(BslPlugin.createErrorStatus("Error occured when applying quick fix", e)); //$NON-NLS-1$
}
}
else
{
// Nothing at the moment
}
}
private TextEdit fixIssue(IXtextInteractiveBslModuleFixModel fixModel, XtextResource xtextResource)
{
Issue issue = fixModel.getIssue();
if (issue.getOffset() == null)
{
return null;
}
try
{
return fixIssue(xtextResource, fixModel);
}
catch (Exception e)
{
BslPlugin.log(BslPlugin.createErrorStatus("Error occured when applying quick fix", e)); //$NON-NLS-1$
}
return null;
}
private Collection<IFixChange> prepareChanges(ISingleVariantXtextModuleFixChangeDelegate changeDelegate)
{
return Collections.singleton(new SingleVariantModuleFixChange(changeDelegate));
}
/*
* Applies configuration provided by the fix developer
*/
private void applyConfiguration(FixConfigurer configurer)
{
this.descriptionSupplier = configurer.descriptionSupplier;
if (this.descriptionSupplier == null)
{
// Description isn't specified - adding the safety loopback
this.descriptionSupplier = (context, session) -> Pair.newPair(StringUtils.EMPTY, StringUtils.EMPTY);
}
this.isInteractive = configurer.isInteractive;
}
/*
* Single variant fix change unique for the SingleVariantModelBasicFix
*/
private static final class SingleVariantModuleFixChange
implements IFixChange
{
private final ISingleVariantXtextModuleFixChangeDelegate delegate;
SingleVariantModuleFixChange(ISingleVariantXtextModuleFixChangeDelegate delegate)
{
this.delegate = delegate;
}
public void applyFix(SingleVariantXtextBslModuleFixContext context, IFixSession session)
{
delegate.applyFix(context, session);
}
}
/*
* Single variant fix change processor unique for the SingleVariantModelBasicFix
*/
private static final class SingleVariantModuleFixChangeProcessor
implements IFixChangeProcessor<SingleVariantModuleFixChange, SingleVariantXtextBslModuleFixContext>
{
@Override
public void applyFix(SingleVariantModuleFixChange fixChange, SingleVariantXtextBslModuleFixContext context,
IFixSession session)
{
fixChange.applyFix(context, session);
}
@Override
public Class<SingleVariantModuleFixChange> getProcessedFixType()
{
return SingleVariantModuleFixChange.class;
}
}
/**
* Configuration container for the {@link SingleVariantXtextBslModuleFixContext} descendants allowing them to
* specify fix parameters via the pure Java API
*
* @author Alexander Tretyakevich
*/
protected static final class FixConfigurer
{
private BiFunction<SingleVariantXtextBslModuleFixContext, IFixSession, Pair<String, String>> descriptionSupplier; //CHECKSTYLE.OFF: LineLength
private boolean isInteractive = true;
private String description = StringUtils.EMPTY;
private String details = StringUtils.EMPTY;
/**
* Sets the dynamic description supplier for the fix. The description may be formed using the data from
* the {@link SingleVariantXtextBslModuleFixContext}
*
* @param descriptionSupplier The supplier to set. May not be {@code null}
* @return the instance of the fix configurer, never {@code null}
*/
public FixConfigurer description(
BiFunction<SingleVariantXtextBslModuleFixContext, IFixSession, Pair<String, String>> descriptionSupplier)
{
this.descriptionSupplier = descriptionSupplier;
return this;
}
/**
* Sets the static description for the fix
*
* @param description The description to set. May not be {@code null}
* @return the instance of the fix configurer, never {@code null}
*/
public FixConfigurer description(String description)
{
this.description = description;
descriptionSupplier = (context, session) -> Pair.newPair(description, details);
return this;
}
/**
* Sets the static details for the fix
*
* @param description The description to set. May not be {@code null}
* @return the instance of the fix configurer, never {@code null}
*/
public FixConfigurer details(String details)
{
this.details = details;
descriptionSupplier = (context, session) -> Pair.newPair(description, details);
return this;
}
/**
* Sets the modification model type - either interactive (UI) or not
*
* @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise
* @return the instance of the fix configurer, never {@code null}
*/
public FixConfigurer interactive(boolean isInteractive)
{
this.isInteractive = isInteractive;
return this;
}
}
}

View File

@ -1,79 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.validation.Issue.IssueImpl;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.e1c.g5.v8.dt.check.qfix.components.BasicFixContext;
/**
* Single-variant xtext module quick fix context
*
* @author Vadim Geraskin
*/
public class SingleVariantXtextBslModuleFixContext
extends BasicFixContext
{
private final URI targetModuleUri;
private final IssueImpl issue;
private final IXtextBslModuleFixProvider provider;
/**
* Creates quick fix context
*
* @param targetModuleUri the module {@code URI}, cannot be {@code null}
* @param issue the {@code IssueImpl} instance, cannot be {@code null}
* @param provider the {@code IXtextBslModuleFixProvider} instance, cannot be {@code null}
* @param dtProject the DT project, cannot be {@code null}
*/
public SingleVariantXtextBslModuleFixContext(URI targetModuleUri, IssueImpl issue,
IXtextBslModuleFixProvider provider, IDtProject dtProject)
{
super(dtProject);
this.targetModuleUri = targetModuleUri;
this.issue = issue;
this.provider = provider;
}
/**
* Provides the target module URI
*
* @return the targetModuleUri, never {@code null}
*/
public URI getTargetModuleUri()
{
return targetModuleUri;
}
/**
* Provides the {@code IssueImpl} for quick fix
*
* @return xtext issue, never {@code null}
*/
public IssueImpl getIssue()
{
return issue;
}
/**
* Provides the model {@code IXtextBslModuleFixModel} for quick fix
*
* @param session {@link IFixSession}, cannot be {@code null}
* @param isInteractive {@code true} if quick fix supports inbteractive (UI) model, {@code false} otherwise
* @return model {@code IXtextBslModuleFixModel}, never {@code null}
*/
public IXtextBslModuleFixModel getModel(IFixSession session, boolean isInteractive)
{
return provider.getXtextFixModel(getDtProject(), issue, session, targetModuleUri, isInteractive);
}
}

View File

@ -1,54 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.validation.CheckType;
import org.eclipse.xtext.validation.Issue.IssueImpl;
import com._1c.g5.v8.dt.bsl.validation.BslValidationUtil;
import com._1c.g5.v8.dt.validation.marker.IMarkerWrapper;
import com._1c.g5.v8.dt.validation.marker.PlainEObjectMarker;
import com.e1c.g5.v8.dt.check.qfix.IFixContextFactory;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* Context factory for {@link SingleVariantXtextBslModuleFixContext}
*
* @author Vadim Geraskin
*/
@Singleton
public class SingleVariantXtextBslModuleFixContextFactory
implements IFixContextFactory<SingleVariantXtextBslModuleFixContext>
{
@Inject
private IXtextBslModuleFixProvider provider;
@Override
public final SingleVariantXtextBslModuleFixContext createContext(IMarkerWrapper marker, IFixSession session)
{
if (marker.getMarker() instanceof PlainEObjectMarker)
{
PlainEObjectMarker plainObjectMarker = (PlainEObjectMarker)marker.getMarker();
URI uri = plainObjectMarker.getURI();
IssueImpl issue = BslValidationUtil.createIssue(plainObjectMarker, CheckType.EXPENSIVE);
return new SingleVariantXtextBslModuleFixContext(uri, issue, provider, session.getDtProject());
}
return null;
}
@Override
public final Class<SingleVariantXtextBslModuleFixContext> getProvidedContextType()
{
return SingleVariantXtextBslModuleFixContext.class;
}
}

View File

@ -1,158 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
import com._1c.g5.v8.dt.common.PreferenceUtils;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8Project;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com.e1c.v8codestyle.internal.bsl.BslPlugin;
import com.google.common.base.Preconditions;
/**
* The xtext module quick fix model
*
* @author Vadim Geraskin
*/
public class XtextBslModuleFixModel
implements IXtextBslModuleFixModel
{
protected final IV8Project v8project;
private final Supplier<Module> moduleSupp;
private final BslGrammarAccess bslGrammar;
private final IResourceLookup resourceLookup;
private final Issue issue;
private IDocument document;
/**
* Creates module quick fix model
*
* @param moduleSupp supplier for {@link Module}, cannot be {@code null}
* @param v8projectManager V8 project manager, cannot be {@code null}
* @param bslGrammar BSL grammar, cannot be {@code null}
* @param resourceLookup resource lookup service, cannot be {@code null}
* @param issue issue, cannot be {@code null}
* @param dtProject {@code IDtProject}, cannot be {@code null}
*/
public XtextBslModuleFixModel(Supplier<Module> moduleSupp, IV8ProjectManager v8projectManager,
BslGrammarAccess bslGrammar, IResourceLookup resourceLookup, Issue issue, IDtProject dtProject)
{
this.moduleSupp = Preconditions.checkNotNull(moduleSupp);
this.bslGrammar = Preconditions.checkNotNull(bslGrammar);
this.resourceLookup = Preconditions.checkNotNull(resourceLookup);
this.issue = Preconditions.checkNotNull(issue);
this.v8project = v8projectManager.getProject(dtProject);
}
@Override
public IDocument getDocument()
{
if (document == null)
{
Module module = moduleSupp.get();
if (module != null)
{
URI uri = EcoreUtil.getURI(module).trimFragment();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(URIConverter.INSTANCE.createInputStream(uri), StandardCharsets.UTF_8)))
{
Stream<String> lines = reader.lines();
String content = lines.collect(Collectors.joining(System.lineSeparator()));
document = new Document(content);
}
catch (IOException e)
{
BslPlugin.log(BslPlugin.createErrorStatus("Unable to read bsl module file", e)); //$NON-NLS-1$
}
}
}
return document;
}
@Override
public IResourceLookup getResourceLookup()
{
return resourceLookup;
}
@Override
public EObject getElement()
{
URI uriToProblem = issue.getUriToProblem();
String fragment = uriToProblem != null ? uriToProblem.fragment() : null;
if (fragment != null)
{
Module module = moduleSupp.get();
return module != null ? module.eResource().getEObject(fragment) : null;
}
return null;
}
@Override
public Issue getIssue()
{
return issue;
}
@Override
public String[] getIssueData()
{
return issue.getData();
}
@Override
public BslGrammarAccess getBslGrammar()
{
return bslGrammar;
}
@Override
public ScriptVariant getScriptVariant()
{
return getScriptVariant(v8project);
}
@Override
public String getLineSeparator()
{
return PreferenceUtils.getLineSeparator(v8project.getProject());
}
protected static ScriptVariant getScriptVariant(IV8Project v8project)
{
if (v8project != null)
{
return v8project.getScriptVariant();
}
return Locale.getDefault().getLanguage().equals(new Locale("ru").getLanguage()) ? ScriptVariant.RUSSIAN //$NON-NLS-1$
: ScriptVariant.ENGLISH;
}
}

View File

@ -1,79 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.function.Supplier;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider;
import com.e1c.g5.v8.dt.check.qfix.IFixSession;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Singleton;
/**
* Xtext BSl module quick fix provider
*
* @author Vadim Geraskin
*/
@Singleton
public class XtextBslModuleFixProvider
implements IXtextBslModuleFixProvider
{
private final IV8ProjectManager v8projectManager;
private final BslGrammarAccess bslGrammar;
private final IResourceLookup resourceLookup;
private final IndentTextEditorProvider indentProvider;
private final BslGeneratorMultiLangProposals bslGenProp;
private final IURIEditorOpener editorOpener;
@Inject
/**
* @param v8projectManager V8 project manager, cannot be {@code null}
* @param bslGrammar BSl grammar, cannot be {@code null}
* @param resourceLookup resource lookup, cannot be {@code null}
* @param indentProvider indent provider, cannot be {@code null}
* @param bslGenProp BSL multi-language proposals generator, cannot be {@code null}
* @param editorOpener editor opener, cannot be {@code null}
*/
public XtextBslModuleFixProvider(IV8ProjectManager v8projectManager, BslGrammarAccess bslGrammar,
IResourceLookup resourceLookup, IndentTextEditorProvider indentProvider,
BslGeneratorMultiLangProposals bslGenProp, IURIEditorOpener editorOpener)
{
this.v8projectManager = Preconditions.checkNotNull(v8projectManager);
this.bslGrammar = Preconditions.checkNotNull(bslGrammar);
this.resourceLookup = Preconditions.checkNotNull(resourceLookup);
this.indentProvider = Preconditions.checkNotNull(indentProvider);
this.bslGenProp = Preconditions.checkNotNull(bslGenProp);
this.editorOpener = Preconditions.checkNotNull(editorOpener);
}
@Override
public IXtextBslModuleFixModel getXtextFixModel(IDtProject dtProject, Issue issue, IFixSession session,
URI targetModuleUri, boolean isInteractive)
{
Supplier<Module> moduleSupp = () -> session.getModule(targetModuleUri);
if (isInteractive)
{
return new XtextInteractiveBslModuleFixModel(moduleSupp, v8projectManager, bslGrammar, resourceLookup,
indentProvider, bslGenProp, issue, dtProject, editorOpener);
}
return new XtextBslModuleFixModel(moduleSupp, v8projectManager, bslGrammar, resourceLookup, issue, dtProject);
}
}

View File

@ -1,186 +0,0 @@
/*******************************************************************************
* 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
*******************************************************************************/
package com.e1c.v8codestyle.bsl.qfix.external;
import java.util.Optional;
import java.util.function.Supplier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.link.LinkedModeModel;
import org.eclipse.jface.text.link.LinkedModeUI;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
import org.eclipse.xtext.validation.Issue;
import com._1c.g5.v8.dt.bsl.model.Module;
import com._1c.g5.v8.dt.bsl.services.BslGrammarAccess;
import com._1c.g5.v8.dt.bsl.ui.BslGeneratorMultiLangProposals;
import com._1c.g5.v8.dt.bsl.ui.quickfix.BslQuickFixUtil;
import com._1c.g5.v8.dt.common.PreferenceUtils;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com.google.common.base.Preconditions;
/**
* The xtext module quick fix model
*
* @author Vadim Geraskin
*/
public class XtextInteractiveBslModuleFixModel
extends XtextBslModuleFixModel
implements IXtextInteractiveBslModuleFixModel
{
private final IndentTextEditorProvider indentProvider;
private final BslGeneratorMultiLangProposals bslGenProp;
private final IModificationContext modificationContext;
private final IXtextDocument document;
private final LinkedModeModel linkedModeModel;
/**
/**
* Creates module quick fix model
*
* @param moduleSupp supplier for {@link Module}, cannot be {@code null}
* @param v8projectManager V8 project manager, cannot be {@code null}
* @param bslGrammar BSL grammar, cannot be {@code null}
* @param resourceLookup resource lookup service, cannot be {@code null}
* @param indentProvider indent provider, cannot be {@code null}
* @param bslGenProp Multi-lang BSL proposals generator, cannot be {@code null}
* @param issue issue, cannot be {@code null}
* @param dtProject {@code IDtProject}, cannot be {@code null}
* @param editorOpener {@code IURIEditorOpener}, cannot be {@code null}
*/
public XtextInteractiveBslModuleFixModel(Supplier<Module> moduleSupp, IV8ProjectManager v8projectManager,
BslGrammarAccess bslGrammar, IResourceLookup resourceLookup, IndentTextEditorProvider indentProvider,
BslGeneratorMultiLangProposals bslGenProp, Issue issue, IDtProject dtProject, IURIEditorOpener editorOpener)
{
super(moduleSupp, v8projectManager, bslGrammar, resourceLookup, issue, dtProject);
this.indentProvider = Preconditions.checkNotNull(indentProvider);
this.bslGenProp = Preconditions.checkNotNull(bslGenProp);
this.modificationContext = new BslIssueModificationContext(issue, Preconditions.checkNotNull(editorOpener));
this.document = modificationContext.getXtextDocument(issue.getUriToProblem());
linkedModeModel = new LinkedModeModel();
boolean isRussian = getScriptVariant(v8project) == ScriptVariant.RUSSIAN;
bslGenProp.setRussianLang(isRussian);
}
@Override
public IXtextDocument getDocument()
{
return document;
}
@Override
public IndentTextEditorProvider getIndentProvider()
{
return indentProvider;
}
@Override
public BslGeneratorMultiLangProposals getBslGeneratorMultiLangProposals()
{
return bslGenProp;
}
@Override
public IModificationContext getModificationContext()
{
return modificationContext;
}
@Override
public IRegion getLineInformationOfOffset(int offset) throws BadLocationException
{
return document.getLineInformationOfOffset(offset);
}
@Override
public String getLineSeparator()
{
return PreferenceUtils.getLineSeparator(getResourceLookup().getProject(document.getResourceURI()));
}
@Override
public Optional<String> getFormatString(EObject eObject) throws BadLocationException
{
INode node = NodeModelUtils.findActualNodeFor(eObject);
if (node == null)
{
return Optional.empty();
}
IRegion lineInformation = getLineInformationOfOffset(node.getOffset());
String indent = computeFormatLine(document, lineInformation).toString();
return Optional.ofNullable(indent);
}
@Override
public LinkedModeModel getLinkedModeModel()
{
return linkedModeModel;
}
@Override
public void enterUiMode()
{
LinkedModeUI ui = new LinkedModeUI(linkedModeModel, BslQuickFixUtil.getTextViewer(modificationContext));
ui.enter();
}
@Override
public void selectAndRevealForLinkedModeModel(int posStart, int length)
{
selectAndRevealForLinkedModeModel(BslQuickFixUtil.getTextViewer(modificationContext), posStart, length);
}
private static StringBuilder computeFormatLine(IDocument doc, IRegion lineInformation) throws BadLocationException
{
String lineContent = doc.get(lineInformation.getOffset(), lineInformation.getLength());
StringBuilder builder = new StringBuilder();
for (int i = 0; i < lineContent.length(); ++i)
{
if (Character.isWhitespace(lineContent.charAt(i)))
{
builder.append(lineContent.charAt(i));
}
else
{
break;
}
}
return builder;
}
private static void selectAndRevealForLinkedModeModel(ITextViewer viewer, int posStart, int length)
{
viewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener()
{
@Override
public void selectionChanged(SelectionChangedEvent event)
{
viewer.getSelectionProvider().removeSelectionChangedListener(this);
viewer.revealRange(posStart, length);
viewer.setSelectedRange(posStart, length);
}
});
}
}

View File

@ -30,7 +30,6 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.naming.IQualifiedNameConverter;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.scoping.IScope;
@ -38,21 +37,13 @@ import org.eclipse.xtext.scoping.IScopeProvider;
import com._1c.g5.v8.dt.bsl.common.IBslPreferences;
import com._1c.g5.v8.dt.bsl.documentation.comment.BslMultiLineCommentDocumentationProvider;
import com._1c.g5.v8.dt.bsl.model.BslPackage;
import com._1c.g5.v8.dt.bsl.model.DynamicFeatureAccess;
import com._1c.g5.v8.dt.bsl.model.ExplicitVariable;
import com._1c.g5.v8.dt.bsl.model.FeatureAccess;
import com._1c.g5.v8.dt.bsl.model.ForEachStatement;
import com._1c.g5.v8.dt.bsl.model.ForToStatement;
import com._1c.g5.v8.dt.bsl.model.FormalParam;
import com._1c.g5.v8.dt.bsl.model.Invocation;
import com._1c.g5.v8.dt.bsl.model.SimpleStatement;
import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess;
import com._1c.g5.v8.dt.bsl.model.Variable;
import com._1c.g5.v8.dt.bsl.model.typesytem.TypeSystemMode;
import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTreeTypeState;
import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTreeTypeStateWithSubStates;
import com._1c.g5.v8.dt.bsl.model.typesytem.VariableTypeState;
import com._1c.g5.v8.dt.bsl.resource.DynamicFeatureAccessComputer;
import com._1c.g5.v8.dt.bsl.resource.TypesComputer;
import com._1c.g5.v8.dt.bsl.typesystem.util.TypeSystemUtil;
@ -179,11 +170,12 @@ public abstract class AbstractTypeCheck
{
if (object instanceof Variable && object.eContainer() instanceof FeatureAccess)
{
return getActualTypesForFeatureVariable((Variable)object, object.eContainer(), envs);
return TypeSystemUtil.getVariableTypesAfterModelObject((Variable)object, object.eContainer());
}
else if (object instanceof StaticFeatureAccess && ((StaticFeatureAccess)object).getImplicitVariable() != null)
{
return getActualTypesForFeatureVariable(((StaticFeatureAccess)object).getImplicitVariable(), object, envs);
return TypeSystemUtil.getVariableTypesAfterModelObject(((StaticFeatureAccess)object).getImplicitVariable(),
object);
}
List<TypeItem> types = typeComputer.computeTypes(object, envs);
@ -389,71 +381,4 @@ public abstract class AbstractTypeCheck
}
}
// TODO replace this with utility com._1c.g5.v8.dt.bsl.typesystem.util.TypeSystemUtil after 2022.1
private List<TypeItem> getActualTypesForFeatureVariable(Variable variable, EObject featureObject, Environments envs)
{
SimpleStatement statement = EcoreUtil2.getContainerOfType(featureObject, SimpleStatement.class);
Invocation inv = EcoreUtil2.getContainerOfType(featureObject, Invocation.class);
List<TypeItem> allTypes = null;
int actualOffset = -1;
if (statement != null && statement.getRight() != null && statement.getLeft() == featureObject)
{
actualOffset = NodeModelUtils.findActualNodeFor(statement).getTotalEndOffset();
}
else if (inv != null && inv.getParams().contains(featureObject))
{
actualOffset = NodeModelUtils.findActualNodeFor(featureObject).getTotalEndOffset();
}
else if (inv == null && statement == null && variable instanceof FormalParam)
{
actualOffset = NodeModelUtils.findActualNodeFor(featureObject).getTotalEndOffset();
}
else if (featureObject.eContainingFeature() == BslPackage.Literals.FOR_STATEMENT__VARIABLE_ACCESS)
{
if (featureObject.eContainer() instanceof ForEachStatement
&& ((ForEachStatement)featureObject.eContainer()).getCollection() != null)
{
actualOffset =
NodeModelUtils.findActualNodeFor(((ForEachStatement)featureObject.eContainer()).getCollection())
.getTotalEndOffset() + 1;
}
else if (featureObject.eContainer() instanceof ForToStatement
&& ((ForToStatement)featureObject.eContainer()).getInitializer() != null)
{
actualOffset =
NodeModelUtils.findActualNodeFor(((ForToStatement)featureObject.eContainer()).getInitializer())
.getTotalEndOffset() + 1;
}
}
if (actualOffset != -1 && variable.getTypeStateProvider() != null)
{
allTypes = new ArrayList<>();
List<VariableTypeState> nearestStates =
variable.getTypeStateProvider().get(TypeSystemMode.NORMAL).getNearestByOffset(envs, actualOffset);
for (VariableTypeState nearestState : nearestStates)
{
if (nearestState != null)
{
if (nearestState instanceof VariableTreeTypeStateWithSubStates)
{
for (VariableTreeTypeState subState : ((VariableTreeTypeStateWithSubStates)nearestState)
.getSubStates(envs))
{
subState.getTypes().forEach(allTypes::add);
}
}
else
{
nearestState.getTypes().forEach(allTypes::add);
}
}
}
}
else
{
allTypes = typeComputer.computeTypes(featureObject, envs);
}
return allTypes;
}
}

View File

@ -25,9 +25,9 @@ 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.bsl.check.qfix.IXtextBslModuleFixModel;
import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix;
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;

View File

@ -21,7 +21,6 @@ import com._1c.g5.v8.dt.bsl.model.BslPackage;
import com._1c.g5.wiring.InjectorAwareServiceRegistrator;
import com._1c.g5.wiring.ServiceInitialization;
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
import com.e1c.v8codestyle.bsl.qfix.external.BslCheckFixBoostrap;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -132,7 +131,6 @@ public class BslPlugin
ServiceInitialization.schedule(() -> {
// register services from injector
registrator.service(IModuleStructureProvider.class).registerInjected();
registrator.managedService(BslCheckFixBoostrap.class).activateBeforeRegistration().registerInjected();
registrator.managedService(MultiCheckFixRegistrator.class).activateBeforeRegistration().registerInjected();
});
}

View File

@ -20,7 +20,6 @@ import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.resource.IResourceDescription;
import org.eclipse.xtext.resource.IResourceServiceProvider;
import org.eclipse.xtext.scoping.IScopeProvider;
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
import com._1c.g5.v8.dt.bsl.common.IBslPreferences;
import com._1c.g5.v8.dt.bsl.contextdef.IBslModuleContextDefService;
@ -30,7 +29,6 @@ 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.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
@ -80,10 +78,5 @@ class ExternalDependenciesModule
bind(IBslOwnerComputerService.class).toProvider(() -> rsp.get(IBslOwnerComputerService.class));
bind(IScopeProvider.class).toProvider(() -> rsp.get(IScopeProvider.class));
bind(IQualifiedNameProvider.class).toProvider(() -> rsp.get(IQualifiedNameProvider.class));
// Remove this after 2021.1
bind(BslGrammarAccess.class).toProvider(() -> rsp.get(BslGrammarAccess.class));
bind(IURIEditorOpener.class).toProvider(() -> rsp.get(IURIEditorOpener.class));
}
}

View File

@ -13,8 +13,6 @@
package com.e1c.v8codestyle.internal.bsl;
import com.e1c.v8codestyle.bsl.IModuleStructureProvider;
import com.e1c.v8codestyle.bsl.qfix.external.IXtextBslModuleFixProvider;
import com.e1c.v8codestyle.bsl.qfix.external.XtextBslModuleFixProvider;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
@ -31,9 +29,6 @@ public class ServiceModule
protected void configure()
{
bind(IModuleStructureProvider.class).to(ModuleStructureProvider.class).in(Singleton.class);
// Remove this after 2022.1
bind(IXtextBslModuleFixProvider.class).to(XtextBslModuleFixProvider.class).in(Singleton.class);
}
}