1
0
mirror of https://github.com/1C-Company/v8-code-style.git synced 2026-05-21 02:19:05 +02:00

fix and add test ru variant

This commit is contained in:
IvanSergeev
2025-12-16 16:53:17 +04:00
parent e71a1cc120
commit 83036f1059
17 changed files with 251 additions and 66 deletions
@@ -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$
}
}
}
@@ -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
@@ -41,9 +41,9 @@ ServerExecutionSafeModeFix_description = Включить безопасный
ServerExecutionSafeModeFix_details = Добавить включение безопасного режима перед вызовом метода "Выполнить" или "Вычислить"
LinkPartSpaceFix_Description = Добавить пропущенный пробел
LinkPartSpaceFix_Description = Привести ссылку к правильному формату 'См. Ссылка'
LinkPartSpaceFix_Details = Добавить пропущенный пробел
LinkPartSpaceFix_Details = Привести ссылку к правильному формату 'См. Ссылка'
UndefinedMethodFix_func_desc = Создать новую функцию в модуле
@@ -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);
}
}
}
}
}
}
@@ -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;
@@ -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
@@ -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}" указан в документирующем комментарии
@@ -0,0 +1,8 @@
#Region Abcd
//IncorrectLink - См.: Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//IncorrectLink - См.:_Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//IncorrectLink - См.:Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//IncorrectLink - См._Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,9 @@
#Region Abcd
//CorrectLink - См. Catalog.Catalog1
//IncorrectLink - См.Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,9 @@
#Region Abcd
//IncorrectLink - См.Catalog.Catalog1
//CorrectLink - См. Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//IncorrectLink - См.Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//CorrectLink - См. Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -0,0 +1,8 @@
#Region Abcd
//CorrectLink - См. Catalog.Catalog1
Procedure Test()
EndProcedure
#EndRegion
@@ -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<Marker> 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<Marker> 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<Marker> 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<Marker> 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<Marker> 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<Marker> 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<Marker> 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<Marker> markers = getModuleMarkers();
assertTrue(markers.isEmpty());
}
/**
* Test correct link with tab.
*
@@ -176,4 +302,18 @@ public class LinkPartSpaceCheckTest
List<Marker> 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<Marker> markers = getModuleMarkers();
assertTrue(markers.isEmpty());
}
}