You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-17 13:07:50 +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.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Spliterator;
|
||||||
|
import java.util.Spliterators;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.emf.ecore.resource.Resource;
|
import org.eclipse.emf.ecore.resource.Resource;
|
||||||
|
import org.eclipse.xtext.EcoreUtil2;
|
||||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||||
import org.eclipse.xtext.scoping.IScope;
|
import org.eclipse.xtext.scoping.IScope;
|
||||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||||
@ -152,11 +156,10 @@ public class FunctionCtorReturnSectionCheck
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkDocumentationCommentObject(IDescriptionPart object, BslDocumentationComment root,
|
protected void checkDocumentationCommentObject(IDescriptionPart object, BslDocumentationComment root,
|
||||||
DocumentationCommentResultAcceptor resultAceptor, ICheckParameters parameters,
|
DocumentationCommentResultAcceptor resultAceptor, ICheckParameters parameters, BmOperationContext context,
|
||||||
BmOperationContext context, IProgressMonitor monitor)
|
IProgressMonitor monitor)
|
||||||
{
|
{
|
||||||
if (monitor.isCanceled()
|
if (monitor.isCanceled() || !(root.getMethod() instanceof Function)
|
||||||
|| !(root.getMethod() instanceof Function)
|
|
||||||
|| parameters.getBoolean(PARAM_CHECK_ANNOTATION_IN_MODULE_DESCRIPTION)
|
|| parameters.getBoolean(PARAM_CHECK_ANNOTATION_IN_MODULE_DESCRIPTION)
|
||||||
&& !StrictTypeUtil.hasStrictTypeAnnotation(root.getModule()))
|
&& !StrictTypeUtil.hasStrictTypeAnnotation(root.getModule()))
|
||||||
{
|
{
|
||||||
@ -189,14 +192,13 @@ public class FunctionCtorReturnSectionCheck
|
|||||||
|
|
||||||
if (isUserDataTypes(computedReturnTypeNames, checkTypes))
|
if (isUserDataTypes(computedReturnTypeNames, checkTypes))
|
||||||
{
|
{
|
||||||
|
List<ReturnStatement> returns =
|
||||||
//@formatter:off
|
StreamSupport
|
||||||
List<ReturnStatement> returns = method.allStatements()
|
.stream(Spliterators.spliteratorUnknownSize(EcoreUtil2.getAllContents(method, false),
|
||||||
.stream()
|
Spliterator.ORDERED), false)
|
||||||
.filter(ReturnStatement.class::isInstance)
|
.filter(ReturnStatement.class::isInstance)
|
||||||
.map(ReturnStatement.class::cast)
|
.map(ReturnStatement.class::cast)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
//@formatter:on
|
|
||||||
|
|
||||||
Resource res = method.eResource();
|
Resource res = method.eResource();
|
||||||
|
|
||||||
@ -282,19 +284,25 @@ public class FunctionCtorReturnSectionCheck
|
|||||||
.flatMap(p -> p.getTypes().stream())
|
.flatMap(p -> p.getTypes().stream())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
List<TypeItem> types2 = types.stream()
|
List<TypeItem> missingTypes = types.stream().filter(t -> {
|
||||||
.filter(t -> {
|
|
||||||
String typeName = McoreUtil.getTypeName(t);
|
String typeName = McoreUtil.getTypeName(t);
|
||||||
return typeName != null && !declaredType.contains(typeName);
|
if (typeName != null)
|
||||||
})
|
{
|
||||||
.collect(Collectors.toList());
|
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())
|
if (types.isEmpty())
|
||||||
{
|
{
|
||||||
addWarningDeclaredNonReturningProperty(statment, useRussianScript, declaredProperty, resultAceptor);
|
addWarningDeclaredNonReturningProperty(statment, useRussianScript, declaredProperty, resultAceptor);
|
||||||
}
|
}
|
||||||
else if (!types2.isEmpty())
|
else if (!missingTypes.isEmpty())
|
||||||
{
|
{
|
||||||
addWarningDeclaredNonReturningPropertyType(statment, useRussianScript, declaredProperty, types2,
|
addWarningDeclaredNonReturningPropertyType(statment, useRussianScript, declaredProperty, missingTypes,
|
||||||
resultAceptor);
|
resultAceptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,3 +20,26 @@ Function Complaint() Export
|
|||||||
|
|
||||||
EndFunction
|
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);
|
Module module = updateAndGetModule(checkId);
|
||||||
|
|
||||||
List<Function> finctions = EcoreUtil2.eAllOfType(module, Function.class);
|
List<Function> finctions = EcoreUtil2.eAllOfType(module, Function.class);
|
||||||
assertEquals(2, finctions.size());
|
assertEquals(4, finctions.size());
|
||||||
|
|
||||||
List<Marker> markers = getMarters(checkId, module);
|
List<Marker> markers = getMarters(checkId, module);
|
||||||
|
|
||||||
assertEquals(2, markers.size());
|
assertEquals(3, markers.size());
|
||||||
|
|
||||||
Marker marker = markers.get(0);
|
Marker marker = markers.get(0);
|
||||||
assertEquals("9", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
assertEquals("9", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||||
@ -399,6 +399,10 @@ public class CommonModuleStrictTypesTest
|
|||||||
marker = markers.get(1);
|
marker = markers.get(1);
|
||||||
assertEquals("9", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
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