You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-07-17 21:17:41 +02:00
Merge pull request #1050 from 1C-Company/bugfix/994-common-module-type-intersect
Ложное срабатывание проверки: statement-type-change для типов общего
This commit is contained in:
@ -43,6 +43,7 @@
|
|||||||
- Ложное срабатывание проверки: invocation-parameter-type-intersect для Списка значений
|
- Ложное срабатывание проверки: invocation-parameter-type-intersect для Списка значений
|
||||||
- Ложное срабатывание проверки: invocation-parameter-type-intersect - для методов с несколькими вариантами вызова
|
- Ложное срабатывание проверки: invocation-parameter-type-intersect - для методов с несколькими вариантами вызова
|
||||||
- Ложное срабатывание проверки: doc-comment-ref-link Учет точки в конце ссылки на метод
|
- Ложное срабатывание проверки: doc-comment-ref-link Учет точки в конце ссылки на метод
|
||||||
|
- Ложное срабатывание проверки: statement-type-change для типов общего модуля
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import java.util.ArrayDeque;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -28,7 +29,9 @@ import org.eclipse.emf.ecore.EObject;
|
|||||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||||
import org.eclipse.xtext.EcoreUtil2;
|
import org.eclipse.xtext.EcoreUtil2;
|
||||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||||
|
import org.eclipse.xtext.naming.QualifiedName;
|
||||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||||
|
import org.eclipse.xtext.resource.IEObjectDescription;
|
||||||
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
import org.eclipse.xtext.resource.IResourceServiceProvider;
|
||||||
import org.eclipse.xtext.scoping.IScope;
|
import org.eclipse.xtext.scoping.IScope;
|
||||||
import org.eclipse.xtext.scoping.IScopeProvider;
|
import org.eclipse.xtext.scoping.IScopeProvider;
|
||||||
@ -82,6 +85,10 @@ public abstract class AbstractTypeCheck
|
|||||||
IEObjectDynamicTypeNames.BP_REF_TYPE_NAME, IEObjectDynamicTypeNames.BP_ROUTEPOINT_TYPE_NAME,
|
IEObjectDynamicTypeNames.BP_REF_TYPE_NAME, IEObjectDynamicTypeNames.BP_ROUTEPOINT_TYPE_NAME,
|
||||||
IEObjectDynamicTypeNames.TASK_REF_TYPE_NAME, IEObjectDynamicTypeNames.EXCHANGE_PLAN_REF_TYPE_NAME);
|
IEObjectDynamicTypeNames.TASK_REF_TYPE_NAME, IEObjectDynamicTypeNames.EXCHANGE_PLAN_REF_TYPE_NAME);
|
||||||
|
|
||||||
|
private static final String COMMON_MODULE = "CommonModule"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
private static final QualifiedName QN_COMMON_MODULE = QualifiedName.create(COMMON_MODULE);
|
||||||
|
|
||||||
/** The resource lookup service. */
|
/** The resource lookup service. */
|
||||||
protected final IResourceLookup resourceLookup;
|
protected final IResourceLookup resourceLookup;
|
||||||
|
|
||||||
@ -234,7 +241,7 @@ public abstract class AbstractTypeCheck
|
|||||||
* @param context {@link EObject} for resolving proxy checking types, cannot be <code>null</code>
|
* @param context {@link EObject} for resolving proxy checking types, cannot be <code>null</code>
|
||||||
* @return <code>true</code> if intersection was detected
|
* @return <code>true</code> if intersection was detected
|
||||||
*/
|
*/
|
||||||
protected static boolean intersectTypeItem(Collection<TypeItem> expectedTypes, Collection<TypeItem> realTypes,
|
protected boolean intersectTypeItem(Collection<TypeItem> expectedTypes, Collection<TypeItem> realTypes,
|
||||||
EObject context)
|
EObject context)
|
||||||
{
|
{
|
||||||
if (expectedTypes.isEmpty())
|
if (expectedTypes.isEmpty())
|
||||||
@ -255,7 +262,7 @@ public abstract class AbstractTypeCheck
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Collection<TypeItem> withParentTypes = getParentTypes(realTypes, context);
|
Collection<TypeItem> withParentTypes = getParentsOfRealTypes(realTypes, context);
|
||||||
Collection<String> realTypesNames = getTypeNames(withParentTypes, context);
|
Collection<String> realTypesNames = getTypeNames(withParentTypes, context);
|
||||||
|
|
||||||
if (!expectedTypesNames.isEmpty() && !realTypesNames.isEmpty())
|
if (!expectedTypesNames.isEmpty() && !realTypesNames.isEmpty())
|
||||||
@ -282,10 +289,10 @@ public abstract class AbstractTypeCheck
|
|||||||
return castTypeNames;
|
return castTypeNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<TypeItem> getParentTypes(Collection<TypeItem> theFirstCollectionTypes, EObject context)
|
private Collection<TypeItem> getParentsOfRealTypes(Collection<TypeItem> realTypes, EObject context)
|
||||||
{
|
{
|
||||||
Deque<TypeItem> types = new ArrayDeque<>(theFirstCollectionTypes);
|
Deque<TypeItem> types = new ArrayDeque<>(realTypes);
|
||||||
List<TypeItem> parentTypes = new ArrayList<>();
|
List<TypeItem> parentTypes = new LinkedList<>();
|
||||||
while (!types.isEmpty())
|
while (!types.isEmpty())
|
||||||
{
|
{
|
||||||
TypeItem type = types.pollFirst();
|
TypeItem type = types.pollFirst();
|
||||||
@ -299,6 +306,20 @@ public abstract class AbstractTypeCheck
|
|||||||
{
|
{
|
||||||
types.add(((Type)type).getParentType());
|
types.add(((Type)type).getParentType());
|
||||||
}
|
}
|
||||||
|
else if (type instanceof Type && COMMON_MODULE.equals(McoreUtil.getTypeCategory(type)))
|
||||||
|
{
|
||||||
|
// Here is bypass of wrong type hierarchy of types for common modules
|
||||||
|
IScope typeScope = scopeProvider.getScope(context, McorePackage.Literals.TYPE_DESCRIPTION__TYPES);
|
||||||
|
IEObjectDescription element = typeScope.getSingleElement(QN_COMMON_MODULE);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
EObject parentCommonModuleType = element.getEObjectOrProxy();
|
||||||
|
if (parentCommonModuleType instanceof TypeItem)
|
||||||
|
{
|
||||||
|
parentTypes.add((TypeItem)parentCommonModuleType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return parentTypes;
|
return parentTypes;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
// @strict-types
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// Module - CommonModule - abstract type of any common module
|
||||||
|
Procedure NonComplaint(Module) Export
|
||||||
|
Module = 10;
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
// Parameters:
|
||||||
|
// Module - CommonModule - abstract type of any common module
|
||||||
|
Procedure Complaint(Module) Export
|
||||||
|
Module = CommonModule; // here is the name of common module
|
||||||
|
EndProcedure
|
@ -350,6 +350,29 @@ public class CommonModuleStrictTypesTest
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of {@link SimpleStatementTypeCheck} that the statement change type of existing object type.
|
||||||
|
* Should correctly intersects with {@code CommonModule} type
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSimpleStatementTypeCheckCommonModule() throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
String checkId = "statement-type-change";
|
||||||
|
String resourceName = "statement-type-change-common-module";
|
||||||
|
|
||||||
|
Module module = updateAndGetModule(resourceName);
|
||||||
|
|
||||||
|
List<Marker> markers = getMarters(checkId, module);
|
||||||
|
assertEquals(1, markers.size());
|
||||||
|
|
||||||
|
Marker marker = markers.get(0);
|
||||||
|
assertEquals("6", marker.getExtraInfo().get(IExtraInfoKeys.TEXT_EXTRA_INFO_LINE_KEY));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of {@link FunctionCtorReturnSectionCheck} that the statement change type of existing object type.
|
* Test of {@link FunctionCtorReturnSectionCheck} that the statement change type of existing object type.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user