diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/LinkPartSpaceFix.java b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/LinkPartSpaceFix.java index 8b387695..9a5cfbf6 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/LinkPartSpaceFix.java +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/LinkPartSpaceFix.java @@ -12,17 +12,16 @@ *******************************************************************************/ package com.e1c.v8codestyle.bsl.ui.qfix; -import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.text.BadLocationException; import org.eclipse.text.edits.DeleteEdit; import org.eclipse.text.edits.InsertEdit; import org.eclipse.text.edits.ReplaceEdit; import org.eclipse.text.edits.TextEdit; +import org.eclipse.xtext.EcoreUtil2; import org.eclipse.xtext.nodemodel.INode; import org.eclipse.xtext.nodemodel.util.NodeModelUtils; import org.eclipse.xtext.resource.XtextResource; -import com._1c.g5.v8.dt.bsl.model.Method; import com._1c.g5.v8.dt.bsl.model.Module; import com.e1c.g5.v8.dt.bsl.check.qfix.IXtextBslModuleFixModel; import com.e1c.g5.v8.dt.bsl.check.qfix.SingleVariantXtextBslModuleFix; @@ -50,49 +49,34 @@ public class LinkPartSpaceFix protected TextEdit fixIssue(XtextResource state, IXtextBslModuleFixModel model) throws BadLocationException { int issueOffset = model.getIssue().getOffset(); - Method method = (Method)model.getElement(); - EObject eObject = getModule(method); - while (!(eObject instanceof Module)) + Module module = EcoreUtil2.getContainerOfType(model.getElement(), Module.class); + INode moduleNode = NodeModelUtils.findActualNodeFor(module); + if (moduleNode == null) { - eObject = getModule(eObject); + return null; } - if (eObject instanceof Module) + String editText = moduleNode.getText(); + if (editText.length() < issueOffset + 1) { - INode node = NodeModelUtils.findActualNodeFor(eObject); - if (node == null) - { - return null; - } - String editText = node.getText(); - if (editText.length() < issueOffset + 1) - { - return null; - } - char checkChar = editText.charAt(issueOffset + 1); + return null; + } + char checkChar = editText.charAt(issueOffset + 1); - if (!Character.isLetter(checkChar)) + if (!Character.isLetter(checkChar)) + { + String nextChar = String.valueOf(editText.charAt(issueOffset + 2)); + if (nextChar.equals(" ") || nextChar.equals("\t")) //$NON-NLS-1$ //$NON-NLS-2$ { - String nextChar = String.valueOf(editText.charAt(issueOffset + 2)); - if (nextChar.equals(" ") || nextChar.equals("\t")) //$NON-NLS-1$ //$NON-NLS-2$ - { - return new DeleteEdit(issueOffset + 1, 1); - } - else - { - return new ReplaceEdit(issueOffset + 1, 1, " "); //$NON-NLS-1$ - } + return new DeleteEdit(issueOffset + 1, 1); } else { - return new InsertEdit(issueOffset + 1, " "); //$NON-NLS-1$ + return new ReplaceEdit(issueOffset + 1, 1, " "); //$NON-NLS-1$ } } - return null; - } - - private EObject getModule(EObject eObject) - { - EObject nextContainer = eObject.eContainer(); - return nextContainer; + else + { + return new InsertEdit(issueOffset + 1, " "); //$NON-NLS-1$ + } } } \ No newline at end of file diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages.properties b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages.properties index 520927ab..fbb113ea 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages.properties +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages.properties @@ -29,8 +29,8 @@ SelfAssignFix_Description = Remove self-assign variable SelfAssignFix_Details = Remove self-assign variable ServerExecutionSafeModeFix_description = Enable safe mode ServerExecutionSafeModeFix_details = Insert safe mode enable statement before "Execute" or "Eval" method call -LinkPartSpaceFix_Description = Add missing space -LinkPartSpaceFix_Details = Add missing space +LinkPartSpaceFix_Description = Correct the link format 'See link' +LinkPartSpaceFix_Details = Correct the link format 'See link' UndefinedMethodFix_func_title=Create function UndefinedMethodFix_func_desc=Create a new function in the module UndefinedMethodFix_proc_title=Create procedure diff --git a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages_ru.properties b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages_ru.properties index 91641e33..ad5bbb33 100644 --- a/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages_ru.properties +++ b/bundles/com.e1c.v8codestyle.bsl.ui/src/com/e1c/v8codestyle/bsl/ui/qfix/messages_ru.properties @@ -41,9 +41,9 @@ ServerExecutionSafeModeFix_description = Включить безопасный ServerExecutionSafeModeFix_details = Добавить включение безопасного режима перед вызовом метода "Выполнить" или "Вычислить" -LinkPartSpaceFix_Description = Добавить пропущенный пробел +LinkPartSpaceFix_Description = Привести ссылку к правильному формату 'См. Ссылка' -LinkPartSpaceFix_Details = Добавить пропущенный пробел +LinkPartSpaceFix_Details = Привести ссылку к правильному формату 'См. Ссылка' UndefinedMethodFix_func_desc = Создать новую функцию в модуле diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/LinkPartSpaceCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/LinkPartSpaceCheck.java index df03609e..d5eeda1e 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/LinkPartSpaceCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/LinkPartSpaceCheck.java @@ -94,15 +94,15 @@ public class LinkPartSpaceCheck String checkString = linkPart.getInitialContent(); String stringLink = linkPart.getLinkText(); Method method = root.getMethod(); - INode node = NodeModelUtils.findActualNodeFor(method); - if (node == null) - { - return; - } - String textMethod = node.getText(); if (checkString.toLowerCase().indexOf(IBslCommentToken.LINK_RU.toLowerCase()) != -1 || checkString.toLowerCase().indexOf(IBslCommentToken.LINK.toLowerCase()) != -1) { + INode node = NodeModelUtils.findActualNodeFor(method); + if (node == null) + { + return; + } + String textMethod = node.getText(); int indexCheckChar = textMethod.indexOf(checkString); int indexLinkText = checkString.indexOf(stringLink); if (indexLinkText == -1 || indexCheckChar == -1 || indexLinkText == 0) @@ -118,18 +118,10 @@ public class LinkPartSpaceCheck { return; } - if (stringLink.equals(":") || stringLink.equals("_")) //$NON-NLS-1$ //$NON-NLS-2$ - { - resultAceptor.addIssue(Messages.LinkPartSpaceCheck_issueColon, linkPart.getLineNumber(), - linkPart.getLinkTextOffset() - 1, 2); - } - else - { - resultAceptor.addIssue(Messages.LinkPartSpaceCheck_issue, linkPart.getLineNumber(), - linkPart.getLinkTextOffset() - 1, 2); - } + resultAceptor.addIssue(Messages.LinkPartSpaceCheck_issue, linkPart.getLineNumber(), + linkPart.getLinkTextOffset() - 1, 2); } } } } -} \ No newline at end of file +} diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/Messages.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/Messages.java index 87711af1..3069b784 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/Messages.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/Messages.java @@ -76,7 +76,6 @@ final class Messages public static String LinkPartSpaceCheck_description; public static String LinkPartSpaceCheck_issue; public static String LinkPartSpaceCheck_title; - public static String LinkPartSpaceCheck_issueColon; public static String TypeDefinitionCheck_description; public static String TypeDefinitionCheck_title; public static String TypeDefinitionCheck_Unkown_type_M_specified; diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages.properties b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages.properties index 76b0810b..81df3ebb 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages.properties +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages.properties @@ -118,9 +118,7 @@ LinkPartSpaceCheck_description = Check for space after 'See' before link LinkPartSpaceCheck_title = Check for space after 'See' before link -LinkPartSpaceCheck_issue = There is a space missing after 'See' before the link - -LinkPartSpaceCheck_issueColon = There is extra colon before the link +LinkPartSpaceCheck_issue = There must be a space after 'See' before the link TypeDefinitionCheck_Unkown_type_M_specified = Unknown type "{0}" specified in documentation comment diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages_ru.properties b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages_ru.properties index 6ae6eeaf..bce41e8e 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages_ru.properties +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/comment/check/messages_ru.properties @@ -114,13 +114,11 @@ RefLinkPartCheck_description = Ссылка документирующего к RefLinkPartCheck_title = Ссылка документирующего комментария на существующий объект -LinkPartSpaceCheck_description = Проверка наличия пробела после 'См.' перед ссылкой +LinkPartSpaceCheck_description = Проверка наличия пробельных символов после 'См.' перед ссылкой -LinkPartSpaceCheck_title = Проверка наличия пробела после 'См.' перед ссылкой +LinkPartSpaceCheck_title = Проверка наличия пробельных символов после 'См.' перед ссылкой -LinkPartSpaceCheck_issue = Отсутствует пробел после 'См.' перед ссылкой - -LinkPartSpaceCheck_issueColon = Лишнее двоеточие перед ссылкой +LinkPartSpaceCheck_issue = Должен быть пробельный символ после 'См.' перед ссылкой TypeDefinitionCheck_Unkown_type_M_specified = Неизвестный тип "{0}" указан в документирующем комментарии diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-space-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-space-link-part-ru.bsl new file mode 100644 index 00000000..46ec9ab4 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-space-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//IncorrectLink - См.: Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-underscore-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-underscore-link-part-ru.bsl new file mode 100644 index 00000000..935b167f --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-before-underscore-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//IncorrectLink - См.:_Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-link-part-ru.bsl new file mode 100644 index 00000000..8becb5b2 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-colon-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//IncorrectLink - См.:Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-underscore-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-underscore-link-part-ru.bsl new file mode 100644 index 00000000..8b27fe20 --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/extra-underscore-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//IncorrectLink - См._Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-after-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-after-ru.bsl new file mode 100644 index 00000000..5298a67d --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-after-ru.bsl @@ -0,0 +1,9 @@ +#Region Abcd + +//CorrectLink - См. Catalog.Catalog1 +//IncorrectLink - См.Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-before-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-before-ru.bsl new file mode 100644 index 00000000..1825618d --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-before-ru.bsl @@ -0,0 +1,9 @@ +#Region Abcd + +//IncorrectLink - См.Catalog.Catalog1 +//CorrectLink - См. Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-ru.bsl new file mode 100644 index 00000000..d59229ae --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-missing-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//IncorrectLink - См.Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-link-part-ru.bsl new file mode 100644 index 00000000..c666e10f --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//CorrectLink - См. Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-tab-link-part-ru.bsl b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-tab-link-part-ru.bsl new file mode 100644 index 00000000..c666e10f --- /dev/null +++ b/tests/com.e1c.v8codestyle.bsl.itests/resources/space-non-missing-tab-link-part-ru.bsl @@ -0,0 +1,8 @@ +#Region Abcd + +//CorrectLink - См. Catalog.Catalog1 +Procedure Test() + +EndProcedure + +#EndRegion diff --git a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/comment/check/itests/LinkPartSpaceCheckTest.java b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/comment/check/itests/LinkPartSpaceCheckTest.java index baf58ea5..ed42d9da 100644 --- a/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/comment/check/itests/LinkPartSpaceCheckTest.java +++ b/tests/com.e1c.v8codestyle.bsl.itests/src/com/e1c/v8codestyle/bsl/comment/check/itests/LinkPartSpaceCheckTest.java @@ -53,6 +53,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link. + * + * @throws Exception the exception + */ + @Test + public void testIncorrectLinkRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "space-missing-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link with underscore. * @@ -69,6 +85,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link with underscore. + * + * @throws Exception the exception + */ + @Test + public void testIncorrectLinkWithUnderscoreRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "extra-underscore-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link with colon before. * @@ -85,6 +117,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link with colon before. + * + * @throws Exception the exception + */ + @Test + public void testIncorrectLinkWithColonBeforeUnderscoreRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "extra-colon-before-underscore-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link with colon. * @@ -101,6 +149,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link with colon. + * + * @throws Exception the exception + */ + @Test + public void testIncorrectLinkWithColonRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "extra-colon-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link with colon before space. * @@ -117,6 +181,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link with colon before space. + * + * @throws Exception the exception + */ + @Test + public void testIncorrectLinkWithColonBeforeSpaceRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "extra-colon-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link after another link. * @@ -133,6 +213,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(4), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link after another link. + * + * @throws Exception the exception + */ + @Test + public void testLinkAfterRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "space-missing-link-part-after-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(4), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test incorrect link before another link * @@ -149,6 +245,22 @@ public class LinkPartSpaceCheckTest assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); } + /** + * Test incorrect link before another link + * + * @throws Exception the exception + */ + @Test + public void testLinkBeforeRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "space-missing-link-part-before-ru.bsl"); + + List markers = getModuleMarkers(); + assertEquals(1, markers.size()); + Marker marker = markers.get(0); + assertEquals(Integer.valueOf(3), marker.getExtraInfo().get(StandardExtraInfo.TEXT_LINE)); + } + /** * Test correct link. * @@ -163,6 +275,20 @@ public class LinkPartSpaceCheckTest assertTrue(markers.isEmpty()); } + /** + * Test correct link. + * + * @throws Exception the exception + */ + @Test + public void testCorrectLinkRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "space-non-missing-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertTrue(markers.isEmpty()); + } + /** * Test correct link with tab. * @@ -176,4 +302,18 @@ public class LinkPartSpaceCheckTest List markers = getModuleMarkers(); assertTrue(markers.isEmpty()); } + + /** + * Test correct link with tab. + * + * @throws Exception the exception + */ + @Test + public void testCorrectLinkWithTabRu() throws Exception + { + updateModule(FOLDER_RESOURCE + "space-non-missing-tab-link-part-ru.bsl"); + + List markers = getModuleMarkers(); + assertTrue(markers.isEmpty()); + } }