diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cfd408f..de644ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ ### Прочие изменения +- Контекстная команда форматирования документирующего комментария в редакторе модуля #1418 ### Исправленные ошибки @@ -313,6 +314,7 @@ - Исправлен расчета типов возвращаемых значений функций с вызовом сервера - Испрвление проверки типа локальной переменной в variable-value-type - Проверка типов invocation-parameter-type-intersect при вызове метода, если существуют документирующие комментарии использует только декларированные типы +- Исправлена ошибка, при которой не выполнялась автосортировка вложенных подсистем при включенной автосортировке верхнеуровневых объектов метаданных ## 0.1.0 diff --git a/bundles/com.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/SortService.java b/bundles/com.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/SortService.java index 70e5a53c..14c54593 100644 --- a/bundles/com.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/SortService.java +++ b/bundles/com.e1c.v8codestyle.autosort/src/com/e1c/v8codestyle/internal/autosort/SortService.java @@ -467,6 +467,23 @@ public class SortService } } + private void appendSubordinateSubsystems(Collection result, IBmTransaction transaction) + { + for (Iterator iterator = + transaction.getTopObjectIterator(MdClassPackage.Literals.SUBSYSTEM); iterator.hasNext();) + { + IBmObject subsystem = iterator.next(); + + EList subordinateSubsystems = + (EList)subsystem.eGet(MdClassPackage.Literals.SUBSYSTEM__SUBSYSTEMS, false); + if (subordinateSubsystems.size() > 1) + { + String fqn = subsystem.bmGetFqn(); + result.add(new SortItem(fqn, MdClassPackage.Literals.SUBSYSTEM__SUBSYSTEMS, sorter)); + } + } + } + private Map> getSubordinateListsToSort(Iterator eClassIterator, IProject project) { @@ -474,7 +491,8 @@ public class SortService while (eClassIterator.hasNext()) { EClass topObjectEClass = eClassIterator.next(); - if (topObjectEClass.equals(CONFIGURATION) || !MD_OBJECT.isSuperTypeOf(topObjectEClass)) + if (topObjectEClass.equals(CONFIGURATION) || topObjectEClass.equals(MdClassPackage.Literals.SUBSYSTEM) + || !MD_OBJECT.isSuperTypeOf(topObjectEClass)) { continue; } @@ -516,6 +534,10 @@ public class SortService { result.add(new SortItem(CONFIGURATION_FQN, feature, sorter)); } + if (feature.equals(MdClassPackage.Literals.CONFIGURATION__SUBSYSTEMS)) + { + appendSubordinateSubsystems(result, transaction); + } } } } diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF b/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF index 475c7a6a..5774e30f 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF +++ b/bundles/com.e1c.v8codestyle.bsl.ui/META-INF/MANIFEST.MF @@ -22,6 +22,7 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.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)", com._1c.g5.v8.dt.bsl.documentation.comment;version="[4.0.0,5.0.0)", + com._1c.g5.v8.dt.bsl.formatting;version="[3.0.0,4.0.0)", com._1c.g5.v8.dt.bsl.model;version="[5.0.0,6.0.0)", com._1c.g5.v8.dt.bsl.model.util;version="[4.7.0,5.0.0)", com._1c.g5.v8.dt.bsl.resource.owner;version="[2.0.0,3.0.0)", @@ -38,6 +39,7 @@ Import-Package: com._1c.g5.ides.ui.texteditor.xtext.embedded;version="[6.0.0,7.0 com._1c.g5.v8.dt.core.model;version="[6.0.0,7.0.0)", com._1c.g5.v8.dt.core.platform;version="[11.0.0,12.0.0)", com._1c.g5.v8.dt.form.model;version="[11.1.0,12.0.0)", + com._1c.g5.v8.dt.lcore.nodemodel.util;version="[1.0.0,2.0.0)", com._1c.g5.v8.dt.lcore.ui.texteditor;version="[1.1.0,2.0.0)", com._1c.g5.v8.dt.mcore;version="[7.0.0,8.0.0)", com._1c.g5.v8.dt.metadata.mdclass;version="[9.0.0,10.0.0)", diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/plugin.properties b/bundles/com.e1c.v8codestyle.bsl.ui/plugin.properties index 030d1477..125741e3 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/plugin.properties +++ b/bundles/com.e1c.v8codestyle.bsl.ui/plugin.properties @@ -15,6 +15,8 @@ command.enableStrictTypes.mnemonic = E command.enableStrictTypes.name = Enable @strict-types in modules +command.formatDocComment.mnemonic = F +command.formatDocComment.name = Format Method Documentation Comment menu.label = Source diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml b/bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml index cfc9ceba..8e325cfd 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml +++ b/bundles/com.e1c.v8codestyle.bsl.ui/plugin.xml @@ -237,6 +237,10 @@ id="com.e1c.v8codestyle.bsl.ui.commands.addStrictTypesAnnotationCommand" name="%command.enableStrictTypes.name"> + + @@ -330,6 +334,16 @@ + + + + + + @@ -343,6 +357,14 @@ definitionId="com._1c.g5.v8.dt.bsl.Bsl.Editor.editable"> + + + + + diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/plugin_ru.properties b/bundles/com.e1c.v8codestyle.bsl.ui/plugin_ru.properties index a8dc3db0..4c929945 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/plugin_ru.properties +++ b/bundles/com.e1c.v8codestyle.bsl.ui/plugin_ru.properties @@ -14,6 +14,8 @@ command.enableStrictTypes.mnemonic = В command.enableStrictTypes.name = Включить строгую типизацию (@strict-types) в модулях +command.formatDocComment.mnemonic = Ф +command.formatDocComment.name = Форматировать документирующий комментарий метода menu.label = Исходники diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/ExternalDependenciesModule.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/ExternalDependenciesModule.java index 9e8deabe..6ccaedf7 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/ExternalDependenciesModule.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/ExternalDependenciesModule.java @@ -19,10 +19,12 @@ import org.eclipse.xtext.resource.IResourceServiceProvider; 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.ui.contentassist.BslProposalProvider; import com._1c.g5.v8.dt.core.filesystem.IQualifiedNameFilePathConverter; import com._1c.g5.v8.dt.core.model.IModelEditingSupport; 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.wiring.AbstractServiceAwareModule; import com.e1c.g5.v8.dt.check.qfix.IFixRepository; import com.e1c.v8codestyle.bsl.IModuleStructureProvider; @@ -59,6 +61,8 @@ class ExternalDependenciesModule bind(BslMultiLineCommentDocumentationProvider.class) .toProvider(() -> rsp.get(BslMultiLineCommentDocumentationProvider.class)); bind(EObjectAtOffsetHelper.class).toProvider(() -> rsp.get(EObjectAtOffsetHelper.class)); + bind(BslProposalProvider.class).toProvider(() -> rsp.get(BslProposalProvider.class)); + bind(IndentTextEditorProvider.class).toProvider(() -> rsp.get(IndentTextEditorProvider.class)); // CodeStyle Services bind(IModuleStructureProvider.class).toService(); diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/handlers/FormatDocCommentModuleEditorHandler.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/handlers/FormatDocCommentModuleEditorHandler.java new file mode 100644 index 00000000..de5cc242 --- /dev/null +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/internal/bsl/ui/handlers/FormatDocCommentModuleEditorHandler.java @@ -0,0 +1,235 @@ +/******************************************************************************* + * Copyright (C) 2024, 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.ui.handlers; + +import java.util.List; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.handly.buffer.BufferChange; +import org.eclipse.handly.snapshot.NonExpiringSnapshot; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.text.edits.ReplaceEdit; +import org.eclipse.text.edits.TextEdit; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.xtext.EcoreUtil2; +import org.eclipse.xtext.nodemodel.ICompositeNode; +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 org.eclipse.xtext.ui.editor.XtextEditor; +import org.eclipse.xtext.ui.editor.model.IXtextDocument; +import org.eclipse.xtext.util.CancelIndicator; +import org.eclipse.xtext.util.Triple; +import org.eclipse.xtext.util.Tuples; +import org.eclipse.xtext.util.concurrent.CancelableUnitOfWork; + +import com._1c.g5.ides.ui.texteditor.xtext.embedded.EmbeddedEditorBuffer; +import com._1c.g5.v8.dt.bsl.common.IBslPreferences; +import com._1c.g5.v8.dt.bsl.documentation.comment.BslCommentUtils; +import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocCommentSerializer; +import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment; +import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment.Description; +import com._1c.g5.v8.dt.bsl.documentation.comment.BslMultiLineCommentDocumentationProvider; +import com._1c.g5.v8.dt.bsl.documentation.comment.IDescriptionPart; +import com._1c.g5.v8.dt.bsl.documentation.comment.TextPart; +import com._1c.g5.v8.dt.bsl.model.Method; +import com._1c.g5.v8.dt.bsl.model.Module; +import com._1c.g5.v8.dt.bsl.ui.contentassist.BslProposalProvider; +import com._1c.g5.v8.dt.bsl.ui.menu.BslHandlerUtil; +import com._1c.g5.v8.dt.bsl.util.BslUtil; +import com._1c.g5.v8.dt.common.PreferenceUtils; +import com._1c.g5.v8.dt.common.StringUtils; +import com._1c.g5.v8.dt.core.model.EditingMode; +import com._1c.g5.v8.dt.core.model.IModelEditingSupport; +import com._1c.g5.v8.dt.core.platform.IV8Project; +import com._1c.g5.v8.dt.core.platform.IV8ProjectManager; +import com._1c.g5.v8.dt.lcore.nodemodel.util.CustomNodeModelUtils; +import com._1c.g5.v8.dt.lcore.ui.texteditor.IndentTextEditorProvider; +import com.e1c.v8codestyle.internal.bsl.ui.UiPlugin; +import com.google.inject.Inject; + +/** + * The Handler to format current method's documentation comment in opened in BSL editor. + * + * @author Dmitriy Marmyshev + */ +public class FormatDocCommentModuleEditorHandler + extends AbstractHandler +{ + + @Inject + private BslMultiLineCommentDocumentationProvider commentProvider; + + @Inject + private BslProposalProvider proposalProvider; + + @Inject + private IBslPreferences bslPreferences; + + @Inject + private IV8ProjectManager v8projectManager; + + @Inject + private IndentTextEditorProvider indentProvider; + + @Inject + private IModelEditingSupport modelEditingSupport; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException + { + IWorkbenchPart part = HandlerUtil.getActivePart(event); + + XtextEditor target = BslHandlerUtil.extractXtextEditor(part); + if (target != null) + { + final ITextViewer viewer = BslHandlerUtil.getTextViewer(target); + IXtextDocument document = target.getDocument(); + + Triple content = + document.readOnly(new CancelableUnitOfWork, XtextResource>() + { + @Override + public Triple exec(XtextResource resource, CancelIndicator monitor) + throws Exception + { + if (resource.getContents() != null && !resource.getContents().isEmpty()) + { + EObject obj = resource.getContents().get(0); + if (obj instanceof Module) + return getFormatedDocComment((Module)obj, viewer); + } + return null; + } + + }); + + if (content != null && content.getFirst() > -1 && content.getSecond() > -1 && content.getThird() != null) + { + replaceDocComment(document, content.getThird(), content.getFirst(), content.getSecond()); + } + + } + return null; + } + + private void replaceDocComment(IXtextDocument document, String comment, int insertOffset, int length) + { + TextEdit change = new ReplaceEdit(insertOffset, length, comment); + + try (EmbeddedEditorBuffer buffer = new EmbeddedEditorBuffer(document)) + { + NonExpiringSnapshot snapshot = new NonExpiringSnapshot(buffer); + BufferChange bufferChange = new BufferChange(change); + bufferChange.setBase(snapshot); + buffer.applyChange(bufferChange, new NullProgressMonitor()); + } + catch (CoreException e) + { + UiPlugin.logError(e); + } + } + + private Triple getFormatedDocComment(Module module, ITextViewer viewer) + { + if (!modelEditingSupport.canEdit(module, EditingMode.DIRECT)) + { + return null; + } + + Method method = getNearestMethod(module, (viewer.getSelectedRange()).x); + if (method != null) + { + List lines = commentProvider.getDocumentationNodes(method); + if (lines.isEmpty()) + { + return null; + } + int methodOffset = lines.get(0).getOffset(); + int length = lines.get(lines.size() - 1).getEndOffset() - methodOffset; + + String lineFormatter = proposalProvider.getLineFormatter(module, methodOffset, viewer.getDocument()); + IV8Project project = v8projectManager.getProject(module); + boolean oldFormat = (project != null && project.getProject() != null) + ? this.bslPreferences.getDocumentCommentProperties(project.getProject()).oldCommentFormat() : true; + + BslDocumentationComment docComment = + BslCommentUtils.parseTemplateComment(method, oldFormat, commentProvider); + if (isEmpty(docComment.getDescription())) + { + docComment.getDescription().getParts().clear(); + } + + boolean isRussian = BslUtil.isRussian(method, v8projectManager); + String indent = indentProvider.getIndent(); + + String lineSeparator = resolveLineSeparator(project); + String comment = BslDocCommentSerializer.newBuilder() + .setOldFormat(oldFormat) + .setScriptVariant(isRussian) + .lineSeparator(lineSeparator) + .ignoreLineNumbers() + .build() + .serialize(docComment, lineFormatter, indent) + .concat(lineSeparator); + + return Tuples.create(methodOffset, length, comment); + } + return null; + } + + private boolean isEmpty(Description description) + { + for (IDescriptionPart part : description.getParts()) + { + if (part instanceof TextPart) + { + String text = ((TextPart)part).getText(); + if (StringUtils.isNotBlank(text)) + { + return false; + } + } + else + { + return false; + } + } + return true; + } + + private Method getNearestMethod(Module module, int offset) + { + ICompositeNode iCompositeNode = NodeModelUtils.findActualNodeFor(module); + ILeafNode node = CustomNodeModelUtils.findLeafNodeAtOffset(iCompositeNode, offset); + EObject actualObject = NodeModelUtils.findActualSemanticObjectFor(node); + if (actualObject instanceof Method) + return (Method)actualObject; + return EcoreUtil2.getContainerOfType(actualObject, Method.class); + } + + private static String resolveLineSeparator(IV8Project v8project) + { + if (v8project == null) + return System.lineSeparator(); + return PreferenceUtils.getLineSeparator(v8project.getProject()); + } + +} diff --git a/tests/com.e1c.v8codestyle.autosort.itests/META-INF/MANIFEST.MF b/tests/com.e1c.v8codestyle.autosort.itests/META-INF/MANIFEST.MF index 050d2b4e..a37bfe5a 100644 --- a/tests/com.e1c.v8codestyle.autosort.itests/META-INF/MANIFEST.MF +++ b/tests/com.e1c.v8codestyle.autosort.itests/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Fragment-Host: com.e1c.v8codestyle.autosort;bundle-version="[0.7.0,0.8.0)" Automatic-Module-Name: com.e1c.v8codestyle.autosort.itests Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-Localization: fragment -Import-Package: com._1c.g5.v8.dt.testing;version="[3.1.0,4.0.0)", +Import-Package: com._1c.g5.v8.dt.platform.version;version="[2.14.0,3.0.0)", + com._1c.g5.v8.dt.testing;version="[3.1.0,4.0.0)", org.junit;version="[4.13.0,5.0.0)", org.junit.runner;version="[4.13.0,5.0.0)" diff --git a/tests/com.e1c.v8codestyle.autosort.itests/src/com/e1c/v8codestyle/autosort/itests/SortSubsystemsTest.java b/tests/com.e1c.v8codestyle.autosort.itests/src/com/e1c/v8codestyle/autosort/itests/SortSubsystemsTest.java new file mode 100644 index 00000000..aed3e4d4 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/src/com/e1c/v8codestyle/autosort/itests/SortSubsystemsTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (C) 2024, 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.autosort.itests; + +import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com._1c.g5.v8.bm.core.IBmObject; +import com._1c.g5.v8.bm.core.IBmTransaction; +import com._1c.g5.v8.bm.integration.AbstractBmTask; +import com._1c.g5.v8.bm.integration.IBmModel; +import com._1c.g5.v8.dt.core.platform.IBmModelManager; +import com._1c.g5.v8.dt.core.platform.IDtProject; +import com._1c.g5.v8.dt.core.platform.IDtProjectManager; +import com._1c.g5.v8.dt.metadata.mdclass.Configuration; +import com._1c.g5.v8.dt.platform.version.Version; +import com._1c.g5.v8.dt.testing.GuiceModules; +import com._1c.g5.v8.dt.testing.JUnitGuiceRunner; +import com._1c.g5.v8.dt.testing.TestingPlatformSupport; +import com._1c.g5.v8.dt.testing.TestingWorkspace; +import com.e1c.v8codestyle.autosort.ISortService; +import com.google.inject.Inject; + +/** + * Test ensuring subsystems are sorted properly when top metadata sorting enabled. + * + * @author Tihon Tihonin + */ +@RunWith(JUnitGuiceRunner.class) +@GuiceModules(modules = { ExternalDependenciesModule.class }) +public class SortSubsystemsTest +{ + private static final String PROJECT_NAME = "SubsystemsAutoSort"; + + @Rule + public TestingWorkspace testingWorkspace = new TestingWorkspace(true, true); + + @ClassRule + public static final TestingPlatformSupport testingPlatformSupport = new TestingPlatformSupport(Version.V8_3_19); + + @Inject + private ISortService sortService; + + @Inject + public IDtProjectManager dtProjectManager; + + @Inject + public IBmModelManager bmModelManager; + + @Test + public void testSortSubsystems() throws Exception + { + IProject project = testingWorkspace.setUpProject(PROJECT_NAME, getClass()); + assertNotNull(project); + IDtProject dtProject = dtProjectManager.getDtProject(project); + assertNotNull(dtProject); + + IBmObject object = getTopObjectByFqn(CONFIGURATION.getName(), dtProject); + Configuration configuration = (Configuration)object; + + assertEquals("Subsystem2", configuration.getSubsystems().get(0).getSubsystems().get(0).getName()); + assertEquals("Subsystem1", configuration.getSubsystems().get(0).getSubsystems().get(1).getName()); + + sortService.sortAllMetadata(dtProject, new NullProgressMonitor()); + + assertEquals("Subsystem1", configuration.getSubsystems().get(0).getSubsystems().get(0).getName()); + assertEquals("Subsystem2", configuration.getSubsystems().get(0).getSubsystems().get(1).getName()); + } + + protected IBmObject getTopObjectByFqn(final String fqn, IDtProject dtProject) + { + IBmModel model = bmModelManager.getModel(dtProject); + return model.executeReadonlyTask(new AbstractBmTask("GetObject") + { + @Override + public IBmObject execute(IBmTransaction transaction, IProgressMonitor progressMonitor) + { + return transaction.getTopObjectByFqn(fqn); + } + }); + } +} diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.project b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.project new file mode 100644 index 00000000..a04e0788 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.project @@ -0,0 +1,18 @@ + + + SubsystemsAutoSort + + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + com._1c.g5.v8.dt.core.V8ConfigurationNature + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.autosort.prefs b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.autosort.prefs new file mode 100644 index 00000000..23b06250 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.autosort.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +topObjects=true diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.prefs b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.prefs new file mode 100644 index 00000000..9e9b57e5 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/com.e1c.v8codestyle.prefs @@ -0,0 +1,3 @@ +commonChecks=true +eclipse.preferences.version=1 +standardChecks=true diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/org.eclipse.core.resources.prefs b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/DT-INF/PROJECT.PMF b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/DT-INF/PROJECT.PMF new file mode 100644 index 00000000..6835f1cd --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/DT-INF/PROJECT.PMF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Runtime-Version: 8.3.19 diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/CommandInterface.cmi b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/CommandInterface.cmi new file mode 100644 index 00000000..0cf6de8a --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/CommandInterface.cmi @@ -0,0 +1,2 @@ + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/Configuration.mdo b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/Configuration.mdo new file mode 100644 index 00000000..01bbe7a3 --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/Configuration.mdo @@ -0,0 +1,42 @@ + + + SubsystemsAutoSort + + en + Subsystems auto sort + + + + + + + + + 8.3.19 + ManagedApplication + PersonalComputer + + + true + + + OSBackup + true + + + Language.English + Managed + NotAutoFree + DontUse + DontUse + 8.3.19 + + English + + en + English + + en + + Subsystem.Subsystem + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/MainSectionCommandInterface.cmi b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/MainSectionCommandInterface.cmi new file mode 100644 index 00000000..0cf6de8a --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Configuration/MainSectionCommandInterface.cmi @@ -0,0 +1,2 @@ + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/CommandInterface.cmi b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/CommandInterface.cmi new file mode 100644 index 00000000..0cf6de8a --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/CommandInterface.cmi @@ -0,0 +1,2 @@ + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystem.mdo b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystem.mdo new file mode 100644 index 00000000..5e4e5d0e --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystem.mdo @@ -0,0 +1,12 @@ + + + Subsystem + + en + Subsystem + + true + true + Subsystem2 + Subsystem1 + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/CommandInterface.cmi b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/CommandInterface.cmi new file mode 100644 index 00000000..0cf6de8a --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/CommandInterface.cmi @@ -0,0 +1,2 @@ + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/Subsystem1.mdo b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/Subsystem1.mdo new file mode 100644 index 00000000..3c0a817d --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem1/Subsystem1.mdo @@ -0,0 +1,11 @@ + + + Subsystem1 + + en + Subsystem1 + + true + true + Subsystem.Subsystem + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/CommandInterface.cmi b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/CommandInterface.cmi new file mode 100644 index 00000000..0cf6de8a --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/CommandInterface.cmi @@ -0,0 +1,2 @@ + + diff --git a/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/Subsystem2.mdo b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/Subsystem2.mdo new file mode 100644 index 00000000..f68805aa --- /dev/null +++ b/tests/com.e1c.v8codestyle.autosort.itests/workspace/SubsystemsAutoSort/src/Subsystems/Subsystem/Subsystems/Subsystem2/Subsystem2.mdo @@ -0,0 +1,11 @@ + + + Subsystem2 + + en + Subsystem2 + + true + true + Subsystem.Subsystem + diff --git a/tests/com.e1c.v8codestyle.bsl.ui.itests/META-INF/MANIFEST.MF b/tests/com.e1c.v8codestyle.bsl.ui.itests/META-INF/MANIFEST.MF index c1badea2..c8d818f0 100644 --- a/tests/com.e1c.v8codestyle.bsl.ui.itests/META-INF/MANIFEST.MF +++ b/tests/com.e1c.v8codestyle.bsl.ui.itests/META-INF/MANIFEST.MF @@ -12,4 +12,5 @@ Import-Package: com._1c.g5.v8.dt.bsl.ui.editor;version="[9.0.0,10.0.0)", com._1c.g5.v8.dt.testing;version="[3.1.0,4.0.0)", com._1c.g5.v8.dt.ui.util;version="[7.0.0,8.0.0)", org.junit;version="[4.13.0,5.0.0)" -Require-Bundle: org.eclipse.ui.forms;bundle-version="[3.11.0,4.0.0)" +Require-Bundle: org.eclipse.ui.forms;bundle-version="[3.11.0,4.0.0)", + org.eclipse.core.expressions;bundle-version="[3.8.0,4.0.0)" diff --git a/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format-result.bsl b/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format-result.bsl new file mode 100644 index 00000000..bf478940 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format-result.bsl @@ -0,0 +1,9 @@ + +// Method description +// +// Parameters: +// Parameters - Structure - : +// * Key1 - has not type for key +Procedure Test(Parameters) Export + // empty +EndProcedure diff --git a/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format.bsl b/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format.bsl new file mode 100644 index 00000000..c4a64fd1 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.ui.itests/resources/doc-comment-format.bsl @@ -0,0 +1,11 @@ + +// Method description +// +// +// +// Parameters: +// Parameters - Structure: +// * Key1 - has not type for key +Procedure Test(Parameters) Export + // empty +EndProcedure diff --git a/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/BslDocCommentViewTest.java b/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/BslDocCommentViewTest.java index eb15b9e0..5f38af77 100644 --- a/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/BslDocCommentViewTest.java +++ b/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/BslDocCommentViewTest.java @@ -74,6 +74,16 @@ public class BslDocCommentViewTest @Before public void setUp() throws CoreException { + IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro(); + PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart); + + boolean closed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); + assertTrue(closed); + Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(); + while (!display.isDisposed() && display.readAndDispatch()) + { + // do it + } project = testingWorkspace.getProject(PROJECT_NAME); @@ -82,16 +92,17 @@ public class BslDocCommentViewTest testingWorkspace.cleanUpWorkspace(); project = this.testingWorkspace.setUpProject(PROJECT_NAME, getClass()); } - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); - - IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro(); - PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart); } @After public void shutDown() { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); + Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(); + while (!display.isDisposed() && display.readAndDispatch()) + { + // do it + } } /** diff --git a/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/handlers/FormatDocCommentModuleEditorHandlerTest.java b/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/handlers/FormatDocCommentModuleEditorHandlerTest.java new file mode 100644 index 00000000..e1d72509 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.ui.itests/src/com/e1c/v8codestyle/bsl/ui/itests/handlers/FormatDocCommentModuleEditorHandlerTest.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (C) 2024, 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.itests.handlers; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.text.TextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.intro.IIntroPart; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import com._1c.g5.v8.dt.bsl.ui.editor.BslXtextEditor; +import com._1c.g5.v8.dt.testing.TestingWorkspace; +import com._1c.g5.v8.dt.ui.util.OpenHelper; +import com.e1c.v8codestyle.internal.bsl.ui.handlers.FormatDocCommentModuleEditorHandler; + +/** + * Test {@link FormatDocCommentModuleEditorHandler} + * + * @author Dmitriy Marmyshev + */ +public class FormatDocCommentModuleEditorHandlerTest +{ + + private static final String COMMAND_ID = "com.e1c.v8codestyle.bsl.ui.commands.formatDocCommentCommand"; + + private static final String PROJECT_NAME = "CommonModule"; + + private static final String COMMON_MODULE_FILE_NAME = "/src/CommonModules/CommonModule/Module.bsl"; + + @Rule + public TestingWorkspace testingWorkspace = new TestingWorkspace(true, false); + + protected static final String FOLDER_RESOURCE = "/resources/"; + + private IProject project; + + private OpenHelper openHelper = new OpenHelper(); + + private ICommandService commandService; + private IHandlerService handlerService; + + @Before + public void setUp() throws CoreException + { + commandService = PlatformUI.getWorkbench().getService(ICommandService.class); + handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); + + IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro(); + PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart); + + boolean closed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); + assertTrue(closed); + Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(); + while (!display.isDisposed() && display.readAndDispatch()) + { + // do it + } + + project = testingWorkspace.getProject(PROJECT_NAME); + + if (!project.exists() || !project.isAccessible()) + { + testingWorkspace.cleanUpWorkspace(); + project = this.testingWorkspace.setUpProject(PROJECT_NAME, getClass()); + } + } + + @After + public void shutDown() + { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false); + Display display = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay(); + while (!display.isDisposed() && display.readAndDispatch()) + { + // do it + } + } + + /** + * Test format of doc comment. + * + * @throws Exception the exception + */ + @Test + public void testFormatDocComment() throws Exception + { + updateModule(FOLDER_RESOURCE + "doc-comment-format.bsl"); + + IFile file = project.getFile(COMMON_MODULE_FILE_NAME); + + ISelection selection = new TextSelection(14, 1); + IEditorPart fEditor = openHelper.openEditor(file, selection); + assertTrue(fEditor instanceof FormEditor); + + IEditorPart editor = ((FormEditor)fEditor).getActiveEditor(); + assertTrue(editor instanceof BslXtextEditor); + + + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(editor); + + BslXtextEditor bslEditor = (BslXtextEditor)editor; + String expected = getResourceText(FOLDER_RESOURCE + "doc-comment-format.bsl"); + assertEquals(expected, bslEditor.getDocument().get()); + + Command command = commandService.getCommand(COMMAND_ID); + assertNotNull(command); + + ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, new Event()); + assertNotNull(executionEvent); + + command.executeWithChecks(executionEvent); + + expected = getResourceText(FOLDER_RESOURCE + "doc-comment-format-result.bsl"); + assertEquals(expected, bslEditor.getDocument().get()); + } + + private String getResourceText(String pathToResource) throws Exception + { + try (InputStream in = getClass().getResourceAsStream(pathToResource)) + { + return new String(in.readAllBytes(), StandardCharsets.UTF_8); + } + } + + private void updateModule(String pathToResource) throws Exception + { + IFile file = project.getFile(COMMON_MODULE_FILE_NAME); + try (InputStream in = getClass().getResourceAsStream(pathToResource)) + { + if (file.exists()) + { + file.setContents(in, true, true, new NullProgressMonitor()); + } + else + { + file.create(in, true, new NullProgressMonitor()); + } + } + testingWorkspace.waitForBuildCompletion(); + } +}