From 19832c00117d42d97048b443dd2824c6da3ec37d Mon Sep 17 00:00:00 2001 From: bhashinee Date: Mon, 1 Apr 2024 11:50:36 +0530 Subject: [PATCH] Address review suggstions --- .../compiler/PersistModelDefinitionValidator.java | 3 --- .../stdlib/persist/compiler/utils/Utils.java | 2 +- .../compiler/utils/ValidatorsByDatastore.java | 14 +++++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java index ebc7d214..2ea3de93 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/PersistModelDefinitionValidator.java @@ -134,9 +134,6 @@ public void perform(SyntaxNodeAnalysisContext ctx) { try { datastore = getDatastore(ctx); } catch (BalException e) { - if (e.getMessage().contains("the persist.datastore configuration does not exist")) { - return; - } throw new RuntimeException(e); } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java index 8940892f..e5e7d4a1 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/Utils.java @@ -221,7 +221,7 @@ private static String getDataStoreName(Path configPath) throws BalException { } } } - throw new BalException("the persist.datastore configuration does not exist in the Ballerina.toml file"); + return null; } catch (IOException e) { throw new BalException("error while reading persist configurations. " + e.getMessage()); } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java index b58d4bbd..811856ca 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/persist/compiler/utils/ValidatorsByDatastore.java @@ -55,7 +55,7 @@ public static boolean validateSimpleTypes(Entity entity, Node typeNode, String t List> properties, String type, String datastore) { boolean validFlag = true; - if (isOptionalType && datastore.equals(Constants.Datastores.GOOGLE_SHEETS)) { + if (isOptionalType && Constants.Datastores.GOOGLE_SHEETS.equals(datastore)) { entity.reportDiagnostic(PERSIST_308.getCode(), MessageFormat.format(PERSIST_308.getMessage(), type), PERSIST_308.getSeverity(), typeNode.location(), properties); @@ -87,6 +87,10 @@ public static boolean validateSimpleTypes(Entity entity, Node typeNode, String t } public static boolean isValidSimpleType(String type, String datastore) { + // If the datastore is null(ex: generate command), ignore the data type validation. + if (null == datastore) { + return true; + } switch (datastore) { case Constants.Datastores.MYSQL: return isValidMysqlType(type); @@ -104,6 +108,10 @@ public static boolean isValidSimpleType(String type, String datastore) { } public static boolean isValidArrayType(String type, String datastore) { + // If the datastore is null(ex: generate command), ignore the data type validation. + if (null == datastore) { + return true; + } switch (datastore) { case Constants.Datastores.MYSQL: return isValidMysqlArrayType(type); @@ -121,6 +129,10 @@ public static boolean isValidArrayType(String type, String datastore) { } public static boolean isValidImportedType(String modulePrefix, String identifier, String datastore) { + // If the datastore is null(ex: generate command), ignore the data type validation. + if (null == datastore) { + return true; + } switch (datastore) { case Constants.Datastores.MYSQL: return isValidMysqlImportedType(modulePrefix, identifier);