From 57eed0c55657138b51ea7927dc127d4b5cb86244 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 4 Jul 2024 14:28:32 +0530 Subject: [PATCH 1/4] Remove public construct check for configurables --- .../main/java/org/ballerinalang/docgen/Generator.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java index 6ebaa7c740fb..9747a08bb2cf 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java @@ -164,16 +164,15 @@ public static boolean setModuleFromSyntaxTree(Module module, SyntaxTree syntaxTr ((EnumDeclarationNode) node).qualifier().isPresent() && ((EnumDeclarationNode) node).qualifier().get().kind().equals(SyntaxKind.PUBLIC_KEYWORD)) { module.enums.add(getEnumModel((EnumDeclarationNode) node)); - } else if (node.kind() == SyntaxKind.MODULE_VAR_DECL && - ((ModuleVariableDeclarationNode) node).visibilityQualifier().isPresent() && - ((ModuleVariableDeclarationNode) node).visibilityQualifier().get().kind() - .equals(SyntaxKind.PUBLIC_KEYWORD)) { + } else if (node.kind() == SyntaxKind.MODULE_VAR_DECL) { DefaultableVariable defaultableVariable = getModuleVariable((ModuleVariableDeclarationNode) node, semanticModel, module); if (containsToken(((ModuleVariableDeclarationNode) node).qualifiers(), SyntaxKind.CONFIGURABLE_KEYWORD)) { module.configurables.add(defaultableVariable); - } else { + } else if (((ModuleVariableDeclarationNode) node).visibilityQualifier().isPresent() && + ((ModuleVariableDeclarationNode) node).visibilityQualifier().get().kind() + .equals(SyntaxKind.PUBLIC_KEYWORD)) { module.variables.add(defaultableVariable); } } From fce9514149400568609c14bfd4410a998b6c22ef Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Thu, 25 Jul 2024 15:25:35 +0530 Subject: [PATCH 2/4] Address review suggestions --- .../main/java/org/ballerinalang/docgen/Generator.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java index 9747a08bb2cf..f8fcb42e3b07 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java @@ -165,13 +165,14 @@ public static boolean setModuleFromSyntaxTree(Module module, SyntaxTree syntaxTr ((EnumDeclarationNode) node).qualifier().get().kind().equals(SyntaxKind.PUBLIC_KEYWORD)) { module.enums.add(getEnumModel((EnumDeclarationNode) node)); } else if (node.kind() == SyntaxKind.MODULE_VAR_DECL) { - DefaultableVariable defaultableVariable = getModuleVariable((ModuleVariableDeclarationNode) node, + ModuleVariableDeclarationNode variableDeclarationNode = (ModuleVariableDeclarationNode) node; + DefaultableVariable defaultableVariable = getModuleVariable(variableDeclarationNode, semanticModel, module); - if (containsToken(((ModuleVariableDeclarationNode) node).qualifiers(), + if (containsToken(variableDeclarationNode.qualifiers(), SyntaxKind.CONFIGURABLE_KEYWORD)) { module.configurables.add(defaultableVariable); - } else if (((ModuleVariableDeclarationNode) node).visibilityQualifier().isPresent() && - ((ModuleVariableDeclarationNode) node).visibilityQualifier().get().kind() + } else if (variableDeclarationNode.visibilityQualifier().isPresent() && + variableDeclarationNode.visibilityQualifier().get().kind() .equals(SyntaxKind.PUBLIC_KEYWORD)) { module.variables.add(defaultableVariable); } From c570d53212d0b441f3d4f4213f7c731460162f76 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 26 Jul 2024 10:29:27 +0530 Subject: [PATCH 3/4] Add test for configurable variables in API doc gen --- .../test/documentation/DocModelTest.java | 23 +++++++++++++++++++ .../documentation/docerina_project/main.bal | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java index 0cc80329947b..1c060bfa174e 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java @@ -634,6 +634,29 @@ public void testModuleVariables() { Assert.assertEquals(tuple.get().type.memberTypes.get(1).category, "builtin"); } + @Test(description = "Test module configurable variables") + public void testModuleConfigurableVariables() { + Optional confString = testModule.configurables.stream() + .filter(client -> client.name.equals("confString")).findAny(); + Assert.assertTrue(confString.isPresent()); + + Assert.assertEquals(confString.get().description, "A configurable variable of string type without " + + "default value" + System.lineSeparator()); + Assert.assertEquals(confString.get().defaultValue, "\"?\""); + Assert.assertEquals(confString.get().type.category, "builtin"); + Assert.assertEquals(confString.get().type.name, "string"); + + Optional defaultConfString = testModule.configurables.stream() + .filter(client -> client.name.equals("defaultConfString")).findAny(); + Assert.assertTrue(defaultConfString.isPresent()); + + Assert.assertEquals(defaultConfString.get().description, "A configurable variable of string type with " + + "default value" + System.lineSeparator()); + Assert.assertEquals(defaultConfString.get().defaultValue, "\"confidential\""); + Assert.assertEquals(defaultConfString.get().type.category, "builtin"); + Assert.assertEquals(defaultConfString.get().type.name, "string"); + } + @Test(description = "Test record rest field") public void testRecordRestField() { Optional keyValRec = testModule.records.stream() diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/documentation/docerina_project/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/documentation/docerina_project/main.bal index b86a3836dfd2..761e292029e9 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/documentation/docerina_project/main.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/documentation/docerina_project/main.bal @@ -47,6 +47,12 @@ public [int, float] [a, b] = [1, 1.5]; # A public variable of string type public string pubString = "123"; +# A configurable variable of string type without default value +configurable string confString = ?; + +# A configurable variable of string type with default value +configurable string defaultConfString = "confidential"; + public type Coordinates record {| decimal latitude; decimal longitude; From 56ca67df800aa6eff835d6144a95bd91e1267900 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 26 Jul 2024 10:31:47 +0530 Subject: [PATCH 4/4] Update test --- .../java/org/ballerinalang/test/documentation/DocModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java index 1c060bfa174e..e45625443d04 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/documentation/DocModelTest.java @@ -642,7 +642,7 @@ public void testModuleConfigurableVariables() { Assert.assertEquals(confString.get().description, "A configurable variable of string type without " + "default value" + System.lineSeparator()); - Assert.assertEquals(confString.get().defaultValue, "\"?\""); + Assert.assertEquals(confString.get().defaultValue, "?"); Assert.assertEquals(confString.get().type.category, "builtin"); Assert.assertEquals(confString.get().type.name, "string");