From 078e21a7c84f7768c006ac349ee781fbc5fef46c Mon Sep 17 00:00:00 2001 From: Dzyuba Maksim Date: Tue, 11 Apr 2023 09:01:49 +0300 Subject: [PATCH] =?UTF-8?q?G5V8DT-23259=20=D0=9F=D0=B0=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20NPE=20=D0=B2=20=D0=BA=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D1=81=D1=87=D0=B5=D1=82=D0=B0=20=D1=82=D0=B8=D0=BF=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../check/ReadingAttributesFromDataBaseCheck.java | 2 +- .../check/FunctionCtorReturnSectionCheck.java | 8 +++++++- .../check/InvocationParamIntersectionCheck.java | 4 +++- .../strict/check/SimpleStatementTypeCheck.java | 15 +++++++++------ .../TypedValueAddingToUntypedCollectionCheck.java | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/ReadingAttributesFromDataBaseCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/ReadingAttributesFromDataBaseCheck.java index 03e8b659..c440ed6c 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/ReadingAttributesFromDataBaseCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/check/ReadingAttributesFromDataBaseCheck.java @@ -138,7 +138,7 @@ public class ReadingAttributesFromDataBaseCheck } String typeName = McoreUtil.getTypeName(type); - if (McoreUtil.getTypeName(type) == null) + if (typeName == null) { return; } diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/FunctionCtorReturnSectionCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/FunctionCtorReturnSectionCheck.java index 8ac9d5fe..f531305a 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/FunctionCtorReturnSectionCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/FunctionCtorReturnSectionCheck.java @@ -283,7 +283,10 @@ public class FunctionCtorReturnSectionCheck .collect(Collectors.toList()); List types2 = types.stream() - .filter(t -> McoreUtil.getTypeName(t) != null && !declaredType.contains(McoreUtil.getTypeName(t))) + .filter(t -> { + String typeName = McoreUtil.getTypeName(t); + return typeName != null && !declaredType.contains(typeName); + }) .collect(Collectors.toList()); if (types.isEmpty()) { @@ -353,6 +356,7 @@ public class FunctionCtorReturnSectionCheck property.getTypes() .stream() .map(useRussianScript ? McoreUtil::getTypeNameRu : McoreUtil::getTypeName) + .filter(Objects::nonNull) .collect(Collectors.toList()))); resultAceptor.addIssue(message, statment, Literals.RETURN_STATEMENT__EXPRESSION); @@ -367,10 +371,12 @@ public class FunctionCtorReturnSectionCheck property.getTypes() .stream() .map(useRussianScript ? McoreUtil::getTypeNameRu : McoreUtil::getTypeName) + .filter(Objects::nonNull) .collect(Collectors.toList())), String.join(", ", //$NON-NLS-1$ missingTypes.stream() .map(useRussianScript ? McoreUtil::getTypeNameRu : McoreUtil::getTypeName) + .filter(Objects::nonNull) .collect(Collectors.toList()))); resultAceptor.addIssue(message, statment, Literals.RETURN_STATEMENT__EXPRESSION); diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java index af7453b9..aff12a7c 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/InvocationParamIntersectionCheck.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -491,7 +492,8 @@ public class InvocationParamIntersectionCheck ScriptVariant variant = project.getScriptVariant(); Function nameFunc = variant == ScriptVariant.RUSSIAN ? McoreUtil::getTypeNameRu : McoreUtil::getTypeName; - List typeNames = targetTypes.stream().map(nameFunc).collect(Collectors.toList()); + List typeNames = + targetTypes.stream().map(nameFunc).filter(Objects::nonNull).collect(Collectors.toList()); String name = parameter == null ? String.valueOf(index + 1) : parameter.getName(); if (parameter instanceof DuallyNamedElement && variant == ScriptVariant.RUSSIAN) diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/SimpleStatementTypeCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/SimpleStatementTypeCheck.java index 9a3ef2f1..fb0b88b3 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/SimpleStatementTypeCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/SimpleStatementTypeCheck.java @@ -17,7 +17,9 @@ import static com._1c.g5.v8.dt.bsl.model.BslPackage.Literals.SIMPLE_STATEMENT; import java.text.MessageFormat; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; @@ -35,7 +37,6 @@ import com._1c.g5.v8.dt.bsl.model.Invocation; import com._1c.g5.v8.dt.bsl.model.SimpleStatement; import com._1c.g5.v8.dt.bsl.model.StaticFeatureAccess; import com._1c.g5.v8.dt.bsl.model.Variable; -import com._1c.g5.v8.dt.bsl.util.BslUtil; 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.IV8ProjectManager; @@ -50,7 +51,6 @@ import com.e1c.g5.v8.dt.check.ICheckParameters; import com.e1c.g5.v8.dt.check.components.ModuleTopObjectNameFilterExtension; import com.e1c.g5.v8.dt.check.settings.IssueSeverity; import com.e1c.g5.v8.dt.check.settings.IssueType; -import com.google.common.collect.Sets; import com.google.inject.Inject; /** @@ -204,11 +204,14 @@ public class SimpleStatementTypeCheck return false; } - Set targetNames = Sets.newLinkedHashSet(BslUtil.transform(target, BslUtil.TYPE_NAME)); - - if (canResetToUndefined && targetNames.contains(IEObjectTypeNames.UNDEFINED) && targetNames.size() == 1) + if (canResetToUndefined) { - return true; + Set targetNames = + target.stream().map(McoreUtil::getTypeName).filter(Objects::nonNull).collect(Collectors.toSet()); + if (targetNames.contains(IEObjectTypeNames.UNDEFINED) && targetNames.size() == 1) + { + return true; + } } return intersectTypeItem(source, target, context); diff --git a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/TypedValueAddingToUntypedCollectionCheck.java b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/TypedValueAddingToUntypedCollectionCheck.java index 105c096f..1b5a5be8 100644 --- a/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/TypedValueAddingToUntypedCollectionCheck.java +++ b/bundles/com.e1c.v8codestyle.bsl/src/com/e1c/v8codestyle/bsl/strict/check/TypedValueAddingToUntypedCollectionCheck.java @@ -216,7 +216,7 @@ public class TypedValueAddingToUntypedCollectionCheck private boolean isActualCollectionItemTypeEmpty(Collection actualTypes) { - actualTypes.removeIf(p -> McoreUtil.getTypeName(p).equals(IEObjectTypeNames.ARBITRARY)); + actualTypes.removeIf(p -> IEObjectTypeNames.ARBITRARY.equals(McoreUtil.getTypeName(p))); return actualTypes.isEmpty(); }