You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2026-05-18 10:01:04 +02:00
G5V8DT-28953 Ложные ошибки в строгой типизации при выключенной валидации
по определенному окружению
This commit is contained in:
+10
-29
@@ -21,7 +21,6 @@ import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.EcoreUtil2;
|
||||
import org.eclipse.xtext.naming.IQualifiedNameConverter;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmTransaction;
|
||||
@@ -35,7 +34,6 @@ import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.mcore.Environmental;
|
||||
import com._1c.g5.v8.dt.mcore.TypeItem;
|
||||
import com._1c.g5.v8.dt.mcore.util.Environments;
|
||||
import com._1c.g5.v8.dt.mcore.util.McoreUtil;
|
||||
@@ -135,11 +133,16 @@ public abstract class AbstractDynamicFeatureAccessTypeCheck
|
||||
{
|
||||
return;
|
||||
}
|
||||
Environments actualEnvs = getActualEnvironments(fa);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isMethod = BslUtil.getInvocation(fa) != null;
|
||||
if (isMethod == isCheckDfaMethod()
|
||||
&& (isMethod && isEmptySource(fa) || !isMethod && isEmptyTypes(fa, bmTransaction)) && !monitor.isCanceled()
|
||||
&& !isSkipSourceType(fa, parameters, monitor))
|
||||
&& (isMethod && isEmptySource(fa, actualEnvs) || !isMethod && isEmptyTypes(fa, actualEnvs, bmTransaction))
|
||||
&& !monitor.isCanceled() && !isSkipSourceType(fa, actualEnvs, parameters, monitor))
|
||||
{
|
||||
String message = getErrorMessage(fa);
|
||||
|
||||
@@ -147,24 +150,14 @@ public abstract class AbstractDynamicFeatureAccessTypeCheck
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmptySource(DynamicFeatureAccess object)
|
||||
private boolean isEmptySource(DynamicFeatureAccess object, Environments actualEnvs)
|
||||
{
|
||||
Environmental envs = EcoreUtil2.getContainerOfType(object, Environmental.class);
|
||||
if (envs == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Environments actualEnvs = bslPreferences.getLoadEnvs(object).intersect(envs.environments());
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
List<FeatureEntry> objects = dynamicFeatureAccessComputer.getLastObject(object, actualEnvs);
|
||||
return objects.isEmpty();
|
||||
}
|
||||
|
||||
private boolean isSkipSourceType(DynamicFeatureAccess fa, ICheckParameters parameters, IProgressMonitor monitor)
|
||||
private boolean isSkipSourceType(DynamicFeatureAccess fa, Environments actualEnvs, ICheckParameters parameters,
|
||||
IProgressMonitor monitor)
|
||||
{
|
||||
String typesString = parameters.getString(PARAMETER_SKIP_SOURCE_TYPES);
|
||||
if (StringUtils.isBlank(typesString))
|
||||
@@ -180,18 +173,6 @@ public abstract class AbstractDynamicFeatureAccessTypeCheck
|
||||
}
|
||||
Expression source = fa.getSource();
|
||||
|
||||
Environmental envs = EcoreUtil2.getContainerOfType(source, Environmental.class);
|
||||
if (monitor.isCanceled() || envs == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Environments actualEnvs = bslPreferences.getLoadEnvs(source).intersect(envs.environments());
|
||||
if (monitor.isCanceled() || actualEnvs.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
List<TypeItem> types = computeTypes(source, actualEnvs);
|
||||
return !monitor.isCanceled() && !types.isEmpty() && types.stream().anyMatch(t -> {
|
||||
String typeName = McoreUtil.getTypeName(t);
|
||||
|
||||
+1
-12
@@ -168,19 +168,8 @@ public abstract class AbstractTypeCheck
|
||||
* @param object the object, cannot be {@code null}.
|
||||
* @return true, if the object has empty types
|
||||
*/
|
||||
protected boolean isEmptyTypes(EObject object, IBmTransaction bmTransaction)
|
||||
protected boolean isEmptyTypes(EObject object, Environments actualEnvs, IBmTransaction bmTransaction)
|
||||
{
|
||||
Environmental envs = EcoreUtil2.getContainerOfType(object, Environmental.class);
|
||||
if (envs == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Environments actualEnvs = bslPreferences.getLoadEnvs(object).intersect(envs.environments());
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (object instanceof Invocation && !actualEnvs.containsAny(Environments.SERVER)
|
||||
&& ((Invocation)object).isIsServerCall())
|
||||
{
|
||||
|
||||
+8
-2
@@ -24,6 +24,7 @@ import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.mcore.McorePackage;
|
||||
import com._1c.g5.v8.dt.mcore.util.Environments;
|
||||
import com.e1c.g5.dt.core.api.naming.INamingService;
|
||||
import com.e1c.g5.v8.dt.check.CheckComplexity;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
@@ -85,12 +86,17 @@ public class FunctionReturnTypeCheck
|
||||
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
|
||||
IBmTransaction bmTransaction, IProgressMonitor monitor)
|
||||
{
|
||||
if (monitor.isCanceled() || !(object instanceof EObject))
|
||||
if (monitor.isCanceled() || !(object instanceof EObject eObject))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Environments actualEnvs = getActualEnvironments(eObject);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEmptyTypes((EObject)object, bmTransaction))
|
||||
if (isEmptyTypes((EObject)object, actualEnvs, bmTransaction))
|
||||
{
|
||||
resultAceptor.addIssue(Messages.FunctionReturnTypeCheck_Function_has_no_return_value_type,
|
||||
McorePackage.Literals.NAMED_ELEMENT__NAME);
|
||||
|
||||
+8
-1
@@ -28,6 +28,7 @@ import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.mcore.util.Environments;
|
||||
import com.e1c.g5.dt.core.api.naming.INamingService;
|
||||
import com.e1c.g5.v8.dt.check.CheckComplexity;
|
||||
import com.e1c.g5.v8.dt.check.ICheckParameters;
|
||||
@@ -96,7 +97,13 @@ public class MethodParamTypeCheck
|
||||
|
||||
FormalParam param = (FormalParam)object;
|
||||
|
||||
if (isEmptyTypes(param, bmTransaction))
|
||||
Environments actualEnvs = getActualEnvironments(param);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEmptyTypes(param, actualEnvs, bmTransaction))
|
||||
{
|
||||
String message =
|
||||
MessageFormat.format(Messages.MethodParamTypeCheck_Method_param_N_has_no_value_type, param.getName());
|
||||
|
||||
+8
-1
@@ -31,6 +31,7 @@ import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8Project;
|
||||
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
|
||||
import com._1c.g5.v8.dt.mcore.util.Environments;
|
||||
import com._1c.g5.v8.dt.mcore.util.McoreUtil;
|
||||
import com._1c.g5.v8.dt.platform.IEObjectTypeNames;
|
||||
import com.e1c.g5.dt.core.api.naming.INamingService;
|
||||
@@ -102,6 +103,12 @@ public class StructureCtorValueTypeCheck
|
||||
return;
|
||||
}
|
||||
|
||||
Environments actualEnvs = getActualEnvironments(osc);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StringLiteral literal = (StringLiteral)osc.getParams().get(0);
|
||||
|
||||
String content = String.join("", literal.lines(true)); //$NON-NLS-1$
|
||||
@@ -119,7 +126,7 @@ public class StructureCtorValueTypeCheck
|
||||
if (totalParams > i && osc.getParams().get(i + 1) != null)
|
||||
{
|
||||
Expression param = osc.getParams().get(i + 1);
|
||||
if (isEmptyTypes(param, bmTransaction))
|
||||
if (isEmptyTypes(param, actualEnvs, bmTransaction))
|
||||
{
|
||||
param = param instanceof EmptyExpression ? literal : param;
|
||||
String message = MessageFormat.format(
|
||||
|
||||
+11
-3
@@ -131,18 +131,26 @@ public class VariableTypeCheck
|
||||
private void checkVariable(Variable variable, EObject checkObject, ResultAcceptor resultAceptor,
|
||||
IBmTransaction bmTransaction, IProgressMonitor monitor)
|
||||
{
|
||||
Environments actualEnvs;
|
||||
if (variable instanceof Environmental)
|
||||
{
|
||||
//checks only variables with selected validation Environments
|
||||
Environments actualEnvs =
|
||||
bslPreferences.getLoadEnvs(checkObject).intersect(((Environmental)variable).environments());
|
||||
actualEnvs = getActualEnvironments(variable);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
actualEnvs = getActualEnvironments(checkObject);
|
||||
if (actualEnvs.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkObject != null && variable != null && isEmptyTypes(checkObject, bmTransaction)
|
||||
if (checkObject != null && variable != null && isEmptyTypes(checkObject, actualEnvs, bmTransaction)
|
||||
&& !monitor.isCanceled())
|
||||
{
|
||||
String message =
|
||||
|
||||
Reference in New Issue
Block a user