You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-16 04:34:14 +02:00
Merge pull request #1361 from 1C-Company/G5V8DT-23827
G5V8DT-23827 Ошибочные диагностики типов по документирующим комментариям
This commit is contained in:
@ -21,12 +21,16 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||
import org.eclipse.xtext.scoping.IScope;
|
||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||
@ -152,11 +156,10 @@ public class FunctionCtorReturnSectionCheck
|
||||
|
||||
@Override
|
||||
protected void checkDocumentationCommentObject(IDescriptionPart object, BslDocumentationComment root,
|
||||
DocumentationCommentResultAcceptor resultAceptor, ICheckParameters parameters,
|
||||
BmOperationContext context, IProgressMonitor monitor)
|
||||
DocumentationCommentResultAcceptor resultAceptor, ICheckParameters parameters, BmOperationContext context,
|
||||
IProgressMonitor monitor)
|
||||
{
|
||||
if (monitor.isCanceled()
|
||||
|| !(root.getMethod() instanceof Function)
|
||||
if (monitor.isCanceled() || !(root.getMethod() instanceof Function)
|
||||
|| parameters.getBoolean(PARAM_CHECK_ANNOTATION_IN_MODULE_DESCRIPTION)
|
||||
&& !StrictTypeUtil.hasStrictTypeAnnotation(root.getModule()))
|
||||
{
|
||||
@ -189,14 +192,13 @@ public class FunctionCtorReturnSectionCheck
|
||||
|
||||
if (isUserDataTypes(computedReturnTypeNames, checkTypes))
|
||||
{
|
||||
|
||||
//@formatter:off
|
||||
List<ReturnStatement> returns = method.allStatements()
|
||||
.stream()
|
||||
.filter(ReturnStatement.class::isInstance)
|
||||
.map(ReturnStatement.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
//@formatter:on
|
||||
List<ReturnStatement> returns =
|
||||
StreamSupport
|
||||
.stream(Spliterators.spliteratorUnknownSize(EcoreUtil2.getAllContents(method, false),
|
||||
Spliterator.ORDERED), false)
|
||||
.filter(ReturnStatement.class::isInstance)
|
||||
.map(ReturnStatement.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Resource res = method.eResource();
|
||||
|
||||
@ -282,19 +284,25 @@ public class FunctionCtorReturnSectionCheck
|
||||
.flatMap(p -> p.getTypes().stream())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<TypeItem> types2 = types.stream()
|
||||
.filter(t -> {
|
||||
String typeName = McoreUtil.getTypeName(t);
|
||||
return typeName != null && !declaredType.contains(typeName);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
List<TypeItem> missingTypes = types.stream().filter(t -> {
|
||||
String typeName = McoreUtil.getTypeName(t);
|
||||
if (typeName != null)
|
||||
{
|
||||
if (!declaredType.contains(typeName))
|
||||
{
|
||||
return !"CommonModule".equals(McoreUtil.getTypeCategory(t)) //$NON-NLS-1$
|
||||
|| !declaredType.contains("CommonModule"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}).collect(Collectors.toList());
|
||||
if (types.isEmpty())
|
||||
{
|
||||
addWarningDeclaredNonReturningProperty(statment, useRussianScript, declaredProperty, resultAceptor);
|
||||
}
|
||||
else if (!types2.isEmpty())
|
||||
else if (!missingTypes.isEmpty())
|
||||
{
|
||||
addWarningDeclaredNonReturningPropertyType(statment, useRussianScript, declaredProperty, types2,
|
||||
addWarningDeclaredNonReturningPropertyType(statment, useRussianScript, declaredProperty, missingTypes,
|
||||
resultAceptor);
|
||||
}
|
||||
}
|
||||
|
@ -20,3 +20,26 @@ Function Complaint() Export
|
||||
|
||||
EndFunction
|
||||
|
||||
// Returns:
|
||||
// Structure - complaint:
|
||||
// * Key1 - Number -
|
||||
// * Key2 - String -
|
||||
Function MissingReturnType() Export
|
||||
if (1 < 1) then
|
||||
return true;
|
||||
endif;
|
||||
|
||||
return new Structure("Key1, Key2", 10, "");
|
||||
EndFunction
|
||||
|
||||
// Returns:
|
||||
// Structure - complaint:
|
||||
// * Key1 - Number -
|
||||
// * Key2 - CommonModule -
|
||||
Function CorrectCheckForCommonModule() Export
|
||||
|
||||
return new Structure("Key1, Key2", 10, CommonModule);
|
||||
EndFunction
|
||||
|
||||
|
||||
|
||||
|
@ -387,11 +387,11 @@ public class CommonModuleStrictTypesTest
|
||||
Module module = updateAndGetModule(checkId);
|
||||
|
||||
List<Function> finctions = EcoreUtil2.eAllOfType(module, Function.class);
|
||||
assertEquals(2, finctions.size());
|
||||
assertEquals(4, finctions.size());
|
||||
|
||||
List<Marker> markers = getMarters(checkId, module);
|
||||
|
||||
assertEquals(2, markers.size());
|
||||
assertEquals(3, markers.size());
|
||||
|
||||
Marker marker = markers.get(0);
|
||||
assertEquals("9", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
@ -399,6 +399,10 @@ public class CommonModuleStrictTypesTest
|
||||
marker = markers.get(1);
|
||||
assertEquals("9", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
|
||||
// missing type
|
||||
marker = markers.get(2);
|
||||
assertEquals("29", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user