Skip to content

Commit

Permalink
Проверка на уникальность имени поля в doc-comment-field-name #1392
Browse files Browse the repository at this point in the history
  • Loading branch information
marmyshev committed Dec 21, 2023
1 parent ce6eb37 commit 2346fe2
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#### Код модулей

- Проверка на уникальность имени поля в doc-comment-field-name #1392

#### Запросы

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
package com.e1c.v8codestyle.bsl.comment.check;

import java.text.MessageFormat;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

import com._1c.g5.v8.dt.bsl.documentation.comment.BslDocumentationComment;
import com._1c.g5.v8.dt.bsl.documentation.comment.IDescriptionPart;
import com._1c.g5.v8.dt.bsl.documentation.comment.TypeSection.FieldDefinition;
import com._1c.g5.v8.dt.bsl.documentation.comment.TypeSection.TypeDefinition;
import com._1c.g5.v8.dt.common.StringUtils;
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
Expand Down Expand Up @@ -84,5 +86,35 @@ protected void checkDocumentationCommentObject(IDescriptionPart object, BslDocum
resultAceptor.addIssue(message, fieldDef.getLineNumber(), fieldDef.getNameOffset(),
fieldDef.getName().length());
}
else if (!isUnique(fieldDef))
{
String message = MessageFormat.format(Messages.FieldDefinitionNameCheck_Field_name__N__is_not_unique,
fieldDef.getName());
resultAceptor.addIssue(message, fieldDef.getLineNumber(), fieldDef.getNameOffset(),
fieldDef.getName().length());
}
}

private boolean isUnique(FieldDefinition fieldDef)
{
IDescriptionPart parent = fieldDef.getParent();
if (parent instanceof TypeDefinition)
{
List<FieldDefinition> fields = ((TypeDefinition)parent).getFieldDefinitionExtension();
String name = fieldDef.getName();
for (FieldDefinition field : fields)
{
if (field == fieldDef)
{
return true;
}
else if (name.equalsIgnoreCase(field.getName()))
{
return false;
}
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class Messages
public static String ExportMethodCommentDescriptionCheck_title;
public static String FieldDefinitionNameCheck_description;
public static String FieldDefinitionNameCheck_Field_name__N__is_incorrect_name;
public static String FieldDefinitionNameCheck_Field_name__N__is_not_unique;
public static String FieldDefinitionNameCheck_title;
public static String FieldDefinitionTypeCheck_description;
public static String FieldDefinitionTypeCheck_Field_M_has_no_type_definition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ExportMethodCommentDescriptionCheck_title=Missing Description section in the com

FieldDefinitionNameCheck_Field_name__N__is_incorrect_name = Field name "{0}" is incorrect name

FieldDefinitionNameCheck_Field_name__N__is_not_unique = Field name "{0}" is not unique

FieldDefinitionNameCheck_description = Documentation comment field is correct name

FieldDefinitionNameCheck_title = Documentation comment field is correct name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ExportMethodCommentDescriptionCheck_title=В комментарии к эксп

FieldDefinitionNameCheck_Field_name__N__is_incorrect_name = Имя поля "{0}" является некорректным

FieldDefinitionNameCheck_Field_name__N__is_not_unique = Имя поля "{0}" не уникально

FieldDefinitionNameCheck_description = Поле документирующего комментария является корректным именем

FieldDefinitionNameCheck_title = Поле документирующего комментария является корректным именем
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

// Parameters:
// Parameter1 - Structure:
// * Name - correct name
// * Name - incorrect name, ununique
//
Procedure NonComplaint(Parameter1)

EndProcedure


// Parameters:
// Parameter1 - Structure:
// * Name - correct name
//
Procedure Complaint(Parameter1)

EndProcedure

Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ public void testInvalidFieldName() throws Exception
Marker marker = markers.get(0);
assertEquals("4", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}

/**
* Test the documentation comment field name is unique name
*
* @throws Exception the exception
*/
@Test
public void testInvalidFieldNameUnunique() throws Exception
{
updateModule(FOLDER_RESOURCE + "doc-comment-field-name-ununique.bsl");

List<Marker> markers = getModuleMarkers();
assertEquals(1, markers.size());
Marker marker = markers.get(0);
assertEquals("5", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
}
}

0 comments on commit 2346fe2

Please sign in to comment.