From 2c98498dc028bcf35e2b16fcbcc0310e167abb0d Mon Sep 17 00:00:00 2001 From: Chiran Fernando Date: Mon, 24 Oct 2022 11:41:29 +0530 Subject: [PATCH 001/209] Get type intersection for lhs false and rhs true --- .../compiler/semantics/analyzer/TypeNarrower.java | 8 ++++++-- .../test/statements/ifelse/TypeGuardTest.java | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeNarrower.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeNarrower.java index fb7b68f28dde..f280ce8fd2e3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeNarrower.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeNarrower.java @@ -345,8 +345,12 @@ private NarrowedTypes getNarrowedTypesForBinaryOp(Map var nonLoggingContext = Types.IntersectionContext.typeTestIntersectionCalculationContext(); if (operator == OperatorKind.AND) { trueType = types.getTypeIntersection(nonLoggingContext, lhsTrueType, rhsTrueType, this.env); - BType tmpType = types.getTypeIntersection(nonLoggingContext, lhsTrueType, rhsFalseType, this.env); - falseType = getTypeUnion(lhsFalseType, tmpType); + BType tmpType1 = types.getTypeIntersection(nonLoggingContext, lhsTrueType, rhsFalseType, this.env); + BType tmpType2 = types.getTypeIntersection(nonLoggingContext, lhsFalseType, rhsTrueType, this.env); + if (tmpType1.tag == TypeTags.SEMANTIC_ERROR) { + tmpType1 = tmpType2; + } + falseType = getTypeUnion(lhsFalseType, tmpType1); } else { BType tmpType = types.getTypeIntersection(nonLoggingContext, lhsFalseType, rhsTrueType, this.env); trueType = lhsTypes.containsKey(symbol) ? getTypeUnion(lhsTrueType, tmpType) : diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java index 064f81b60b7a..24b2a9f5260c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java @@ -142,6 +142,8 @@ public void testTypeGuardSemanticsNegative() { // 190, 17); // BAssertUtil.validateError(negativeResult, i++, // "incompatible types: expected 'string', found '(boolean|int|string)'", 192, 20); + BAssertUtil.validateError(negativeResult, i++, + "incompatible types: expected 'string', found 'boolean'", 192, 20); BAssertUtil.validateError(negativeResult, i++, "incompatible types: expected 'int', found '(int|boolean)'", 199, 17); BAssertUtil.validateError(negativeResult, i++, "incompatible types: expected 'string', found '(float|string)'", From d08e7ea6ff84cfb508e2e69064cda16badc327e0 Mon Sep 17 00:00:00 2001 From: Chiran Fernando Date: Mon, 24 Oct 2022 11:57:00 +0530 Subject: [PATCH 002/209] Add singleton type narrowing tests --- .../test/statements/ifelse/TypeGuardTest.java | 5 +++ .../test-src/statements/ifelse/type-guard.bal | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java index 24b2a9f5260c..9afe4df2bbc1 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/ifelse/TypeGuardTest.java @@ -753,6 +753,11 @@ public void testCustomCircularTupleTypeWithIsCheck() { BRunUtil.invoke(result, "testCustomCircularTupleTypeWithIsCheck"); } + @Test + public void testSingletonTypeNarrowedTypeDesc() { + BRunUtil.invoke(result, "testSingletonTypeNarrowedTypeDesc"); + } + @Test public void testTypeGuardsAccountingForSemTypes1() { CompileResult result = BCompileUtil.compile("test-src/statements/ifelse/test_type_guard_sem_types_1.bal"); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/statements/ifelse/type-guard.bal b/tests/jballerina-unit-test/src/test/resources/test-src/statements/ifelse/type-guard.bal index 4c4ecd5d090d..72acd764670c 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/statements/ifelse/type-guard.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/statements/ifelse/type-guard.bal @@ -1815,6 +1815,47 @@ function checkIsExpressionWithCircularTuple2(Type t) returns string? { } } +function testSingletonTypeNarrowedTypeDesc() { + assertEquality(testSingletonTypeNarrowedTypeDesc1(1,1), 1); + assertEquality(testSingletonTypeNarrowedTypeDesc2(3,1), 3); + assertEquality(testSingletonTypeNarrowedTypeDesc3("","abc"), "abc"); +} + +function testSingletonTypeNarrowedTypeDesc1(int foo, int bar) returns int { + if foo != 1 { + return foo; + } else if bar != 1 && foo == 1 { + return bar; + } else if foo == 1 && bar == 1 { + return 1; + } + return -1; +} + +function testSingletonTypeNarrowedTypeDesc2(1|2|3 foo, int bar) returns int { + if foo == 1 { + return foo; + } else if bar != 1 && foo == 2 { + return bar; + } else if foo == 3 && bar == 1 { + return 3; + } + return -1; +} + +function testSingletonTypeNarrowedTypeDesc3(string foo, string bar) returns string { + if foo != "" { + return foo; + } + if bar != "" && foo == "" { + return bar; + } + if foo == "" && bar == "" { + return ""; + } + return ""; +} + function assertTrue(anydata actual) { assertEquality(true, actual); } From 767c9c359602d880c3f2c781d6c0acf0d5815745 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Tue, 21 Nov 2023 11:33:23 +0530 Subject: [PATCH 003/209] Add push,pull support --- .../io/ballerina/cli/cmd/PushCommand.java | 54 +++++++++++ .../io/ballerina/cli/cmd/ToolCommand.java | 96 ++++++++++++++++--- .../cli/launcher/util/BalToolsUtil.java | 5 +- .../ballerina/projects/BalToolsManifest.java | 47 +++++---- .../io/ballerina/projects/BalToolsToml.java | 28 ++++-- .../internal/BalToolsManifestBuilder.java | 13 ++- 6 files changed, 198 insertions(+), 45 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java index ff3ee3e9cc70..fa3b4a658c7f 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java @@ -17,6 +17,9 @@ */ package io.ballerina.cli.cmd; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import io.ballerina.cli.BLauncherCmd; import io.ballerina.cli.utils.FileUtils; import io.ballerina.projects.DependencyManifest; @@ -44,9 +47,12 @@ import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; +import java.io.BufferedReader; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -389,6 +395,7 @@ private void pushBalaToCustomRepo(Path balaFilePath) { ProjectUtils.deleteDirectory(balaCachesPath); } ProjectUtils.extractBala(balaFilePath, balaDestPath); + handleLocalTools(balaDestPath, org, packageName, repoPath.resolve(ProjectConstants.BALA_DIR_NAME)); } catch (IOException e) { throw new ProjectException("error while pushing bala file '" + balaFilePath + "' to '" + ProjectConstants.LOCAL_REPOSITORY_NAME + "' repository. " + e.getMessage()); @@ -404,6 +411,53 @@ private void pushBalaToCustomRepo(Path balaFilePath) { + " to '" + repositoryName + "' repository."); } + private void handleLocalTools(Path balaDestPath, String org, String packageName, Path localRepoBalaPath) { + Path balToolJsonPath = balaDestPath.resolve("tool").resolve("bal-tool.json"); + String toolId = null; + JsonObject balToolJson; + JsonObject localToolJson; + Gson gson = new Gson(); + if (!balToolJsonPath.toFile().exists()) { + return; + } + try (BufferedReader bufferedReader = Files.newBufferedReader(balToolJsonPath, StandardCharsets.UTF_8)) { + balToolJson = gson.fromJson(bufferedReader, JsonObject.class); + } catch (IOException e) { + throw new ProjectException("Failed to read bal-tools.json file: " + e.getMessage()); + } + toolId = balToolJson.get("tool_id").getAsString(); + + if (toolId == null) { + return; + } + + JsonObject packageDesc = new JsonObject(); + packageDesc.addProperty("org", org); + packageDesc.addProperty("name", packageName); + Path localToolJsonPath = localRepoBalaPath.resolve("local-tools.json"); + if (localToolJsonPath.toFile().exists()) { + try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, + StandardCharsets.UTF_8)) { + localToolJson = gson.fromJson(bufferedReader, JsonObject.class); + if (localToolJson.has(toolId)) { + localToolJson.remove(toolId); + } + localToolJson.add(toolId, packageDesc); + } catch (IOException e) { + throw new ProjectException("Failed to read local-tools.json file: " + e.getMessage()); + } + } else { + localToolJson = new JsonObject(); + localToolJson.add(toolId, packageDesc); + } + + try (FileWriter writer = new FileWriter(localToolJsonPath.toFile())) { + writer.write(gson.toJson(localToolJson)); + } catch (IOException e) { + throw new ProjectException("Failed to write local-tools.json file: " + e.getMessage()); + } + } + /** * Push a bala file to remote repository. * diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java index 509c966daf05..b855bc2b7f67 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java @@ -18,6 +18,8 @@ package io.ballerina.cli.cmd; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import io.ballerina.cli.BLauncherCmd; import io.ballerina.cli.utils.PrintUtils; import io.ballerina.projects.BalToolsManifest; @@ -42,8 +44,10 @@ import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; +import java.io.BufferedReader; import java.io.IOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -88,6 +92,7 @@ public class ToolCommand implements BLauncherCmd { private static final String TOOL_REMOVE_USAGE_TEXT = "bal tool remove :[]"; private static final String TOOL_SEARCH_USAGE_TEXT = "bal tool search [|]"; private static final String TOOL_UPDATE_USAGE_TEXT = "bal tool update "; + private static final String EMPTY_STRING = ""; private final boolean exitWhenFinish; private final PrintStream outStream; @@ -101,6 +106,9 @@ public class ToolCommand implements BLauncherCmd { @CommandLine.Option(names = {"--help", "-h"}, hidden = true) private boolean helpFlag; + @CommandLine.Option(names = "--repository") + private String repositoryName; + private String toolId; private String org; private String name; @@ -151,6 +159,14 @@ public void execute() { return; } + if (repositoryName != null && !repositoryName.equals(ProjectConstants.LOCAL_REPOSITORY_NAME)) { + String errMsg = "unsupported repository '" + repositoryName + "' found. Only '" + + ProjectConstants.LOCAL_REPOSITORY_NAME + "' repository is supported."; + CommandUtil.printError(this.errStream, errMsg, null, false); + CommandUtil.exitError(this.exitWhenFinish); + return; + } + String command = argList.get(0); switch (command) { case TOOL_PULL_COMMAND -> handlePullCommand(); @@ -208,6 +224,13 @@ private void handlePullCommand() { return; } + if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName) && EMPTY_STRING.equals(version)) { + CommandUtil.printError(errStream, "a version should be provided when pulling a tool from local " + + "repository", null, false); + CommandUtil.exitError(this.exitWhenFinish); + return; + } + if (!validateToolName(toolId)) { CommandUtil.printError(errStream, "invalid tool id.", TOOL_PULL_USAGE_TEXT, false); CommandUtil.exitError(this.exitWhenFinish); @@ -269,7 +292,7 @@ private void handleUseCommand() { BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - Optional tool = balToolsManifest.getTool(toolId, version); + Optional tool = balToolsManifest.getTool(toolId, version, repositoryName); if (tool.isEmpty()) { CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not found. " + "Run 'bal tool pull " + toolId + ":" + version @@ -292,7 +315,7 @@ private void handleUseCommand() { return; } - balToolsManifest.setActiveToolVersion(toolId, version); + balToolsManifest.setActiveToolVersion(toolId, version, repositoryName); balToolsToml.modify(balToolsManifest); outStream.println("tool '" + toolId + ":" + version + "' successfully set as the active version."); } @@ -413,6 +436,15 @@ public void pullToolAndUpdateBalToolsToml(String toolIdArg, String versionArg) { String supportedPlatform = Arrays.stream(JvmTarget.values()) .map(JvmTarget::code) .collect(Collectors.joining(",")); + if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + if (!isToolAvailableInLocalRepo(toolId, version)) { + errStream.println("tool '" + toolId + ":" + version + "' is not available in local repository.\nPlease " + + "publish it first with 'bal push --repository=local' command."); + CommandUtil.exitError(this.exitWhenFinish); + } + addToBalToolsToml(); + return; + } try { if (isToolAvailableLocally(toolId, version)) { outStream.println("tool '" + toolId + ":" + version + "' is already available locally."); @@ -430,6 +462,31 @@ public void pullToolAndUpdateBalToolsToml(String toolIdArg, String versionArg) { } } + private boolean isToolAvailableInLocalRepo(String toolId, String version) { + JsonObject localToolJson; + Gson gson = new Gson(); + Path localBalaPath = RepoUtils.createAndGetHomeReposPath().resolve(Path.of(REPOSITORIES_DIR, + ProjectConstants.LOCAL_REPOSITORY_NAME, BALA_DIR_NAME)); + Path localToolJsonPath = localBalaPath.resolve("local-tools.json"); + + if (!Files.exists(localToolJsonPath)) { + return false; + } + + try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, StandardCharsets.UTF_8)) { + localToolJson = gson.fromJson(bufferedReader, JsonObject.class); + JsonObject pkgDesc = localToolJson.get(toolId).getAsJsonObject(); + if (pkgDesc.isEmpty()) { + return false; + } + org = pkgDesc.get("org").getAsString(); + name = pkgDesc.get("name").getAsString(); + return Files.exists(localBalaPath.resolve(org).resolve(name).resolve(version)); + } catch (IOException e) { + throw new ProjectException("Failed to read local-tools.json file: " + e.getMessage()); + } + } + private void pullToolFromCentral(String supportedPlatform, Path balaCacheDirPath) throws CentralClientException { Settings settings; try { @@ -475,7 +532,7 @@ private void addToBalToolsToml() { return; } - balToolsManifest.addTool(toolId, org, name, version, true); + balToolsManifest.addTool(toolId, org, name, version, true, repositoryName); balToolsToml.modify(balToolsManifest); outStream.println("tool '" + toolId + ":" + version + "' successfully set as the active version."); } @@ -485,7 +542,7 @@ private List listBalToolsTomlFile() { BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); List flattenedTools = new ArrayList<>(); balToolsManifest.tools().values().stream() - .flatMap(map -> map.values().stream()) + .flatMap(map -> map.values().stream()).flatMap(map -> map.values().stream()) .sorted(Comparator.comparing(BalToolsManifest.Tool::id) .thenComparing(BalToolsManifest.Tool::version).reversed()) .forEach(flattenedTools::add); @@ -496,7 +553,7 @@ private void removeAllToolVersions() { BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - Optional> toolVersions = + Optional>> toolVersions = Optional.ofNullable(balToolsManifest.tools().get(toolId)); if (toolVersions.isEmpty() || toolVersions.get().isEmpty()) { CommandUtil.printError(errStream, "tool '" + toolId + "' not found.", null, false); @@ -506,7 +563,8 @@ private void removeAllToolVersions() { balToolsManifest.removeTool(toolId); balToolsToml.modify(balToolsManifest); - Optional tool = toolVersions.get().values().stream().findAny(); + Optional tool = toolVersions.get().values().stream().findAny() + .flatMap(value -> value.values().stream().findAny()); tool.ifPresent(value -> deleteAllCachedToolVersions(value.org(), value.name())); outStream.println("tool '" + toolId + "' successfully removed."); } @@ -515,7 +573,7 @@ private void removeSpecificToolVersion() { BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - Optional tool = balToolsManifest.getTool(toolId, version); + Optional tool = balToolsManifest.getTool(toolId, version, repositoryName); if (tool.isEmpty()) { CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' not found.", null, false); CommandUtil.exitError(this.exitWhenFinish); @@ -536,7 +594,7 @@ private void removeSpecificToolVersion() { return; } - balToolsManifest.removeToolVersion(toolId, version); + balToolsManifest.removeToolVersion(toolId, version, repositoryName); balToolsToml.modify(balToolsManifest); deleteCachedToolVersion(tool.get().org(), tool.get().name(), version); outStream.println("tool '" + toolId + ":" + version + "' successfully removed."); @@ -597,7 +655,7 @@ private void searchToolsInCentral(String keyword) { } } catch (CentralClientException e) { String errorMessage = e.getMessage(); - if (null != errorMessage && !"".equals(errorMessage.trim())) { + if (null != errorMessage && !EMPTY_STRING.equals(errorMessage.trim())) { // removing the error stack if (errorMessage.contains("\n\tat")) { errorMessage = errorMessage.substring(0, errorMessage.indexOf("\n\tat")); @@ -617,7 +675,7 @@ private boolean isToolAvailableLocally(String toolId, String version) { } BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - Optional toolOptional = balToolsManifest.getTool(toolId, version); + Optional toolOptional = balToolsManifest.getTool(toolId, version, repositoryName); if (toolOptional.isEmpty()) { return false; } @@ -640,7 +698,9 @@ private boolean isToolAvailableLocally(String toolId, String version) { private boolean checkToolDistCompatibility() { SemanticVersion currentDistVersion = SemanticVersion.from(RepoUtils.getBallerinaShortVersion()); - SemanticVersion toolDistVersion = getToolDistVersionFromCentralCache(); + SemanticVersion toolDistVersion = ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName) + ? getToolDistVersionFromLocalCache() + : getToolDistVersionFromCentralCache(); if (!isCompatibleWithLocalDistVersion(currentDistVersion, toolDistVersion)) { CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not compatible with the " + "current Ballerina distribution '" + RepoUtils.getBallerinaShortVersion() + @@ -660,6 +720,15 @@ private SemanticVersion getToolDistVersionFromCentralCache() { return SemanticVersion.from(packageJson.getBallerinaVersion()); } + private SemanticVersion getToolDistVersionFromLocalCache() { + Path localBalaDirPath = ProjectUtils.createAndGetHomeReposPath() + .resolve(REPOSITORIES_DIR).resolve(ProjectConstants.LOCAL_REPOSITORY_NAME) + .resolve(ProjectConstants.BALA_DIR_NAME); + Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, localBalaDirPath); + PackageJson packageJson = BalaFiles.readPackageJson(balaPath); + return SemanticVersion.from(packageJson.getBallerinaVersion()); + } + private boolean isCompatibleWithLocalDistVersion(SemanticVersion localDistVersion, SemanticVersion toolDistVersion) { return localDistVersion.major() == toolDistVersion.major() @@ -673,8 +742,9 @@ private boolean isToolVersionAlreadyActive(String toolId, String version) { BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); if (balToolsManifest.tools().containsKey(toolId)) { - Map toolVersions = balToolsManifest.tools().get(toolId); - return toolVersions.containsKey(version) && toolVersions.get(version).active(); + Map> toolVersions = balToolsManifest.tools().get(toolId); + return toolVersions.containsKey(version) && toolVersions.get(version).containsKey(repositoryName) && + toolVersions.get(version).get(repositoryName).active(); } return false; } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java index 5b7393419c79..0d70291407b4 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java @@ -174,6 +174,7 @@ private static List getToolCommandJarAndDependencyJars(String commandName) // we load all tool jars for the help, default commands and --help, -h options if (HELP_COMMAND.equals(commandName)) { return balToolsManifest.tools().values().stream() + .flatMap(map -> map.values().stream()) .flatMap(map -> map.values().stream()) .filter(BalToolsManifest.Tool::active) .map(tool1 -> findJarFiles(CommandUtil.getPlatformSpecificBalaPath( @@ -270,8 +271,8 @@ public static void updateOldBalToolsToml() { boolean isActive = balToolsManifest.getActiveTool(tool.id()).isEmpty() && latestVersion.isPresent() && latestVersion.get().equals(version); - if (balToolsManifest.getTool(tool.id(), version).isEmpty()) { - balToolsManifest.addTool(tool.id(), tool.org(), tool.name(), version, isActive); + if (balToolsManifest.getTool(tool.id(), version, null).isEmpty()) { + balToolsManifest.addTool(tool.id(), tool.org(), tool.name(), version, isActive, null); } }); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java index fecdb77a02e9..4c5a7df6696c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java @@ -17,7 +17,10 @@ */ package io.ballerina.projects; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; @@ -27,9 +30,9 @@ * @since 2201.6.0 */ public class BalToolsManifest { - private final Map> tools; + private final Map>> tools; - private BalToolsManifest(Map> tools) { + private BalToolsManifest(Map>> tools) { this.tools = tools; } @@ -37,42 +40,46 @@ public static BalToolsManifest from() { return new BalToolsManifest(new HashMap<>()); } - public static BalToolsManifest from(Map> tools) { + public static BalToolsManifest from(Map>>tools) { return new BalToolsManifest(tools); } - public Map> tools() { + public Map>> tools() { return tools; } - public void addTool(String id, String org, String name, String version, Boolean active) { + public void addTool(String id, String org, String name, String version, Boolean active, String repository) { if (!tools.containsKey(id)) { tools.put(id, new HashMap<>()); } + if (!tools.get(id).containsKey(version)) { + tools.get(id).put(version, new HashMap<>()); + } + if (active) { flipCurrentActiveToolVersion(id); } - tools.get(id).put(version, new Tool(id, org, name, version, active)); + tools.get(id).get(version).put(repository, new Tool(id, org, name, version, active, repository)); } - public Optional getTool(String id, String version) { - if (tools.containsKey(id)) { - return Optional.ofNullable(tools.get(id).get(version)); + public Optional getTool(String id, String version, String repository) { + if (tools.containsKey(id) && tools.get(id).containsKey(version)) { + return Optional.ofNullable(tools.get(id).get(version).get(repository)); } return Optional.empty(); } public Optional getActiveTool(String id) { if (tools.containsKey(id)) { - return tools.get(id).values().stream().filter(Tool::active).findFirst(); + tools.get(id).values().stream().flatMap(v -> v.values().stream()).filter(Tool::active).findFirst(); } return Optional.empty(); } - public void setActiveToolVersion(String id, String version) { + public void setActiveToolVersion(String id, String version, String repository) { if (tools.containsKey(id)) { flipCurrentActiveToolVersion(id); - tools.get(id).get(version).setActive(true); + tools.get(id).get(version).get(repository).setActive(true); } } @@ -83,14 +90,14 @@ public void removeTool(String id) { tools.remove(id); } - public void removeToolVersion(String id, String version) { - if (tools.containsKey(id)) { - tools.get(id).remove(version); + public void removeToolVersion(String id, String version, String repository) { + if (tools.containsKey(id) && tools.get(id).containsKey(version)) { + tools.get(id).get(version).remove(repository); } } private void flipCurrentActiveToolVersion(String id) { - tools.get(id).forEach((k, v) -> v.setActive(false)); + tools.get(id).forEach((k, v) -> v.forEach((k1, v1) -> v1.setActive(false))); } /** @@ -104,13 +111,15 @@ public static class Tool { private final String name; private final String version; private Boolean active; + private String repository; - public Tool(String id, String org, String name, String version, Boolean active) { + public Tool(String id, String org, String name, String version, Boolean active, String repository) { this.id = id; this.org = org; this.name = name; this.version = version; this.active = active; + this.repository = repository; } public String id() { @@ -133,6 +142,10 @@ public Boolean active() { return active; } + public String repository() { + return repository; + } + public void setActive(boolean active) { this.active = active; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java index 34515b7ec492..e1c52b342006 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java @@ -29,6 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.Set; import static io.ballerina.projects.util.ProjectConstants.BAL_TOOLS_TOML; @@ -102,17 +103,26 @@ public void modify(BalToolsManifest balToolsManifest) { private String generateContent(BalToolsManifest balToolsManifest) { StringBuilder content = new StringBuilder(); content.append(getAutoGenCode()); - for (Map.Entry> toolVersions: balToolsManifest.tools().entrySet()) { - for (Map.Entry tool : toolVersions.getValue().entrySet()) { - content.append("[[tool]]\n"); - content.append("id = \"").append(tool.getValue().id()).append("\"\n"); - content.append("org = \"").append(tool.getValue().org()).append("\"\n"); - content.append("name = \"").append(tool.getValue().name()).append("\"\n"); - content.append("version = \"").append(tool.getValue().version()).append("\"\n"); - content.append("active = ").append(tool.getValue().active()).append("\n"); - content.append("\n"); + for (Map.Entry>> toolEntry : balToolsManifest.tools() + .entrySet()) { + for (Map.Entry> toolVersions : toolEntry.getValue().entrySet()) { + for (Map.Entry tool : toolVersions.getValue().entrySet()) { + content.append("[[tool]]\n"); + content.append("id = \"").append(tool.getValue().id()).append("\"\n"); + content.append("org = \"").append(tool.getValue().org()).append("\"\n"); + content.append("name = \"").append(tool.getValue().name()).append("\"\n"); + content.append("version = \"").append(tool.getValue().version()).append("\"\n"); + content.append("active = ").append(tool.getValue().active()).append("\n"); + if (tool.getValue().repository() != null) { + content.append("repository = \"").append(tool.getValue().repository()).append("\"\n"); + } + content.append("\n"); + } } } + + + return String.valueOf(content); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java index dd16749c360a..0ec73e7c110f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalToolsManifestBuilder.java @@ -84,7 +84,7 @@ private BalToolsManifest parseAsBalToolsManifest() { return BalToolsManifest.from(); } validateBalToolsTomlAgainstSchema(); - Map> tools = getTools(); + Map>> tools = getTools(); return BalToolsManifest.from(tools); } @@ -102,7 +102,7 @@ private void validateBalToolsTomlAgainstSchema() { balToolsTomlValidator.validate(balToolsToml.get().toml()); } - private Map> getTools() { + private Map>> getTools() { if (balToolsToml.isEmpty()) { return new HashMap<>(); } @@ -118,7 +118,7 @@ private Map> getTools() { return new HashMap<>(); } - Map> tools = new HashMap<>(); + Map>> tools = new HashMap<>(); if (toolEntries.kind() == TomlType.TABLE_ARRAY) { TomlTableArrayNode toolTableArray = (TomlTableArrayNode) toolEntries; @@ -128,6 +128,7 @@ private Map> getTools() { String name = getStringValueFromToolNode(toolNode, "name"); String version = getStringValueFromToolNode(toolNode, "version"); Optional active = getBooleanFromToolNode(toolNode, "active"); + String repository = getStringValueFromToolNode(toolNode, "repository"); // If id, org or name, one of the value is null, ignore tool record if (id == null || org == null || name == null) { @@ -148,7 +149,11 @@ private Map> getTools() { if (!tools.containsKey(id)) { tools.put(id, new HashMap<>()); } - tools.get(id).put(version, new BalToolsManifest.Tool(id, org, name, version, active.get())); + if (!tools.get(id).containsKey(version)) { + tools.get(id).put(version, new HashMap<>()); + } + tools.get(id).get(version).put(repository, new BalToolsManifest.Tool(id, org, name, version, + active.get(), repository)); } } return tools; From c228a5a3d7218edfdcc21f0adb916734d919902e Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Wed, 22 Nov 2023 08:46:42 +0530 Subject: [PATCH 004/209] Add use, remove support for local repo --- .../main/java/io/ballerina/cli/cmd/ToolCommand.java | 12 +++++++++++- .../java/io/ballerina/projects/BalToolsManifest.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java index b855bc2b7f67..11b0a8b8e72b 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java @@ -55,6 +55,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -304,7 +305,8 @@ private void handleUseCommand() { this.name = tool.get().name(); Optional currentActiveTool = balToolsManifest.getActiveTool(toolId); - if (currentActiveTool.isPresent() && currentActiveTool.get().version().equals(tool.get().version())) { + if (currentActiveTool.isPresent() && currentActiveTool.get().version().equals(tool.get().version()) && + Objects.equals(currentActiveTool.get().repository(), tool.get().repository())) { outStream.println("tool '" + toolId + ":" + version + "' is the current active version."); return; } @@ -563,6 +565,10 @@ private void removeAllToolVersions() { balToolsManifest.removeTool(toolId); balToolsToml.modify(balToolsManifest); + if (repositoryName != null) { + outStream.println("tool '" + toolId + "' successfully removed."); + return; + } Optional tool = toolVersions.get().values().stream().findAny() .flatMap(value -> value.values().stream().findAny()); tool.ifPresent(value -> deleteAllCachedToolVersions(value.org(), value.name())); @@ -596,6 +602,10 @@ private void removeSpecificToolVersion() { balToolsManifest.removeToolVersion(toolId, version, repositoryName); balToolsToml.modify(balToolsManifest); + if (repositoryName != null) { + outStream.println("tool '" + toolId + ":" + version + "' successfully removed."); + return; + } deleteCachedToolVersion(tool.get().org(), tool.get().name(), version); outStream.println("tool '" + toolId + ":" + version + "' successfully removed."); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java index 4c5a7df6696c..b0a0ba71bf30 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java @@ -71,7 +71,7 @@ public Optional getTool(String id, String version, String repository) { public Optional getActiveTool(String id) { if (tools.containsKey(id)) { - tools.get(id).values().stream().flatMap(v -> v.values().stream()).filter(Tool::active).findFirst(); + return tools.get(id).values().stream().flatMap(v -> v.values().stream()).filter(Tool::active).findFirst(); } return Optional.empty(); } From 3f563ee73c37e9abbbb2633ef4bcbdf67b1c0ab1 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Thu, 23 Nov 2023 09:43:35 +0530 Subject: [PATCH 005/209] Modify help text --- .../ballerina/cli/launcher/LauncherUtils.java | 27 ++++++++++++++++--- .../cli/launcher/util/BalToolsUtil.java | 14 +++++++--- .../io/ballerina/cli/utils/PrintUtils.java | 11 ++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java index 06e98741e9b4..23a8b0ba1c92 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java @@ -19,7 +19,11 @@ import io.ballerina.cli.BLauncherCmd; import io.ballerina.cli.launcher.util.BalToolsUtil; +import io.ballerina.projects.BalToolsManifest; +import io.ballerina.projects.BalToolsToml; +import io.ballerina.projects.internal.BalToolsManifestBuilder; import io.ballerina.runtime.api.values.BError; +import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; import java.io.IOException; @@ -28,10 +32,13 @@ import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.HashMap; import java.util.List; import java.util.Map; import static io.ballerina.cli.launcher.BallerinaCliCommands.HELP; +import static io.ballerina.projects.util.ProjectConstants.BAL_TOOLS_TOML; +import static io.ballerina.projects.util.ProjectConstants.CONFIG_DIR; /** * Contains utility methods for executing a Ballerina program. @@ -103,13 +110,26 @@ static String generateGeneralHelp(Map subCommands) { StringBuilder helpBuilder = new StringBuilder(); helpBuilder.append(BLauncherCmd.getCommandUsageInfo(HELP)); + Path balToolsTomlPath = RepoUtils.createAndGetHomeReposPath().resolve(Path.of(CONFIG_DIR, BAL_TOOLS_TOML)); + BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); + BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + Map activeToolsVsRepos = new HashMap<>(); + // if there are any tools, add Tool Commands section List toolNames = subCommands.keySet().stream() .filter(BalToolsUtil::isNonBuiltInToolCommand) .sorted().toList(); + if (!toolNames.isEmpty()) { + toolNames.forEach(toolName -> { + balToolsManifest.getActiveTool(toolName).ifPresent(tool -> { + activeToolsVsRepos.put(toolName, tool.repository() == null ? "" : "[" + tool.repository() + .toUpperCase() + "] "); + }); + }); helpBuilder.append("\n\n Tool Commands:"); - toolNames.forEach(key -> generateCommandDescription(subCommands.get(key), helpBuilder)); + toolNames.forEach(key -> generateCommandDescription(subCommands.get(key), helpBuilder, + activeToolsVsRepos.get(key))); } return helpBuilder.toString(); } @@ -124,7 +144,8 @@ static String generateCommandHelp(String commandName, Map s return commandUsageInfo.toString(); } - private static void generateCommandDescription(CommandLine command, StringBuilder stringBuilder) { + private static void generateCommandDescription(CommandLine command, StringBuilder stringBuilder, + String repository) { String commandName = command.getCommandName(); BLauncherCmd bLauncherCmd = (BLauncherCmd) command.getCommandSpec().userObject(); CommandLine.Command annotation = bLauncherCmd.getClass().getAnnotation(CommandLine.Command.class); @@ -138,7 +159,7 @@ private static void generateCommandDescription(CommandLine command, StringBuilde } stringBuilder.append("\n") .append(" ") - .append(String.format("%-15s %s", commandName, commandDescription)); + .append(String.format("%-15s %s", commandName, repository + commandDescription)); } static String wrapString(String str, int wrapLength, int indent) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java index 0d70291407b4..59bb175aadbf 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java @@ -168,6 +168,8 @@ private static List getToolCommandJarAndDependencyJars(String commandName) Path balToolsTomlPath = userHomeDirPath.resolve(Path.of(CONFIG_DIR, BAL_TOOLS_TOML)); Path centralBalaDirPath = userHomeDirPath.resolve( Path.of(REPOSITORIES_DIR, CENTRAL_REPOSITORY_CACHE_NAME, BALA_DIR_NAME)); + Path localBalaDirPath = userHomeDirPath.resolve( + Path.of(REPOSITORIES_DIR, ProjectConstants.LOCAL_REPOSITORY_NAME, BALA_DIR_NAME)); BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); @@ -178,7 +180,9 @@ private static List getToolCommandJarAndDependencyJars(String commandName) .flatMap(map -> map.values().stream()) .filter(BalToolsManifest.Tool::active) .map(tool1 -> findJarFiles(CommandUtil.getPlatformSpecificBalaPath( - tool1.org(), tool1.name(), tool1.version(), centralBalaDirPath).resolve(TOOL).resolve(LIBS) + tool1.org(), tool1.name(), tool1.version(), ProjectConstants.LOCAL_REPOSITORY_NAME + .equals(tool1.repository()) ? localBalaDirPath : centralBalaDirPath) + .resolve(TOOL).resolve(LIBS) .toFile())) .flatMap(List::stream) .collect(Collectors.toList()); @@ -196,7 +200,8 @@ private static List getToolCommandJarAndDependencyJars(String commandName) throw LauncherUtils.createLauncherException(errMsg); } Path platformPath = CommandUtil.getPlatformSpecificBalaPath( - tool.org(), tool.name(), tool.version(), centralBalaDirPath); + tool.org(), tool.name(), tool.version(), ProjectConstants.LOCAL_REPOSITORY_NAME + .equals(tool.repository()) ? localBalaDirPath : centralBalaDirPath); File libsDir = platformPath.resolve(Path.of(TOOL, LIBS)).toFile(); return findJarFiles(libsDir); } @@ -212,8 +217,11 @@ private static boolean isToolDistCompatibilityWithCurrentDist(BalToolsManifest.T private static SemanticVersion getToolDistVersionFromCentralCache(BalToolsManifest.Tool tool) { Path centralBalaDirPath = ProjectUtils.createAndGetHomeReposPath().resolve( Path.of(REPOSITORIES_DIR, CENTRAL_REPOSITORY_CACHE_NAME, ProjectConstants.BALA_DIR_NAME)); + Path localBalaPath = ProjectUtils.createAndGetHomeReposPath().resolve( + Path.of(REPOSITORIES_DIR, ProjectConstants.LOCAL_REPOSITORY_NAME, ProjectConstants.BALA_DIR_NAME)); Path balaPath = CommandUtil.getPlatformSpecificBalaPath( - tool.org(), tool.name(), tool.version(), centralBalaDirPath); + tool.org(), tool.name(), tool.version(), ProjectConstants.LOCAL_REPOSITORY_NAME + .equals(tool.repository()) ? localBalaPath : centralBalaDirPath); PackageJson packageJson = BalaFiles.readPackageJson(balaPath); return SemanticVersion.from(packageJson.getBallerinaVersion()); } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java index 9668dd7a2158..34eb56bc09d6 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java @@ -19,6 +19,7 @@ package io.ballerina.cli.utils; import io.ballerina.projects.BalToolsManifest; +import io.ballerina.projects.util.ProjectConstants; import org.ballerinalang.central.client.model.Package; import org.ballerinalang.central.client.model.Tool; @@ -56,30 +57,36 @@ public static void printLocalTools(List tools, String ter } } int versionColWidth = 15; + int repositoryColWidth = 10; int padding = 2; int minimumToolIdColWidth = 20; int remainingWidth = Math.max(minimumToolIdColWidth, width - versionColWidth); int toolIdColWidth = Math.max(minimumToolIdColWidth, Math.min(maxToolIdNameLength, remainingWidth)) + padding; - printListLocalTableHeader(toolIdColWidth, versionColWidth); + printListLocalTableHeader(toolIdColWidth, versionColWidth, repositoryColWidth); for (BalToolsManifest.Tool tool: tools) { + String repository = ProjectConstants.LOCAL_REPOSITORY_NAME.equals(tool.repository()) ? "local" : "central"; + tool.repository(); String activeIndicator = tool.active() ? "* " : " "; printInCLI("|" + tool.id(), toolIdColWidth); printInCLI(activeIndicator + tool.version(), versionColWidth); + printInCLI(repository, repositoryColWidth); outStream.println(); } outStream.println(); outStream.println(tools.size() + " tools found."); } - private static void printListLocalTableHeader(int toolIdColWidth, int versionColWidth) { + private static void printListLocalTableHeader(int toolIdColWidth, int versionColWidth, int repositoryColWidth) { printInCLI("|TOOL ID", toolIdColWidth); printInCLI("VERSION", versionColWidth); + printInCLI("REPO", repositoryColWidth); outStream.println(); printCharacter("|-", toolIdColWidth, "-", true); printCharacter("-", versionColWidth, "-", true); + printCharacter("-", repositoryColWidth, "-", true); outStream.println(); } From 830e439c2643cafab854be817ebe0c3418bce13e Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Fri, 24 Nov 2023 14:53:03 +0530 Subject: [PATCH 006/209] Add tests --- .../io/ballerina/cli/cmd/PushCommand.java | 3 +- .../io/ballerina/cli/cmd/ToolCommand.java | 35 +++- .../io/ballerina/cli/utils/PrintUtils.java | 1 - .../cli-help/ballerina-tool-pull.help | 7 + .../cli-help/ballerina-tool-remove.help | 7 + .../cli-help/ballerina-tool-use.help | 7 + .../io/ballerina/cli/cmd/PushCommandTest.java | 57 +++++++ .../io/ballerina/cli/cmd/ToolCommandTest.java | 153 ++++++++++++++++++ .../command-outputs/unix/tool-help.txt | 55 ++++--- .../unix/tool-search-with-no-args.txt | 2 +- .../unix/tool-search-with-too-many-args.txt | 2 +- .../command-outputs/windows/tool-help.txt | 55 ++++--- .../windows/tool-search-with-no-args.txt | 2 +- .../tool-search-with-too-many-args.txt | 2 +- .../tool_gayal/1.1.0/java17/bala.json | 4 + .../compiler-plugin/compiler-plugin.json | 6 + .../1.1.0/java17/dependency-graph.json | 88 ++++++++++ .../tool_gayal/1.1.0/java17/docs/Package.md | 4 + .../1.1.0/java17/modules/tool_gayal/main.bal | 5 + .../tool_gayal/1.1.0/java17/package.json | 14 ++ .../1.1.0/java17/tool/bal-tool.json | 6 + .../tool_gayal/1.2.0/java17/bala.json | 4 + .../compiler-plugin/compiler-plugin.json | 6 + .../1.2.0/java17/dependency-graph.json | 88 ++++++++++ .../tool_gayal/1.2.0/java17/docs/Package.md | 4 + .../1.2.0/java17/modules/tool_gayal/main.bal | 5 + .../tool_gayal/1.2.0/java17/package.json | 14 ++ .../1.2.0/java17/tool/bal-tool.json | 6 + .../tool_gayal/1.3.0/java17/bala.json | 4 + .../compiler-plugin/compiler-plugin.json | 6 + .../1.3.0/java17/dependency-graph.json | 88 ++++++++++ .../tool_gayal/1.3.0/java17/docs/Package.md | 4 + .../1.3.0/java17/modules/tool_gayal/main.bal | 5 + .../tool_gayal/1.3.0/java17/package.json | 14 ++ .../1.3.0/java17/tool/bal-tool.json | 6 + .../tool_gayal/2.2.4/java17/bala.json | 4 + .../compiler-plugin/compiler-plugin.json | 6 + .../2.2.4/java17/dependency-graph.json | 88 ++++++++++ .../tool_gayal/2.2.4/java17/docs/Package.md | 4 + .../2.2.4/java17/modules/tool_gayal/main.bal | 5 + .../tool_gayal/2.2.4/java17/package.json | 14 ++ .../2.2.4/java17/tool/bal-tool.json | 6 + .../tool_gayal/2.2.5/java17/bala.json | 4 + .../compiler-plugin/compiler-plugin.json | 6 + .../2.2.5/java17/dependency-graph.json | 88 ++++++++++ .../tool_gayal/2.2.5/java17/docs/Package.md | 4 + .../2.2.5/java17/modules/tool_gayal/main.bal | 5 + .../tool_gayal/2.2.5/java17/package.json | 14 ++ .../2.2.5/java17/tool/bal-tool.json | 6 + .../repositories/local/bala/local-tools.json | 1 + .../ballerina/projects/BalToolsManifest.java | 5 +- .../io/ballerina/projects/BalToolsToml.java | 1 - 52 files changed, 962 insertions(+), 68 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/bala.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/dependency-graph.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/docs/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/modules/tool_gayal/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/package.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/bal-tool.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/bala.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/dependency-graph.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/docs/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/modules/tool_gayal/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/package.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/bal-tool.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/bala.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/dependency-graph.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/docs/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/modules/tool_gayal/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/package.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/bal-tool.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/bala.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/dependency-graph.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/docs/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/modules/tool_gayal/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/package.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/bal-tool.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/bala.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/dependency-graph.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/docs/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/modules/tool_gayal/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/package.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/bal-tool.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/local-tools.json diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java index fa3b4a658c7f..33ff95af9c12 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java @@ -18,7 +18,6 @@ package io.ballerina.cli.cmd; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.ballerina.cli.BLauncherCmd; import io.ballerina.cli.utils.FileUtils; @@ -451,7 +450,7 @@ private void handleLocalTools(Path balaDestPath, String org, String packageName, localToolJson.add(toolId, packageDesc); } - try (FileWriter writer = new FileWriter(localToolJsonPath.toFile())) { + try (FileWriter writer = new FileWriter(localToolJsonPath.toFile(), StandardCharsets.UTF_8)) { writer.write(gson.toJson(localToolJson)); } catch (IOException e) { throw new ProjectException("Failed to write local-tools.json file: " + e.getMessage()); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java index 11b0a8b8e72b..98af1d696211 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java @@ -297,7 +297,8 @@ private void handleUseCommand() { if (tool.isEmpty()) { CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not found. " + "Run 'bal tool pull " + toolId + ":" + version - + "' to fetch and set as the active version.", null, false); + + "' or 'bal tool pull " + toolId + ":" + version + + " --repository=local' to fetch and set as the active version.", null, false); CommandUtil.exitError(this.exitWhenFinish); return; } @@ -349,6 +350,12 @@ private void handleSearchCommand() { CommandUtil.exitError(this.exitWhenFinish); return; } + if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + CommandUtil.printError(errStream, "tool search command is not supported for local repository.", + null, false); + CommandUtil.exitError(this.exitWhenFinish); + return; + } String searchArgs = argList.get(1); searchToolsInCentral(searchArgs); @@ -417,6 +424,12 @@ private void handleUpdateCommand() { CommandUtil.exitError(this.exitWhenFinish); return; } + if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + CommandUtil.printError(errStream, "tool update command is not supported for local repository.", + null, false); + CommandUtil.exitError(this.exitWhenFinish); + return; + } toolId = argList.get(1); @@ -431,7 +444,7 @@ private void handleUpdateCommand() { public void pullToolAndUpdateBalToolsToml(String toolIdArg, String versionArg) { toolId = toolIdArg; version = versionArg; - Path balaCacheDirPath = ProjectUtils.createAndGetHomeReposPath() + Path balaCacheDirPath = RepoUtils.createAndGetHomeReposPath() .resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME) .resolve(ProjectConstants.BALA_DIR_NAME); @@ -440,8 +453,8 @@ public void pullToolAndUpdateBalToolsToml(String toolIdArg, String versionArg) { .collect(Collectors.joining(",")); if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { if (!isToolAvailableInLocalRepo(toolId, version)) { - errStream.println("tool '" + toolId + ":" + version + "' is not available in local repository.\nPlease " + - "publish it first with 'bal push --repository=local' command."); + errStream.println("tool '" + toolId + ":" + version + "' is not available in local repository." + + "\nPlease publish it first with 'bal push --repository=local' command."); CommandUtil.exitError(this.exitWhenFinish); } addToBalToolsToml(); @@ -693,7 +706,7 @@ private boolean isToolAvailableLocally(String toolId, String version) { org = tool.org(); name = tool.name(); - Path toolCacheDir = ProjectUtils.createAndGetHomeReposPath() + Path toolCacheDir = RepoUtils.createAndGetHomeReposPath() .resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME) .resolve(ProjectConstants.BALA_DIR_NAME).resolve(tool.org()).resolve(tool.name()); if (toolCacheDir.toFile().isDirectory()) { @@ -722,7 +735,7 @@ private boolean checkToolDistCompatibility() { } private SemanticVersion getToolDistVersionFromCentralCache() { - Path centralBalaDirPath = ProjectUtils.createAndGetHomeReposPath() + Path centralBalaDirPath = RepoUtils.createAndGetHomeReposPath() .resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME) .resolve(ProjectConstants.BALA_DIR_NAME); Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, centralBalaDirPath); @@ -731,7 +744,7 @@ private SemanticVersion getToolDistVersionFromCentralCache() { } private SemanticVersion getToolDistVersionFromLocalCache() { - Path localBalaDirPath = ProjectUtils.createAndGetHomeReposPath() + Path localBalaDirPath = RepoUtils.createAndGetHomeReposPath() .resolve(REPOSITORIES_DIR).resolve(ProjectConstants.LOCAL_REPOSITORY_NAME) .resolve(ProjectConstants.BALA_DIR_NAME); Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, localBalaDirPath); @@ -769,7 +782,13 @@ private void updateToolToLatestVersion() { return; } - Path balaCacheDirPath = ProjectUtils.createAndGetHomeReposPath() + if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(tool.get().repository())) { + CommandUtil.printError(errStream, "tools from local repository can not be updated. ", + null, false); + CommandUtil.exitError(this.exitWhenFinish); + } + + Path balaCacheDirPath = RepoUtils.createAndGetHomeReposPath() .resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME) .resolve(ProjectConstants.BALA_DIR_NAME); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java index 34eb56bc09d6..54ae8cda1855 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/PrintUtils.java @@ -67,7 +67,6 @@ public static void printLocalTools(List tools, String ter for (BalToolsManifest.Tool tool: tools) { String repository = ProjectConstants.LOCAL_REPOSITORY_NAME.equals(tool.repository()) ? "local" : "central"; - tool.repository(); String activeIndicator = tool.active() ? "* " : " "; printInCLI("|" + tool.id(), toolIdColWidth); printInCLI(activeIndicator + tool.version(), versionColWidth); diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help index f04ba3388a98..4d1362429601 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help @@ -8,6 +8,9 @@ OPTIONS -h, --help Print the usage details of tool pull command. + --repository + Pull a tool from a custom repository. + DESCRIPTION Fetch a given tool from the Ballerina Central and install it as a Ballerina CLI command. @@ -16,3 +19,7 @@ DESCRIPTION distribution version. If the tool version is not specified, the latest version compatible with the current distribution will be fetched. + +EXAMPLES + Pull the '1.1.0' version of the 'eod' tool from local repository. + $ bal tool pull eod:1.1.0 --repository=local diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-remove.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-remove.help index 18671ce2ae0b..962c53e53d8f 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-remove.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-remove.help @@ -8,6 +8,9 @@ OPTIONS -h, --help Print the usage details of tool remove command. + --repository + Remove a tool from a custom repository. + DESCRIPTION Remove a tool that was installed into to the local environment. @@ -16,3 +19,7 @@ DESCRIPTION If the version is not specified, all versions of the tool will be removed including the active version. + +EXAMPLES + Remove the '1.1.0' version of the 'eod' tool from local repository. + $ bal tool remove eod:1.1.0 --repository=local diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-use.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-use.help index 737351170118..012a4dfc3a47 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-use.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-use.help @@ -8,6 +8,9 @@ OPTIONS -h, --help Print the usage details of tool use command. + --repository + Use a tool from a custom repository. + DESCRIPTION Mark a specified version of a tool available in the local environment as the active version. @@ -17,3 +20,7 @@ DESCRIPTION EXAMPLES Change the active version of a tool. $ bal tool use health:1.0.0 + + Change the active version to a local repository tool. + $ bal tool use eod:1.1.0 --repository=local + diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java index 2e19ff3bf5b5..d931535f27d2 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java @@ -18,6 +18,8 @@ package io.ballerina.cli.cmd; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import io.ballerina.projects.ProjectException; import io.ballerina.projects.Settings; import io.ballerina.projects.TomlDocument; @@ -34,9 +36,11 @@ import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; +import java.io.BufferedReader; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -205,6 +209,59 @@ public void testPushWithCustomPath() throws IOException { } + @Test(description = "Push a tool to local repository") + public void testPushToolToLocal() throws IOException { + Path validBalProject = Paths.get("build").resolve("tool-gayals"); + + FileUtils.copyDirectory( + this.testResources.resolve("tool-gayals").toFile(), validBalProject.toFile()); + FileUtils.moveDirectory( + validBalProject.resolve("target-dir").toFile(), validBalProject.resolve("custom").toFile()); + + Path customTargetDirBalaPath = validBalProject.resolve("custom").resolve("bala") + .resolve("gayaldassanayake-tool_gayal-java17-1.1.0.bala"); + PushCommand pushCommand = new PushCommand(validBalProject, printStream, printStream, false, + customTargetDirBalaPath); + String[] args = { "--repository=local" }; + new CommandLine(pushCommand).parse(args); + + Path mockRepo = Paths.get("build").resolve("ballerina-home"); + + try (MockedStatic repoUtils = Mockito.mockStatic(RepoUtils.class)) { + repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockRepo); + repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("1.0.0"); + repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from()); + pushCommand.execute(); + } + + String buildLog = readOutput(true); + String actual = buildLog.replaceAll("\r", ""); + String expected = "Successfully pushed " + customTargetDirBalaPath.toString() + " to 'local' repository."; + Assert.assertTrue(actual.contains(expected)); + + try { + ProjectFiles.validateBalaProjectPath(mockRepo.resolve("repositories").resolve("local") + .resolve("bala").resolve("gayaldassanayake").resolve("tool_gayal") + .resolve("1.1.0").resolve("java17")); + } catch (ProjectException e) { + Assert.fail(e.getMessage()); + } + + Path localToolJsonPath = mockRepo.resolve("repositories").resolve("local").resolve("bala") + .resolve("local-tools.json"); + + Assert.assertTrue(Files.exists(localToolJsonPath)); + + try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, StandardCharsets.UTF_8)) { + JsonObject localToolJson = new Gson().fromJson(bufferedReader, JsonObject.class); + JsonObject pkgDesc = localToolJson.get("luhee").getAsJsonObject(); + + Assert.assertEquals(pkgDesc.get("org").getAsString(), "gayaldassanayake"); + Assert.assertEquals(pkgDesc.get("name").getAsString(), "tool_gayal"); + } + + } + @Test(description = "Push package without bala directory") public void testPushWithoutBalaDir() throws IOException { String expected = "cannot find bala file for the package: winery. Run " diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ToolCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ToolCommandTest.java index 79949bab2a2c..cc57ff9fdc56 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ToolCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/ToolCommandTest.java @@ -18,12 +18,27 @@ package io.ballerina.cli.cmd; +import io.ballerina.projects.BalToolsManifest; +import io.ballerina.projects.BalToolsToml; +import io.ballerina.projects.Settings; +import io.ballerina.projects.internal.BalToolsManifestBuilder; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Objects; +import java.util.Optional; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; @@ -33,6 +48,144 @@ * @since 2201.6.0 */ public class ToolCommandTest extends BaseCommandTest { + + private Path testResources; + + @BeforeClass + public void setup() throws IOException { + super.setup(); + try { + this.testResources = super.tmpDir.resolve("build-test-resources"); + URI testResourcesURI = Objects.requireNonNull(getClass().getClassLoader().getResource("test-resources")) + .toURI(); + Files.walkFileTree(Paths.get(testResourcesURI), + new BuildCommandTest.Copy(Paths.get(testResourcesURI), this.testResources)); + } catch (URISyntaxException e) { + Assert.fail("error loading resources"); + } + } + + @Test(description = "Pull a tool from local repository") + public void testPullToolFromLocal() throws IOException { + Path mockHomeRepo = testResources.resolve("local-tool-test").resolve("ballerina-cache"); + try (MockedStatic repoUtils = Mockito.mockStatic(RepoUtils.class)) { + repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockHomeRepo); + repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("2201.9.0"); + repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from()); + + ToolCommand toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("pull", "luhee:1.1.0", "--repository=local"); + toolCommand.execute(); + } + + String buildLog = readOutput(true); + Assert.assertEquals(buildLog, "tool 'luhee:1.1.0' successfully set as the active version.\n"); + Assert.assertTrue(Files.exists(mockHomeRepo.resolve(".config").resolve("bal-tools.toml"))); + BalToolsToml balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config").resolve("bal-tools.toml")); + BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + Optional tool = balToolsManifest.getActiveTool("luhee"); + Assert.assertTrue(tool.isPresent()); + Assert.assertEquals(tool.get().version(), "1.1.0"); + Assert.assertEquals(tool.get().repository(), "local"); + Assert.assertEquals(tool.get().org(), "gayaldassanayake"); + Assert.assertEquals(tool.get().name(), "tool_gayal"); + } + + @Test(description = "Switch active version from local") + public void testUseToolFromLocal() throws IOException { + Path mockHomeRepo = testResources.resolve("local-tool-test").resolve("ballerina-cache"); + try (MockedStatic repoUtils = Mockito.mockStatic(RepoUtils.class)) { + repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockHomeRepo); + repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("2201.9.0"); + repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from()); + + ToolCommand toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("pull", "luhee:1.1.0", "--repository=local"); + toolCommand.execute(); + new CommandLine(toolCommand).parseArgs("pull", "luhee:1.2.0", "--repository=local"); + toolCommand.execute(); + + String buildLog = readOutput(true); + Assert.assertTrue(buildLog.contains("tool 'luhee:1.2.0' successfully set as the active version.\n")); + Assert.assertTrue(Files.exists(mockHomeRepo.resolve(".config").resolve("bal-tools.toml"))); + BalToolsToml balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config").resolve("bal-tools.toml")); + BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + Optional tool = balToolsManifest.getActiveTool("luhee"); + Assert.assertTrue(tool.isPresent()); + Assert.assertEquals(tool.get().version(), "1.2.0"); + Assert.assertEquals(tool.get().repository(), "local"); + Assert.assertEquals(tool.get().org(), "gayaldassanayake"); + Assert.assertEquals(tool.get().name(), "tool_gayal"); + + toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("use", "luhee:1.1.0", "--repository=local"); + toolCommand.execute(); + buildLog = readOutput(true); + Assert.assertTrue(buildLog.contains("tool 'luhee:1.1.0' successfully set as the active version.\n")); + balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config").resolve("bal-tools.toml")); + balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + tool = balToolsManifest.getActiveTool("luhee"); + Assert.assertTrue(tool.isPresent()); + Assert.assertEquals(tool.get().version(), "1.1.0"); + Assert.assertEquals(tool.get().repository(), "local"); + Assert.assertEquals(tool.get().org(), "gayaldassanayake"); + Assert.assertEquals(tool.get().name(), "tool_gayal"); + } + } + + @Test(description = "Remove a tool from local repository") + public void testRemoveToolFromLocal() throws IOException { + Path mockHomeRepo = testResources.resolve("local-tool-test").resolve("ballerina-cache"); + try (MockedStatic repoUtils = Mockito.mockStatic(RepoUtils.class)) { + repoUtils.when(RepoUtils::createAndGetHomeReposPath).thenReturn(mockHomeRepo); + repoUtils.when(RepoUtils::getBallerinaShortVersion).thenReturn("2201.9.0"); + repoUtils.when(RepoUtils::readSettings).thenReturn(Settings.from()); + + ToolCommand toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("pull", "luhee:1.1.0", "--repository=local"); + toolCommand.execute(); + new CommandLine(toolCommand).parseArgs("pull", "luhee:1.2.0", "--repository=local"); + toolCommand.execute(); + + String buildLog = readOutput(true); + Assert.assertTrue(buildLog.contains("tool 'luhee:1.2.0' successfully set as the active version.\n")); + Assert.assertTrue(Files.exists(mockHomeRepo.resolve(".config").resolve("bal-tools.toml"))); + BalToolsToml balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config") + .resolve("bal-tools.toml")); + BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + Optional tool = balToolsManifest.getActiveTool("luhee"); + Assert.assertTrue(tool.isPresent()); + Assert.assertEquals(tool.get().version(), "1.2.0"); + Assert.assertEquals(tool.get().repository(), "local"); + Assert.assertEquals(tool.get().org(), "gayaldassanayake"); + Assert.assertEquals(tool.get().name(), "tool_gayal"); + + toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("use", "luhee:1.1.0", "--repository=local"); + toolCommand.execute(); + buildLog = readOutput(true); + Assert.assertTrue(buildLog.contains("tool 'luhee:1.1.0' successfully set as the active version.\n")); + balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config").resolve("bal-tools.toml")); + balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + tool = balToolsManifest.getActiveTool("luhee"); + Assert.assertTrue(tool.isPresent()); + Assert.assertEquals(tool.get().version(), "1.1.0"); + Assert.assertEquals(tool.get().repository(), "local"); + Assert.assertEquals(tool.get().org(), "gayaldassanayake"); + Assert.assertEquals(tool.get().name(), "tool_gayal"); + + toolCommand = new ToolCommand(printStream, printStream, false); + new CommandLine(toolCommand).parseArgs("remove", "luhee:1.2.0", "--repository=local"); + toolCommand.execute(); + buildLog = readOutput(true); + Assert.assertTrue(buildLog.contains("tool 'luhee:1.2.0' successfully removed.\n")); + balToolsToml = BalToolsToml.from(mockHomeRepo.resolve(".config").resolve("bal-tools.toml")); + balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); + tool = balToolsManifest.getTool("luhee", "1.2.0", "local"); + Assert.assertTrue(tool.isEmpty()); + } + } + @Test(description = "Test tool command with the help flag") public void testToolCommandWithHelpFlag() throws IOException { String expected = getOutput("tool-help.txt"); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt index 831c6a3e49c2..fd0068a761de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-help.txt @@ -1,48 +1,55 @@ NAME - ballerina-tool - Manage the tools provided by Ballerina + ballerina-tool - Extend the Ballerina CLI with custom commands. SYNOPSIS bal tool [<-h> |<--help>] bal tool [args] DESCRIPTION - Manage Ballerina command line tools via bal tool chain. + Register and manage custom commands for the Ballerina CLI. - Facilitate pulling tools from Ballerina Central and removing - previously pulled tools. + This command facilitates searching, pulling, and updating tools from the + Ballerina Central, switching between installed versions, and listing and + removing installed tools. - Provide subcommands to list all the locally available tools and search - for tools that are available in Ballerina Central. OPTIONS -h, --help Print the usage details of all tool commands. -TOOL COMMANDS +SUBCOMMANDS The following is a list of available subcommands: - pull Pull a tool from Ballerina Central. - list List all the tools available locally. - search Search Ballerina Central for tools. - remove Remove a tool. + pull Pull a tool from the Ballerina Central. + remove Remove a tool from the local environment. + update Update a tool to the latest version. + use Set a tool version as the active version. + list List all tools available in the local environment. + search Search the Ballerina Central for tools. EXAMPLES - Pull a tool from Ballerina Central. - $ bal tool pull openapi + Pull a tool from the Ballerina Central. + $ bal tool pull health - Pull a specific version of a tool from Ballerina Central. - $ bal tool pull openapi:1.5.0 + Pull a specific version of a tool from the Ballerina Central. + $ bal tool pull health:1.0.0 - List all the tools available locally. - $ bal tool list + Remove a specific version of an installed tool. + $ bal tool remove health:1.0.0 + + Remove all the versions of an installed tool. + $ bal tool remove health - Search Ballerina Central for tools. - $ bal tool search openapi + Update a tool to the latest version compatible with the current distribution. + $ bal tool update health - Remove a specific version of previously pulled tool. - $ bal tool remove openapi:1.5.0 + Change the active version of a tool. + $ bal tool use health:1.0.0 + + List all tools available in the local environment. + $ bal tool list - Remove all the versions of a previously pulled tool. - $ bal tool remove openapi + Search the Ballerina Central for tools. + $ bal tool search health -Use 'bal tool --help' for more information on a specific command. +Use 'bal tool --help' for more information on a specific tool subcommand. diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-no-args.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-no-args.txt index d8786ac17268..2e97de5247d3 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-no-args.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-no-args.txt @@ -1,4 +1,4 @@ ballerina: no keyword given. USAGE: - bal tool search [|||] + bal tool search [|] diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-too-many-args.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-too-many-args.txt index 88756253cc5e..5edd841119c7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-too-many-args.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/tool-search-with-too-many-args.txt @@ -1,4 +1,4 @@ ballerina: too many arguments. USAGE: - bal tool search [|||] + bal tool search [|] diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-help.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-help.txt index 831c6a3e49c2..fd0068a761de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-help.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-help.txt @@ -1,48 +1,55 @@ NAME - ballerina-tool - Manage the tools provided by Ballerina + ballerina-tool - Extend the Ballerina CLI with custom commands. SYNOPSIS bal tool [<-h> |<--help>] bal tool [args] DESCRIPTION - Manage Ballerina command line tools via bal tool chain. + Register and manage custom commands for the Ballerina CLI. - Facilitate pulling tools from Ballerina Central and removing - previously pulled tools. + This command facilitates searching, pulling, and updating tools from the + Ballerina Central, switching between installed versions, and listing and + removing installed tools. - Provide subcommands to list all the locally available tools and search - for tools that are available in Ballerina Central. OPTIONS -h, --help Print the usage details of all tool commands. -TOOL COMMANDS +SUBCOMMANDS The following is a list of available subcommands: - pull Pull a tool from Ballerina Central. - list List all the tools available locally. - search Search Ballerina Central for tools. - remove Remove a tool. + pull Pull a tool from the Ballerina Central. + remove Remove a tool from the local environment. + update Update a tool to the latest version. + use Set a tool version as the active version. + list List all tools available in the local environment. + search Search the Ballerina Central for tools. EXAMPLES - Pull a tool from Ballerina Central. - $ bal tool pull openapi + Pull a tool from the Ballerina Central. + $ bal tool pull health - Pull a specific version of a tool from Ballerina Central. - $ bal tool pull openapi:1.5.0 + Pull a specific version of a tool from the Ballerina Central. + $ bal tool pull health:1.0.0 - List all the tools available locally. - $ bal tool list + Remove a specific version of an installed tool. + $ bal tool remove health:1.0.0 + + Remove all the versions of an installed tool. + $ bal tool remove health - Search Ballerina Central for tools. - $ bal tool search openapi + Update a tool to the latest version compatible with the current distribution. + $ bal tool update health - Remove a specific version of previously pulled tool. - $ bal tool remove openapi:1.5.0 + Change the active version of a tool. + $ bal tool use health:1.0.0 + + List all tools available in the local environment. + $ bal tool list - Remove all the versions of a previously pulled tool. - $ bal tool remove openapi + Search the Ballerina Central for tools. + $ bal tool search health -Use 'bal tool --help' for more information on a specific command. +Use 'bal tool --help' for more information on a specific tool subcommand. diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-no-args.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-no-args.txt index d8786ac17268..2e97de5247d3 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-no-args.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-no-args.txt @@ -1,4 +1,4 @@ ballerina: no keyword given. USAGE: - bal tool search [|||] + bal tool search [|] diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-too-many-args.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-too-many-args.txt index 88756253cc5e..5edd841119c7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-too-many-args.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/tool-search-with-too-many-args.txt @@ -1,4 +1,4 @@ ballerina: too many arguments. USAGE: - bal tool search [|||] + bal tool search [|] diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/bala.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/bala.json new file mode 100644 index 000000000000..fd0a01921270 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/bala.json @@ -0,0 +1,4 @@ +{ + "bala_version": "2.0.0", + "built_by": "WSO2" +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json new file mode 100644 index 000000000000..66bfe83d52a2 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json @@ -0,0 +1,6 @@ +{ + "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", + "dependency_paths": [ + "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/dependency-graph.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/dependency-graph.json new file mode 100644 index 000000000000..f4a609f60ccb --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/dependency-graph.json @@ -0,0 +1,88 @@ +{ + "packages": [ + { + "org": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.1.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + } + ], + "modules": [ + { + "org": "gayaldassanayake", + "package_name": "tool_gayal", + "version": "1.1.0", + "module_name": "tool_gayal", + "dependencies": [ + { + "org": "ballerina", + "package_name": "io", + "version": "1.6.0", + "module_name": "io", + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/docs/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/docs/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/docs/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/modules/tool_gayal/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/modules/tool_gayal/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/modules/tool_gayal/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/package.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/package.json new file mode 100644 index 000000000000..25e7a82eb4cf --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/package.json @@ -0,0 +1,14 @@ +{ + "organization": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.1.0", + "export": [ + "tool_gayal" + ], + "ballerina_version": "2201.9.0-SNAPSHOT", + "implementation_vendor": "WSO2", + "language_spec_version": "2023R1", + "platform": "java17", + "graalvmCompatible": true, + "template": false +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/bal-tool.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/bal-tool.json new file mode 100644 index 000000000000..bb78684d86b9 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/bal-tool.json @@ -0,0 +1,6 @@ +{ + "tool_id": "luhee", + "dependency_paths": [ + "tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/bala.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/bala.json new file mode 100644 index 000000000000..fd0a01921270 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/bala.json @@ -0,0 +1,4 @@ +{ + "bala_version": "2.0.0", + "built_by": "WSO2" +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json new file mode 100644 index 000000000000..66bfe83d52a2 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json @@ -0,0 +1,6 @@ +{ + "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", + "dependency_paths": [ + "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/dependency-graph.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/dependency-graph.json new file mode 100644 index 000000000000..5956fbe2398c --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/dependency-graph.json @@ -0,0 +1,88 @@ +{ + "packages": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.2.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + } + ], + "modules": [ + { + "org": "gayaldassanayake", + "package_name": "tool_gayal", + "version": "1.2.0", + "module_name": "tool_gayal", + "dependencies": [ + { + "org": "ballerina", + "package_name": "io", + "version": "1.6.0", + "module_name": "io", + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/docs/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/docs/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/docs/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/modules/tool_gayal/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/modules/tool_gayal/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/modules/tool_gayal/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/package.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/package.json new file mode 100644 index 000000000000..03ed7d045493 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/package.json @@ -0,0 +1,14 @@ +{ + "organization": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.2.0", + "export": [ + "tool_gayal" + ], + "ballerina_version": "2201.9.0-SNAPSHOT", + "implementation_vendor": "WSO2", + "language_spec_version": "2023R1", + "platform": "java17", + "graalvmCompatible": true, + "template": false +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/bal-tool.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/bal-tool.json new file mode 100644 index 000000000000..bb78684d86b9 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/bal-tool.json @@ -0,0 +1,6 @@ +{ + "tool_id": "luhee", + "dependency_paths": [ + "tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/bala.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/bala.json new file mode 100644 index 000000000000..fd0a01921270 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/bala.json @@ -0,0 +1,4 @@ +{ + "bala_version": "2.0.0", + "built_by": "WSO2" +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json new file mode 100644 index 000000000000..66bfe83d52a2 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json @@ -0,0 +1,6 @@ +{ + "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", + "dependency_paths": [ + "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/dependency-graph.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/dependency-graph.json new file mode 100644 index 000000000000..d79edcfd7999 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/dependency-graph.json @@ -0,0 +1,88 @@ +{ + "packages": [ + { + "org": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.3.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + } + ], + "modules": [ + { + "org": "gayaldassanayake", + "package_name": "tool_gayal", + "version": "1.3.0", + "module_name": "tool_gayal", + "dependencies": [ + { + "org": "ballerina", + "package_name": "io", + "version": "1.6.0", + "module_name": "io", + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/docs/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/docs/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/docs/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/modules/tool_gayal/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/modules/tool_gayal/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/modules/tool_gayal/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/package.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/package.json new file mode 100644 index 000000000000..3854d0043286 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/package.json @@ -0,0 +1,14 @@ +{ + "organization": "gayaldassanayake", + "name": "tool_gayal", + "version": "1.3.0", + "export": [ + "tool_gayal" + ], + "ballerina_version": "2201.9.0-SNAPSHOT", + "implementation_vendor": "WSO2", + "language_spec_version": "2023R1", + "platform": "java17", + "graalvmCompatible": true, + "template": false +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/bal-tool.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/bal-tool.json new file mode 100644 index 000000000000..bb78684d86b9 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/bal-tool.json @@ -0,0 +1,6 @@ +{ + "tool_id": "luhee", + "dependency_paths": [ + "tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/bala.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/bala.json new file mode 100644 index 000000000000..fd0a01921270 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/bala.json @@ -0,0 +1,4 @@ +{ + "bala_version": "2.0.0", + "built_by": "WSO2" +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json new file mode 100644 index 000000000000..66bfe83d52a2 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json @@ -0,0 +1,6 @@ +{ + "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", + "dependency_paths": [ + "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/dependency-graph.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/dependency-graph.json new file mode 100644 index 000000000000..0ea50a01b58a --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/dependency-graph.json @@ -0,0 +1,88 @@ +{ + "packages": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "gayaldassanayake", + "name": "tool_gayal", + "version": "2.2.4", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + } + ], + "modules": [ + { + "org": "gayaldassanayake", + "package_name": "tool_gayal", + "version": "2.2.4", + "module_name": "tool_gayal", + "dependencies": [ + { + "org": "ballerina", + "package_name": "io", + "version": "1.6.0", + "module_name": "io", + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/docs/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/docs/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/docs/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/modules/tool_gayal/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/modules/tool_gayal/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/modules/tool_gayal/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/package.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/package.json new file mode 100644 index 000000000000..32939af72c39 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/package.json @@ -0,0 +1,14 @@ +{ + "organization": "gayaldassanayake", + "name": "tool_gayal", + "version": "2.2.4", + "export": [ + "tool_gayal" + ], + "ballerina_version": "2201.9.0-SNAPSHOT", + "implementation_vendor": "WSO2", + "language_spec_version": "2023R1", + "platform": "java17", + "graalvmCompatible": true, + "template": false +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/bal-tool.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/bal-tool.json new file mode 100644 index 000000000000..300d1b1a0c10 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/bal-tool.json @@ -0,0 +1,6 @@ +{ + "tool_id": "gayals", + "dependency_paths": [ + "tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/bala.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/bala.json new file mode 100644 index 000000000000..fd0a01921270 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/bala.json @@ -0,0 +1,4 @@ +{ + "bala_version": "2.0.0", + "built_by": "WSO2" +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json new file mode 100644 index 000000000000..66bfe83d52a2 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json @@ -0,0 +1,6 @@ +{ + "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", + "dependency_paths": [ + "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/dependency-graph.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/dependency-graph.json new file mode 100644 index 000000000000..67966f371406 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/dependency-graph.json @@ -0,0 +1,88 @@ +{ + "packages": [ + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "gayaldassanayake", + "name": "tool_gayal", + "version": "2.2.5", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "io", + "version": "1.6.0", + "transitive": false, + "dependencies": [ + { + "org": "ballerina", + "name": "lang.value", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + }, + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [] + }, + { + "org": "ballerina", + "name": "jballerina.java", + "version": "0.0.0", + "transitive": false, + "dependencies": [], + "modules": [] + } + ], + "modules": [ + { + "org": "gayaldassanayake", + "package_name": "tool_gayal", + "version": "2.2.5", + "module_name": "tool_gayal", + "dependencies": [ + { + "org": "ballerina", + "package_name": "io", + "version": "1.6.0", + "module_name": "io", + "dependencies": [] + } + ] + } + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/docs/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/docs/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/docs/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/modules/tool_gayal/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/modules/tool_gayal/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/modules/tool_gayal/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/package.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/package.json new file mode 100644 index 000000000000..959fd9a8722b --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/package.json @@ -0,0 +1,14 @@ +{ + "organization": "gayaldassanayake", + "name": "tool_gayal", + "version": "2.2.5", + "export": [ + "tool_gayal" + ], + "ballerina_version": "2201.9.0-SNAPSHOT", + "implementation_vendor": "WSO2", + "language_spec_version": "2023R1", + "platform": "java17", + "graalvmCompatible": true, + "template": false +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/bal-tool.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/bal-tool.json new file mode 100644 index 000000000000..bb78684d86b9 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/bal-tool.json @@ -0,0 +1,6 @@ +{ + "tool_id": "luhee", + "dependency_paths": [ + "tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" + ] +} \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/local-tools.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/local-tools.json new file mode 100644 index 000000000000..3e8e08bb5768 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/local-tools.json @@ -0,0 +1 @@ +{"gayal":{"org":"gayaldassanayake","name":"tool_gayal"},"gayals":{"org":"gayaldassanayake","name":"tool_gayal"},"luhee":{"org":"gayaldassanayake","name":"tool_gayal"}} \ No newline at end of file diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java index b0a0ba71bf30..8164aece980f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsManifest.java @@ -17,10 +17,7 @@ */ package io.ballerina.projects; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Optional; @@ -40,7 +37,7 @@ public static BalToolsManifest from() { return new BalToolsManifest(new HashMap<>()); } - public static BalToolsManifest from(Map>>tools) { + public static BalToolsManifest from(Map>> tools) { return new BalToolsManifest(tools); } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java index e1c52b342006..10820cd1d1ac 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/BalToolsToml.java @@ -29,7 +29,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; -import java.util.Set; import static io.ballerina.projects.util.ProjectConstants.BAL_TOOLS_TOML; From f4dd75bae9d97d7900d32545ca46797141961217 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 27 Nov 2023 15:34:10 +0530 Subject: [PATCH 007/209] Add hover support for resource paths --- .../common/constants/ContextConstants.java | 2 + .../langserver/hover/HoverObjectResolver.java | 42 +++++++++++++++++-- .../langserver/hover/HoverUtil.java | 15 ++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java index 4e7d7cb8fba6..166208e246e6 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java @@ -27,6 +27,8 @@ public class ContextConstants { public static final String TYPE_DEF = "TYPE_DEF"; public static final String DESCRIPTION = "Description"; public static final String PARAM_TITLE = "Parameters"; + public static final String PATH_PARAM_TITLE = "Path Parameters"; + public static final String QUERY_PARAM_TITLE = "Query Parameters"; public static final String RETURN_TITLE = "Return"; public static final String FIELD_TITLE = "Fields"; public static final String METHOD_TITLE = "Methods"; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java index 4b549da7301a..e498b7a730a4 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java @@ -22,15 +22,20 @@ import io.ballerina.compiler.api.symbols.ObjectTypeSymbol; import io.ballerina.compiler.api.symbols.ParameterKind; import io.ballerina.compiler.api.symbols.ParameterSymbol; +import io.ballerina.compiler.api.symbols.PathParameterSymbol; import io.ballerina.compiler.api.symbols.RecordTypeSymbol; import io.ballerina.compiler.api.symbols.ResourceMethodSymbol; import io.ballerina.compiler.api.symbols.Symbol; +import io.ballerina.compiler.api.symbols.SymbolKind; import io.ballerina.compiler.api.symbols.TypeDefinitionSymbol; import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.api.symbols.UnionTypeSymbol; import io.ballerina.compiler.api.symbols.VariableSymbol; +import io.ballerina.compiler.api.symbols.resourcepath.PathRestParam; +import io.ballerina.compiler.api.symbols.resourcepath.PathSegmentList; +import io.ballerina.compiler.api.symbols.resourcepath.ResourcePath; import io.ballerina.compiler.syntax.tree.DefaultableParameterNode; import io.ballerina.compiler.syntax.tree.Node; import io.ballerina.compiler.syntax.tree.NonTerminalNode; @@ -159,11 +164,42 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { } List hoverContent = new ArrayList<>(); documentation.get().description().ifPresent(hoverContent::add); - + List parameterSymbols = new ArrayList<>(); + boolean isResourceMethod = functionSymbol.kind() == SymbolKind.RESOURCE_METHOD; + + if (isResourceMethod) { + ResourcePath resourcePath = ((ResourceMethodSymbol) functionSymbol).resourcePath(); + if (resourcePath.kind() == ResourcePath.Kind.PATH_SEGMENT_LIST) { + PathSegmentList pathSegmentList = (PathSegmentList) resourcePath; + List pathParameterSymbols = pathSegmentList.pathParameters(); + parameterSymbols.addAll(pathParameterSymbols); + if (pathSegmentList.pathRestParameter().isPresent()) { + parameterSymbols.add(pathSegmentList.pathRestParameter().get()); + } + } else if (resourcePath.kind() == ResourcePath.Kind.PATH_REST_PARAM) { + parameterSymbols.add(((PathRestParam) resourcePath).parameter()); + } + } Map paramsMap = documentation.get().parameterMap(); + List params = new ArrayList<>(); + + if (!parameterSymbols.isEmpty()) { + params.add(MarkupUtils.header(3, ContextConstants.PATH_PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); + params.addAll(parameterSymbols.stream().map(param -> { + if (param.getName().isEmpty()) { + return MarkupUtils.quotedString(NameUtil + .getModifiedTypeName(context, param.typeDescriptor())); + } + String paramName = param.getName().get(); + String desc = paramsMap.getOrDefault(paramName, ""); + return MarkupUtils.quotedString(NameUtil.getModifiedTypeName(context, param.typeDescriptor())) + " " + + MarkupUtils.italicString(MarkupUtils.boldString(paramName)) + " : " + desc; + }).collect(Collectors.toList())); + } + if (!paramsMap.isEmpty()) { - List params = new ArrayList<>(); - params.add(MarkupUtils.header(3, ContextConstants.PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); + params.add(MarkupUtils.header(3, isResourceMethod ? ContextConstants.QUERY_PARAM_TITLE + : ContextConstants.PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); params.addAll(functionSymbol.typeDescriptor().params().get().stream().map(param -> { if (param.getName().isEmpty()) { return MarkupUtils.quotedString(NameUtil diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java index 6fde38a0f2ba..27c5e55fdc6f 100755 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java @@ -26,6 +26,7 @@ import io.ballerina.compiler.syntax.tree.ExpressionNode; import io.ballerina.compiler.syntax.tree.ModulePartNode; import io.ballerina.compiler.syntax.tree.NonTerminalNode; +import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.compiler.syntax.tree.Token; import io.ballerina.projects.Document; import io.ballerina.projects.ModuleId; @@ -70,7 +71,7 @@ public static Hover getHover(HoverContext context) { LinePosition linePosition = LinePosition.from(cursorPosition.getLine(), cursorPosition.getCharacter()); // Check for the cancellation before the time-consuming operation context.checkCancelled(); - Optional symbolAtCursor = semanticModel.get().symbol(srcFile.get(), linePosition); + Optional symbolAtCursor = getSymbolAtCursor(context, semanticModel.get(), srcFile.get(), linePosition); // Check for the cancellation after the time-consuming operation context.checkCancelled(); @@ -117,6 +118,18 @@ public static Hover getHover(HoverContext context) { return hoverObj; } + private static Optional getSymbolAtCursor(HoverContext context, SemanticModel semanticModel, + Document srcFile, LinePosition linePosition) { + NonTerminalNode cursor = context.getNodeAtCursor(); + if (cursor.kind() == SyntaxKind.LIST || cursor.kind() == SyntaxKind.PARENTHESIZED_ARG_LIST + || cursor.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE + && cursor.parent().kind() == SyntaxKind.CLIENT_RESOURCE_ACCESS_ACTION ) { + return semanticModel.symbol(cursor.parent()); + } else { + return semanticModel.symbol(srcFile, linePosition); + } + } + /** * returns the default hover object. * From 17ae2864a6acb4fa52741b108a69e08a7b66b8f2 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 27 Nov 2023 15:34:30 +0530 Subject: [PATCH 008/209] Add unit tests --- .../configs/hover_for_resource_path1.json | 21 +++++++++++++++++++ .../configs/hover_for_resource_path2.json | 21 +++++++++++++++++++ .../configs/hover_for_resource_path3.json | 21 +++++++++++++++++++ .../configs/hover_resource_method_def1.json | 2 +- .../hover/source/hover_for_resource_path.bal | 17 +++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json new file mode 100644 index 000000000000..04579cf8808c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 15, + "character": 34 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json new file mode 100644 index 000000000000..02685db1e52e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 15, + "character": 39 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json new file mode 100644 index 000000000000..25ca3bedb547 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 15, + "character": 55 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json index aa4b0f12f518..df9e8a37e385 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description2 for testResource1\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : a Parameter Description2 \n \n--- \n \n### Return \n`int` : Return Value Description2" + "value": "Test Description2 for testResource1\n \n \n--- \n \n### Query Parameters \n \n`int` ***param1*** : a Parameter Description2 \n \n--- \n \n### Return \n`int` : Return Value Description2" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal new file mode 100644 index 000000000000..62bed8b1e5df --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal @@ -0,0 +1,17 @@ +client class Client { + # Test Description. + # + # + param1 - parameter description + # + param2 - parameter description + # + param3 - parameter description + # + param4 - parameter description + # + return - return value description + resource function post path/[string param1]/path2/[string ...param2](string param3, int ...param4) returns string { + return "post"; + } +} + +public function test() { + Client cli = new Client(); + string stringResult = cli->/path/[""]/path2/[""].post("", 1); +} From 1b8b7cb4b96fc465f5bf0241f2f9a64d3d4f8d13 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 27 Nov 2023 17:23:22 +0530 Subject: [PATCH 009/209] Fix checkstyle failure --- .../main/java/org/ballerinalang/langserver/hover/HoverUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java index 27c5e55fdc6f..e8f844a3bbd5 100755 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java @@ -123,7 +123,7 @@ private static Optional getSymbolAtCursor(HoverContext context, Semantic NonTerminalNode cursor = context.getNodeAtCursor(); if (cursor.kind() == SyntaxKind.LIST || cursor.kind() == SyntaxKind.PARENTHESIZED_ARG_LIST || cursor.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE - && cursor.parent().kind() == SyntaxKind.CLIENT_RESOURCE_ACCESS_ACTION ) { + && cursor.parent().kind() == SyntaxKind.CLIENT_RESOURCE_ACCESS_ACTION) { return semanticModel.symbol(cursor.parent()); } else { return semanticModel.symbol(srcFile, linePosition); From b03ad3da0a335bda2426bd0a0b972ba108ce2d49 Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Wed, 29 Nov 2023 14:18:15 +0530 Subject: [PATCH 010/209] Analyze the type node of tuple variable --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 4f83042c1965..6b8025b68aab 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -1609,6 +1609,7 @@ public void visit(BLangTupleVariable varNode, AnalyzerData data) { typeChecker.checkExpr(varNode.expr, currentEnv, varNode.getBType(), data.prevEnvs, data.commonAnalyzerData); checkSelfReferencesInVarNode(varNode, varNode.expr, data); + analyzeNode(varNode.typeNode, data); } private void checkSelfReferencesInVarNode(BLangVariable variable, BLangExpression rhsExpr, AnalyzerData data) { From 52ed2b887f03c4e759fa169a91c3c582f0562f6e Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Wed, 29 Nov 2023 14:18:55 +0530 Subject: [PATCH 011/209] Add unit tests --- .../annotations/AnnotationAttachmentNegativeTest.java | 8 +++++++- .../test-src/annotations/annot_attachments_negative.bal | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index fd2ccdc03900..bafa8abcc0da 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 277); + Assert.assertEquals(compileResult.getErrorCount(), 278); } @Test @@ -520,6 +520,12 @@ public void testInvalidConstAnnotElements() { validateError(compileResult, index, "expression is not a constant expression", line + 7, 16); } + public void testInvalidAnnotationAttachmentOnField() { + int index = 277; + int line = 980; + validateError(compileResult, index, "undefined annotation 'UndefinedAnnotation'", line, 6); + } + @AfterClass public void tearDown() { compileResult = null; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index 8dd83a0524d2..7a09f63bb467 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -975,3 +975,7 @@ type F4 record {| type F5 record {| int x; |}; + +function testInvalidAnnotationAttachmentOnField() { + [@UndefinedAnnotation int, int] [first, second] = [1, 2]; +} From ead12847192fc98cbf5e486df015bff91fa08420 Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Fri, 8 Dec 2023 11:52:54 +0530 Subject: [PATCH 012/209] Fix annotations for service remote method attach point --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 1398f14a277d..56ac5c9e987f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -502,7 +502,7 @@ public void visit(BLangFunction funcNode, AnalyzerData data) { // annotation validation for workers is done for the invocation. funcNode.annAttachments.forEach(annotationAttachment -> { if (Symbols.isFlagOn(funcNode.symbol.flags, Flags.REMOTE) && funcNode.receiver != null - && Symbols.isService(funcNode.receiver.symbol)) { + && Symbols.isService(funcNode.receiver.getBType().tsymbol)) { annotationAttachment.attachPoints.add(AttachPoint.Point.SERVICE_REMOTE); } else if (funcNode.attachedFunction) { annotationAttachment.attachPoints.add(AttachPoint.Point.OBJECT_METHOD); From f33745f9054a6ddfbc7206bf07e3fc0c72ee4daa Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Mon, 11 Dec 2023 11:43:55 +0530 Subject: [PATCH 013/209] Add tests --- .../jvm/servicetests/ServiceValue.java | 9 +++ .../AnnotationAttachmentNegativeTest.java | 43 +++++++++++- .../AnnotationAttachmentSymbolsTest.java | 13 ++++ .../annotations/AnnotationAttachmentTest.java | 66 ++++++++++++++++--- .../annotations/AnnotationRuntimeTest.java | 6 ++ .../annotations/annot_attachments.bal | 31 +++++++++ .../annot_attachments_negative.bal | 54 +++++++++++++++ .../service_remote_method_annotations.bal | 56 ++++++++++++++++ 8 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java index d1482fbdbe9a..8be3dd409875 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java @@ -191,6 +191,15 @@ public static BValue getResourceMethodAnnotations(BObject service, BString metho return null; } + public static BValue getRemoteMethodAnnotations(BObject service, BString method, BString annotName) { + for (var methodType : ((ServiceType) service.getOriginalType()).getRemoteMethods()) { + if (methodType.getName().equals(method.getValue())) { + return (BValue) methodType.getAnnotation(annotName); + } + } + return null; + } + public static BArray getParamDefaultability(BObject service, BString name) { ServiceType serviceType = (ServiceType) service.getType(); Optional func = Arrays.stream(serviceType.getResourceMethods()) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index fd2ccdc03900..09a91349f9a6 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 277); + Assert.assertEquals(compileResult.getErrorCount(), 292); } @Test @@ -520,6 +520,47 @@ public void testInvalidConstAnnotElements() { validateError(compileResult, index, "expression is not a constant expression", line + 7, 16); } + @Test + public void testInvalidAttachmentOnServiceRemoteMethod() { + int index = 277; + int line = 984; + validateError(compileResult, index++, "annotation 'v1' is not allowed on service_remote, function", + line, 5); + validateError(compileResult, index++, "annotation 'v2' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v4' is not allowed on service_remote, function", + line += 6, 5); + validateError(compileResult, index++, "annotation 'v5' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v6' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v7' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v8' is not allowed on service_remote, function", + ++line, 5); + validateError(compileResult, index++, "annotation 'v9' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v10' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v11' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v12' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index++, "annotation 'v13' is not allowed on service_remote, function", + line += 3, 5); + validateError(compileResult, index, "annotation 'v15' is not allowed on service_remote, function", + line + 3, 5); + } + + @Test + public void testInvalidServiceRemoteMethodAttachmentOnNonRemoteServiceMethods() { + int index = 290; + validateError(compileResult, index++, "annotation 'v26' is not allowed on object_method, function", + 1026, 5); + validateError(compileResult, index, "annotation 'v26' is not allowed on object_method, function", + 1029, 5); + } + @AfterClass public void tearDown() { compileResult = null; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java index e5b8194f7502..7c55a82b99fc 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java @@ -394,6 +394,19 @@ public void testConstAnnots() { assertAttachmentSymbol(attachmentsF4.get(0), "v29", true, "increment", -2L); } + @Test + public void testAnnotWithServiceRemoteMethodAttachmentPoint() { + BLangFunction function = getFunction("ServiceClass.serviceRemoteFn1"); + List attachments = function.symbol.getAnnotations(); + Assert.assertEquals(attachments.size(), 2); + + AnnotationAttachmentSymbol v31 = attachments.get(0); + Assert.assertFalse(v31.isConstAnnotation()); + assertAttachmentSymbol(v31, "v31"); + + assertAttachmentSymbol(attachments.get(1), "v32", true, "increment", 1112L); + } + private BLangTypeDefinition getTypeDefinition(List typeDefinitions, String name) { for (TypeDefinition typeDefinition : typeDefinitions) { BLangTypeDefinition bLangTypeDefinition = (BLangTypeDefinition) typeDefinition; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentTest.java index 1c3eb247ac2f..2f99f36bfd2f 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentTest.java @@ -18,6 +18,7 @@ import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.elements.PackageID; +import org.ballerinalang.model.tree.ClassDefinition; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.ServiceNode; import org.ballerinalang.model.tree.TopLevelNode; @@ -51,6 +52,7 @@ import org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral; import org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef; import org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr; +import org.wso2.ballerinalang.compiler.tree.types.BLangObjectTypeNode; import org.wso2.ballerinalang.compiler.tree.types.BLangTupleTypeNode; import org.wso2.ballerinalang.compiler.util.TypeTags; @@ -161,15 +163,7 @@ public void testAnnotOnListener() { @Test public void testAnnotOnServiceOne() { - List attachments = (List) - compileResult.getAST().getServices().stream() - .filter(serviceNode -> - serviceNode.getAbsolutePath().stream().anyMatch(p -> p.getValue().contains("ser"))) - .findFirst() - .get().getServiceClass().getAnnotationAttachments() - .stream() - .filter(ann -> !isServiceIntropAnnot((BLangAnnotationAttachment) ann)) - .collect(Collectors.toList()); + List attachments = getServiceClassAnnotations("ser"); Assert.assertEquals(attachments.size(), 1); assertAnnotationNameAndKeyValuePair(attachments.get(0), "v8", "val", "v8"); } @@ -568,6 +562,43 @@ public void testAnnotOnTupleMember() { Assert.assertEquals(m1.annAttachments.get(0).annotationName.getValue(), "v30"); } + @Test + public void testAnnotOnServiceRemoteMethodOfServiceClass() { + BLangClassDefinition serviceClass = getClassDefinition(((BLangPackage) compileResult.getAST()).topLevelNodes, + "ServiceClass"); + List attachments = + serviceClass.functions.stream() + .filter(f -> f.name.value.equals("serviceRemoteFn1")) + .findFirst() + .get().getAnnotationAttachments(); + Assert.assertEquals(attachments.size(), 2); + assertAnnotationNameAndKeyValuePair(attachments.get(0), "v31", "increment", 1111L); + assertAnnotationNameAndKeyValuePair(attachments.get(1), "v32", "increment", 1112L); + } + + @Test + public void testAnnotOnServiceRemoteMethodOfServiceType() { + BLangTypeDefinition serviceObject = getTypeDefinition(compileResult.getAST().getTypeDefinitions(), + "ServiceObject"); + List attachments = + ((BLangObjectTypeNode) serviceObject.typeNode).functions.stream() + .filter(f -> f.name.value.equals("serviceRemoteFn2")) + .findFirst() + .get().getAnnotationAttachments(); + Assert.assertEquals(attachments.size(), 1); + assertAnnotationNameAndKeyValuePair(attachments.get(0), "v31", "increment", 1113L); + } + + @Test + public void testAnnotOnServiceRemoteMethodOfServiceDecl() { + List attachments = getServiceClassForServiceDecl("ser2").getFunctions().stream() + .filter(f -> f.name.value.equals("serviceRemoteFn3")) + .findFirst() + .get().getAnnotationAttachments(); + Assert.assertEquals(attachments.size(), 1); + assertAnnotationNameAndKeyValuePair(attachments.get(0), "v32", "increment", 1114L); + } + private BLangTypeDefinition getTypeDefinition(List typeDefinitions, String name) { for (TypeDefinition typeDefinition : typeDefinitions) { BLangTypeDefinition bLangTypeDefinition = (BLangTypeDefinition) typeDefinition; @@ -592,6 +623,23 @@ private BLangClassDefinition getClassDefinition(List typ throw new RuntimeException("Class Definition '" + name + "' not found."); } + private List getServiceClassAnnotations(String name) { + return (List) + getServiceClassForServiceDecl(name).getAnnotationAttachments() + .stream() + .filter(ann -> !isServiceIntropAnnot((BLangAnnotationAttachment) ann)) + .collect(Collectors.toList()); + } + + private ClassDefinition getServiceClassForServiceDecl(String name) { + return compileResult.getAST().getServices().stream() + .filter(serviceNode -> + serviceNode.getAbsolutePath().stream() + .anyMatch(p -> p.getValue().contains(name))) + .findFirst() + .get().getServiceClass(); + } + @AfterClass public void tearDown() { compileResult = null; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationRuntimeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationRuntimeTest.java index e83dd7806b40..af8cd3af966a 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationRuntimeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationRuntimeTest.java @@ -210,6 +210,12 @@ public void testListExprInConstAnnot() { BRunUtil.invoke(resultOne, "testListExprInConstAnnot"); } + @Test + public void testServiceRemoteMethodAnnotations() { + CompileResult result = BCompileUtil.compile("test-src/annotations/service_remote_method_annotations.bal"); + BRunUtil.invoke(result, "testServiceRemoteMethodAnnotations"); + } + @AfterClass public void tearDown() { resultOne = null; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal index 37ad9aec0a6b..020aeecb26ac 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal @@ -337,3 +337,34 @@ type F3 record {| type F4 record {| int x; |}; + +public annotation record {| int increment; |} v31 on service remote function; +public const annotation record {| int increment; |} v32 on source type, source service remote function; + +service class ServiceClass { + @v31 { + increment: 1111 + } + @v32 { + increment: 1112 + } + remote function serviceRemoteFn1() { + + } +} + +type ServiceObject service object { + @v31 { + increment: 1113 + } + remote function serviceRemoteFn2(); +}; + +service /ser2 on new Listener() { + @v32 { + increment: 1114 + } + remote function serviceRemoteFn3() { + + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index 8dd83a0524d2..ccc473fc18b1 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -975,3 +975,57 @@ type F4 record {| type F5 record {| int x; |}; + +public annotation v26 on service remote function; + +service class ServiceClass2 { + string name = "ballerina"; + + @v1 { + val: "v1" + } + @v2 { + val: "v2" + } + @v3 { // OK + val: "v3" + } + @v4 { // OK?, but error atm + x: 1 + } + @v5 { + val: "v5" + } + @v6 { + val: "v6" + } + @v7 + @v8 { + val: "v8" + } + @v9 { + val: "v9" + } + @v10 { + val: "v10" + } + @v11 { + val: 11 + } + @v12 { + val: "v12" + } + @v13 { + val: "v13" + } + @v15 { + val: false + } + remote function getName() returns string { return self.name; } + + @v26 + resource function get name() returns string { return self.name; } + + @v26 + function getFirstName() returns string { return self.name; } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal new file mode 100644 index 000000000000..feef5089aa67 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal @@ -0,0 +1,56 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +type Rec record {| + int increment; +|}; + +public annotation Rec srma on service remote function; + +service class ServiceClass { + @srma { + increment: 1111 + } + remote function serviceRemoteFn() { + + } +} + +function testServiceRemoteMethodAnnotations() returns error? { + any annots = getRemoteMethodAnnotations(new ServiceClass(), "serviceRemoteFn", "srma"); + assertTrue(annots is Rec); + Rec rec = annots; + assertEquality({increment: 1111}, rec); +} + +function getRemoteMethodAnnotations(service object {} obj, string methodName, string annotName) returns any = + @java:Method { + 'class: "org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue" + } external; + +function assertTrue(anydata actual) { + assertEquality(true, actual); +} + +function assertEquality(anydata expected, anydata actual) { + if expected == actual { + return; + } + + panic error(string `expected ${expected.toBalString()}, found ${actual.toBalString()}`); +} From fde9bfb6a5f268195fee992adf77a5b461d73c73 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 11 Dec 2023 12:02:23 +0530 Subject: [PATCH 014/209] Address review suggestions --- .../common/constants/ContextConstants.java | 2 - .../langserver/hover/HoverObjectResolver.java | 39 +++++++++++-------- .../langserver/hover/HoverUtil.java | 5 ++- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java index 166208e246e6..4e7d7cb8fba6 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/common/constants/ContextConstants.java @@ -27,8 +27,6 @@ public class ContextConstants { public static final String TYPE_DEF = "TYPE_DEF"; public static final String DESCRIPTION = "Description"; public static final String PARAM_TITLE = "Parameters"; - public static final String PATH_PARAM_TITLE = "Path Parameters"; - public static final String QUERY_PARAM_TITLE = "Query Parameters"; public static final String RETURN_TITLE = "Return"; public static final String FIELD_TITLE = "Fields"; public static final String METHOD_TITLE = "Methods"; diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java index e498b7a730a4..ae8dd891bf10 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java @@ -15,6 +15,7 @@ */ package org.ballerinalang.langserver.hover; +import io.ballerina.compiler.api.symbols.ArrayTypeSymbol; import io.ballerina.compiler.api.symbols.ClassSymbol; import io.ballerina.compiler.api.symbols.Documentation; import io.ballerina.compiler.api.symbols.FunctionSymbol; @@ -169,22 +170,27 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { if (isResourceMethod) { ResourcePath resourcePath = ((ResourceMethodSymbol) functionSymbol).resourcePath(); - if (resourcePath.kind() == ResourcePath.Kind.PATH_SEGMENT_LIST) { - PathSegmentList pathSegmentList = (PathSegmentList) resourcePath; - List pathParameterSymbols = pathSegmentList.pathParameters(); - parameterSymbols.addAll(pathParameterSymbols); - if (pathSegmentList.pathRestParameter().isPresent()) { - parameterSymbols.add(pathSegmentList.pathRestParameter().get()); - } - } else if (resourcePath.kind() == ResourcePath.Kind.PATH_REST_PARAM) { - parameterSymbols.add(((PathRestParam) resourcePath).parameter()); + switch (resourcePath.kind()) { + case PATH_SEGMENT_LIST: + PathSegmentList pathSegmentList = (PathSegmentList) resourcePath; + List pathParameterSymbols = pathSegmentList.pathParameters(); + parameterSymbols.addAll(pathParameterSymbols); + if (pathSegmentList.pathRestParameter().isPresent()) { + parameterSymbols.add(pathSegmentList.pathRestParameter().get()); + } + break; + case PATH_REST_PARAM: + parameterSymbols.add(((PathRestParam) resourcePath).parameter()); + break; + default: + // ignore } } Map paramsMap = documentation.get().parameterMap(); List params = new ArrayList<>(); - if (!parameterSymbols.isEmpty()) { - params.add(MarkupUtils.header(3, ContextConstants.PATH_PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); + if (!paramsMap.isEmpty() || !parameterSymbols.isEmpty()) { + params.add(MarkupUtils.header(3, ContextConstants.PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); params.addAll(parameterSymbols.stream().map(param -> { if (param.getName().isEmpty()) { return MarkupUtils.quotedString(NameUtil @@ -195,11 +201,6 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { return MarkupUtils.quotedString(NameUtil.getModifiedTypeName(context, param.typeDescriptor())) + " " + MarkupUtils.italicString(MarkupUtils.boldString(paramName)) + " : " + desc; }).collect(Collectors.toList())); - } - - if (!paramsMap.isEmpty()) { - params.add(MarkupUtils.header(3, isResourceMethod ? ContextConstants.QUERY_PARAM_TITLE - : ContextConstants.PARAM_TITLE) + CommonUtil.MD_LINE_SEPARATOR); params.addAll(functionSymbol.typeDescriptor().params().get().stream().map(param -> { if (param.getName().isEmpty()) { return MarkupUtils.quotedString(NameUtil @@ -232,7 +233,11 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { Optional restParam = functionSymbol.typeDescriptor().restParam(); if (restParam.isPresent()) { - String modifiedTypeName = NameUtil.getModifiedTypeName(context, restParam.get().typeDescriptor()); + TypeSymbol typeSymbol = restParam.get().typeDescriptor(); + String modifiedTypeName = typeSymbol.typeKind() == TypeDescKind.ARRAY ? NameUtil + .getModifiedTypeName(context, ((ArrayTypeSymbol) typeSymbol).memberTypeDescriptor()) + : NameUtil.getModifiedTypeName(context, typeSymbol); + StringBuilder restParamBuilder = new StringBuilder(MarkupUtils.quotedString(modifiedTypeName + "...")); if (restParam.get().getName().isPresent()) { restParamBuilder.append(" ") diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java index e8f844a3bbd5..c517e74c4d78 100755 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java @@ -121,8 +121,9 @@ public static Hover getHover(HoverContext context) { private static Optional getSymbolAtCursor(HoverContext context, SemanticModel semanticModel, Document srcFile, LinePosition linePosition) { NonTerminalNode cursor = context.getNodeAtCursor(); - if (cursor.kind() == SyntaxKind.LIST || cursor.kind() == SyntaxKind.PARENTHESIZED_ARG_LIST - || cursor.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE + SyntaxKind kind = cursor.kind(); + if (kind == SyntaxKind.LIST || kind == SyntaxKind.PARENTHESIZED_ARG_LIST + || kind == SyntaxKind.SIMPLE_NAME_REFERENCE && cursor.parent().kind() == SyntaxKind.CLIENT_RESOURCE_ACCESS_ACTION) { return semanticModel.symbol(cursor.parent()); } else { From 16efd84ac5eea534d95016971d1c96b19d816fe7 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 11 Dec 2023 12:04:28 +0530 Subject: [PATCH 015/209] Add more tests --- .../configs/hover_for_resource_path4.json | 21 +++++++++++++++++++ .../configs/hover_for_resource_path5.json | 21 +++++++++++++++++++ .../hover/source/hover_for_resource_path.bal | 16 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json new file mode 100644 index 000000000000..e973d99c86ea --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 30, + "character": 34 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Description.\n \n \n--- \n \n### Parameters \n \n`int` ***ids*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json new file mode 100644 index 000000000000..2a020065261b --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 31, + "character": 35 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Description.\n \n \n--- \n \n### Parameters \n \n`int` ***ids*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal index 62bed8b1e5df..cb3ee1da0d7b 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal +++ b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal @@ -9,9 +9,25 @@ client class Client { resource function post path/[string param1]/path2/[string ...param2](string param3, int ...param4) returns string { return "post"; } + + # Description. + # + # + ids - parameter description + # + return - return value description + resource function get [int... ids]() returns string { + return "get"; + } + + # Description. + # + return - return value description + resource function get path2/[int... ]() returns string { + return "get"; + } } public function test() { Client cli = new Client(); string stringResult = cli->/path/[""]/path2/[""].post("", 1); + string stringResult2 = cli->/[0]; + string stringResult3 = cli->/[0]; } From 3225a5b97f1492ae8644154a2595238507a61368 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 11 Dec 2023 12:05:28 +0530 Subject: [PATCH 016/209] Fix failing tests --- .../resources/hover/configs/hover_for_api_docs_function1.json | 2 +- .../resources/hover/configs/hover_for_resource_path1.json | 4 ++-- .../resources/hover/configs/hover_for_resource_path2.json | 4 ++-- .../resources/hover/configs/hover_for_resource_path3.json | 4 ++-- .../configs/hover_function_call_with_defaultable_param2.json | 2 +- .../src/test/resources/hover/configs/hover_function_def1.json | 2 +- .../src/test/resources/hover/configs/hover_function_def2.json | 2 +- .../resources/hover/configs/hover_resource_method_def1.json | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_function1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_function1.json index 6710c8b7f3ea..a531799090ac 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_function1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_function1.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Returns the maximum of one or more int values.\n\n```ballerina\nint:max(50, 20, 30, 70, 65) ⇒ 70\n[int, int, int] scores = [52, 95, 76];\nint:max(...scores) ⇒ 95\nint n = 18;\nn.max(25, 30, 4, 15) ⇒ 30\n```\n \n \n--- \n \n### Parameters \n \n`int` ***n*** : first int value \n`int[]...` ***ns*** : other int values \n \n--- \n \n### Return \n`int` : maximum value of value of parameter `n` and all of parameter `ns` \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/lang.int/0.0.0#max)" + "value": "Returns the maximum of one or more int values.\n\n```ballerina\nint:max(50, 20, 30, 70, 65) ⇒ 70\n[int, int, int] scores = [52, 95, 76];\nint:max(...scores) ⇒ 95\nint n = 18;\nn.max(25, 30, 4, 15) ⇒ 30\n```\n \n \n--- \n \n### Parameters \n \n`int` ***n*** : first int value \n`int...` ***ns*** : other int values \n \n--- \n \n### Return \n`int` : maximum value of value of parameter `n` and all of parameter `ns` \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/lang.int/0.0.0#max)" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json index 04579cf8808c..e0c404b849e8 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json @@ -1,6 +1,6 @@ { "position": { - "line": 15, + "line": 29, "character": 34 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json index 02685db1e52e..52264e7bbebc 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json @@ -1,6 +1,6 @@ { "position": { - "line": 15, + "line": 29, "character": 39 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json index 25ca3bedb547..afb3b9d72ef9 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json @@ -1,6 +1,6 @@ { "position": { - "line": 15, + "line": 29, "character": 55 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Path Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n### Query Parameters \n \n`string` ***param3*** : parameter description \n`int[]...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_call_with_defaultable_param2.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_call_with_defaultable_param2.json index 61ca5cf37bb8..cfd36ebb1661 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_call_with_defaultable_param2.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_call_with_defaultable_param2.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "This is function4 with input parameters\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description \n`float[]...` ***param4*** : param4 Parameter Description \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#function4)" + "value": "This is function4 with input parameters\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description \n`float...` ***param4*** : param4 Parameter Description \n \n--- \n \n[View API Docs](https://lib.ballerina.io/ballerina/module1/0.1.0#function4)" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def1.json index 31faac721b6d..e501c6a9aaea 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def1.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Description\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description`(default: \"\")` \n`int[]...` ***restparam*** : restparam Parameter Description \n \n--- \n \n### Return \n`int` : Return Value Description" + "value": "Description\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description`(default: \"\")` \n`int...` ***restparam*** : restparam Parameter Description \n \n--- \n \n### Return \n`int` : Return Value Description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def2.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def2.json index c3c6d739f136..5b7b3bbf1cb4 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def2.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_function_def2.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Description\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description`(default: \"\")` \n`int[]...` ***restparam*** : restparam Parameter Description \n \n--- \n \n### Return \n`int` : Return Value Description" + "value": "Description\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : param1 Parameter Description \n`int` ***param2*** : param2 Parameter Description \n`string` ***param3*** : param3 Parameter Description`(default: \"\")` \n`int...` ***restparam*** : restparam Parameter Description \n \n--- \n \n### Return \n`int` : Return Value Description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json index df9e8a37e385..aa4b0f12f518 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_resource_method_def1.json @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description2 for testResource1\n \n \n--- \n \n### Query Parameters \n \n`int` ***param1*** : a Parameter Description2 \n \n--- \n \n### Return \n`int` : Return Value Description2" + "value": "Test Description2 for testResource1\n \n \n--- \n \n### Parameters \n \n`int` ***param1*** : a Parameter Description2 \n \n--- \n \n### Return \n`int` : Return Value Description2" } }, "id": { From 7e9b96396bb05f473917d25ff959dcd525407734 Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 11 Dec 2023 12:09:01 +0530 Subject: [PATCH 017/209] Remove negative tests --- .../configs/hover_for_api_docs_negative.json | 21 ------------------- .../source/hover_for_api_docs_negative.bal | 18 ---------------- 2 files changed, 39 deletions(-) delete mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_negative.json delete mode 100644 language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_api_docs_negative.bal diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_negative.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_negative.json deleted file mode 100644 index a2b638e8b888..000000000000 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_api_docs_negative.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "position": { - "line": 16, - "character": 29 - }, - "source": { - "file": "hover_for_api_docs_negative.bal" - }, - "expected": { - "result": { - "contents": { - "kind": "markdown", - "value": "" - } - }, - "id": { - "left": "324" - }, - "jsonrpc": "2.0" - } -} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_api_docs_negative.bal b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_api_docs_negative.bal deleted file mode 100644 index 5ce0cfe1b655..000000000000 --- a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_api_docs_negative.bal +++ /dev/null @@ -1,18 +0,0 @@ -public client class Client { - public string url; - - public function init(string url) { - self.url = url; - } - - resource function post path2/[string id]/path4(string str, int a) returns string { - return ""; - } - -} - - -public function test() { - Client cl = new (""); - string a = cl-> /path2/[""]/path4.post() -} From 1f274f574c8c5c1b40d560f1067852e546225226 Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Mon, 11 Dec 2023 13:59:43 +0530 Subject: [PATCH 018/209] Add the object method attach point also for service remote method annots --- .../semantics/analyzer/SemanticAnalyzer.java | 1 + .../AnnotationAttachmentNegativeTest.java | 52 +++++++++---------- .../annot_attachments_negative.bal | 4 +- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 56ac5c9e987f..8601b15e3621 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -504,6 +504,7 @@ public void visit(BLangFunction funcNode, AnalyzerData data) { if (Symbols.isFlagOn(funcNode.symbol.flags, Flags.REMOTE) && funcNode.receiver != null && Symbols.isService(funcNode.receiver.getBType().tsymbol)) { annotationAttachment.attachPoints.add(AttachPoint.Point.SERVICE_REMOTE); + annotationAttachment.attachPoints.add(AttachPoint.Point.OBJECT_METHOD); } else if (funcNode.attachedFunction) { annotationAttachment.attachPoints.add(AttachPoint.Point.OBJECT_METHOD); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index 09a91349f9a6..6aea0fbab274 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 292); + Assert.assertEquals(compileResult.getErrorCount(), 290); } @Test @@ -524,37 +524,33 @@ public void testInvalidConstAnnotElements() { public void testInvalidAttachmentOnServiceRemoteMethod() { int index = 277; int line = 984; - validateError(compileResult, index++, "annotation 'v1' is not allowed on service_remote, function", - line, 5); - validateError(compileResult, index++, "annotation 'v2' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v4' is not allowed on service_remote, function", - line += 6, 5); - validateError(compileResult, index++, "annotation 'v5' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v6' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v7' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v8' is not allowed on service_remote, function", - ++line, 5); - validateError(compileResult, index++, "annotation 'v9' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v10' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v11' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v12' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index++, "annotation 'v13' is not allowed on service_remote, function", - line += 3, 5); - validateError(compileResult, index, "annotation 'v15' is not allowed on service_remote, function", - line + 3, 5); + validateError(compileResult, index++, "annotation 'v1' is not allowed on service_remote, object_method, " + + "function", line, 5); + validateError(compileResult, index++, "annotation 'v2' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v6' is not allowed on service_remote, object_method, " + + "function", line += 12, 5); + validateError(compileResult, index++, "annotation 'v7' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v8' is not allowed on service_remote, object_method, " + + "function", ++line, 5); + validateError(compileResult, index++, "annotation 'v9' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v10' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v11' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v12' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index++, "annotation 'v13' is not allowed on service_remote, object_method, " + + "function", line += 3, 5); + validateError(compileResult, index, "annotation 'v15' is not allowed on service_remote, object_method, " + + "function", line + 3, 5); } @Test public void testInvalidServiceRemoteMethodAttachmentOnNonRemoteServiceMethods() { - int index = 290; + int index = 288; validateError(compileResult, index++, "annotation 'v26' is not allowed on object_method, function", 1026, 5); validateError(compileResult, index, "annotation 'v26' is not allowed on object_method, function", diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index ccc473fc18b1..f8a82dff70bc 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -990,10 +990,10 @@ service class ServiceClass2 { @v3 { // OK val: "v3" } - @v4 { // OK?, but error atm + @v4 { // OK x: 1 } - @v5 { + @v5 { // OK val: "v5" } @v6 { From 47d9cf7d7e654b00c3ed917b62c618fd45f1d587 Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Mon, 11 Dec 2023 14:09:26 +0530 Subject: [PATCH 019/209] Refactor extraction code --- .../nativeimpl/jvm/servicetests/ServiceValue.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java index 8be3dd409875..529b5c37935e 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/servicetests/ServiceValue.java @@ -23,6 +23,7 @@ import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.types.RemoteMethodType; import io.ballerina.runtime.api.types.ResourceMethodType; import io.ballerina.runtime.api.types.ServiceType; import io.ballerina.runtime.api.utils.StringUtils; @@ -192,8 +193,9 @@ public static BValue getResourceMethodAnnotations(BObject service, BString metho } public static BValue getRemoteMethodAnnotations(BObject service, BString method, BString annotName) { - for (var methodType : ((ServiceType) service.getOriginalType()).getRemoteMethods()) { - if (methodType.getName().equals(method.getValue())) { + String methodName = method.getValue(); + for (RemoteMethodType methodType : ((ServiceType) service.getOriginalType()).getRemoteMethods()) { + if (methodType.getName().equals(methodName)) { return (BValue) methodType.getAnnotation(annotName); } } From 3061333ea931df02ed0d2a269ed048b1cd38514e Mon Sep 17 00:00:00 2001 From: gabilang Date: Mon, 11 Dec 2023 18:19:34 +0530 Subject: [PATCH 020/209] Fix zero exit code when test init failures --- .../bir/codegen/methodgen/MainMethodGen.java | 9 +++- ...ngleTestExecutionWithInitFailuresTest.java | 47 +++++++++++++++++++ ...tFailures-testExecutionWithInitFailure.txt | 10 ++++ ...tFailures-testExecutionWithInitFailure.txt | 10 ++++ .../bal-test-with-init-failure.bal | 23 +++++++++ .../src/test/resources/testng.xml | 1 + 6 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java create mode 100644 tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt create mode 100644 tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt create mode 100644 tests/testerina-integration-test/src/test/resources/single-file-tests/single-test-execution/bal-test-with-init-failure.bal diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java index 8369450757fd..2fe2265cfb15 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java @@ -55,8 +55,10 @@ import static org.objectweb.asm.Opcodes.INVOKESPECIAL; import static org.objectweb.asm.Opcodes.INVOKESTATIC; import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; +import static org.objectweb.asm.Opcodes.LCONST_1; import static org.objectweb.asm.Opcodes.NEW; import static org.objectweb.asm.Opcodes.PUTFIELD; +import static org.objectweb.asm.Opcodes.PUTSTATIC; import static org.objectweb.asm.Opcodes.RETURN; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.CLI_SPEC; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.COMPATIBILITY_CHECKER; @@ -91,6 +93,7 @@ import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.STRING_VALUE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TEST_ARGUMENTS; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TEST_CONFIG_ARGS; +import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TEST_EXECUTION_STATE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.THROWABLE; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmConstants.TOML_DETAILS; import static org.wso2.ballerinalang.compiler.bir.codegen.JvmSignatures.ADD_SHUTDOWN_HOOK; @@ -436,7 +439,7 @@ private void genSubmitToScheduler(String initClass, MethodVisitor mv, boolean is mv.visitFieldInsn(PUTFIELD, STRAND_CLASS, MethodGenUtils.FRAMES, STACK_FRAMES); startScheduler(indexMap.get(SCHEDULER_VAR), mv); - handleErrorFromFutureValue(mv, isTestFunction); + handleErrorFromFutureValue(mv, initClass, isTestFunction); } private void stopListeners(MethodVisitor mv, boolean isServiceEPAvailable) { @@ -444,7 +447,7 @@ private void stopListeners(MethodVisitor mv, boolean isServiceEPAvailable) { mv.visitMethodInsn(INVOKESTATIC , LAUNCH_UTILS, "stopListeners", "(Z)V", false); } - private void handleErrorFromFutureValue(MethodVisitor mv, boolean isTestFunction) { + private void handleErrorFromFutureValue(MethodVisitor mv, String initClass, boolean isTestFunction) { mv.visitVarInsn(ALOAD, indexMap.get(INIT_FUTURE_VAR)); mv.visitInsn(DUP); mv.visitFieldInsn(GETFIELD , FUTURE_VALUE , PANIC_FIELD, GET_THROWABLE); @@ -455,6 +458,8 @@ private void handleErrorFromFutureValue(MethodVisitor mv, boolean isTestFunction if (isTestFunction) { mv.visitFieldInsn(GETFIELD , FUTURE_VALUE , PANIC_FIELD, GET_THROWABLE); mv.visitMethodInsn(INVOKESTATIC, RUNTIME_UTILS, HANDLE_STOP_PANIC_METHOD, HANDLE_THROWABLE, false); + mv.visitInsn(LCONST_1); + mv.visitFieldInsn(PUTSTATIC, initClass, TEST_EXECUTION_STATE, "J"); } else { mv.visitFieldInsn(GETFIELD, FUTURE_VALUE, PANIC_FIELD, GET_THROWABLE); mv.visitMethodInsn(INVOKESTATIC, RUNTIME_UTILS, HANDLE_THROWABLE_METHOD, HANDLE_THROWABLE, false); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java new file mode 100644 index 000000000000..450a98e660be --- /dev/null +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.testerina.test; + +import org.ballerinalang.test.context.BMainInstance; +import org.ballerinalang.test.context.BallerinaTestException; +import org.ballerinalang.testerina.test.utils.AssertionUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.HashMap; + +public class SingleTestExecutionWithInitFailuresTest extends BaseTestCase { + + private BMainInstance balClient; + private String projectPath; + + @BeforeClass + public void setup() throws BallerinaTestException { + balClient = new BMainInstance(balServer); + projectPath = singleFileTestsPath.resolve("single-test-execution").toString(); + } + + @Test + public void testSingleBalTestExecutionWithInitFailure() throws BallerinaTestException, IOException { + String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunc", "bal-test-with-init-failure.bal"}); + String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, false); + AssertionUtils.assertOutput("TestExecutionWithInitFailures-testExecutionWithInitFailure.txt", output); + } +} diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt new file mode 100644 index 000000000000..f7fda808fadd --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt @@ -0,0 +1,10 @@ +Code coverage is not yet supported with single bal files. Ignoring the flag and continuing the test run... +warning: ignoring --includes flag since code coverage is not enabled +Compiling source + bal-test-with-init-failure.bal + +Running Tests + + bal-test-with-init-failure.bal +error: {ballerina}DivisionByZero {"message":" / by zero"} +error: there are test failures diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt new file mode 100644 index 000000000000..d3adad116c12 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt @@ -0,0 +1,10 @@ +Code coverage is not yet supported with single bal files. Ignoring the flag and continuing the test run... +warning: ignoring --includes flag since code coverage is not enabled +Compiling source + bal-test-with-init-failure.bal + +Running Tests + + bal-test-with-init-failure.bal +error: {ballerina}DivisionByZero {"message":" / by zero"} +error: there are test failures diff --git a/tests/testerina-integration-test/src/test/resources/single-file-tests/single-test-execution/bal-test-with-init-failure.bal b/tests/testerina-integration-test/src/test/resources/single-file-tests/single-test-execution/bal-test-with-init-failure.bal new file mode 100644 index 000000000000..d40fc002ccb1 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/single-file-tests/single-test-execution/bal-test-with-init-failure.bal @@ -0,0 +1,23 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +int a = 1/0; + +@test:Config {} +public function testFunc() { +} diff --git a/tests/testerina-integration-test/src/test/resources/testng.xml b/tests/testerina-integration-test/src/test/resources/testng.xml index deb6726227db..6988519fe7d7 100644 --- a/tests/testerina-integration-test/src/test/resources/testng.xml +++ b/tests/testerina-integration-test/src/test/resources/testng.xml @@ -57,6 +57,7 @@ under the License. + From e31683b6815597ea940b08fd8033b3305f4d2ed2 Mon Sep 17 00:00:00 2001 From: mindula Date: Tue, 12 Dec 2023 10:14:32 +0530 Subject: [PATCH 021/209] Address review suggestions --- .../java/org/ballerinalang/langserver/hover/HoverUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java index c517e74c4d78..229e418b1b7f 100755 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverUtil.java @@ -126,9 +126,8 @@ private static Optional getSymbolAtCursor(HoverContext context, Semantic || kind == SyntaxKind.SIMPLE_NAME_REFERENCE && cursor.parent().kind() == SyntaxKind.CLIENT_RESOURCE_ACCESS_ACTION) { return semanticModel.symbol(cursor.parent()); - } else { - return semanticModel.symbol(srcFile, linePosition); } + return semanticModel.symbol(srcFile, linePosition); } /** From 364a292016d25aefe0850e6ce70495253154adb5 Mon Sep 17 00:00:00 2001 From: Anjana S Porawagama Date: Tue, 28 Nov 2023 17:25:38 +0530 Subject: [PATCH 022/209] Update component fetch logic --- .../ballerina/packages/BallerinaPackageService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java index 3a00f737896a..7d87fa691e1d 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java @@ -98,15 +98,21 @@ public CompletableFuture components(PackageComponents try { Arrays.stream(documentIdentifiers).iterator().forEachRemaining(documentIdentifier -> { PathUtil.getPathFromURI(documentIdentifier.getUri()).ifPresent(path -> { - Optional project = this.workspaceManager.project(path); - project.ifPresent(value -> jsonPackages.add(getPackageComponents(value))); + Project project = null; + try { + project = this.workspaceManager.loadProject(path); + jsonPackages.add(getPackageComponents(project)); + } catch (Throwable e) { + String msg = "Operation 'ballerinaPackage/components' load project failed!"; + this.clientLogger.logError(PackageContext.PACKAGE_COMPONENTS, msg, e, null, (Position) null); + } }); }); - response.setProjectPackages(jsonPackages); } catch (Throwable e) { String msg = "Operation 'ballerinaPackage/components' failed!"; this.clientLogger.logError(PackageContext.PACKAGE_COMPONENTS, msg, e, null, (Position) null); } + response.setProjectPackages(jsonPackages); return response; }); } From 567b3a3ed69cea9847c017e6fe6f53812266c3d6 Mon Sep 17 00:00:00 2001 From: Anjana S Porawagama Date: Wed, 29 Nov 2023 11:00:42 +0530 Subject: [PATCH 023/209] Update checkstyle --- .../extensions/ballerina/packages/BallerinaPackageService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java index 7d87fa691e1d..aaa2a4211f50 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/extensions/ballerina/packages/BallerinaPackageService.java @@ -104,7 +104,7 @@ public CompletableFuture components(PackageComponents jsonPackages.add(getPackageComponents(project)); } catch (Throwable e) { String msg = "Operation 'ballerinaPackage/components' load project failed!"; - this.clientLogger.logError(PackageContext.PACKAGE_COMPONENTS, msg, e, null, (Position) null); + this.clientLogger.logError(PackageContext.PACKAGE_COMPONENTS, msg, e, null); } }); }); From 1d98fded88d6fc41f48367e808da1d86234f2220 Mon Sep 17 00:00:00 2001 From: Anjana S Porawagama Date: Wed, 29 Nov 2023 13:24:19 +0530 Subject: [PATCH 024/209] Update tests --- .../org/ballerinalang/langserver/packages/ComponentsTest.java | 4 ++-- .../packages/components/project-exception_expected.json | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/packages/components/project-exception_expected.json diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/packages/ComponentsTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/packages/ComponentsTest.java index bde559486cd7..eeaf2c24a8f8 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/packages/ComponentsTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/packages/ComponentsTest.java @@ -61,7 +61,6 @@ public void packageComponentsTestCase(String[] projects, String expected) throws List filePaths = new ArrayList<>(); for (String project : projects) { Path path = configsPath.resolve(project).resolve("main.bal").toAbsolutePath(); - TestUtil.openDocument(serviceEndpoint, path); filePaths.add(path.toString()); } @@ -133,7 +132,8 @@ public Object[][] getDataProvider() { {new String[]{"project", "project-functions", "project-services", "single-file"}, "multiple-packages_expected.json"}, {new String[]{"single-file"}, "single-file-package_expected.json"}, - {new String[]{"project-other"}, "project-other_expected.json"} + {new String[]{"project-other"}, "project-other_expected.json"}, + {new String[]{"non-exist"}, "project-exception_expected.json"} }; } } diff --git a/language-server/modules/langserver-core/src/test/resources/packages/components/project-exception_expected.json b/language-server/modules/langserver-core/src/test/resources/packages/components/project-exception_expected.json new file mode 100644 index 000000000000..4677642a3ac7 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/packages/components/project-exception_expected.json @@ -0,0 +1,3 @@ +{ + "result": [] +} From 49abde8f524bcd1406764c29dfd6480c6445f95e Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Thu, 14 Dec 2023 11:23:04 +0530 Subject: [PATCH 025/209] Fix review suggestions --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 6b8025b68aab..b8bd3cfc5dec 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -1530,6 +1530,7 @@ public void visit(BLangRecordVariable varNode, AnalyzerData data) { varNode.setBType(symResolver.resolveTypeNode(varNode.typeNode, currentEnv)); } + analyzeNode(varNode.typeNode, data); long ownerSymTag = currentEnv.scope.owner.tag; // If this is a module record variable, checkTypeAndVarCountConsistency already done at symbolEnter. if ((ownerSymTag & SymTag.PACKAGE) != SymTag.PACKAGE && @@ -1584,6 +1585,7 @@ public void visit(BLangTupleVariable varNode, AnalyzerData data) { varNode.setBType(symResolver.resolveTypeNode(varNode.typeNode, currentEnv)); } + analyzeNode(varNode.typeNode, data); long ownerSymTag = currentEnv.scope.owner.tag; // If this is a module tuple variable, checkTypeAndVarCountConsistency already done at symbolEnter. if ((ownerSymTag & SymTag.PACKAGE) != SymTag.PACKAGE && @@ -1609,7 +1611,6 @@ public void visit(BLangTupleVariable varNode, AnalyzerData data) { typeChecker.checkExpr(varNode.expr, currentEnv, varNode.getBType(), data.prevEnvs, data.commonAnalyzerData); checkSelfReferencesInVarNode(varNode, varNode.expr, data); - analyzeNode(varNode.typeNode, data); } private void checkSelfReferencesInVarNode(BLangVariable variable, BLangExpression rhsExpr, AnalyzerData data) { From f02002e6d47d9020fc00dc71921218af8b2839f5 Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Thu, 14 Dec 2023 11:51:02 +0530 Subject: [PATCH 026/209] Add unit tests --- .../AnnotationAttachmentNegativeTest.java | 8 ++++++-- .../annotations/annot_attachments_negative.bal | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index bafa8abcc0da..b9b7f89837b4 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 278); + Assert.assertEquals(compileResult.getErrorCount(), 282); } @Test @@ -523,7 +523,11 @@ public void testInvalidConstAnnotElements() { public void testInvalidAnnotationAttachmentOnField() { int index = 277; int line = 980; - validateError(compileResult, index, "undefined annotation 'UndefinedAnnotation'", line, 6); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line, 6); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 6); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 7); + validateError(compileResult, index++, "undefined annotation 'annot'", line += 1, 14); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 13, 2); } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index 7a09f63bb467..21da8bf20b3d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -978,4 +978,20 @@ type F5 record {| function testInvalidAnnotationAttachmentOnField() { [@UndefinedAnnotation int, int] [first, second] = [1, 2]; + [@UndefinedAnnotation int, int, int] [a, b, c] = [1, 2, 3]; + [[@UndefinedAnnotation int, int], int] [[a1, b1], c1] = [[1, 2], 3]; + record {|@annot string fname; string lname;|} {fname, lname} = getPerson(); } + +type Person record {| + string fname; + string lname; +|}; + +function getPerson() returns Person { + Person person = {fname: "Anne", lname: "Frank"}; + return person; +} + +[@UndefinedAnnotation int, int] [w, e] = [1, 2]; + From a3ea619320f203e421156061f5080c3a8248d178 Mon Sep 17 00:00:00 2001 From: gabilang Date: Tue, 19 Dec 2023 10:42:53 +0530 Subject: [PATCH 027/209] Remove redundant use of decodeIdentifier method --- .../java/io/ballerina/runtime/internal/types/BMethodType.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java index 7d59045957be..982954ae088d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java @@ -63,8 +63,7 @@ public String getName() { @Override public String getAnnotationKey() { - return Utils.decodeIdentifier(parentObjectType.getAnnotationKey()) + "." + - Utils.decodeIdentifier(funcName); + return Utils.decodeIdentifier(parentObjectType.getAnnotationKey()) + "." + funcName; } @Override From c05638c2650bcd96300ef5888c30ccd070598f69 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Wed, 20 Dec 2023 11:35:31 +0530 Subject: [PATCH 028/209] Address the review --- .../io/ballerina/cli/cmd/PushCommand.java | 34 ++++---- .../io/ballerina/cli/cmd/ToolCommand.java | 77 ++++++++----------- .../ballerina/cli/launcher/LauncherUtils.java | 2 +- .../cli-help/ballerina-tool-pull.help | 2 +- .../io/ballerina/cli/cmd/PushCommandTest.java | 1 - .../projects/util/ProjectConstants.java | 3 + 6 files changed, 59 insertions(+), 60 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java index 33ff95af9c12..70d71324f47e 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java @@ -57,6 +57,7 @@ import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Arrays; +import java.util.Optional; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -65,6 +66,7 @@ import static io.ballerina.cli.utils.CentralUtils.authenticate; import static io.ballerina.cli.utils.CentralUtils.getBallerinaCentralCliTokenUrl; import static io.ballerina.cli.utils.CentralUtils.getCentralPackageURL; +import static io.ballerina.projects.util.ProjectConstants.LOCAL_TOOLS_JSON; import static io.ballerina.projects.util.ProjectConstants.SETTINGS_FILE_NAME; import static io.ballerina.projects.util.ProjectUtils.getAccessTokenOfCLI; import static io.ballerina.projects.util.ProjectUtils.initializeProxy; @@ -78,6 +80,11 @@ @CommandLine.Command(name = PUSH_COMMAND, description = "Publish a package to Ballerina Central") public class PushCommand implements BLauncherCmd { + private static final String TOOL_DIR = "tool"; + private static final String BAL_TOOL_JSON = "bal-tool.json"; + private static final String TOOL_ID = "tool_id"; + private static final String ORG = "org"; + private static final String PACKAGE_NAME = "name"; @CommandLine.Parameters (arity = "0..1") private Path balaPath; @@ -394,10 +401,11 @@ private void pushBalaToCustomRepo(Path balaFilePath) { ProjectUtils.deleteDirectory(balaCachesPath); } ProjectUtils.extractBala(balaFilePath, balaDestPath); - handleLocalTools(balaDestPath, org, packageName, repoPath.resolve(ProjectConstants.BALA_DIR_NAME)); + createLocalToolsJsonIfLocalTool(balaDestPath, org, packageName, repoPath.resolve( + ProjectConstants.BALA_DIR_NAME)); } catch (IOException e) { throw new ProjectException("error while pushing bala file '" + balaFilePath + "' to '" - + ProjectConstants.LOCAL_REPOSITORY_NAME + "' repository. " + e.getMessage()); + + ProjectConstants.LOCAL_REPOSITORY_NAME + "' repository: " + e.getMessage()); } Path relativePathToBalaFile; @@ -410,9 +418,9 @@ private void pushBalaToCustomRepo(Path balaFilePath) { + " to '" + repositoryName + "' repository."); } - private void handleLocalTools(Path balaDestPath, String org, String packageName, Path localRepoBalaPath) { - Path balToolJsonPath = balaDestPath.resolve("tool").resolve("bal-tool.json"); - String toolId = null; + private void createLocalToolsJsonIfLocalTool(Path balaDestPath, String org, String packageName, + Path localRepoBalaPath) { + Path balToolJsonPath = balaDestPath.resolve(TOOL_DIR).resolve(BAL_TOOL_JSON); JsonObject balToolJson; JsonObject localToolJson; Gson gson = new Gson(); @@ -424,19 +432,17 @@ private void handleLocalTools(Path balaDestPath, String org, String packageName, } catch (IOException e) { throw new ProjectException("Failed to read bal-tools.json file: " + e.getMessage()); } - toolId = balToolJson.get("tool_id").getAsString(); - - if (toolId == null) { + Optional optionalToolId = Optional.ofNullable(balToolJson.get(TOOL_ID).getAsString()); + if (optionalToolId.isEmpty()) { return; } - + String toolId = optionalToolId.get(); JsonObject packageDesc = new JsonObject(); - packageDesc.addProperty("org", org); - packageDesc.addProperty("name", packageName); - Path localToolJsonPath = localRepoBalaPath.resolve("local-tools.json"); + packageDesc.addProperty(ORG, org); + packageDesc.addProperty(PACKAGE_NAME, packageName); + Path localToolJsonPath = localRepoBalaPath.resolve(LOCAL_TOOLS_JSON); if (localToolJsonPath.toFile().exists()) { - try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, - StandardCharsets.UTF_8)) { + try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, StandardCharsets.UTF_8)) { localToolJson = gson.fromJson(bufferedReader, JsonObject.class); if (localToolJson.has(toolId)) { localToolJson.remove(toolId); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java index 98af1d696211..d8385e3a2b74 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/ToolCommand.java @@ -66,6 +66,7 @@ import static io.ballerina.projects.util.ProjectConstants.BAL_TOOLS_TOML; import static io.ballerina.projects.util.ProjectConstants.CENTRAL_REPOSITORY_CACHE_NAME; import static io.ballerina.projects.util.ProjectConstants.CONFIG_DIR; +import static io.ballerina.projects.util.ProjectConstants.LOCAL_REPOSITORY_NAME; import static io.ballerina.projects.util.ProjectConstants.REPOSITORIES_DIR; import static io.ballerina.projects.util.ProjectUtils.getAccessTokenOfCLI; import static io.ballerina.projects.util.ProjectUtils.initializeProxy; @@ -93,7 +94,7 @@ public class ToolCommand implements BLauncherCmd { private static final String TOOL_REMOVE_USAGE_TEXT = "bal tool remove :[]"; private static final String TOOL_SEARCH_USAGE_TEXT = "bal tool search [|]"; private static final String TOOL_UPDATE_USAGE_TEXT = "bal tool update "; - private static final String EMPTY_STRING = ""; + private static final String EMPTY_STRING = Names.EMPTY.getValue(); private final boolean exitWhenFinish; private final PrintStream outStream; @@ -160,9 +161,9 @@ public void execute() { return; } - if (repositoryName != null && !repositoryName.equals(ProjectConstants.LOCAL_REPOSITORY_NAME)) { + if (repositoryName != null && !repositoryName.equals(LOCAL_REPOSITORY_NAME)) { String errMsg = "unsupported repository '" + repositoryName + "' found. Only '" - + ProjectConstants.LOCAL_REPOSITORY_NAME + "' repository is supported."; + + LOCAL_REPOSITORY_NAME + "' repository is supported."; CommandUtil.printError(this.errStream, errMsg, null, false); CommandUtil.exitError(this.exitWhenFinish); return; @@ -225,8 +226,8 @@ private void handlePullCommand() { return; } - if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName) && EMPTY_STRING.equals(version)) { - CommandUtil.printError(errStream, "a version should be provided when pulling a tool from local " + + if (LOCAL_REPOSITORY_NAME.equals(repositoryName) && EMPTY_STRING.equals(version)) { + CommandUtil.printError(errStream, "tool version should be provided when pulling a tool from local " + "repository", null, false); CommandUtil.exitError(this.exitWhenFinish); return; @@ -295,16 +296,23 @@ private void handleUseCommand() { BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); Optional tool = balToolsManifest.getTool(toolId, version, repositoryName); if (tool.isEmpty()) { + boolean isLocalTool = isToolAvailableInLocalRepo(toolId, version); + if (isLocalTool) { + CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not found. " + + "Run 'bal tool pull " + toolId + ":" + version + + "' or 'bal tool pull " + toolId + ":" + version + + " --repository=local' to fetch and set as the active version.", null, false); + CommandUtil.exitError(this.exitWhenFinish); + return; + } CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not found. " + - "Run 'bal tool pull " + toolId + ":" + version - + "' or 'bal tool pull " + toolId + ":" + version - + " --repository=local' to fetch and set as the active version.", null, false); + "Run 'bal tool pull " + toolId + ":" + version + + "' to fetch and set as the active version.", null, false); CommandUtil.exitError(this.exitWhenFinish); return; } this.org = tool.get().org(); this.name = tool.get().name(); - Optional currentActiveTool = balToolsManifest.getActiveTool(toolId); if (currentActiveTool.isPresent() && currentActiveTool.get().version().equals(tool.get().version()) && Objects.equals(currentActiveTool.get().repository(), tool.get().repository())) { @@ -350,8 +358,8 @@ private void handleSearchCommand() { CommandUtil.exitError(this.exitWhenFinish); return; } - if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { - CommandUtil.printError(errStream, "tool search command is not supported for local repository.", + if (LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + CommandUtil.printError(errStream, "Local repository option is not supported with tool search command", null, false); CommandUtil.exitError(this.exitWhenFinish); return; @@ -424,7 +432,7 @@ private void handleUpdateCommand() { CommandUtil.exitError(this.exitWhenFinish); return; } - if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + if (LOCAL_REPOSITORY_NAME.equals(repositoryName)) { CommandUtil.printError(errStream, "tool update command is not supported for local repository.", null, false); CommandUtil.exitError(this.exitWhenFinish); @@ -432,7 +440,6 @@ private void handleUpdateCommand() { } toolId = argList.get(1); - if (!validateToolName(toolId)) { CommandUtil.printError(errStream, "invalid tool id.", TOOL_UPDATE_USAGE_TEXT, false); CommandUtil.exitError(this.exitWhenFinish); @@ -451,10 +458,10 @@ public void pullToolAndUpdateBalToolsToml(String toolIdArg, String versionArg) { String supportedPlatform = Arrays.stream(JvmTarget.values()) .map(JvmTarget::code) .collect(Collectors.joining(",")); - if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName)) { + if (LOCAL_REPOSITORY_NAME.equals(repositoryName)) { if (!isToolAvailableInLocalRepo(toolId, version)) { errStream.println("tool '" + toolId + ":" + version + "' is not available in local repository." + - "\nPlease publish it first with 'bal push --repository=local' command."); + "\nUse 'bal push --repository=local' to publish it."); CommandUtil.exitError(this.exitWhenFinish); } addToBalToolsToml(); @@ -481,21 +488,19 @@ private boolean isToolAvailableInLocalRepo(String toolId, String version) { JsonObject localToolJson; Gson gson = new Gson(); Path localBalaPath = RepoUtils.createAndGetHomeReposPath().resolve(Path.of(REPOSITORIES_DIR, - ProjectConstants.LOCAL_REPOSITORY_NAME, BALA_DIR_NAME)); - Path localToolJsonPath = localBalaPath.resolve("local-tools.json"); - + LOCAL_REPOSITORY_NAME, BALA_DIR_NAME)); + Path localToolJsonPath = localBalaPath.resolve(ProjectConstants.LOCAL_TOOLS_JSON); if (!Files.exists(localToolJsonPath)) { return false; } - try (BufferedReader bufferedReader = Files.newBufferedReader(localToolJsonPath, StandardCharsets.UTF_8)) { localToolJson = gson.fromJson(bufferedReader, JsonObject.class); JsonObject pkgDesc = localToolJson.get(toolId).getAsJsonObject(); if (pkgDesc.isEmpty()) { return false; } - org = pkgDesc.get("org").getAsString(); - name = pkgDesc.get("name").getAsString(); + org = pkgDesc.get(ProjectConstants.ORG).getAsString(); + name = pkgDesc.get(ProjectConstants.PACKAGE_NAME).getAsString(); return Files.exists(localBalaPath.resolve(org).resolve(name).resolve(version)); } catch (IOException e) { throw new ProjectException("Failed to read local-tools.json file: " + e.getMessage()); @@ -546,7 +551,6 @@ private void addToBalToolsToml() { CommandUtil.exitError(this.exitWhenFinish); return; } - balToolsManifest.addTool(toolId, org, name, version, true, repositoryName); balToolsToml.modify(balToolsManifest); outStream.println("tool '" + toolId + ":" + version + "' successfully set as the active version."); @@ -575,7 +579,6 @@ private void removeAllToolVersions() { CommandUtil.exitError(this.exitWhenFinish); return; } - balToolsManifest.removeTool(toolId); balToolsToml.modify(balToolsManifest); if (repositoryName != null) { @@ -604,7 +607,6 @@ private void removeSpecificToolVersion() { CommandUtil.exitError(this.exitWhenFinish); return; } - org = tool.get().org(); name = tool.get().name(); boolean isDistsCompatible = checkToolDistCompatibility(); @@ -612,7 +614,6 @@ private void removeSpecificToolVersion() { CommandUtil.exitError(this.exitWhenFinish); return; } - balToolsManifest.removeToolVersion(toolId, version, repositoryName); balToolsToml.modify(balToolsManifest); if (repositoryName != null) { @@ -721,9 +722,9 @@ private boolean isToolAvailableLocally(String toolId, String version) { private boolean checkToolDistCompatibility() { SemanticVersion currentDistVersion = SemanticVersion.from(RepoUtils.getBallerinaShortVersion()); - SemanticVersion toolDistVersion = ProjectConstants.LOCAL_REPOSITORY_NAME.equals(repositoryName) - ? getToolDistVersionFromLocalCache() - : getToolDistVersionFromCentralCache(); + SemanticVersion toolDistVersion = LOCAL_REPOSITORY_NAME.equals(repositoryName) + ? getToolDistVersionFromCache(LOCAL_REPOSITORY_NAME) + : getToolDistVersionFromCache(CENTRAL_REPOSITORY_CACHE_NAME); if (!isCompatibleWithLocalDistVersion(currentDistVersion, toolDistVersion)) { CommandUtil.printError(errStream, "tool '" + toolId + ":" + version + "' is not compatible with the " + "current Ballerina distribution '" + RepoUtils.getBallerinaShortVersion() + @@ -734,20 +735,11 @@ private boolean checkToolDistCompatibility() { return true; } - private SemanticVersion getToolDistVersionFromCentralCache() { - Path centralBalaDirPath = RepoUtils.createAndGetHomeReposPath() - .resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME) + private SemanticVersion getToolDistVersionFromCache(String repositoryName) { + Path balaDirPath = RepoUtils.createAndGetHomeReposPath() + .resolve(REPOSITORIES_DIR).resolve(repositoryName) .resolve(ProjectConstants.BALA_DIR_NAME); - Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, centralBalaDirPath); - PackageJson packageJson = BalaFiles.readPackageJson(balaPath); - return SemanticVersion.from(packageJson.getBallerinaVersion()); - } - - private SemanticVersion getToolDistVersionFromLocalCache() { - Path localBalaDirPath = RepoUtils.createAndGetHomeReposPath() - .resolve(REPOSITORIES_DIR).resolve(ProjectConstants.LOCAL_REPOSITORY_NAME) - .resolve(ProjectConstants.BALA_DIR_NAME); - Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, localBalaDirPath); + Path balaPath = CommandUtil.getPlatformSpecificBalaPath(org, name, version, balaDirPath); PackageJson packageJson = BalaFiles.readPackageJson(balaPath); return SemanticVersion.from(packageJson.getBallerinaVersion()); } @@ -781,8 +773,7 @@ private void updateToolToLatestVersion() { CommandUtil.exitError(this.exitWhenFinish); return; } - - if (ProjectConstants.LOCAL_REPOSITORY_NAME.equals(tool.get().repository())) { + if (LOCAL_REPOSITORY_NAME.equals(tool.get().repository())) { CommandUtil.printError(errStream, "tools from local repository can not be updated. ", null, false); CommandUtil.exitError(this.exitWhenFinish); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java index 23a8b0ba1c92..bec861a1fe25 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java @@ -110,7 +110,7 @@ static String generateGeneralHelp(Map subCommands) { StringBuilder helpBuilder = new StringBuilder(); helpBuilder.append(BLauncherCmd.getCommandUsageInfo(HELP)); - Path balToolsTomlPath = RepoUtils.createAndGetHomeReposPath().resolve(Path.of(CONFIG_DIR, BAL_TOOLS_TOML)); + Path balToolsTomlPath = RepoUtils.createAndGetHomeReposPath().resolve(CONFIG_DIR).resolve(BAL_TOOLS_TOML); BalToolsToml balToolsToml = BalToolsToml.from(balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); Map activeToolsVsRepos = new HashMap<>(); diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help index 4d1362429601..90f2f61efa36 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-tool-pull.help @@ -9,7 +9,7 @@ OPTIONS Print the usage details of tool pull command. --repository - Pull a tool from a custom repository. + Pull a tool from local repository. DESCRIPTION Fetch a given tool from the Ballerina Central and install it diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java index d931535f27d2..f277a1836fc6 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PushCommandTest.java @@ -206,7 +206,6 @@ public void testPushWithCustomPath() throws IOException { } catch (ProjectException e) { Assert.fail(e.getMessage()); } - } @Test(description = "Push a tool to local repository") diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java index c4f462799e78..142a0194be37 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java @@ -129,4 +129,7 @@ public class ProjectConstants { public static final String EXISTING_PACKAGE_FILES_DIR = "directories-with-existing-package-files-for-bal-new"; public static final String CONFIG_ARGS_PATTERN = "-C[\\w\\W]+=([\\w\\W]+)"; public static final String CONFIG_DIR = ".config"; + public static final String ORG = "org"; + public static final String PACKAGE_NAME = "name"; + public static final String LOCAL_TOOLS_JSON = "local-tools.json"; } From a78881663b63a46ca6fc4478bae7bd449ec969e3 Mon Sep 17 00:00:00 2001 From: gabilang Date: Thu, 21 Dec 2023 09:40:03 +0530 Subject: [PATCH 029/209] Remove repeated lines --- .../compiler/bir/codegen/methodgen/MainMethodGen.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java index 2fe2265cfb15..5a4ec872f1a1 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/methodgen/MainMethodGen.java @@ -450,18 +450,17 @@ private void stopListeners(MethodVisitor mv, boolean isServiceEPAvailable) { private void handleErrorFromFutureValue(MethodVisitor mv, String initClass, boolean isTestFunction) { mv.visitVarInsn(ALOAD, indexMap.get(INIT_FUTURE_VAR)); mv.visitInsn(DUP); - mv.visitFieldInsn(GETFIELD , FUTURE_VALUE , PANIC_FIELD, GET_THROWABLE); + mv.visitFieldInsn(GETFIELD, FUTURE_VALUE, PANIC_FIELD, GET_THROWABLE); // handle any runtime errors Label labelIf = new Label(); mv.visitJumpInsn(IFNULL, labelIf); + mv.visitFieldInsn(GETFIELD, FUTURE_VALUE, PANIC_FIELD, GET_THROWABLE); if (isTestFunction) { - mv.visitFieldInsn(GETFIELD , FUTURE_VALUE , PANIC_FIELD, GET_THROWABLE); mv.visitMethodInsn(INVOKESTATIC, RUNTIME_UTILS, HANDLE_STOP_PANIC_METHOD, HANDLE_THROWABLE, false); mv.visitInsn(LCONST_1); mv.visitFieldInsn(PUTSTATIC, initClass, TEST_EXECUTION_STATE, "J"); } else { - mv.visitFieldInsn(GETFIELD, FUTURE_VALUE, PANIC_FIELD, GET_THROWABLE); mv.visitMethodInsn(INVOKESTATIC, RUNTIME_UTILS, HANDLE_THROWABLE_METHOD, HANDLE_THROWABLE, false); } mv.visitInsn(RETURN); From 3872573b6596da77992c91dfaaa5e0b8e38267c6 Mon Sep 17 00:00:00 2001 From: Dilhasha Date: Thu, 21 Dec 2023 09:38:58 +0530 Subject: [PATCH 030/209] Add name for readonly records during config schema generation --- .../internal/configschema/TypeConverter.java | 16 ++++++++------ .../ComplexTypeConfigs2/expected-schema.json | 21 ++++++++++++++++++- .../ComplexTypeConfigs2/main.bal | 6 ++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java index e4286cdddc38..4f6e0566732c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java @@ -181,14 +181,18 @@ private JsonObject generateRecordType(BRecordType effectiveType, BIntersectionTy if (!requiredFields.isEmpty()) { typeNode.add("required", requiredFields); } - // Get record type and set the type name as a property - for (BType bType : intersectionType.getConstituentTypes()) { - // Does not consider anonymous records - if (bType.tag == TypeTags.TYPEREFDESC) { - typeNode.addProperty("name", bType.toString().trim()); + // The tsymbol name is empty for anon intersection type created due to inferred readonly + if (!intersectionType.tsymbol.name.value.isEmpty()) { + typeNode.addProperty("name", intersectionType.tsymbol.toString().trim()); + } else { + // Get record type and set the type name as a property + for (BType bType : intersectionType.getConstituentTypes()) { + // Does not consider anonymous records + if (bType.tag == TypeTags.TYPEREFDESC) { + typeNode.addProperty("name", bType.toString().trim()); + } } } - return typeNode; } diff --git a/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/expected-schema.json b/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/expected-schema.json index 4ecaf0f1979d..38666331f1d7 100644 --- a/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/expected-schema.json +++ b/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/expected-schema.json @@ -140,12 +140,31 @@ } }, "description": "" + }, + "employeeReadOnly": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "salary": { + "type": "integer" + } + }, + "additionalProperties": false, + "required": [ + "name", + "salary" + ], + "name": "dilhashanazeer/complexconfigs2:0.1.0:EmployeeReadOnly", + "description": "" } }, "additionalProperties": false, "required": [ "employeeArray", - "empMapArray" + "empMapArray", + "employeeReadOnly" ] } }, diff --git a/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/main.bal b/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/main.bal index b853b3a28d88..13cc853ef4f8 100644 --- a/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/main.bal +++ b/misc/compiler-plugins/modules/configurable-schema-generator/src/test/resources/DefaultModuleProjects/ComplexTypeConfigs2/main.bal @@ -10,6 +10,11 @@ type Employee record { int salary; }; +type EmployeeReadOnly readonly & record { + string name; + int salary; +}; + configurable table key(name) t = table [ { name: "John", salary: 100 }, { name: "Jane", salary: 200 } @@ -22,6 +27,7 @@ configurable map[] myArray = [{"val1" : 22}, {"val2" : 32}]; configurable Employee[] employeeArray = ?; configurable map employeeMap = {"emp1": {name: "user1", salary: 1200}}; configurable map[] empMapArray = ?; +configurable EmployeeReadOnly employeeReadOnly = ?; public function main() { } From 97817a0817a51e5d9f43389a4c0a8b669ae76c45 Mon Sep 17 00:00:00 2001 From: gabilang Date: Fri, 22 Dec 2023 13:52:44 +0530 Subject: [PATCH 031/209] Replace '$' with '&' in identifier utils --- .../runtime/internal/types/BMethodType.java | 2 +- .../compiler/bir/codegen/JvmConstants.java | 4 ++-- .../main/java/io/ballerina/identifier/Utils.java | 16 ++++++++-------- .../test/runtime/util/TesterinaConstants.java | 2 +- .../nativeimpl/jvm/runtime/api/tests/Async.java | 12 ++++++------ .../test-src/klass/simple_service_class.bal | 2 +- .../test-src/runtime/api/async/main.bal | 4 ++-- .../runtime/api/identifier_utils/main.bal | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java index 982954ae088d..360829a47f11 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BMethodType.java @@ -63,7 +63,7 @@ public String getName() { @Override public String getAnnotationKey() { - return Utils.decodeIdentifier(parentObjectType.getAnnotationKey()) + "." + funcName; + return Utils.decodeIdentifier(parentObjectType.getAnnotationKey()) + "." + Utils.decodeIdentifier(funcName); } @Override diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java index a83d919ed8a4..388089ae40b0 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmConstants.java @@ -344,8 +344,8 @@ public class JvmConstants { public static final String TYPEDESC_CLASS_PREFIX = "$typedesc$"; public static final String FRAME_CLASS_PREFIX = "frames/$frame$"; public static final String BALLERINA = "ballerina"; - public static final String ENCODED_DOT_CHARACTER = "$0046"; - public static final String ENCODED_JAVA_MODULE = "jballerina$0046java"; + public static final String ENCODED_DOT_CHARACTER = "&0046"; + public static final String ENCODED_JAVA_MODULE = "jballerina&0046java"; public static final PackageID DEFAULT = new PackageID(Names.ANON_ORG, new Name(ENCODED_DOT_CHARACTER), DEFAULT_VERSION); public static final String BUILT_IN_PACKAGE_NAME = "lang" + ENCODED_DOT_CHARACTER + "annotations"; diff --git a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java index d0a5916552bd..57636019dc03 100644 --- a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java +++ b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java @@ -33,7 +33,7 @@ public class Utils { private static final String UNICODE_REGEX = "\\\\(\\\\*)u\\{([a-fA-F0-9]+)\\}"; public static final Pattern UNICODE_PATTERN = Pattern.compile(UNICODE_REGEX); - private static final String CHAR_PREFIX = "$"; + private static final String CHAR_PREFIX = "&"; private static final String ESCAPE_PREFIX = "\\"; private static final Pattern UNESCAPED_SPECIAL_CHAR_SET = Pattern.compile("([$&+,:;=\\?@#\\\\|/'\\ \\[\\}\\]<\\>" + ".\"^*{}~`()%!-])"); @@ -110,8 +110,8 @@ private static Identifier encodeGeneratedName(String identifier) { } private static String getFormattedStringForQuotedIdentifiers(char c) { - if (c == '$') { - return "0036"; + if (c == '&') { + return "0038"; } return getFormattedStringForJvmReservedSet(c); } @@ -154,7 +154,7 @@ public static String decodeIdentifier(String encodedIdentifier) { StringBuilder sb = new StringBuilder(); int index = 0; while (index < encodedIdentifier.length()) { - if (encodedIdentifier.charAt(index) == '$' && index + 4 < encodedIdentifier.length()) { + if (encodedIdentifier.charAt(index) == '&' && index + 4 < encodedIdentifier.length()) { if (isUnicodePoint(encodedIdentifier, index)) { sb.append((char) Integer.parseInt(encodedIdentifier.substring(index + 1, index + 5))); index += 5; @@ -259,13 +259,13 @@ public static String encodeFunctionIdentifier(String functionName) { functionName = encodeIdentifier(functionName); switch (functionName) { case ".": - return "$gen$$0046$0060init$0062"; + return "$gen$&0046&0060init&0062"; case ".": - return "$gen$$0046$0060start$0062"; + return "$gen$&0046&0060start&0062"; case ".": - return "$gen$$0046$0060stop$0062"; + return "$gen$&0046&0060stop&0062"; case ".": - return "$gen$$0046$0060testinit$0062"; + return "$gen$&0046&0060testinit&0062"; } Identifier encodedName = encodeGeneratedName(functionName); return encodedName.isEncoded ? GENERATED_METHOD_PREFIX + encodedName.name : functionName; diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaConstants.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaConstants.java index bd2619450817..5e6084bd5391 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaConstants.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/util/TesterinaConstants.java @@ -25,7 +25,7 @@ */ public class TesterinaConstants { - public static final String DOT_REPLACER = "$0046"; + public static final String DOT_REPLACER = "&0046"; public static final String BALLERINA_SOURCE_ROOT = "ballerina.source.root"; public static final String TESTERINA_TEMP_DIR = ".testerina"; public static final String TESTERINA_TEST_SUITE = "test_suit.json"; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Async.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Async.java index 9ad21188a523..0082cbddda6c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Async.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Async.java @@ -89,7 +89,7 @@ public static long getA(Environment env, BObject obj) { } public static long getResourceA(Environment env, BObject obj) { - invokeAsync(env, obj, "$gen$$getA$$0046"); + invokeAsync(env, obj, "$gen$$getA$&0046"); return 0; } @@ -117,12 +117,12 @@ public static long nonIsolatedGetA(Environment env, BObject obj) { } public static long getNonIsolatedResourceA(Environment env, BObject obj) { - invokeMethodAsyncConcurrently(env, obj, "$gen$$getA$$0046"); + invokeMethodAsyncConcurrently(env, obj, "$gen$$getA$&0046"); return 0; } public static long getNonIsolatedResourceB(Environment env, BObject obj) { - invokeMethodAsyncConcurrently(env, obj, "$gen$$getB$$0046"); + invokeMethodAsyncConcurrently(env, obj, "$gen$$getB$&0046"); return 0; } @@ -135,7 +135,7 @@ public static boolean nonIsolatedClassIsIsolatedFunction(BObject obj) { } public static long isolatedServiceGetA(Environment env, BObject obj) { - invokeMethodAsyncConcurrently(env, obj, "$gen$$getA$$0046"); + invokeMethodAsyncConcurrently(env, obj, "$gen$$getA$&0046"); return 0; } @@ -148,7 +148,7 @@ public static boolean isolatedServiceIsIsolatedFunction(BObject obj) { } public static long nonIsolatedServiceGetA(Environment env, BObject obj) { - invokeMethodAsyncSequentially(env, obj, "$gen$$getA$$0046"); + invokeMethodAsyncSequentially(env, obj, "$gen$$getA$&0046"); return 0; } @@ -253,7 +253,7 @@ public void notifyFailure(BError error) { private static boolean isResourceMethodIsolated(BObject obj) { MethodType[] methods = ((BServiceType) obj.getType()).getResourceMethods(); for (MethodType method : methods) { - if (method.getName().equals("$gen$$getA$$0046")) { + if (method.getName().equals("$gen$$getA$&0046")) { return method.isIsolated(); } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal index 9ae5d0989f34..44f52a7e6593 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal @@ -80,7 +80,7 @@ function testServiceObjectValue() { assertEquality(y, s.message + "foo"); // "$get$." is encorded into "$gen$$get$$0046" - var z = wait callMethod(s, "$gen$$get$$0046"); + var z = wait callMethod(s, "$gen$$get$&0046"); assertEquality(z, s.message + "dot"); var rParamVal0 = wait callMethodWithParams(s, "$get$foo$^", [1]); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/async/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/async/main.bal index adaf1a209dfa..011406a86148 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/async/main.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/async/main.bal @@ -337,14 +337,14 @@ public function main() { test:assertEquals(isolatedServiceClass.asyncGetA(), 3); test:assertTrue(isolatedServiceClass.isIsolated()); test:assertTrue(isolatedServiceClass.isIsolatedFunction()); - test:assertTrue(isolatedServiceClass.isIsolatedFunctionWithName("$gen$$getA$$0046")); + test:assertTrue(isolatedServiceClass.isIsolatedFunctionWithName("$gen$$getA$&0046")); NonIsolatedServiceClass nonIsolatedServiceClass = new (); test:assertEquals(nonIsolatedServiceClass.callGetA(), 4); test:assertEquals(nonIsolatedServiceClass.asyncGetA(), 4); test:assertFalse(nonIsolatedServiceClass.isIsolated()); test:assertFalse(nonIsolatedServiceClass.isIsolatedFunction()); - test:assertFalse(nonIsolatedServiceClass.isIsolatedFunctionWithName("$gen$$getA$$0046")); + test:assertFalse(nonIsolatedServiceClass.isIsolatedFunctionWithName("$gen$$getA$&0046")); // invokeAsync api calls negative test cases diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal index 8b8fa9362fbf..f3970e5cfe0d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal @@ -54,7 +54,7 @@ function testFunctionParameters() { function testIdentifierDecoding() { test:assertEquals(decodeIdentifier("üňĩćőđę_ƈȏɳʂʈ_IL"), "üňĩćőđę_ƈȏɳʂʈ_IL"); test:assertEquals(decodeIdentifier("const_IL_123"), "const_IL_123"); - test:assertEquals(decodeIdentifier(" $0047$0058@$0091`{~_IL"), " /:@[`{~_IL"); + test:assertEquals(decodeIdentifier(" &0047&0058@&0091`{~_IL"), " /:@[`{~_IL"); } function testEscapeSpecialCharacters() { From 7acf8040cdbc1145d5a03798f7e51a0bc9db0cb4 Mon Sep 17 00:00:00 2001 From: gabilang Date: Tue, 26 Dec 2023 21:43:49 +0530 Subject: [PATCH 032/209] Change encode identifier char used in testerina --- .codecov.yml | 2 +- .../test-src/klass/simple_service_class.bal | 2 +- .../test/CodeCoverageReportTest.java | 50 +++++++++---------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index df4b673ce290..72dcaaf4c845 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -3,7 +3,7 @@ codecov: max_report_age: off fixes: - - "ballerina/lang$0046*/*/::langlib/lang.*/src/main/ballerina/" + - "ballerina/lang&0046*/*/::langlib/lang.*/src/main/ballerina/" ignore: - "**/tests" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal index 44f52a7e6593..f7b178a9fd12 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal @@ -79,7 +79,7 @@ function testServiceObjectValue() { var y = wait callMethod(s, "$get$foo$path"); assertEquality(y, s.message + "foo"); - // "$get$." is encorded into "$gen$$get$$0046" + // "$get$." is encorded into "$gen$$get$&0046" var z = wait callMethod(s, "$gen$$get$&0046"); assertEquality(z, s.message + "dot"); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java index 82693a89b09d..3e2e37b0c219 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodeCoverageReportTest.java @@ -111,42 +111,42 @@ public void multipleModulePkgCoverageTest() throws BallerinaTestException { copyReportDTDFile(reportRoot); ArrayList expectedPackageNames = new ArrayList<>(); Collections.addAll(expectedPackageNames, - "testerina_report/foo$0046math$test/0/constants", + "testerina_report/foo&0046math$test/0/constants", "testerina_report/foo$test/0/types", - "testerina_report/foo$0046bar/0/creators", - "testerina_report/foo$0046bar$0046tests/0", - "testerina_report/foo$0046math$test/0", + "testerina_report/foo&0046bar/0/creators", + "testerina_report/foo&0046bar&0046tests/0", + "testerina_report/foo&0046math$test/0", "testerina_report/foo/0/creators", - "testerina_report/foo$0046bar$0046tests/0/creators", - "testerina_report/foo$0046bar$0046tests/0/types", - "testerina_report/foo$0046math/0/constants", - "testerina_report/foo$0046bar$0046tests$test/0/constants", - "testerina_report/foo$0046math/0/types", - "testerina_report/foo$0046bar/0/annotations", + "testerina_report/foo&0046bar&0046tests/0/creators", + "testerina_report/foo&0046bar&0046tests/0/types", + "testerina_report/foo&0046math/0/constants", + "testerina_report/foo&0046bar&0046tests$test/0/constants", + "testerina_report/foo&0046math/0/types", + "testerina_report/foo&0046bar/0/annotations", "test-report-tests/modules/math", - "testerina_report/foo$0046math$test/0/creators", - "testerina_report/foo$0046math/0/creators", - "testerina_report/foo$0046bar$0046tests$test/0/types", + "testerina_report/foo&0046math$test/0/creators", + "testerina_report/foo&0046math/0/creators", + "testerina_report/foo&0046bar&0046tests$test/0/types", "test-report-tests", "testerina_report/foo/0/types", - "testerina_report/foo$0046bar/0/types", - "testerina_report/foo$0046bar$0046tests/0/constants", + "testerina_report/foo&0046bar/0/types", + "testerina_report/foo&0046bar&0046tests/0/constants", "testerina_report/foo$test/0", "testerina_report/foo/0", - "testerina_report/foo$0046bar/0", + "testerina_report/foo&0046bar/0", "testerina_report/foo/0/annotations", "testerina_report/foo/0/constants", - "testerina_report/foo$0046math$test/0/types", - "testerina_report/foo$0046math/0/annotations", - "testerina_report/foo$0046bar$0046tests$test/0/creators", - "testerina_report/foo$0046bar$0046tests$test/0", - "testerina_report/foo$0046bar$0046tests/0/annotations", - "testerina_report/foo$0046bar$0046tests$test/0/annotations", - "testerina_report/foo$0046math$test/0/annotations", + "testerina_report/foo&0046math$test/0/types", + "testerina_report/foo&0046math/0/annotations", + "testerina_report/foo&0046bar&0046tests$test/0/creators", + "testerina_report/foo&0046bar&0046tests$test/0", + "testerina_report/foo&0046bar&0046tests/0/annotations", + "testerina_report/foo&0046bar&0046tests$test/0/annotations", + "testerina_report/foo&0046math$test/0/annotations", "testerina_report/foo$test/0/annotations", "testerina_report/foo$test/0/constants", - "testerina_report/foo$0046math/0", - "testerina_report/foo$0046bar/0/constants", + "testerina_report/foo&0046math/0", + "testerina_report/foo&0046bar/0/constants", "test-report-tests/modules/bar", "testerina_report/foo$test/0/creators" ); From 437cbc0d7022e9c361769c3284081b7524a8c48c Mon Sep 17 00:00:00 2001 From: Dilhasha Date: Tue, 2 Jan 2024 09:51:19 +0530 Subject: [PATCH 033/209] Fix PR suggestions --- .../projects/internal/configschema/TypeConverter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java index 4f6e0566732c..eacdb53918ec 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java @@ -33,6 +33,7 @@ import org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType; import org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral; import org.wso2.ballerinalang.compiler.tree.expressions.BLangNumericLiteral; +import org.wso2.ballerinalang.compiler.util.Names; import org.wso2.ballerinalang.compiler.util.TypeTags; import java.util.HashMap; @@ -182,13 +183,14 @@ private JsonObject generateRecordType(BRecordType effectiveType, BIntersectionTy typeNode.add("required", requiredFields); } // The tsymbol name is empty for anon intersection type created due to inferred readonly - if (!intersectionType.tsymbol.name.value.isEmpty()) { + if (intersectionType.tsymbol.name != Names.EMPTY) { typeNode.addProperty("name", intersectionType.tsymbol.toString().trim()); } else { // Get record type and set the type name as a property for (BType bType : intersectionType.getConstituentTypes()) { // Does not consider anonymous records if (bType.tag == TypeTags.TYPEREFDESC) { + // Revisit with https://github.com/ballerina-platform/ballerina-lang/issues/24078 typeNode.addProperty("name", bType.toString().trim()); } } From a1a5651f69eff7a20d5026d1812379b12fa05c7e Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Fri, 8 Dec 2023 15:06:32 +0530 Subject: [PATCH 034/209] Add display annotation support for worker --- .../src/main/ballerina/annotations.bal | 2 +- .../annotations/DisplayAnnotationTest.java | 21 ++++++++++++++++++- .../test-src/annotations/display_annot.bal | 11 ++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/langlib/lang.annotations/src/main/ballerina/annotations.bal b/langlib/lang.annotations/src/main/ballerina/annotations.bal index d697461e45e3..9575dcd4f092 100644 --- a/langlib/lang.annotations/src/main/ballerina/annotations.bal +++ b/langlib/lang.annotations/src/main/ballerina/annotations.bal @@ -103,4 +103,4 @@ public const annotation record { "text"|"password"|"file" kind?; } display on source type, source class, source function, source return, source parameter, source field, source listener, - source var, source const, source annotation, source service; + source var, source const, source annotation, source service, source worker; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java index 3b6c09cba9a3..09533f15043d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java @@ -18,6 +18,7 @@ import org.ballerinalang.model.tree.AnnotationAttachmentNode; import org.ballerinalang.model.tree.ClassDefinition; +import org.ballerinalang.model.tree.FunctionNode; import org.ballerinalang.model.tree.NodeKind; import org.ballerinalang.model.tree.SimpleVariableNode; import org.ballerinalang.model.tree.TypeDefinition; @@ -30,13 +31,17 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment; +import org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody; import org.wso2.ballerinalang.compiler.tree.BLangClassDefinition; import org.wso2.ballerinalang.compiler.tree.BLangFunction; import org.wso2.ballerinalang.compiler.tree.BLangPackage; import org.wso2.ballerinalang.compiler.tree.BLangService; import org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression; import org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation; +import org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction; import org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr; +import org.wso2.ballerinalang.compiler.tree.statements.BLangSimpleVariableDef; +import org.wso2.ballerinalang.compiler.tree.statements.BLangStatement; import java.util.List; @@ -91,7 +96,7 @@ public void testDisplayAnnotOnObjectAndMemberFunction() { @Test public void testDisplayAnnotOnRecord() { - TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(13); + TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(14); List annot = typeDefinition.getAnnotationAttachments(); Assert.assertEquals(annot.size(), 1); Assert.assertEquals(annot.get(0).getExpression().toString(), @@ -104,6 +109,20 @@ public void testDisplayAnnotOnRecord() { "clientSecret field,kind: <\"text\"|\"password\"|\"file\"?> password}"); } + @Test + public void testDisplayAnnotOnWorker() { + BLangBlockFunctionBody bLangBlockFunctionBody = + ((BLangBlockFunctionBody) result.getAST().getFunctions().get(2).getBody()); + BLangStatement bLangStatement = bLangBlockFunctionBody.getStatements().get(1); + FunctionNode workerExpression = + ((BLangLambdaFunction) ((BLangSimpleVariableDef) bLangStatement).getVariable() + .getInitialExpression()).getFunctionNode(); + BLangAnnotationAttachment annot = + (BLangAnnotationAttachment) workerExpression.getAnnotationAttachments().get(0); + Assert.assertEquals(getActualExpressionFromAnnotationAttachmentExpr(annot.expr).toString(), + " {label: worker annotation,type: named,id: hash}"); + } + @Test void testDisplayAnnotationNegative() { BAssertUtil.validateError(negative, 0, "cannot specify more than one annotation value " + "for annotation 'ballerina/lang.annotations:0.0.0:display'", 17, 1); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal index e7cff1656913..8d5a12eda12f 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal @@ -74,3 +74,14 @@ public type RefreshTokenGrantConfig record {| @display {iconPath: "Field.icon", label: "clientSecret field", kind: "password"} string clientSecret; |}; + +function annotationOnWorker() { + @display { + label: "worker annotation", + 'type: "named", + id: "hash" + } + worker testWorker { + + } +} From b2c7ac7005ad1ab6b396b05be1eb0183549104e9 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Sat, 9 Dec 2023 20:44:30 +0530 Subject: [PATCH 035/209] Update LS tests for display annotation --- .../annotation_ctx/config/startActionAnnotation1.json | 9 +++++++++ .../annotation_ctx/config/startActionAnnotation2.json | 9 +++++++++ .../annotation_ctx/config/workerDeclAnnotation1.json | 9 +++++++++ .../annotation_ctx/config/workerDeclAnnotation2.json | 9 +++++++++ 4 files changed, 36 insertions(+) diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation1.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation1.json index eaf621f46a1f..5e1daca3dc0e 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation1.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation1.json @@ -401,6 +401,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation2.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation2.json index b71fc0874085..4fd4102cc768 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation2.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/startActionAnnotation2.json @@ -401,6 +401,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation1.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation1.json index ed4c5d941759..220c7227eda9 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation1.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation1.json @@ -401,6 +401,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation2.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation2.json index bac02a34004a..71bc7bc43d63 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation2.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/workerDeclAnnotation2.json @@ -401,6 +401,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } From 78641d61b96ac79461e835422216660bf72db809 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Fri, 15 Dec 2023 10:50:55 +0530 Subject: [PATCH 036/209] Add display annotation support for external --- .../src/main/ballerina/annotations.bal | 2 +- .../config/externalFunctionAnnotation1.json | 9 +++++++++ .../config/externalFunctionAnnotation2.json | 9 +++++++++ .../test/annotations/DisplayAnnotationTest.java | 14 ++++++++++++-- .../test-src/annotations/display_annot.bal | 2 ++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/langlib/lang.annotations/src/main/ballerina/annotations.bal b/langlib/lang.annotations/src/main/ballerina/annotations.bal index 9575dcd4f092..68219be653ff 100644 --- a/langlib/lang.annotations/src/main/ballerina/annotations.bal +++ b/langlib/lang.annotations/src/main/ballerina/annotations.bal @@ -103,4 +103,4 @@ public const annotation record { "text"|"password"|"file" kind?; } display on source type, source class, source function, source return, source parameter, source field, source listener, - source var, source const, source annotation, source service, source worker; + source var, source const, source annotation, source service, source external, source worker; diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation1.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation1.json index 611cad7857fa..0140641c0aa5 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation1.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation1.json @@ -392,6 +392,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } diff --git a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation2.json b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation2.json index e23f771bff30..83d291b37c27 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation2.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/annotation_ctx/config/externalFunctionAnnotation2.json @@ -392,6 +392,15 @@ "sortText": "P", "insertText": "typedesc", "insertTextFormat": "Snippet" + }, + { + "label": "display", + "kind": "Property", + "detail": "Annotation", + "sortText": "B", + "insertText": "display {\n\tlabel: ${1:\"\"}\n}", + "insertTextFormat": "Snippet", + "additionalTextEdits": [] } ] } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java index 09533f15043d..155c2050b1a3 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/DisplayAnnotationTest.java @@ -33,6 +33,7 @@ import org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment; import org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody; import org.wso2.ballerinalang.compiler.tree.BLangClassDefinition; +import org.wso2.ballerinalang.compiler.tree.BLangExternalFunctionBody; import org.wso2.ballerinalang.compiler.tree.BLangFunction; import org.wso2.ballerinalang.compiler.tree.BLangPackage; import org.wso2.ballerinalang.compiler.tree.BLangService; @@ -96,7 +97,7 @@ public void testDisplayAnnotOnObjectAndMemberFunction() { @Test public void testDisplayAnnotOnRecord() { - TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(14); + TypeDefinition typeDefinition = result.getAST().getTypeDefinitions().get(15); List annot = typeDefinition.getAnnotationAttachments(); Assert.assertEquals(annot.size(), 1); Assert.assertEquals(annot.get(0).getExpression().toString(), @@ -123,7 +124,16 @@ public void testDisplayAnnotOnWorker() { " {label: worker annotation,type: named,id: hash}"); } - @Test void testDisplayAnnotationNegative() { + @Test + public void testDisplayAnnotOnExternalFunctionBody() { + BLangExternalFunctionBody body = (BLangExternalFunctionBody) result.getAST().getFunctions().get(3).getBody(); + BLangAnnotationAttachment annot = (BLangAnnotationAttachment) ((List) body.annAttachments).get(0); + Assert.assertEquals(getActualExpressionFromAnnotationAttachmentExpr(annot.expr).toString(), + " {label: external,id: hash}"); + } + + @Test + void testDisplayAnnotationNegative() { BAssertUtil.validateError(negative, 0, "cannot specify more than one annotation value " + "for annotation 'ballerina/lang.annotations:0.0.0:display'", 17, 1); BAssertUtil.validateError(negative, 1, "incompatible types: expected '\"text\"|\"password\"|\"file\"?'," + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal index 8d5a12eda12f..6cb6f0cd2cd6 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/display_annot.bal @@ -85,3 +85,5 @@ function annotationOnWorker() { } } + +function testExternalFunction() = @display { label: "external", id: "hash" } external; From 8dfc191f465433b1339c519be8a06442f2f4d885 Mon Sep 17 00:00:00 2001 From: gabilang Date: Wed, 3 Jan 2024 17:17:27 +0530 Subject: [PATCH 037/209] Restore string formatter changes --- .../src/main/java/io/ballerina/identifier/Utils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java index 57636019dc03..1457dc1248e7 100644 --- a/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java +++ b/misc/identifier-util/src/main/java/io/ballerina/identifier/Utils.java @@ -110,8 +110,8 @@ private static Identifier encodeGeneratedName(String identifier) { } private static String getFormattedStringForQuotedIdentifiers(char c) { - if (c == '&') { - return "0038"; + if (c == '$') { + return "0036"; } return getFormattedStringForJvmReservedSet(c); } From 0893d434e30e3b2749a152a062e92cbec57fd6a0 Mon Sep 17 00:00:00 2001 From: gabilang Date: Thu, 4 Jan 2024 10:46:06 +0530 Subject: [PATCH 038/209] Add a test case with multiple modules --- ...ngleTestExecutionWithInitFailuresTest.java | 2 +- .../TestExecutionWithInitFailuresTest.java | 67 +++++++++++++++++++ ...ingleFileTestExecutionWithInitFailure.txt} | 0 .../unix/TestExecutionWithInitFailures.txt | 30 +++++++++ ...ingleFileTestExecutionWithInitFailure.txt} | 0 .../windows/TestExecutionWithInitFailures.txt | 30 +++++++++ .../Ballerina.toml | 7 ++ .../test-execution-with-init-failure/main.bal | 29 ++++++++ .../modules/moduleA/main.bal | 24 +++++++ .../modules/moduleA/tests/test.bal | 22 ++++++ .../modules/moduleB/main.bal | 26 +++++++ .../modules/moduleB/tests/test.bal | 22 ++++++ .../modules/moduleC/main.bal | 19 ++++++ .../modules/moduleC/tests/test.bal | 22 ++++++ .../modules/moduleD/main.bal | 19 ++++++ .../modules/moduleD/tests/test.bal | 22 ++++++ .../tests/test_main.bal | 27 ++++++++ .../src/test/resources/testng.xml | 1 + 18 files changed, 368 insertions(+), 1 deletion(-) create mode 100644 tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java rename tests/testerina-integration-test/src/test/resources/command-outputs/unix/{TestExecutionWithInitFailures-testExecutionWithInitFailure.txt => SingleFileTestExecutionWithInitFailure.txt} (100%) create mode 100644 tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures.txt rename tests/testerina-integration-test/src/test/resources/command-outputs/windows/{TestExecutionWithInitFailures-testExecutionWithInitFailure.txt => SingleFileTestExecutionWithInitFailure.txt} (100%) create mode 100644 tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures.txt create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/Ballerina.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/tests/test.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/tests/test.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/tests/test.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/tests/test.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/tests/test_main.bal diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java index 450a98e660be..2556200fc113 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/SingleTestExecutionWithInitFailuresTest.java @@ -42,6 +42,6 @@ public void setup() throws BallerinaTestException { public void testSingleBalTestExecutionWithInitFailure() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunc", "bal-test-with-init-failure.bal"}); String output = balClient.runMainAndReadStdOut("test", args, new HashMap<>(), projectPath, false); - AssertionUtils.assertOutput("TestExecutionWithInitFailures-testExecutionWithInitFailure.txt", output); + AssertionUtils.assertOutput("SingleFileTestExecutionWithInitFailure.txt", output); } } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java new file mode 100644 index 000000000000..906a1aa637e0 --- /dev/null +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/TestExecutionWithInitFailuresTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ballerinalang.testerina.test; + +import org.ballerinalang.test.context.BMainInstance; +import org.ballerinalang.test.context.BallerinaTestException; +import org.ballerinalang.testerina.test.utils.AssertionUtils; +import org.ballerinalang.testerina.test.utils.CommonUtils; +import org.ballerinalang.testerina.test.utils.FileUtils; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.HashMap; + +import static org.ballerinalang.testerina.test.BaseTestCase.balServer; +import static org.ballerinalang.testerina.test.BaseTestCase.projectBasedTestsPath; + +public class TestExecutionWithInitFailuresTest { + + private BMainInstance balClient; + private String projectPath; + + @BeforeClass + public void setup() throws BallerinaTestException { + balClient = new BMainInstance(balServer); + projectPath = projectBasedTestsPath.resolve("test-execution-with-init-failure").toString(); + } + + @Test() + public void testModuleExecutionFlow() throws BallerinaTestException, IOException { + String[] args = new String[]{}; + String output = balClient.runMainAndReadStdOut("test", args, + new HashMap<>(), projectPath, false); + String firstString = "tests.test_execute-generated_"; + String endString = "lineNumber"; + output = CommonUtils.replaceVaryingString(firstString, endString, output); + AssertionUtils.assertOutput("TestExecutionWithInitFailures.txt", output); + } + + @AfterMethod + public void copyExec() { + try { + FileUtils.copyBallerinaExec(Paths.get(projectPath), String.valueOf(System.currentTimeMillis())); + } catch (IOException e) { + // ignore exception + } + } +} diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/SingleFileTestExecutionWithInitFailure.txt similarity index 100% rename from tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt rename to tests/testerina-integration-test/src/test/resources/command-outputs/unix/SingleFileTestExecutionWithInitFailure.txt diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures.txt new file mode 100644 index 000000000000..d17dbb2fdf17 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/TestExecutionWithInitFailures.txt @@ -0,0 +1,30 @@ +Compiling source + wso2/testExecutionWithModuleInitFailure:0.0.0 + +Running Tests + + testExecutionWithModuleInitFailure.moduleD + [pass] testFunc + + + 1 passing + 0 failing + 0 skipped + + testExecutionWithModuleInitFailure +error: {ballerina}DivisionByZero {"message":" / by zero"} + + testExecutionWithModuleInitFailure.moduleA +error: {ballerina}DivisionByZero {"message":" / by zero"} + + testExecutionWithModuleInitFailure.moduleC + [pass] testFunc + + + 1 passing + 0 failing + 0 skipped + + testExecutionWithModuleInitFailure.moduleB +error: {ballerina}DivisionByZero {"message":" / by zero"} +error: there are test failures diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/SingleFileTestExecutionWithInitFailure.txt similarity index 100% rename from tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures-testExecutionWithInitFailure.txt rename to tests/testerina-integration-test/src/test/resources/command-outputs/windows/SingleFileTestExecutionWithInitFailure.txt diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures.txt new file mode 100644 index 000000000000..c235bb1dec8d --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/TestExecutionWithInitFailures.txt @@ -0,0 +1,30 @@ +Compiling source + wso2/testExecutionWithModuleInitFailure:0.0.0 + +Running Tests + + testExecutionWithModuleInitFailure.moduleD + [pass] testFunc + + + 1 passing + 0 failing + 0 skipped + + testExecutionWithModuleInitFailure +error: {ballerina}DivisionByZero {"message":" / by zero"} + + testExecutionWithModuleInitFailure.moduleA +error: {ballerina}DivisionByZero {"message":" / by zero"} + + testExecutionWithModuleInitFailure.moduleC + [pass] testFunc + + + 1 passing + 0 failing + 0 skipped + + testExecutionWithModuleInitFailure.moduleB +error: {ballerina}DivisionByZero {"message":" / by zero"} +error: there are test failures diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/Ballerina.toml new file mode 100644 index 000000000000..c061a3482eee --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/Ballerina.toml @@ -0,0 +1,7 @@ +[package] +org = "wso2" +name = "testExecutionWithModuleInitFailure" +version = "0.0.0" + +[build-options] +observabilityIncluded = false diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/main.bal new file mode 100644 index 000000000000..d1948f463ce6 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/main.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import testExecutionWithModuleInitFailure.moduleA; +import testExecutionWithModuleInitFailure.moduleD; + +public function main() { +} + +public function getGreeting(string s1, string s2) returns string { + return s1 + moduleA:addSpaceAndGetString(s2); +} + +public function getKey(int i) returns int { + return i * moduleD:add(i, i*i); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/main.bal new file mode 100644 index 000000000000..f69e9257e019 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/main.bal @@ -0,0 +1,24 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import testExecutionWithModuleInitFailure.moduleB; + +public function main() { +} + +public function addSpaceAndGetString(string s) returns string { + return " " + moduleB:add(s); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/tests/test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/tests/test.bal new file mode 100644 index 000000000000..0a39e396dbe8 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleA/tests/test.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +public function testFunc() { + test:assertEquals(addSpaceAndGetString("World"), " World!"); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/main.bal new file mode 100644 index 000000000000..8f95342e2231 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/main.bal @@ -0,0 +1,26 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import testExecutionWithModuleInitFailure.moduleC; + +int a = 1/0; + +public function main() { +} + +public function add(string s) returns string { + return s + moduleC:foo(); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/tests/test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/tests/test.bal new file mode 100644 index 000000000000..d656e332ff54 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleB/tests/test.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +function testFunc() { + test:assertEquals(add("World"), "World!"); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/main.bal new file mode 100644 index 000000000000..3a3af34ef109 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/main.bal @@ -0,0 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function foo() returns string { + return "!"; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/tests/test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/tests/test.bal new file mode 100644 index 000000000000..9574618fa2c0 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleC/tests/test.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +public function testFunc() { + test:assertEquals(foo(), "!"); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/main.bal new file mode 100644 index 000000000000..9ee2f5fadc94 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/main.bal @@ -0,0 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +public function add(int a, int b) returns int { + return a + b; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/tests/test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/tests/test.bal new file mode 100644 index 000000000000..906f74278852 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/modules/moduleD/tests/test.bal @@ -0,0 +1,22 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +function testFunc() { + test:assertEquals(add(3, 2), 5); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/tests/test_main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/tests/test_main.bal new file mode 100644 index 000000000000..5c6fb0aee224 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/test-execution-with-init-failure/tests/test_main.bal @@ -0,0 +1,27 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/test; + +@test:Config {} +function testFunc() { + test:assertEquals(getGreeting("Hello", "World"), "Hello World!"); +} + +@test:Config {} +function testFunc2() { + test:assertEquals(getKey(2), 12); +} diff --git a/tests/testerina-integration-test/src/test/resources/testng.xml b/tests/testerina-integration-test/src/test/resources/testng.xml index 6988519fe7d7..db46e1c50239 100644 --- a/tests/testerina-integration-test/src/test/resources/testng.xml +++ b/tests/testerina-integration-test/src/test/resources/testng.xml @@ -58,6 +58,7 @@ under the License. + From 6828000113bb788371e152cb41880792e8ddc495 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Thu, 4 Jan 2024 14:32:29 +0530 Subject: [PATCH 039/209] Fix build failure --- ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 3932 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 3932 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 3932 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 2337 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 3932 bytes .../test-resources/tool-gayals/.DS_Store | Bin 0 -> 6148 bytes .../tool-gayals/.devcontainer.json | 4 ++ .../test-resources/tool-gayals/.gitignore | 3 ++ .../test-resources/tool-gayals/BalTool.toml | 5 ++ .../test-resources/tool-gayals/Ballerina.toml | 8 ++++ .../tool-gayals/CompilerPlugin.toml | 6 +++ .../tool-gayals/Dependencies.toml | 45 ++++++++++++++++++ .../test-resources/tool-gayals/Package.md | 4 ++ .../test-resources/tool-gayals/README.md | 4 ++ .../test-resources/tool-gayals/main.bal | 5 ++ .../tool-gayals/target-dir/.DS_Store | Bin 0 -> 6148 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes ...aldassanayake-tool_gayal-java17-1.1.0.bala | Bin 0 -> 10608 bytes .../test-resources/tool-gayals/test.json | 10 ++++ .../tool/libs/GayalsCommand-1.0-SNAPSHOT.jar | Bin 0 -> 3932 bytes ...with-analyzer-generator-modifier-1.0.0.jar | Bin 0 -> 6119 bytes 26 files changed, 94 insertions(+) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.DS_Store create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.devcontainer.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.gitignore create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/BalTool.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/CompilerPlugin.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Dependencies.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Package.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/README.md create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/.DS_Store create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/gayaldassanayake-tool_gayal-java17-1.1.0.bala create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/test.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/tool/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_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)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..dcb434b1ce56e06dea3ecd52f2a911b94d5764a4 GIT binary patch literal 3932 zcmaJ^2{@Ep8(W6gw_K^Qw33`S%NDN7SFl!=UOkYuauWKDZRgAiGg zElQT`LbCkh|GxT4-~T`Fbj`JPX;+yTs-&r+Z%n(RnEl=9S{(2X=l!UihY};?`FfP(}=snhHoJ!d)yJ1bEb<-C{D#Y z6Vvj7v8jpg(qFg9#F4&3zX2%b+qwubThe`tTT2N~lGZF9&)L+=OYVz)NTALkR&-8kMPE5Q>0v2;;5_H3!^5<4*dFScu&8c#vR} z%QVF?mc)Y2Ga@cYTMUqt`I`kAxz!z2cz{MJmGS*}PL>j^SJ%L-e!bw3Z}})B(*3pn zTlwTXHIYsWN3(9*jPCv`CA1WqPbtmzHtYxcWWBihAIn7HjmU{{mIk0UNDduNz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+xP?v+Sc~2mEiXM2$(cgEX@`yZ@gH-b>r7oOZ#xmWPw1_CIOA=%~FOcF{jX z+OAys%XR|?QHOtvr~gOV6;FTJE-8yT{F}5ZrS=l{N~s^zJlw0_iT@(3_WIg;asT71 zfd02d{L3}I*Viuh$0_V)$X~X*p;*>m&hcly?B(yxmmePTa1Z~L|9`W`6b__rfGVS@ NA3t?fQu}vj{{dI~fg%6^ literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(&9qbk+)DO!sI_0AgPtJyVH=05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b9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..dcb434b1ce56e06dea3ecd52f2a911b94d5764a4 GIT binary patch literal 3932 zcmaJ^2{@Ep8(W6gw_K^Qw33`S%NDN7SFl!=UOkYuauWKDZRgAiGg zElQT`LbCkh|GxT4-~T`Fbj`JPX;+yTs-&r+Z%n(RnEl=9S{(2X=l!UihY};?`FfP(}=snhHoJ!d)yJ1bEb<-C{D#Y z6Vvj7v8jpg(qFg9#F4&3zX2%b+qwubThe`tTT2N~lGZF9&)L+=OYVz)NTALkR&-8kMPE5Q>0v2;;5_H3!^5<4*dFScu&8c#vR} z%QVF?mc)Y2Ga@cYTMUqt`I`kAxz!z2cz{MJmGS*}PL>j^SJ%L-e!bw3Z}})B(*3pn zTlwTXHIYsWN3(9*jPCv`CA1WqPbtmzHtYxcWWBihAIn7HjmU{{mIk0UNDduNzyNcIA2sRL;Yd3T{+UPo9s4*{$ z-w`v8T{UmulrLOlCUglXw}6F;hIp@a;Wh4>R3g<0R-PV$lJNpEJIJZ+Z%7!6RW z7!UYyutAKkRD7QwDLl?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w0_iT@(3_WIg;asT71 zfd02d{L3}I*Viuh$0_V)$X~X*p;*>m&hcly?B(yxmmePTa1Z~L|9`W`6b__rfGVS@ NA3t?fQu}vj{{dI~fg%6^ literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(&9qbk+)DO!sI_0AgPtJyVH=05Y4Ux_P0-p9GfY=@t5 zHet1I+Sb(N)C;h2)~WQSeJpG=saw3pgzs>>?tr!F`s=n2>nh(*;IRoW9Uzw(VRUB# zmf4OiiJwDamjjvW{3_OuDhH{x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N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..dcb434b1ce56e06dea3ecd52f2a911b94d5764a4 GIT binary patch literal 3932 zcmaJ^2{@Ep8(W6gw_K^Qw33`S%NDN7SFl!=UOkYuauWKDZRgAiGg zElQT`LbCkh|GxT4-~T`Fbj`JPX;+yTs-&r+Z%n(RnEl=9S{(2X=l!UihY};?`FfP(}=snhHoJ!d)yJ1bEb<-C{D#Y z6Vvj7v8jpg(qFg9#F4&3zX2%b+qwubThe`tTT2N~lGZF9&)L+=OYVz)NTALkR&-8kMPE5Q>0v2;;5_H3!^5<4*dFScu&8c#vR} z%QVF?mc)Y2Ga@cYTMUqt`I`kAxz!z2cz{MJmGS*}PL>j^SJ%L-e!bw3Z}})B(*3pn zTlwTXHIYsWN3(9*jPCv`CA1WqPbtmzHtYxcWWBihAIn7HjmU{{mIk0UNDduNzyNcIA2sRL;Yd3T{+UPo9s4*{$ z-w`v8T{UmulrLOlCUglXw}6F;hIp@a;Wh4>R3g<0R-PV$lJNpEJIJZ+Z%7!6RW z7!UYyutAKkRD7QwDLl?-&2|3dh^@WM_0lgcNuGR#e*rQYb+HP6f#CUJ=i z3RCP*9u%$R9d{Hkrq@joF%yLR%!Sb|Ok~!LQ+a*2{GhrxXru0MWhO+NGwf})5cUn^ zGc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mV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(&9qbk+)DO!sI_0AgPtJyVH=05Y4Ux_P0-p9GfY=@t5 zHet1I+Sb(N)C;h2)~WQSeJpG=saw3pgzs>>?tr!F`s=n2>nh(*;IRoW9Uzw(VRUB# zmf4OiiJwDamjjvW{3_OuDhH{xud!Ed4_W&jml~-(kFNrrk~R@{@x$TYv*%YT652w` z7n8nQSs3`JyOY(1&9w-S7rGF7V_OabZ`SQKP#RkH=$8gz2ll2uG&)d7yIwuj@+E9O|Kh{HF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ZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..777a206b284eaf0356e0b6791e91aa53a04af8b6 GIT binary patch literal 2337 zcmaKtdpwkB8^_0>LRpJ(ezjO^VMY$i3@WF=9FSu~YmC9z8HRZo%AtuOMb2lDL)wyL z5E{1Aup=Qk%vxee8RtW5EMjN2%`5fp@A=%%b3dQY?{{7I^IU&??UDQf!T`X&eSnlu zk}H5KAn(SN5O<+1olLcCY~c`ofc+=Nni$}mJl7!0U6MPEXj5AoxTT{L7!6-WcRWKO zwZJb9Ahiy6c68Akw0m_&C&ng#yNYr1+g#40>r?#HYV~(<^B^J-6X*lR5-?r~2)S~TMl5RBBs@y?syTp(J1 zd(XW1tV33NRgKCBWi~(B>utGwkTM9~Yh7MT@{@Z|o&RThh#Ol*r@67Oo)-0E@~ycV z8x}CXj%}!M)_o6S0e(2s;{I{0TIv1V{r63V23JzlkpVfsy$9BBg80izx?5%~X!W(Z z71PH+-jU6dwCv+=Pq=DeP=tKm^XWnAO-9z(A)eJU0K)zx;Nw1ZZ^&gisazHOfSf{Cd zj0A$GQH5q=u8U%RL{;Az%h95%R$ng1%2g?!%3C?eWG1@iI6v~gR5%d))0m~L4H|kq zozjQzT2@I1MTNa-w|z7K>%%ai*QOfn`w3>vrj-2*Id6i%ln$*R({ZK|@!jQsf_Nb{ z^>A&rq=~FE(51xBSunoe_Xuh_4E; zAgpHxuhFL1X5F6Cs_%%9Sjl=Nr&@kKx4vK=)TNE-#}OgMbyedwvWpr`0w_bLuT8NO z+K@*a45sGD?@>DBa9WFAcSCa+wU$|2+^P^eEld|>FR;$)BOBuIQ681=7$T)%Cz<(| z)A)79)=$U?){O zEm)Z@DO|@r?WXXN0n<_Rx7{~>9;Cyj-c{uIL92|cyB1$>=!q+V;~Hefh#pPJHi}Cc zk2tu}5Jo~!*{WpG?U!Oouc!?DEy_Yv(hz1`*qU?f{Nxs>f8IaZtM;zEXH*aoZZd3e zV8MaG4M;jy^S(P4|bx?hUxl;JMO7Zdm(us4Q4z=hxgFDvd*6=j0PF4wJoiUx^Z5BeyvAYN?LRdAw-Aq}AH)k4a<~74cx>Gr z+|AaH(K6~Up9a4`+TFEy*^ejZP4a_yhq$q4$G30Kb$5RETt8MQqq4r3|JNzoBL%r3 R0AMfo>gEFgjQ;+Ye*x5Riv9oq literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB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3!~NX1;s_Zi)SCw%jd zRL1kKJ`fIFHE`um0FzF+hSk>Fw!)&Lt^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/tool/libs/GayalsCommand-1.0-SNAPSHOT.jar new file mode 100644 index 0000000000000000000000000000000000000000..dcb434b1ce56e06dea3ecd52f2a911b94d5764a4 GIT binary patch literal 3932 zcmaJ^2{@Ep8(W6gw_K^Qw33`S%NDN7SFl!=UOkYuauWKDZRgAiGg zElQT`LbCkh|GxT4-~T`Fbj`JPX;+yTs-&r+Z%n(RnEl=9S{(2X=l!UihY};?`FfP(}=snhHoJ!d)yJ1bEb<-C{D#Y z6Vvj7v8jpg(qFg9#F4&3zX2%b+qwubThe`tTT2N~lGZF9&)L+=OYVz)NTALkR&-8kMPE5Q>0v2;;5_H3!^5<4*dFScu&8c#vR} z%QVF?mc)Y2Ga@cYTMUqt`I`kAxz!z2cz{MJmGS*}PL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UDpH&LzcR2s za?WTkFN{C-9Gd#@$I9s<(1GV%JTU%x-mY+yVnmx{FT9=dc3JYZ0a7-oz2h~q4gSIC zltEo&x+xP?v+Sc~2mEiXM2$(cgEX@`yZ@gH-b>r7oOZ#xmWPw1_CIOA=%~FOcF{jX z+OAys%XR|?QHOtvr~gOV6;FTJE-8yT{F}5ZrS=l{N~s^zJlw0_iT@(3_WIg;asT71 zfd02d{L3}I*Viuh$0_V)$X~X*p;*>m&hcly?B(yxmmePTa1Z~L|9`W`6b__rfGVS@ NA3t?fQu}vj{{dI~fg%6^ literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.DS_Store b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1ecf824cf4e05e598255d3e90ea6c3fc8470e6a1 GIT binary patch literal 6148 zcmeHK%}T>S5Z-NTlTd^n6nb3nTClbv6fYsx7cim+m70)HgE3p0)E-J9XMG``#OHBl zcXJ39youNu*!^bbXE*af_J=XXy=8R5SeG$oLqp`KY!NhXbu~;dB3E<7tO!^6JWOS{ zWum`m!f$W0f(2~BW~~1GAK^Sr@?tRffB_vS{A@{dQ7Ri+-msymnTwgmJ$9AUO-g-S8pY_FPG~V>Z zdORHT#p!ss**Ny$(ee4!^f`UWf03m!n}NN`sbUF<0b+m{ zAO?1i0dp4Eo!u*)DkcVqfgc#a{XsxObPbjo)z$$WUZ2t5LPP-_-x7$zplh(y2p$lw zQvr1y{s6(7< Xu+)gNpk1W{(nUZKLLD*i3k-Y#>hVlF literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.devcontainer.json b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.devcontainer.json new file mode 100644 index 000000000000..a78c901fb8f0 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.4.0", + "extensions": ["WSO2.ballerina"], +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.gitignore b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.gitignore new file mode 100644 index 000000000000..7512ebe2325f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/BalTool.toml b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/BalTool.toml new file mode 100644 index 000000000000..63969e4c3238 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/BalTool.toml @@ -0,0 +1,5 @@ +[tool] +id = "gayals" # should be the same as Picocli command name + +[[dependency]] +path = "./tool/libs/GayalsCommand-1.0-SNAPSHOT.jar" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Ballerina.toml new file mode 100644 index 000000000000..b2803582a216 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "gayaldassanayake" +name = "tool_gayal" +version = "1.1.0" +distribution = "2201.4.0" + +[build-options] +observabilityIncluded = true diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/CompilerPlugin.toml b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/CompilerPlugin.toml new file mode 100644 index 000000000000..ae97900a6cd4 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/CompilerPlugin.toml @@ -0,0 +1,6 @@ +[plugin] +class = "io.gayal.combined.CombinedCompilerPlugin" + +[[dependency]] +path = "./tool/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Dependencies.toml b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Dependencies.toml new file mode 100644 index 000000000000..8919ebe4db37 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Dependencies.toml @@ -0,0 +1,45 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0-SNAPSHOT" + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "gayaldassanayake" +name = "tool_gayal" +version = "1.1.0" +dependencies = [ + {org = "ballerina", name = "io"} +] +modules = [ + {org = "gayaldassanayake", packageName = "tool_gayal", moduleName = "tool_gayal"} +] + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Package.md b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Package.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/Package.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/README.md b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/README.md new file mode 100644 index 000000000000..43fd57fbd954 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/README.md @@ -0,0 +1,4 @@ +# Gayals Tool + +1. Run `bal pack` with the provided ballerina distribution pack +2. Extract the .bala file to `~.ballerina/repositories/central.ballerina.io/bala/ballerina/gayalstool/0.1.0/any/` diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/main.bal new file mode 100644 index 000000000000..31e8785bf98f --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/main.bal @@ -0,0 +1,5 @@ +import ballerina/io; + +public function main() { + io:println("Hello, World!"); +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/.DS_Store b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9dae4ac68983e1797c8fec95574153d5ca473c0f GIT binary patch literal 6148 zcmeHK%}T>S5Z-O0O(;SR3Oz1(Em&I-f|n5M3mDOZN=-=7V9b^_HHT8jSzpK}@p+ut z-H63{6|pn0`_1oe_JiyXV~hv$bgvCHOfn+JG2(JIi8C34{bpi+ z9q`*N7PE+DEc*KW@gz%UMX&eH8%=9#yVY`9?bdDhAj`0biuo*vrq^g)NSVd89>tgG zxE#5=r!p_1G#^h@L7I#q<>o5Q6Iljwo+mR^8|r}L*v`o9EEaw5xGM$&Z`l(9A`0mEmOvB+eS?)oh=6ci3aCrD zd17!~4t`5TgtsV4@AfmH^Y+H~>!KZ9Rp?IVA+ zge+o!82D!laBCP216Y(fTfZ$2&sqWP4jKyPRj7b~zH$iw1NV`R3hKB(9rApGl|~!| S{i+<0E&_@W>WG0~VBiB0(Ml)) literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 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%edXr+BuB<7y;-~-PW%JobvcmTYVQC zm0u)w&Sl@rkdA=j^uO(bvB=GL3Kl5e#$}_G>Ryth@7q5PH!my+2)TNKTF#dB@N)~t zZ~AyirEaE9HaYq(b!@i>iRfj_ho(oje-wMH4$*DDAUH6l+9JMSwq54`?ap1~$MQ(k zopT<$1&|qQekBnR0T?JYxhpJohr>jXHIXFsE)9u}iuU83wmQQy-YJI}ih^hO%U8EM z2+`V6+ngZZD0$2N*Y#5FBiR`f$EUlybiq$;Y3g9B(qyE(Zzwa{+#;6M@HA**BZAT; zs&6nKZ3Ndkfm`|3!~NX1;s_Zi)SCw%jd zRL1kKJ`fIFHE`um0FzF+hSk>Fw!)&Lt^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/gayaldassanayake-tool_gayal-java17-1.1.0.bala b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/target-dir/bala/gayaldassanayake-tool_gayal-java17-1.1.0.bala new file mode 100644 index 0000000000000000000000000000000000000000..a16fe484cdc8f496c6a9e8378cffdd6e2bad0464 GIT binary patch literal 10608 zcmb`NWmFx@)~<00?(XjHfdqGVcZaobcL?smgS!(5?ykYzT~~s;UUIJN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6P zcI@kZs!pm+22-NYisX^hz@cxRVpX86c)CI^>HBQoy|S=%j%0N{C3j%lkkR~D(gzw& zC@n>@8SOIAwU+EN3cBV$&Z)A%^f}-t#LhoTw1!^xP8L9drqZ+PGdkh#O9X!yCw%s-OhXsc7$72S7 zn%1lHXIikOmm;4CeLZ5liSxD+$dT3{PKV>Otgf0}%FUOsUDa<5e`I>cds2u^vophD zL+ENfctZ`cvc%o|E6!`Kg?xm6|F zq(ab2PO89Cn0m{Q;g?hN43h6n9xw8xs?YWeSQOS5wBvQ0=$gVx+c|2*dA|X5YKrbWc4DgBd)$Ea^PBGlrGAc8a z5O=uv^F8h%Z8EZLd5BTtqkN41AcZeRqOaMaNT$g}FR=Zp>v+tMiIU zeR%s8o%|Fc0T}-vtPAE(bui9779mVUDpH&LzcR2s za?WTkFN{C-9Gd#@$I9s<(1GV%JTU%x-mY+yVnmx{FT9=dc3JYZ0a7-oz2h~q4gSIC zltEo&x+xP?v+Sc~2mEiXM2$(cgEX@`yZ@gH-b>r7oOZ#xmWPw1_CIOA=%~FOcF{jX z+OAys%XR|?QHOtvr~gOV6;FTJE-8yT{F}5ZrS=l{N~s^zJlw0_iT@(3_WIg;asT71 zfd02d{L3}I*Viuh$0_V)$X~X*p;*>m&hcly?B(yxmmePTa1Z~L|9`W`6b__rfGVS@ NA3t?fQu}vj{{dI~fg%6^ literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/tool/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/tool-gayals/tool/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..5ed0821d57dd3a7ab50b2a816de3786418a26db9 GIT binary patch literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA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E9HaYq(b!@i>iRfj_ho(oje-wMH4$*DDAUH6l+9JMSwq54`?ap1~$MQ(k zopT<$1&|qQekBnR0T?JYxhpJohr>jXHIXFsE)9u}iuU83wmQQy-YJI}ih^hO%U8EM z2+`V6+ngZZD0$2N*Y#5FBiR`f$EUlybiq$;Y3g9B(qyE(Zzwa{+#;6M@HA**BZAT; zs&6nKZ3Ndkfm`|3!~NX1;s_Zi)SCw%jd zRL1kKJ`fIFHE`um0FzF+hSk>Fw!)&Lt^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo literal 0 HcmV?d00001 From d79e43ddc06450cd5f8f03b6fdc85ed19573bac0 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Thu, 4 Jan 2024 14:46:20 +0530 Subject: [PATCH 040/209] Fix build failure --- .../java17/compiler-plugin/compiler-plugin.json | 2 +- ...in-with-analyzer-generator-modifier-1.0.0.jar | Bin 6119 -> 0 bytes .../java17/compiler-plugin/compiler-plugin.json | 2 +- ...in-with-analyzer-generator-modifier-1.0.0.jar | Bin 6119 -> 0 bytes .../java17/compiler-plugin/compiler-plugin.json | 2 +- ...in-with-analyzer-generator-modifier-1.0.0.jar | Bin 6119 -> 0 bytes .../java17/compiler-plugin/compiler-plugin.json | 2 +- ...in-with-analyzer-generator-modifier-1.0.0.jar | Bin 6119 -> 0 bytes .../java17/compiler-plugin/compiler-plugin.json | 2 +- ...in-with-analyzer-generator-modifier-1.0.0.jar | Bin 6119 -> 0 bytes 10 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar delete mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar delete mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar delete mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar delete mode 100644 cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json index 66bfe83d52a2..d5949dc5f5e0 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/compiler-plugin.json @@ -1,6 +1,6 @@ { "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", "dependency_paths": [ - "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + "compiler-plugin/libs/a.jar" ] } \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.1.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar deleted file mode 100644 index 5ed0821d57dd3a7ab50b2a816de3786418a26db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(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8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json index 66bfe83d52a2..d5949dc5f5e0 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/compiler-plugin.json @@ -1,6 +1,6 @@ { "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", "dependency_paths": [ - "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + "compiler-plugin/libs/a.jar" ] } \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.2.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar deleted file mode 100644 index 5ed0821d57dd3a7ab50b2a816de3786418a26db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(&9qbk+)DO!sI_0AgPtJyVH=05Y4Ux_P0-p9GfY=@t5 zHet1I+Sb(N)C;h2)~WQSeJpG=saw3pgzs>>?tr!F`s=n2>nh(*;IRoW9Uzw(VRUB# zmf4OiiJwDamjjvW{3_OuDhH{xud!Ed4_W&jml~-(kFNrrk~R@{@x$TYv*%YT652w` z7n8nQSs3`JyOY(1&9w-S7rGF7V_OabZ`SQKP#RkH=$8gz2ll2uG&)d7yIwuj@+E9O|Kh{HFQfeN7iK&EpAr)Oql6qBsO4y6 z8r64AoYWiw$CazzaZ;*%ijlWxgGI~7A|ir=vK%8k2E1%$W}>#ud1N~-onk$D;^R$i z-$BJl=e0I6?>{25PqB}x`EnCWT9G46a;PNHr8f8)GDKvejh>`t!#}JI0pG~{P>pzD z=oCx75V+dE`%1plrT>Nt#yojZ{-G4kR!$IoI)0;2o8z`(M|x8vT!8%X;h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e=ePud%gDEkmsK6a9ANH>1^63f1=mF^6x$kJtbg|WKJaa-nFpGKz}xYvH<)ZB zGkar;=uCWHqOuvcG~&7$=bQNn@ZM;@SExM<%edXr+BuB<7y;-~-PW%JobvcmTYVQC zm0u)w&Sl@rkdA=j^uO(bvB=GL3Kl5e#$}_G>Ryth@7q5PH!my+2)TNKTF#dB@N)~t zZ~AyirEaE9HaYq(b!@i>iRfj_ho(oje-wMH4$*DDAUH6l+9JMSwq54`?ap1~$MQ(k zopT<$1&|qQekBnR0T?JYxhpJohr>jXHIXFsE)9u}iuU83wmQQy-YJI}ih^hO%U8EM z2+`V6+ngZZD0$2N*Y#5FBiR`f$EUlybiq$;Y3g9B(qyE(Zzwa{+#;6M@HA**BZAT; zs&6nKZ3Ndkfm`|3!~NX1;s_Zi)SCw%jd zRL1kKJ`fIFHE`um0FzF+hSk>Fw!)&Lt^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json index 66bfe83d52a2..d5949dc5f5e0 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/compiler-plugin.json @@ -1,6 +1,6 @@ { "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", "dependency_paths": [ - "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + "compiler-plugin/libs/a.jar" ] } \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/1.3.0/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar deleted file mode 100644 index 5ed0821d57dd3a7ab50b2a816de3786418a26db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`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^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json index 66bfe83d52a2..d5949dc5f5e0 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/compiler-plugin.json @@ -1,6 +1,6 @@ { "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", "dependency_paths": [ - "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + "compiler-plugin/libs/a.jar" ] } \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.4/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar deleted file mode 100644 index 5ed0821d57dd3a7ab50b2a816de3786418a26db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=C4k{y0W2RnS=c#STm1tm%)EEHiH(JI4-X4V;+IH;-&0_&E_ROAZd(6)FV{o` zEFB^4?m4&^g2_fGOKzZx2?67}J9W6M=hM)^ zxR=T@!4!zlZS!!5OX~E`lLod4V|(Q!#wX}mJrrpM^9S%I@VNn3_-P(cmaC0YUpYz@ zw3jPQD5h3MIg)PCQc7a1l&-{b$8-SLTFN(+KRI*Z8{ z5=m_Wg0KxWPCpWoSnsc8_q(&9qbk+)DO!sI_0AgPtJyVH=05Y4Ux_P0-p9GfY=@t5 zHet1I+Sb(N)C;h2)~WQSeJpG=saw3pgzs>>?tr!F`s=n2>nh(*;IRoW9Uzw(VRUB# zmf4OiiJwDamjjvW{3_OuDhH{xud!Ed4_W&jml~-(kFNrrk~R@{@x$TYv*%YT652w` z7n8nQSs3`JyOY(1&9w-S7rGF7V_OabZ`SQKP#RkH=$8gz2ll2uG&)d7yIwuj@+E9O|Kh{HFQfeN7iK&EpAr)Oql6qBsO4y6 z8r64AoYWiw$CazzaZ;*%ijlWxgGI~7A|ir=vK%8k2E1%$W}>#ud1N~-onk$D;^R$i z-$B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tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json index 66bfe83d52a2..d5949dc5f5e0 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json +++ b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/compiler-plugin.json @@ -1,6 +1,6 @@ { "plugin_class": "io.gayal.combined.CombinedCompilerPlugin", "dependency_paths": [ - "compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar" + "compiler-plugin/libs/a.jar" ] } \ No newline at end of file diff --git a/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/local-tool-test/ballerina-cache/repositories/local/bala/gayaldassanayake/tool_gayal/2.2.5/java17/compiler-plugin/libs/compiler-plugin-with-analyzer-generator-modifier-1.0.0.jar deleted file mode 100644 index 5ed0821d57dd3a7ab50b2a816de3786418a26db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6119 zcmbtY2UJt(wx)M56oF6#L|W)22vQV~qVx_*F|^R7caRc_^dd-?D!qvWL^=#e6+DlobM{)<-~P@zXaD=`|I<>%#iPN(A|k?i=;dOFg)yA- z6UK-!hq|Jk9RD2+B|%&)t-l4nc!aaXhzS5<4h;OyKy^8dJ4%YWdIIW7yXr%OYO4GK z@5oj8K_f$N>ve?2MVD5WS8*;R!{C3i;$nQehyURFYsmSHVM3q~Ux?!`11bL+=;G)J zwR3j=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FBiR`f$EUlybiq$;Y3g9B(qyE(Zzwa{+#;6M@HA**BZAT; zs&6nKZ3Ndkfm`|3!~NX1;s_Zi)SCw%jd zRL1kKJ`fIFHE`um0FzF+hSk>Fw!)&Lt^)mJJSFZHY9D3>!m4H!lc$bgCA;jntFZ)MfAEB}aEPq5Qi6_@q9Y$*2Z-|9 zt_*;iFQBH52!o~4vHf7%H~6HWHRClnkUc{Hbh z=U`wd{ehPYf8ETX8WEjTm^j{4?YLjOXjgH>i{!Yb9WGyPc`u(?4p`@9(-;^ zAv~D#PuO3y#furvqyG>t&n3hkc24YtaWQJ)uK?$Q;tx9qWMJH%^5U;x=P&(-ox{2? z?oZesV&kvi=VIdzJBROL+<(A-N{<)wT$CRF$W#=eQbsE|_Qh zAG7?fRb6Dcs9pTY(uA2-{!^A8OYb7b#rfw?j%o5=bNqE0x|sFiXXMYUD8R3?{!o-J n$icsVR4%ey>@$C|@KOJZuA`-jPjDVWhWVvnUX$#(JdgE1u)0jo From 75df9ee9a45b0912d50c5a8a58780346925cbcc3 Mon Sep 17 00:00:00 2001 From: Dilhasha Date: Fri, 5 Jan 2024 10:11:45 +0530 Subject: [PATCH 041/209] Address suggestions --- .../projects/internal/configschema/TypeConverter.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java index eacdb53918ec..ad128e640726 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/configschema/TypeConverter.java @@ -20,6 +20,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.wso2.ballerinalang.compiler.semantics.analyzer.Types; +import org.wso2.ballerinalang.compiler.semantics.model.symbols.BTypeSymbol; import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols; import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType; import org.wso2.ballerinalang.compiler.semantics.model.types.BField; @@ -182,9 +183,10 @@ private JsonObject generateRecordType(BRecordType effectiveType, BIntersectionTy if (!requiredFields.isEmpty()) { typeNode.add("required", requiredFields); } - // The tsymbol name is empty for anon intersection type created due to inferred readonly - if (intersectionType.tsymbol.name != Names.EMPTY) { - typeNode.addProperty("name", intersectionType.tsymbol.toString().trim()); + BTypeSymbol intersectionSymbol = intersectionType.tsymbol; + // The tsymbol name is implicitly empty + if (intersectionSymbol.name != Names.EMPTY) { + typeNode.addProperty("name", intersectionSymbol.toString().trim()); } else { // Get record type and set the type name as a property for (BType bType : intersectionType.getConstituentTypes()) { From 57b84dbe0745241aa87effcef7f4bf78224d5e3f Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 5 Jan 2024 09:42:31 +0530 Subject: [PATCH 042/209] Fix handling unresolved values with union types --- .../runtime/internal/JsonInternalUtils.java | 2 +- .../ballerina/runtime/internal/TypeConverter.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java index fc5a48f60dce..c1f9758c663b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java @@ -339,7 +339,7 @@ public static Object convertJSON(Object jsonValue, Type targetType) { return jsonValue; case TypeTags.UNION_TAG: matchingType = TypeConverter.getConvertibleTypeInTargetUnionType(jsonValue, - (BUnionType) targetType, null, new ArrayList<>(), new HashSet<>(), true); + (BUnionType) targetType, null, new ArrayList<>(), true); if (matchingType == null) { throw ErrorHelper.getRuntimeException(ErrorCodes.INCOMPATIBLE_TYPE, targetType, getTypeName(jsonValue)); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java index 6553c3628a52..160c2e8fd829 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java @@ -55,6 +55,7 @@ import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -275,7 +276,7 @@ public static Type getConvertibleType(Object inputValue, Type targetType, String switch (targetTypeTag) { case TypeTags.UNION_TAG: return getConvertibleTypeInTargetUnionType(inputValue, (BUnionType) targetType, varName, - errors, unresolvedValues, allowNumericConversion); + errors, allowNumericConversion); case TypeTags.ARRAY_TAG: if (isConvertibleToArrayType(inputValue, (BArrayType) targetType, unresolvedValues, varName, errors, allowNumericConversion)) { @@ -358,22 +359,21 @@ private static boolean isStringConvertibleToTargetXmlType(Object inputValue, Typ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnionType targetUnionType, String varName, List errors, - Set unresolvedValues, boolean allowNumericConversion) { List memberTypes = targetUnionType.getMemberTypes(); if (TypeChecker.isStructuredType(getType(inputValue))) { return getConvertibleStructuredTypeInUnion(inputValue, varName, errors, - unresolvedValues, allowNumericConversion, memberTypes); + allowNumericConversion, memberTypes); } for (Type memType : memberTypes) { if (TypeChecker.checkIsLikeType(inputValue, memType, false)) { - return getConvertibleType(inputValue, memType, varName, unresolvedValues, errors, false); + return getConvertibleType(inputValue, memType, varName, new HashSet<>(), errors, false); } } for (Type memType : memberTypes) { Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - unresolvedValues, errors, allowNumericConversion); + new HashSet<>(), errors, allowNumericConversion); if (convertibleTypeInUnion != null) { return convertibleTypeInUnion; } @@ -382,7 +382,6 @@ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnion } private static Type getConvertibleStructuredTypeInUnion(Object inputValue, String varName, List errors, - Set unresolvedValues, boolean allowNumericConversion, List memberTypes) { int initialErrorCount; errors.add(ERROR_MESSAGE_UNION_START); @@ -391,7 +390,7 @@ private static Type getConvertibleStructuredTypeInUnion(Object inputValue, Strin for (Type memType : memberTypes) { initialErrorCount = errors.size(); Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - unresolvedValues, errors, allowNumericConversion); + new HashSet<>(), errors, allowNumericConversion); currentErrorListSize = errors.size(); if (convertibleTypeInUnion != null) { errors.subList(initialErrorListSize - 1, currentErrorListSize).clear(); From 3c2a22129d737f1b6e21af39efa890b513e83d18 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 5 Jan 2024 10:11:11 +0530 Subject: [PATCH 043/209] Test converting to union types with cyclic members --- .../test/resources/test-src/valuelib_test.bal | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal index 5be34862ca6a..5922a16c9503 100644 --- a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal +++ b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal @@ -2432,6 +2432,60 @@ function testCloneWithTypeWithAmbiguousUnion() { checkpanic err.detail()["message"]); } +public type CodingExtension record {| + *Element; + + uri url; + Coding valueCoding; +|}; + +public type Coding record {| + *Element; + + string id?; + Extension[] extension?; + uri system?; + string 'version?; + code code?; + string display?; + boolean userSelected?; +|}; + +public type code string; + +public type uri string; + +public type Element record {| + string id?; + Extension[] extension?; + Element...; +|}; + +public type ExtensionExtension record {| + *Element; + + uri url; + Extension[] extension?; +|}; + +public type CodeableConceptExtension record {| + *Element; + + uri url; + CodeableConcept valueCodeableConcept; +|}; + +public type CodeableConcept record {| + *Element; + + string id?; + Extension[] extension?; + Coding[] coding?; + string text?; +|}; + +public type Extension CodeableConceptExtension|ExtensionExtension|CodingExtension; + function testCloneWithTypeToUnion() { int|float|[string, string] unionVar = 2; float|decimal|[string, int]|error tupleValue = unionVar.cloneWithType(UnionTypedesc); @@ -2440,6 +2494,23 @@ function testCloneWithTypeToUnion() { assertFalse(tupleValue is decimal); assertFalse(tupleValue is [string, int]); assertFalse(tupleValue is error); + + json extCoding = { + "valueCoding": { + "system": "http://loinc.org", + "code": "LA29518-0", + "display": "he/him/his/himself" + }, + "url": "http://open.epic.com/FHIR/StructureDefinition/extension/calculated-pronouns-to-use-for-text" + }; + + Extension ext = checkpanic extCoding.cloneWithType(); + assertEquality(ext, { + "url": + "http://open.epic.com/FHIR/StructureDefinition/extension/calculated-pronouns-to-use-for-text", + "valueCoding": {"system": "http://loinc.org", "code": "LA29518-0", "display": "he/him/his/himself"} + }); + assertEquality((typeof ext).toString(), "typedesc CodingExtension"); } type UnionTypedesc typedesc; From f1e4885b276d7069fbeae9fa79835759f4841d9e Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 5 Jan 2024 11:31:56 +0530 Subject: [PATCH 044/209] Revert "Fix handling unresolved values with union types" This reverts commit 2dc76a449311e382273be160d494c91fff51b60c. --- .../runtime/internal/JsonInternalUtils.java | 2 +- .../ballerina/runtime/internal/TypeConverter.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java index c1f9758c663b..fc5a48f60dce 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java @@ -339,7 +339,7 @@ public static Object convertJSON(Object jsonValue, Type targetType) { return jsonValue; case TypeTags.UNION_TAG: matchingType = TypeConverter.getConvertibleTypeInTargetUnionType(jsonValue, - (BUnionType) targetType, null, new ArrayList<>(), true); + (BUnionType) targetType, null, new ArrayList<>(), new HashSet<>(), true); if (matchingType == null) { throw ErrorHelper.getRuntimeException(ErrorCodes.INCOMPATIBLE_TYPE, targetType, getTypeName(jsonValue)); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java index 160c2e8fd829..6553c3628a52 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java @@ -55,7 +55,6 @@ import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -276,7 +275,7 @@ public static Type getConvertibleType(Object inputValue, Type targetType, String switch (targetTypeTag) { case TypeTags.UNION_TAG: return getConvertibleTypeInTargetUnionType(inputValue, (BUnionType) targetType, varName, - errors, allowNumericConversion); + errors, unresolvedValues, allowNumericConversion); case TypeTags.ARRAY_TAG: if (isConvertibleToArrayType(inputValue, (BArrayType) targetType, unresolvedValues, varName, errors, allowNumericConversion)) { @@ -359,21 +358,22 @@ private static boolean isStringConvertibleToTargetXmlType(Object inputValue, Typ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnionType targetUnionType, String varName, List errors, + Set unresolvedValues, boolean allowNumericConversion) { List memberTypes = targetUnionType.getMemberTypes(); if (TypeChecker.isStructuredType(getType(inputValue))) { return getConvertibleStructuredTypeInUnion(inputValue, varName, errors, - allowNumericConversion, memberTypes); + unresolvedValues, allowNumericConversion, memberTypes); } for (Type memType : memberTypes) { if (TypeChecker.checkIsLikeType(inputValue, memType, false)) { - return getConvertibleType(inputValue, memType, varName, new HashSet<>(), errors, false); + return getConvertibleType(inputValue, memType, varName, unresolvedValues, errors, false); } } for (Type memType : memberTypes) { Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - new HashSet<>(), errors, allowNumericConversion); + unresolvedValues, errors, allowNumericConversion); if (convertibleTypeInUnion != null) { return convertibleTypeInUnion; } @@ -382,6 +382,7 @@ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnion } private static Type getConvertibleStructuredTypeInUnion(Object inputValue, String varName, List errors, + Set unresolvedValues, boolean allowNumericConversion, List memberTypes) { int initialErrorCount; errors.add(ERROR_MESSAGE_UNION_START); @@ -390,7 +391,7 @@ private static Type getConvertibleStructuredTypeInUnion(Object inputValue, Strin for (Type memType : memberTypes) { initialErrorCount = errors.size(); Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - new HashSet<>(), errors, allowNumericConversion); + unresolvedValues, errors, allowNumericConversion); currentErrorListSize = errors.size(); if (convertibleTypeInUnion != null) { errors.subList(initialErrorListSize - 1, currentErrorListSize).clear(); From 48d2c46ae4e29d91bfb5d90246e2152c58b61d78 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Fri, 5 Jan 2024 11:45:02 +0530 Subject: [PATCH 045/209] Fix converting to union types with cyclic members --- .../java/io/ballerina/runtime/internal/TypeConverter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java index 6553c3628a52..eaa860e8e382 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeConverter.java @@ -55,6 +55,7 @@ import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -368,12 +369,12 @@ public static Type getConvertibleTypeInTargetUnionType(Object inputValue, BUnion for (Type memType : memberTypes) { if (TypeChecker.checkIsLikeType(inputValue, memType, false)) { - return getConvertibleType(inputValue, memType, varName, unresolvedValues, errors, false); + return getConvertibleType(inputValue, memType, varName, new HashSet<>(unresolvedValues), errors, false); } } for (Type memType : memberTypes) { Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - unresolvedValues, errors, allowNumericConversion); + new HashSet<>(unresolvedValues), errors, allowNumericConversion); if (convertibleTypeInUnion != null) { return convertibleTypeInUnion; } @@ -391,7 +392,7 @@ private static Type getConvertibleStructuredTypeInUnion(Object inputValue, Strin for (Type memType : memberTypes) { initialErrorCount = errors.size(); Type convertibleTypeInUnion = getConvertibleType(inputValue, memType, varName, - unresolvedValues, errors, allowNumericConversion); + new HashSet<>(unresolvedValues), errors, allowNumericConversion); currentErrorListSize = errors.size(); if (convertibleTypeInUnion != null) { errors.subList(initialErrorListSize - 1, currentErrorListSize).clear(); From faac6ff1e9824362aab52c561e92f8616bc5dc46 Mon Sep 17 00:00:00 2001 From: gabilang Date: Fri, 5 Jan 2024 17:45:36 +0530 Subject: [PATCH 046/209] Fix index out of bounds error at param count validation --- .../compiler/bir/codegen/interop/JMethodResolver.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java index d41a5e17ad72..0125a681f9fe 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java @@ -193,13 +193,15 @@ private boolean isAcceptingBundledParams(JMethodRequest jMethodRequest, JMethod return false; } Class[] paramTypes = jMethod.getParamTypes(); - if (count == reducedParamCount && isParamAssignableToBArray(paramTypes[0])) { + if (count == reducedParamCount && paramTypes.length > 1 && isParamAssignableToBArray(paramTypes[0])) { return true; - } else if ((count == (reducedParamCount + 1)) && isParamAssignableToBArray(paramTypes[1])) { + } else if ((count == (reducedParamCount + 1)) && paramTypes.length > 1 && + isParamAssignableToBArray(paramTypes[1])) { // This is for object interop functions when self is passed as a parameter jMethod.setReceiverType(jMethodRequest.receiverType); return jMethodRequest.receiverType != null; - } else if ((count == (reducedParamCount + 2)) && isParamAssignableToBArray(paramTypes[2])) { + } else if ((count == (reducedParamCount + 2)) && paramTypes.length > 2 && + isParamAssignableToBArray(paramTypes[2])) { // This is for object interop functions when both BalEnv and self is passed as parameters. if (jMethodRequest.receiverType != null) { jMethod.setReceiverType(jMethodRequest.receiverType); From 48941a963e01bb662dd60b50b9020b12dc3e1a84 Mon Sep 17 00:00:00 2001 From: gabilang Date: Mon, 8 Jan 2024 11:33:26 +0530 Subject: [PATCH 047/209] Add unit tests --- .../compiler/bir/codegen/interop/JMethodResolver.java | 2 +- .../test/javainterop/basic/NegativeValidationTest.java | 6 +++++- .../test-src/javainterop/negative/method_not_found7.bal | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java index 0125a681f9fe..94191253b4ae 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/interop/JMethodResolver.java @@ -193,7 +193,7 @@ private boolean isAcceptingBundledParams(JMethodRequest jMethodRequest, JMethod return false; } Class[] paramTypes = jMethod.getParamTypes(); - if (count == reducedParamCount && paramTypes.length > 1 && isParamAssignableToBArray(paramTypes[0])) { + if (count == reducedParamCount && paramTypes.length > 0 && isParamAssignableToBArray(paramTypes[0])) { return true; } else if ((count == (reducedParamCount + 1)) && paramTypes.length > 1 && isParamAssignableToBArray(paramTypes[1])) { diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java index 32da1137cfa1..41aadfc88701 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/javainterop/basic/NegativeValidationTest.java @@ -138,7 +138,7 @@ public void testMethodNotFound6() { public void testMethodNotFound7() { String path = "test-src/javainterop/negative/method_not_found7.bal"; CompileResult compileResult = BCompileUtil.compile(path); - Assert.assertEquals(compileResult.getDiagnostics().length, 3); + Assert.assertEquals(compileResult.getDiagnostics().length, 4); String message = "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public static method '%s' with " + "'%s' parameter(s) found in class '%s''"; BAssertUtil.validateError(compileResult, 0, String.format(message, "getPrintableStackTrace", "1", @@ -149,6 +149,10 @@ public void testMethodNotFound7() { "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public method 'concat' " + "with '3' parameter(s) found in class 'io.ballerina.runtime.api.values.BString''", "method_not_found7.bal", 27, 1); + BAssertUtil.validateError(compileResult, 3, + "{ballerina/jballerina.java}METHOD_NOT_FOUND 'No such public static method 'indexOf' " + + "with '0' parameter(s) found in class 'java.lang.String''", + "method_not_found7.bal", 32, 1); } @Test diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal index c6cc062a3d30..169a3c17440a 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/javainterop/negative/method_not_found7.bal @@ -28,3 +28,7 @@ function concatString(handle h, string s1, string s2) returns handle = @java:Met 'class: "io.ballerina.runtime.api.values.BString", name: "concat" } external; + +function indexOf() returns byte = @java:Method { + 'class: "java.lang.String" +} external; From 3eda66b964a36d50770ae36fe76d8353d520b7a2 Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Mon, 8 Jan 2024 13:46:36 +0530 Subject: [PATCH 048/209] Add unit tests --- .../test/annotations/AnnotationAttachmentNegativeTest.java | 3 ++- .../test-src/annotations/annot_attachments_negative.bal | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index b9b7f89837b4..85d4fd13a537 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 282); + Assert.assertEquals(compileResult.getErrorCount(), 283); } @Test @@ -528,6 +528,7 @@ public void testInvalidAnnotationAttachmentOnField() { validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 7); validateError(compileResult, index++, "undefined annotation 'annot'", line += 1, 14); validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 13, 2); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 17); } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index 21da8bf20b3d..77c94c86db03 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -995,3 +995,4 @@ function getPerson() returns Person { [@UndefinedAnnotation int, int] [w, e] = [1, 2]; +error err = error("hi", i = 33); From ade0affa15ec6d37fa5fd12a12af5c10f5d8107e Mon Sep 17 00:00:00 2001 From: mindula Date: Mon, 8 Jan 2024 21:48:18 +0530 Subject: [PATCH 049/209] Address review suggestions --- .../langserver/hover/HoverObjectResolver.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java index ae8dd891bf10..e09a5ac37829 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java @@ -171,19 +171,16 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { if (isResourceMethod) { ResourcePath resourcePath = ((ResourceMethodSymbol) functionSymbol).resourcePath(); switch (resourcePath.kind()) { - case PATH_SEGMENT_LIST: + case PATH_SEGMENT_LIST -> { PathSegmentList pathSegmentList = (PathSegmentList) resourcePath; List pathParameterSymbols = pathSegmentList.pathParameters(); parameterSymbols.addAll(pathParameterSymbols); - if (pathSegmentList.pathRestParameter().isPresent()) { - parameterSymbols.add(pathSegmentList.pathRestParameter().get()); - } - break; - case PATH_REST_PARAM: - parameterSymbols.add(((PathRestParam) resourcePath).parameter()); - break; - default: + pathSegmentList.pathRestParameter().ifPresent(parameterSymbols::add); + } + case PATH_REST_PARAM -> parameterSymbols.add(((PathRestParam) resourcePath).parameter()); + default -> { // ignore + } } } Map paramsMap = documentation.get().parameterMap(); From c53b42c93079c62e512f48e22c18bd45bbae8b88 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Wed, 20 Sep 2023 12:11:02 +0530 Subject: [PATCH 050/209] Fix removal of ws between invalid tokens --- .../core/FormattingTreeModifier.java | 21 ++++++++++++++++--- .../formatter/core/ParserTestFormatter.java | 5 ----- .../actions/query/assert/query_action_4.bal | 5 +++++ .../actions/query/source/query_action_4.bal | 5 +++++ 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/actions/query/assert/query_action_4.bal create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/actions/query/source/query_action_4.bal diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index f37792e9df3b..9a8b5c586148 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -4355,7 +4355,9 @@ private MinutiaeList getTrailingMinutiae(Token token) { // Preserve the necessary trailing minutiae coming from the original token int consecutiveNewlines = 0; - for (Minutiae minutiae : token.trailingMinutiae()) { + int size = token.trailingMinutiae().size(); + for (int i = 0; i < size; i++) { + Minutiae minutiae = token.trailingMinutiae().get(i); switch (minutiae.kind()) { case END_OF_LINE_MINUTIAE: preserveIndentation(true); @@ -4369,16 +4371,25 @@ private MinutiaeList getTrailingMinutiae(Token token) { continue; } - addWhitespace(env.trailingWS, trailingMinutiae); + if (i == size - 1) { + addWhitespace(env.trailingWS, trailingMinutiae); + } else { + addWhitespace(1, trailingMinutiae); + } break; case COMMENT_MINUTIAE: - addWhitespace(1, trailingMinutiae); + if (!matchesMinutiaeKind(prevMinutiae, SyntaxKind.WHITESPACE_MINUTIAE)) { + addWhitespace(1, trailingMinutiae); + } trailingMinutiae.add(minutiae); consecutiveNewlines = 0; break; case INVALID_TOKEN_MINUTIAE_NODE: case INVALID_NODE_MINUTIAE: default: + if (matchesMinutiaeKind(prevMinutiae, SyntaxKind.END_OF_LINE_MINUTIAE)) { + addWhitespace(env.currentIndentation, trailingMinutiae); + } trailingMinutiae.add(minutiae); consecutiveNewlines = 0; break; @@ -4687,6 +4698,10 @@ private boolean hasTrailingNL(Token token) { return false; } + private boolean matchesMinutiaeKind(Minutiae minutiae, SyntaxKind kind) { + return minutiae != null && minutiae.kind() == kind; + } + private NodeList sortAndGroupImportDeclarationNodes( NodeList importDeclarationNodes) { // moduleImports would collect only module level imports if grouping is enabled, diff --git a/misc/formatter/modules/formatter-core/src/test/java/org/ballerinalang/formatter/core/ParserTestFormatter.java b/misc/formatter/modules/formatter-core/src/test/java/org/ballerinalang/formatter/core/ParserTestFormatter.java index 449b6ded79c9..54d2f79ccaea 100644 --- a/misc/formatter/modules/formatter-core/src/test/java/org/ballerinalang/formatter/core/ParserTestFormatter.java +++ b/misc/formatter/modules/formatter-core/src/test/java/org/ballerinalang/formatter/core/ParserTestFormatter.java @@ -89,11 +89,6 @@ public List skipList() { "service_decl_source_02.bal", "service_decl_source_05.bal", "service_decl_source_17.bal", "service_decl_source_20.bal", - // The following tests are disabled due to tokens merging together after formatting. issue #35240 - "query_expr_source_121.bal", "query_expr_source_123.bal", "query_expr_source_124.bal", - "query_expr_source_126.bal", "match_stmt_source_21.bal", - "func_params_source_27.bal", - "separated_node_list_import_decl.bal", "node_location_test_03.bal", // parser tests with syntax errors that cannot be handled by the formatter diff --git a/misc/formatter/modules/formatter-core/src/test/resources/actions/query/assert/query_action_4.bal b/misc/formatter/modules/formatter-core/src/test/resources/actions/query/assert/query_action_4.bal new file mode 100644 index 000000000000..f12c66c254d3 --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/actions/query/assert/query_action_4.bal @@ -0,0 +1,5 @@ +public function main() { + var c = from var i in 0 ... 5 + select i + where i %2 != 0; +} diff --git a/misc/formatter/modules/formatter-core/src/test/resources/actions/query/source/query_action_4.bal b/misc/formatter/modules/formatter-core/src/test/resources/actions/query/source/query_action_4.bal new file mode 100644 index 000000000000..8a3c6a2286e4 --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/actions/query/source/query_action_4.bal @@ -0,0 +1,5 @@ +public function main() { + var c = from var i in 0 ... 5 + select i + where i %2 != 0 ; +} From b29b5e30e4916bc4087e11d37bd832422b043166 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Wed, 18 Oct 2023 15:04:52 +0530 Subject: [PATCH 051/209] Add a comment with the approach on ws. --- .../org/ballerinalang/formatter/core/FormattingTreeModifier.java | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index 9a8b5c586148..fef38a8c4e0e 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -4371,6 +4371,7 @@ private MinutiaeList getTrailingMinutiae(Token token) { continue; } + // If last minutiae, use env.trailingWS; otherwise, add a single space after the invalid node if (i == size - 1) { addWhitespace(env.trailingWS, trailingMinutiae); } else { From 80ef0856fe0752940b379f202d4a8af3969c0a23 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 9 Jan 2024 10:53:33 +0530 Subject: [PATCH 052/209] Update the comment --- .../ballerinalang/formatter/core/FormattingTreeModifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index fef38a8c4e0e..06f19bbd8fac 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -4371,7 +4371,7 @@ private MinutiaeList getTrailingMinutiae(Token token) { continue; } - // If last minutiae, use env.trailingWS; otherwise, add a single space after the invalid node + // We reach here when the prevMinutiae is an invalid node/token if (i == size - 1) { addWhitespace(env.trailingWS, trailingMinutiae); } else { From 74474f62cad2db0b4f0322a6296715194a8048b1 Mon Sep 17 00:00:00 2001 From: mindula Date: Tue, 9 Jan 2024 15:27:02 +0530 Subject: [PATCH 053/209] fix displaying null for rest parameters with no documentation --- .../langserver/hover/HoverObjectResolver.java | 6 +++++- .../configs/hover_for_resource_path1.json | 4 ++-- .../configs/hover_for_resource_path2.json | 4 ++-- .../configs/hover_for_resource_path3.json | 4 ++-- .../configs/hover_for_resource_path4.json | 2 +- .../configs/hover_for_resource_path5.json | 2 +- .../configs/hover_for_resource_path6.json | 21 +++++++++++++++++++ .../hover/source/hover_for_resource_path.bal | 1 - 8 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path6.json diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java index e09a5ac37829..9ae8fc280d9e 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/hover/HoverObjectResolver.java @@ -237,9 +237,13 @@ private Hover getHoverObjectForSymbol(FunctionSymbol functionSymbol) { StringBuilder restParamBuilder = new StringBuilder(MarkupUtils.quotedString(modifiedTypeName + "...")); if (restParam.get().getName().isPresent()) { + String paramName = paramsMap.get(restParam.get().getName().get()); + if (paramName == null) { + paramName = ""; + } restParamBuilder.append(" ") .append(MarkupUtils.italicString(MarkupUtils.boldString(restParam.get().getName().get()))) - .append(" : ").append(paramsMap.get(restParam.get().getName().get())); + .append(" : ").append(paramName); } params.add(restParamBuilder.toString()); } diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json index e0c404b849e8..ef8a552b08b7 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path1.json @@ -1,6 +1,6 @@ { "position": { - "line": 29, + "line": 28, "character": 34 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json index 52264e7bbebc..a04d5db61f5a 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path2.json @@ -1,6 +1,6 @@ { "position": { - "line": 29, + "line": 28, "character": 39 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json index afb3b9d72ef9..9d194b82f512 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path3.json @@ -1,6 +1,6 @@ { "position": { - "line": 29, + "line": 28, "character": 55 }, "source": { @@ -10,7 +10,7 @@ "result": { "contents": { "kind": "markdown", - "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : parameter description \n \n--- \n \n### Return \n`string` : return value description" + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : \n \n--- \n \n### Return \n`string` : return value description" } }, "id": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json index e973d99c86ea..1d675d02ece9 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path4.json @@ -1,6 +1,6 @@ { "position": { - "line": 30, + "line": 29, "character": 34 }, "source": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json index 2a020065261b..6482412964c5 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path5.json @@ -1,6 +1,6 @@ { "position": { - "line": 31, + "line": 30, "character": 35 }, "source": { diff --git a/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path6.json b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path6.json new file mode 100644 index 000000000000..ef8a552b08b7 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/hover/configs/hover_for_resource_path6.json @@ -0,0 +1,21 @@ +{ + "position": { + "line": 28, + "character": 34 + }, + "source": { + "file": "hover_for_resource_path.bal" + }, + "expected": { + "result": { + "contents": { + "kind": "markdown", + "value": "Test Description.\n \n \n--- \n \n### Parameters \n \n`string` ***param1*** : parameter description \n`string` ***param2*** : parameter description \n`string` ***param3*** : parameter description \n`int...` ***param4*** : \n \n--- \n \n### Return \n`string` : return value description" + } + }, + "id": { + "left": "324" + }, + "jsonrpc": "2.0" + } +} diff --git a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal index cb3ee1da0d7b..a582367ae35c 100644 --- a/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal +++ b/language-server/modules/langserver-core/src/test/resources/hover/source/hover_for_resource_path.bal @@ -4,7 +4,6 @@ client class Client { # + param1 - parameter description # + param2 - parameter description # + param3 - parameter description - # + param4 - parameter description # + return - return value description resource function post path/[string param1]/path2/[string ...param2](string param3, int ...param4) returns string { return "post"; From 6f339b34101e07cc8e91f3535aa682cf50c97636 Mon Sep 17 00:00:00 2001 From: gabilang Date: Wed, 10 Jan 2024 12:09:07 +0530 Subject: [PATCH 054/209] Handle tuple creation with no members --- .../org/ballerinalang/langlib/array/utils/ArrayUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java index 6f5c627b64b0..ceb2e4b26271 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java @@ -18,6 +18,7 @@ package org.ballerinalang.langlib.array.utils; +import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.TypeCreator; @@ -121,6 +122,10 @@ public static BArray createEmptyArrayFromTuple(BArray arr) { } // Create an array of one type if the member-type-descriptors are the same if (isSameType) { + // Create an array with never type as element type if the `sameType` is null + if (sameType == null) { + return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); + } ArrayType type = TypeCreator.createArrayType(sameType); return ValueCreator.createArrayValue(type); } From 04bbe97467e73402c4fce57d9a4085e65af7ced6 Mon Sep 17 00:00:00 2001 From: gabilang Date: Wed, 10 Jan 2024 12:24:02 +0530 Subject: [PATCH 055/209] Add unit tests --- .../langlib/test/LangLibArrayTest.java | 4 +++- .../src/test/resources/test-src/arraylib_test.bal | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibArrayTest.java b/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibArrayTest.java index f07bd8627f67..8b7a128b0f10 100644 --- a/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibArrayTest.java +++ b/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibArrayTest.java @@ -602,7 +602,9 @@ public Object[] testFunctions() { "testArrSortWithNamedArgs2", "testArrSortWithNamedArgs3", "testArrayPop", - "testSetLengthNegative" + "testSetLengthNegative", + "testArrayFilterWithEmptyArrayAndTypeBinding", + "testArrayReverseWithEmptyArrayAndTypeBinding" }; } } diff --git a/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal b/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal index e1810ae806b5..b72a545a0747 100644 --- a/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal +++ b/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal @@ -1832,3 +1832,17 @@ function testSetLengthNegative() { checkpanic result.detail()["message"]); } } + +function testArrayFilterWithEmptyArrayAndTypeBinding() { + var x = []; + anydata[] y = x; + anydata[] z = y.filter(v => v is int); + assertValueEquality(z, []); +} + +function testArrayReverseWithEmptyArrayAndTypeBinding() { + var x = []; + anydata[] y = x; + anydata[] z = y.reverse(); + assertValueEquality(z, []); +} From 3e3defd7a5b32526476e65a8f3b2272f0d302727 Mon Sep 17 00:00:00 2001 From: gabilang Date: Thu, 11 Jan 2024 12:28:45 +0530 Subject: [PATCH 056/209] Refactor code --- .../langlib/array/utils/ArrayUtils.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java index ceb2e4b26271..c5f07ea07312 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java @@ -104,12 +104,13 @@ public static BArray createEmptyArrayFromTuple(BArray arr) { TupleType tupleType = (TupleType) arrType; List memTypes = new ArrayList<>(); List tupleTypes = tupleType.getTupleTypes(); - boolean isSameType = true; - Type sameType = null; - if (!tupleTypes.isEmpty()) { - sameType = tupleTypes.get(0); - memTypes.add(sameType); + if (tupleTypes.isEmpty()) { + // Return an array with never type as the element type + return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); } + boolean isSameType = true; + Type sameType = tupleTypes.get(0); + memTypes.add(sameType); for (int i = 1; i < tupleTypes.size(); i++) { isSameType &= sameType == tupleTypes.get(i); memTypes.add(tupleTypes.get(i)); @@ -122,10 +123,6 @@ public static BArray createEmptyArrayFromTuple(BArray arr) { } // Create an array of one type if the member-type-descriptors are the same if (isSameType) { - // Create an array with never type as element type if the `sameType` is null - if (sameType == null) { - return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); - } ArrayType type = TypeCreator.createArrayType(sameType); return ValueCreator.createArrayValue(type); } From 5a96d46b0a1735be3af44ddca4d50049fe2af07e Mon Sep 17 00:00:00 2001 From: gabilang Date: Thu, 11 Jan 2024 16:59:34 +0530 Subject: [PATCH 057/209] Provide java command via the system java path --- .../runtime/profiler/codegen/ProfilerMethodWrapper.java | 3 ++- .../java/io/ballerina/runtime/profiler/util/Constants.java | 1 + .../src/main/java/io/ballerina/cli/task/RunProfilerTask.java | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java index 239d3f1da78d..61aef2762546 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java @@ -42,6 +42,7 @@ import static io.ballerina.runtime.profiler.util.Constants.CURRENT_DIR_KEY; import static io.ballerina.runtime.profiler.util.Constants.ERROR_STREAM; +import static io.ballerina.runtime.profiler.util.Constants.JAVA_COMMAND; import static io.ballerina.runtime.profiler.util.Constants.OUT_STREAM; import static io.ballerina.runtime.profiler.util.Constants.USER_DIR; @@ -55,7 +56,7 @@ public class ProfilerMethodWrapper extends ClassLoader { public void invokeMethods(String debugArg) throws IOException, InterruptedException { String balJarArgs = Main.getBalJarArgs(); List commands = new ArrayList<>(); - commands.add("java"); + commands.add(System.getenv(JAVA_COMMAND)); commands.add("-jar"); if (debugArg != null) { commands.add(debugArg); diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java index ff30884b8ab1..477312431acd 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java @@ -51,6 +51,7 @@ public class Constants { public static final String PROFILE_ANALYZER = "io/ballerina/runtime/profiler/runtime/ProfileAnalyzer"; public static final String GET_INSTANCE_DESCRIPTOR = "()L" + PROFILE_ANALYZER + ";"; public static final String BALLERINA_HOME = "ballerina.home"; + public static final String JAVA_COMMAND = "java.command"; public static final String WORKING_DIRECTORY = "user.dir"; public static final String PROFILE_DATA = "${profile_data}"; public static final String HTML_TEMPLATE_FILE = "profiler_output.html"; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java index f20a22f0f8f2..6f6c33c69cbf 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java @@ -52,6 +52,7 @@ public class RunProfilerTask implements Task { private final PrintStream err; private static final String JAVA_OPTS = "JAVA_OPTS"; private static final String CURRENT_DIR_KEY = "current.dir"; + private static final String JAVA_COMMAND = "java.command"; public RunProfilerTask(PrintStream errStream) { this.err = errStream; @@ -66,7 +67,7 @@ private void initiateProfiler(Project project) { try { Files.copy(sourcePath, targetPath, copyOption); List commands = new ArrayList<>(); - commands.add(System.getProperty("java.command")); + commands.add(System.getProperty(JAVA_COMMAND)); commands.add("-jar"); if (isInDebugMode()) { commands.add(getDebugArgs(err)); @@ -83,6 +84,7 @@ private void initiateProfiler(Project project) { pb.environment().put(JAVA_OPTS, getAgentArgs()); pb.environment().put(BALLERINA_HOME, System.getProperty(BALLERINA_HOME)); pb.environment().put(CURRENT_DIR_KEY, System.getProperty(USER_DIR)); + pb.environment().put(JAVA_COMMAND, System.getProperty(JAVA_COMMAND)); pb.directory(new File(getProfilerPath(project).toUri())); Process process = pb.start(); process.waitFor(); From 1a4f656e28c78ba265d937a58ef524aefa752926 Mon Sep 17 00:00:00 2001 From: kavindu Date: Sat, 13 Jan 2024 14:50:42 +0530 Subject: [PATCH 058/209] Clone on-fail node in match-stmt --- .../java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java index fd187117256d..17bd8441aff5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/parser/NodeCloner.java @@ -696,7 +696,7 @@ public void visit(BLangMatchStatement source) { source.cloneRef = clone; clone.setExpression(clone(source.getExpression())); clone.matchClauses = cloneList(source.matchClauses); - clone.onFailClause = source.onFailClause; + clone.onFailClause = clone(source.onFailClause); } @Override From 998b57c81f707dd5fff3d65943d9211deb0f1f14 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Tue, 28 Nov 2023 14:10:49 +0530 Subject: [PATCH 059/209] Optimize EnvPackageCache using a nested map --- .../environment/EnvironmentPackageCache.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/EnvironmentPackageCache.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/EnvironmentPackageCache.java index 14634773018a..819dbc4c9912 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/EnvironmentPackageCache.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/environment/EnvironmentPackageCache.java @@ -22,15 +22,20 @@ */ public class EnvironmentPackageCache implements WritablePackageCache { - private final Map projects = new HashMap<>(); + private final Map projectsById = new HashMap<>(); + private final Map>> + projectsByOrgNameVersion = new HashMap<>(); public void cache(Package pkg) { - projects.put(pkg.packageId(), pkg.project()); + projectsById.put(pkg.packageId(), pkg.project()); + projectsByOrgNameVersion.computeIfAbsent(pkg.packageOrg(), k -> new HashMap<>()) + .computeIfAbsent(pkg.packageName(), k -> new HashMap<>()) + .put(pkg.packageVersion(), pkg.project()); } @Override public Optional getPackage(PackageId packageId) { - Project project = projects.get(packageId); + Project project = projectsById.get(packageId); if (project == null) { return Optional.empty(); } @@ -40,7 +45,7 @@ public Optional getPackage(PackageId packageId) { @Override public Package getPackageOrThrow(PackageId packageId) { - Project project = projects.get(packageId); + Project project = projectsById.get(packageId); if (project == null) { throw new IllegalStateException("Cannot find a Package for the given PackageId: " + packageId); } @@ -51,23 +56,15 @@ public Package getPackageOrThrow(PackageId packageId) { public Optional getPackage(PackageOrg packageOrg, PackageName packageName, PackageVersion version) { - // Do we have a need to improve this logic? - for (Project project : projects.values()) { - PackageDescriptor pkgDesc = project.currentPackage().descriptor(); - if (pkgDesc.org().equals(packageOrg) && pkgDesc.name().equals(packageName) && - pkgDesc.version().equals(version)) { - return Optional.of(project.currentPackage()); - } - } - return Optional.empty(); + return Optional.ofNullable(projectsByOrgNameVersion.getOrDefault(packageOrg, new HashMap<>()) + .getOrDefault(packageName, new HashMap<>()) + .get(version)).map(Project::currentPackage); } @Override public List getPackages(PackageOrg packageOrg, PackageName packageName) { - // Do we have a need to improve this logic? - // TODO Optimize this logic List foundList = new ArrayList<>(); - for (Project project : projects.values()) { + for (Project project : projectsById.values()) { PackageManifest pkgDesc = project.currentPackage().manifest(); if (pkgDesc.org().equals(packageOrg) && pkgDesc.name().equals(packageName)) { @@ -79,6 +76,14 @@ public List getPackages(PackageOrg packageOrg, PackageName packageName) @Override public void removePackage(PackageId packageId) { - projects.remove(packageId); + Optional project = Optional.ofNullable(projectsById.get(packageId)); + if (project.isEmpty()) { + return; + } + PackageDescriptor pkgDesc = project.get().currentPackage().descriptor(); + projectsByOrgNameVersion.get(pkgDesc.org()) + .get(pkgDesc.name()) + .remove(pkgDesc.version()); + projectsById.remove(packageId); } } From 87945ef2835d44c20bd05f48b7ee42a006c13268 Mon Sep 17 00:00:00 2001 From: gabilang Date: Tue, 16 Jan 2024 11:49:41 +0530 Subject: [PATCH 060/209] Address review suggestion --- .../runtime/profiler/codegen/ProfilerMethodWrapper.java | 3 +-- .../java/io/ballerina/runtime/profiler/util/Constants.java | 1 - .../src/main/java/io/ballerina/cli/task/RunProfilerTask.java | 5 ++--- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java index 61aef2762546..b2c4be7eab31 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/codegen/ProfilerMethodWrapper.java @@ -42,7 +42,6 @@ import static io.ballerina.runtime.profiler.util.Constants.CURRENT_DIR_KEY; import static io.ballerina.runtime.profiler.util.Constants.ERROR_STREAM; -import static io.ballerina.runtime.profiler.util.Constants.JAVA_COMMAND; import static io.ballerina.runtime.profiler.util.Constants.OUT_STREAM; import static io.ballerina.runtime.profiler.util.Constants.USER_DIR; @@ -56,7 +55,7 @@ public class ProfilerMethodWrapper extends ClassLoader { public void invokeMethods(String debugArg) throws IOException, InterruptedException { String balJarArgs = Main.getBalJarArgs(); List commands = new ArrayList<>(); - commands.add(System.getenv(JAVA_COMMAND)); + commands.add(System.getenv("java.command")); commands.add("-jar"); if (debugArg != null) { commands.add(debugArg); diff --git a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java index 477312431acd..ff30884b8ab1 100644 --- a/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java +++ b/bvm/ballerina-profiler/src/main/java/io/ballerina/runtime/profiler/util/Constants.java @@ -51,7 +51,6 @@ public class Constants { public static final String PROFILE_ANALYZER = "io/ballerina/runtime/profiler/runtime/ProfileAnalyzer"; public static final String GET_INSTANCE_DESCRIPTOR = "()L" + PROFILE_ANALYZER + ";"; public static final String BALLERINA_HOME = "ballerina.home"; - public static final String JAVA_COMMAND = "java.command"; public static final String WORKING_DIRECTORY = "user.dir"; public static final String PROFILE_DATA = "${profile_data}"; public static final String HTML_TEMPLATE_FILE = "profiler_output.html"; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java index 6f6c33c69cbf..f1c375b01cb0 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunProfilerTask.java @@ -52,7 +52,6 @@ public class RunProfilerTask implements Task { private final PrintStream err; private static final String JAVA_OPTS = "JAVA_OPTS"; private static final String CURRENT_DIR_KEY = "current.dir"; - private static final String JAVA_COMMAND = "java.command"; public RunProfilerTask(PrintStream errStream) { this.err = errStream; @@ -67,7 +66,7 @@ private void initiateProfiler(Project project) { try { Files.copy(sourcePath, targetPath, copyOption); List commands = new ArrayList<>(); - commands.add(System.getProperty(JAVA_COMMAND)); + commands.add(System.getProperty("java.command")); commands.add("-jar"); if (isInDebugMode()) { commands.add(getDebugArgs(err)); @@ -84,7 +83,7 @@ private void initiateProfiler(Project project) { pb.environment().put(JAVA_OPTS, getAgentArgs()); pb.environment().put(BALLERINA_HOME, System.getProperty(BALLERINA_HOME)); pb.environment().put(CURRENT_DIR_KEY, System.getProperty(USER_DIR)); - pb.environment().put(JAVA_COMMAND, System.getProperty(JAVA_COMMAND)); + pb.environment().put("java.command", System.getProperty("java.command")); pb.directory(new File(getProfilerPath(project).toUri())); Process process = pb.start(); process.waitFor(); From 0bb9b60256cfb54a6d7e4fdc5a2d480647693768 Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 15:39:17 +0530 Subject: [PATCH 061/209] Update the GraphQL CLI help text --- .../src/main/resources/cli-help/ballerina-help.help | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help index 93d96b8eb3aa..ed9149957083 100755 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help @@ -40,9 +40,7 @@ COMMANDS format Format Ballerina source files grpc Generate the Ballerina sources for a given Protocol Buffer definition - graphql Generate the Ballerina client sources for a GraphQL config file, - generate the GraphQL schema for a Ballerina GraphQL service, and - generate the Ballerina GraphQL service for a GraphQL schema + graphql Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. openapi Generate the Ballerina sources for a given OpenAPI definition and vice versa asyncapi Generate the Ballerina sources for a given AsyncAPI definition From be2811a06a094351c9237c42087c905bfa9b26ac Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 15:41:17 +0530 Subject: [PATCH 062/209] Update ballerina-graphql.help --- .../src/main/resources/cli-help/ballerina-graphql.help | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help index 9224928d3bb8..39af95c2ba98 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help @@ -1,7 +1,5 @@ NAME - ballerina-graphql - Generate the Ballerina client sources for a GraphQL config file, - generate the GraphQL schema for a Ballerina GraphQL service, - and generate the Ballerina service sources for a GraphQL schema. + ballerina-graphql - Generate Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. SYNOPSIS From 1e50b67799896d5b3e2c69482ba5b22ec3393abe Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 15:41:57 +0530 Subject: [PATCH 063/209] Update ballerina-help.help From 2e44b34f08029439f66792ffcddb0c5349f16292 Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 15:42:12 +0530 Subject: [PATCH 064/209] Update ballerina-graphql.help --- .../src/main/resources/cli-help/ballerina-graphql.help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help index 39af95c2ba98..c96aba06f24b 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help @@ -1,5 +1,5 @@ NAME - ballerina-graphql - Generate Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. + ballerina-graphql - Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. SYNOPSIS From efcb947a4f2e50a3bfcd9a9d7ad0e2a2c5d7796a Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 17:25:26 +0530 Subject: [PATCH 065/209] Update ballerina-graphql.help --- .../src/main/resources/cli-help/ballerina-graphql.help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help index c96aba06f24b..aabe22b09a7d 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help @@ -1,5 +1,5 @@ NAME - ballerina-graphql - Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. + ballerina-graphql - Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and Ballerina service sources for a GraphQL schema. SYNOPSIS From 3a001161032312ab837f00dd6911352c00a82c08 Mon Sep 17 00:00:00 2001 From: praneesha Date: Tue, 16 Jan 2024 17:25:58 +0530 Subject: [PATCH 066/209] Update ballerina-help.help --- .../src/main/resources/cli-help/ballerina-help.help | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help index ed9149957083..07ecf41512c6 100755 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help @@ -40,7 +40,7 @@ COMMANDS format Format Ballerina source files grpc Generate the Ballerina sources for a given Protocol Buffer definition - graphql Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and vice versa. + graphql Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and Ballerina service sources for a GraphQL schema openapi Generate the Ballerina sources for a given OpenAPI definition and vice versa asyncapi Generate the Ballerina sources for a given AsyncAPI definition From 7c241f415a3381f170009551093e5e114c15939b Mon Sep 17 00:00:00 2001 From: Gabilan Ganeshwaran Date: Wed, 17 Jan 2024 09:23:24 +0530 Subject: [PATCH 067/209] Fix typo Co-authored-by: Hinduja Balasubramaniyam <28644893+HindujaB@users.noreply.github.com> --- .../src/test/resources/test-src/klass/simple_service_class.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal index f7b178a9fd12..5f2e06709592 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/klass/simple_service_class.bal @@ -79,7 +79,7 @@ function testServiceObjectValue() { var y = wait callMethod(s, "$get$foo$path"); assertEquality(y, s.message + "foo"); - // "$get$." is encorded into "$gen$$get$&0046" + // "$get$." is encoded into "$gen$$get$&0046" var z = wait callMethod(s, "$gen$$get$&0046"); assertEquality(z, s.message + "dot"); From 46a1713b019afd2ec70238475f4ab4f7ee80ff58 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 19 Sep 2023 16:14:58 +0530 Subject: [PATCH 068/209] Support collect clause as a sub clause of a query --- .../io/ballerina/compiler/internal/parser/BallerinaParser.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java index 65affc31a52a..d306a0148dd5 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java @@ -11949,7 +11949,8 @@ private STNode parseQueryExprRhs(STNode queryConstructType, boolean isRhsExpr, b } } - if (peek().kind == SyntaxKind.DO_KEYWORD && (!isNestedQueryExpr() || selectClause == null)) { + if (peek().kind == SyntaxKind.DO_KEYWORD && + (!isNestedQueryExpr() || (selectClause == null && collectClause == null))) { STNode intermediateClauses = STNodeFactory.createNodeList(clauses); STNode queryPipeline = STNodeFactory.createQueryPipelineNode(fromClause, intermediateClauses); return parseQueryAction(queryConstructType, queryPipeline, selectClause); From 5869ff75f3a1ced94bbb6572275135ff737df64c Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 19 Sep 2023 16:26:14 +0530 Subject: [PATCH 069/209] Add tests for query actions --- .../org/ballerinalang/test/query/QueryActionTest.java | 5 +++++ .../test/resources/test-src/query/query-action.bal | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java index a717549b4f41..d74089f9ca40 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java @@ -174,6 +174,11 @@ public void testErrorHandlingWithinQueryAction() { public void testReturnStmtWithinQueryAction() { BRunUtil.invoke(result, "testReturnStmtWithinQueryAction"); } + + @Test + public void testQueryActionWithCollectClauseInsideLeClause() { + BRunUtil.invoke(result, "testQueryActionWithCollectClauseInsideLeClause"); + } @Test public void testQueryActionWithDoClauseContainsCheck() { diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal index 5ba711795070..bb06d4692058 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal @@ -862,6 +862,17 @@ function testJoinedQueryActionWithRegExp() { "(?:A|B|[ab-fgh]+(?im-x:[cdeg-k]??AAAB*[^abc-efg](?:A|B|[ab-fgh]+(?im-x:[cdeg-k]??A)|)|^|PQ?)|)|^|PQ?"); } +function testQueryActionWithCollectClauseInsideLeClause() { + int[][] arr = [[1, 2], [3, 4], [5, 6]]; + int total = 0; + from var i in arr + let int tot = from var j in i collect sum(j) + do { + total += tot; + }; + assertEquality(21, total); +} + function assertEquality(any|error expected, any|error actual) { if expected is anydata && actual is anydata && expected == actual { return; From f0b85305ea284059a10559877e20523b3a47cf94 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 17 Jan 2024 09:45:19 +0530 Subject: [PATCH 070/209] Add empty do query action test --- .../org/ballerinalang/test/query/QueryActionTest.java | 7 ++++++- .../test/resources/test-src/query/query-action.bal | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java index d74089f9ca40..2ab2c48a7c4c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionTest.java @@ -177,7 +177,12 @@ public void testReturnStmtWithinQueryAction() { @Test public void testQueryActionWithCollectClauseInsideLeClause() { - BRunUtil.invoke(result, "testQueryActionWithCollectClauseInsideLeClause"); + BRunUtil.invoke(result, "testQueryActionWithCollectClauseInsideLeClause1"); + } + + @Test + public void testQueryActionWithCollectClauseInsideLeClauseWithEmptyDoBody() { + BRunUtil.invoke(result, "testQueryActionWithCollectClauseInsideLeClause2"); } @Test diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal index bb06d4692058..0efc2aed6906 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-action.bal @@ -862,7 +862,7 @@ function testJoinedQueryActionWithRegExp() { "(?:A|B|[ab-fgh]+(?im-x:[cdeg-k]??AAAB*[^abc-efg](?:A|B|[ab-fgh]+(?im-x:[cdeg-k]??A)|)|^|PQ?)|)|^|PQ?"); } -function testQueryActionWithCollectClauseInsideLeClause() { +function testQueryActionWithCollectClauseInsideLeClause1() { int[][] arr = [[1, 2], [3, 4], [5, 6]]; int total = 0; from var i in arr @@ -873,6 +873,15 @@ function testQueryActionWithCollectClauseInsideLeClause() { assertEquality(21, total); } +function testQueryActionWithCollectClauseInsideLeClause2() { + float[][] items = [[1.1, 2.1], [3.1, 4.1], [5.2, 6.2]]; + from var i in items + let float tot = from var j in i collect sum(j) + do { + + }; +} + function assertEquality(any|error expected, any|error actual) { if expected is anydata && actual is anydata && expected == actual { return; From 24da8820c3067629610b1bf8fcc4a24dcf4d174f Mon Sep 17 00:00:00 2001 From: gabilang Date: Wed, 17 Jan 2024 09:54:28 +0530 Subject: [PATCH 071/209] Fix incorrectly refactored logic --- .../langlib/array/utils/ArrayUtils.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java index c5f07ea07312..ea3419c98d58 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java @@ -102,20 +102,20 @@ public static BError createOpNotSupportedError(Type type, String op) { public static BArray createEmptyArrayFromTuple(BArray arr) { Type arrType = TypeUtils.getImpliedType(arr.getType()); TupleType tupleType = (TupleType) arrType; - List memTypes = new ArrayList<>(); List tupleTypes = tupleType.getTupleTypes(); - if (tupleTypes.isEmpty()) { - // Return an array with never type as the element type - return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); - } + Type restType = tupleType.getRestType(); boolean isSameType = true; - Type sameType = tupleTypes.get(0); - memTypes.add(sameType); - for (int i = 1; i < tupleTypes.size(); i++) { - isSameType &= sameType == tupleTypes.get(i); - memTypes.add(tupleTypes.get(i)); + Type sameType = null; + if (!tupleTypes.isEmpty()) { + sameType = tupleTypes.get(0); + for (int i = 1; i < tupleTypes.size(); i++) { + if (tupleTypes.get(i) != sameType) { + isSameType = false; + break; + } + } } - Type restType = tupleType.getRestType(); + List memTypes = new ArrayList<>(tupleTypes); // If there's a tuple-rest-descriptor the array will not be of the same type even if other types are the same if (restType != null) { isSameType = false; @@ -123,6 +123,10 @@ public static BArray createEmptyArrayFromTuple(BArray arr) { } // Create an array of one type if the member-type-descriptors are the same if (isSameType) { + if (sameType == null) { + // Return an array with never type + return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); + } ArrayType type = TypeCreator.createArrayType(sameType); return ValueCreator.createArrayValue(type); } From 5937d2982871d7c127859725b1a7857a59d880ad Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 09:56:06 +0530 Subject: [PATCH 072/209] Change ToolContext getters and implementation --- .../io/ballerina/projects/ToolContext.java | 79 +++++++++++++------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java index 56abbc166512..d84f78e312b0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java @@ -22,7 +22,9 @@ import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static io.ballerina.projects.util.ProjectConstants.GENERATED_MODULES_ROOT; import static io.ballerina.projects.util.ProjectConstants.TARGET_DIR_NAME; @@ -36,75 +38,104 @@ public class ToolContext { private final Package currentPackage; - private final String toolType; private final String toolId; private final String filePath; private final String targetModule; - private final TomlTableNode optionsTable; - private final Path cachePath; - private final Path outputPath; - private List diagnostics = new ArrayList<>(); + private final Map options; + private final List diagnostics = new ArrayList<>(); - ToolContext(Package currentPackage, String type, String toolId, String filePath, + ToolContext(Package currentPackage, String toolId, String filePath, String targetModule, TomlTableNode optionsTable) { this.currentPackage = currentPackage; - this.toolType = type; this.toolId = toolId; this.filePath = filePath; this.targetModule = targetModule; - this.optionsTable = optionsTable; - Path sourceRoot = currentPackage.project().sourceRoot(); - this.cachePath = sourceRoot.resolve(TARGET_DIR_NAME).resolve(TOOL_CACHE_DIR).resolve(toolId); - if (targetModule == null || targetModule.isEmpty()) { - this.outputPath = sourceRoot.resolve(GENERATED_MODULES_ROOT); - } else { - this.outputPath = sourceRoot.resolve(GENERATED_MODULES_ROOT).resolve(targetModule); - } + this.options = getOptions(optionsTable); } public static ToolContext from(PackageManifest.Tool tool, Package currentPackage) { - return new ToolContext(currentPackage, tool.getType(), tool.getId(), + return new ToolContext(currentPackage, tool.getId(), tool.getFilePath(), tool.getTargetModule(), tool.getOptionsTable()); } + /** + * @return the id of the tool configuration. + */ public String toolId() { return this.toolId; } - public String toolType() { - return this.toolType; - } - + /** + * @return the filepath extracted from tool configuration. + */ public String filePath() { return this.filePath; } + /** + * @return the target module extracted from tool configuration. + */ public String targetModule() { return targetModule; } - public TomlTableNode optionsTable() { - return this.optionsTable; + /** + * @return a map of the optional tool configurations. + */ + public Map options() { + return this.options; } + /** + * @return the cache path derived using the tool id. + */ public Path cachePath() { - return cachePath; + Path sourceRoot = currentPackage.project().sourceRoot(); + return sourceRoot.resolve(TARGET_DIR_NAME).resolve(TOOL_CACHE_DIR).resolve(toolId); } + /** + * @return the output path derived using the target module + */ public Path outputPath() { - return outputPath; + Path sourceRoot = currentPackage.project().sourceRoot(); + if (targetModule == null || targetModule.isEmpty()) { + return sourceRoot.resolve(GENERATED_MODULES_ROOT); + } else { + return sourceRoot.resolve(GENERATED_MODULES_ROOT).resolve(targetModule); + } } + /** + * @return the current package instance. + */ public Package currentPackage() { return currentPackage; } + + /** + * @return a list of tool diagnostics. + */ public List diagnostics() { return diagnostics; } + /** + * Reports a diagnostic against the build tool executed. + * + * @param diagnostic the {@code Diagnostic} to be reported + */ public void reportDiagnostic(Diagnostic diagnostic) { diagnostics.add(diagnostic); } + + private Map getOptions(TomlTableNode optionsTable) { + Map options = new HashMap<>(); + for (String option: optionsTable.entries().keySet()) { + options.put(option, optionsTable.entries().get(option).toNativeObject()); + } + return options; + } } From 758cc06dae1c2fe06236b98dd166d9f5499d4cc6 Mon Sep 17 00:00:00 2001 From: gabilang Date: Wed, 17 Jan 2024 10:06:06 +0530 Subject: [PATCH 073/209] Add assertion with never type array --- .../langlib-test/src/test/resources/test-src/arraylib_test.bal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal b/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal index b72a545a0747..00e2d51077f1 100644 --- a/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal +++ b/langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal @@ -1838,6 +1838,7 @@ function testArrayFilterWithEmptyArrayAndTypeBinding() { anydata[] y = x; anydata[] z = y.filter(v => v is int); assertValueEquality(z, []); + assertTrue(z is never[]); } function testArrayReverseWithEmptyArrayAndTypeBinding() { @@ -1845,4 +1846,5 @@ function testArrayReverseWithEmptyArrayAndTypeBinding() { anydata[] y = x; anydata[] z = y.reverse(); assertValueEquality(z, []); + assertTrue(z is never[]); } From 6edfe50fb322850be8689b622fe8dc2e00155b1a Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 17 Jan 2024 10:26:15 +0530 Subject: [PATCH 074/209] Add parser tests for query actions --- .../test/syntax/actions/QueryActionTest.java | 10 + .../query-action/query_action_assert_07.json | 1408 ++++++++++++++++ .../query-action/query_action_assert_08.json | 1416 +++++++++++++++++ .../query-action/query_action_source_07.bal | 14 + .../query-action/query_action_source_08.bal | 14 + .../src/test/resources/test_parser.bal | 14 +- 6 files changed, 2875 insertions(+), 1 deletion(-) create mode 100644 compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_07.json create mode 100644 compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json create mode 100644 compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_07.bal create mode 100644 compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal diff --git a/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/actions/QueryActionTest.java b/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/actions/QueryActionTest.java index 46ec91b6256c..1f57345ad634 100644 --- a/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/actions/QueryActionTest.java +++ b/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/actions/QueryActionTest.java @@ -48,6 +48,16 @@ public void testQueryActionWithLimit() { testFile("query-action/query_action_source_05.bal", "query-action/query_action_assert_05.json"); } + @Test + public void testQueryActionWithGroupBy() { + testFile("query-action/query_action_source_07.bal", "query-action/query_action_assert_07.json"); + } + + @Test + public void testQueryActionWithCollect() { + testFile("query-action/query_action_source_08.bal", "query-action/query_action_assert_08.json"); + } + // Recovery tests @Test diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_07.json b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_07.json new file mode 100644 index 000000000000..eb57fce67243 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_07.json @@ -0,0 +1,1408 @@ +{ + "kind": "FUNCTION_DEFINITION", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "IDENTIFIER_TOKEN", + "value": "foo" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_SIGNATURE", + "children": [ + { + "kind": "OPEN_PAREN_TOKEN" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "CLOSE_PAREN_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "FUNCTION_BODY_BLOCK", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LOCAL_VAR_DECL", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orders", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACKET_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "A" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "23.4" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "A" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "20.4" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "B" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "21.5" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "B" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "21.5" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACKET_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + }, + { + "kind": "ACTION_STATEMENT", + "children": [ + { + "kind": "QUERY_ACTION", + "children": [ + { + "kind": "QUERY_PIPELINE", + "children": [ + { + "kind": "FROM_CLAUSE", + "children": [ + { + "kind": "FROM_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "i", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "IN_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACKET_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "4" + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACKET_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [] + } + ] + }, + { + "kind": "DO_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BLOCK_STATEMENT", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LOCAL_VAR_DECL", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantities", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "QUERY_EXPRESSION", + "children": [ + { + "kind": "QUERY_PIPELINE", + "children": [ + { + "kind": "FROM_CLAUSE", + "children": [ + { + "kind": "FROM_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "MAPPING_BINDING_PATTERN", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "FIELD_BINDING_PATTERN", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "FIELD_BINDING_PATTERN", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "IN_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orders", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "GROUP_BY_CLAUSE", + "children": [ + { + "kind": "GROUP_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BY_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "SELECT_CLAUSE", + "children": [ + { + "kind": "SELECT_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "FUNCTION_CALL", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "sum" + } + ] + }, + { + "kind": "OPEN_PAREN_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "POSITIONAL_ARG", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_PAREN_TOKEN" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json new file mode 100644 index 000000000000..69e1978f9bd6 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json @@ -0,0 +1,1416 @@ +{ + "kind": "FUNCTION_DEFINITION", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "IDENTIFIER_TOKEN", + "value": "foo" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_SIGNATURE", + "children": [ + { + "kind": "OPEN_PAREN_TOKEN" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "CLOSE_PAREN_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "FUNCTION_BODY_BLOCK", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LOCAL_VAR_DECL", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orders", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACKET_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "A" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "23.4" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "A" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "20.4" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "B" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "21.5" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "MAPPING_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orderId" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "itemName" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "STRING_LITERAL", + "children": [ + { + "kind": "STRING_LITERAL_TOKEN", + "value": "B" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_FLOATING_POINT_LITERAL_TOKEN", + "value": "21.5" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SPECIFIC_FIELD", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + }, + { + "kind": "COLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACKET_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + }, + { + "kind": "ACTION_STATEMENT", + "children": [ + { + "kind": "QUERY_ACTION", + "children": [ + { + "kind": "QUERY_PIPELINE", + "children": [ + { + "kind": "FROM_CLAUSE", + "children": [ + { + "kind": "FROM_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "i", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "IN_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST_CONSTRUCTOR", + "children": [ + { + "kind": "OPEN_BRACKET_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "1" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "2" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "3" + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "NUMERIC_LITERAL", + "children": [ + { + "kind": "DECIMAL_INTEGER_LITERAL_TOKEN", + "value": "4" + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACKET_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [] + } + ] + }, + { + "kind": "DO_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BLOCK_STATEMENT", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LOCAL_VAR_DECL", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "income", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "QUERY_EXPRESSION", + "children": [ + { + "kind": "QUERY_PIPELINE", + "children": [ + { + "kind": "FROM_CLAUSE", + "children": [ + { + "kind": "FROM_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "MAPPING_BINDING_PATTERN", + "children": [ + { + "kind": "OPEN_BRACE_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "FIELD_BINDING_PATTERN", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + } + ] + } + ] + }, + { + "kind": "COMMA_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "FIELD_BINDING_PATTERN", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "IN_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "orders", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LET_CLAUSE", + "children": [ + { + "kind": "LET_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "LET_VAR_DECL", + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "VAR_TYPE_DESC", + "children": [ + { + "kind": "VAR_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "totPrice", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BINARY_EXPRESSION", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "price" + } + ] + }, + { + "kind": "ASTERISK_TOKEN" + }, + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "quantity", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "COLLECT_CLAUSE", + "children": [ + { + "kind": "COLLECT_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "FUNCTION_CALL", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "sum" + } + ] + }, + { + "kind": "OPEN_PAREN_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "POSITIONAL_ARG", + "children": [ + { + "kind": "SIMPLE_NAME_REFERENCE", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "totPrice" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_PAREN_TOKEN" + } + ] + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_07.bal b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_07.bal new file mode 100644 index 000000000000..7d0e371ad030 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_07.bal @@ -0,0 +1,14 @@ +function foo() { + var orders = [ + {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, + {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, + {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, + {orderId: 1, itemName: "B", price: 21.5, quantity: 3} + ]; + from var i in [1, 2, 3, 4] + do { + var quantities = from var {itemName, quantity} in orders + group by itemName + select {itemName, quantity: sum(quantity)}; + }; +} diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal new file mode 100644 index 000000000000..0f4543d16156 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal @@ -0,0 +1,14 @@ +function foo() { + var orders = [ + {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, + {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, + {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, + {orderId: 1, itemName: "B", price: 21.5, quantity: 3} + ]; + from var i in [1, 2, 3, 4] + do { + var income = from var {price, quantity} in orders + let var totPrice = price*quantity + collect sum(totPrice); + }; +} diff --git a/compiler/ballerina-parser/src/test/resources/test_parser.bal b/compiler/ballerina-parser/src/test/resources/test_parser.bal index 6b71ef415c69..7d0e371ad030 100644 --- a/compiler/ballerina-parser/src/test/resources/test_parser.bal +++ b/compiler/ballerina-parser/src/test/resources/test_parser.bal @@ -1,2 +1,14 @@ -public function main() { +function foo() { + var orders = [ + {orderId: 1, itemName: "A", price: 23.4, quantity: 2}, + {orderId: 1, itemName: "A", price: 20.4, quantity: 1}, + {orderId: 2, itemName: "B", price: 21.5, quantity: 3}, + {orderId: 1, itemName: "B", price: 21.5, quantity: 3} + ]; + from var i in [1, 2, 3, 4] + do { + var quantities = from var {itemName, quantity} in orders + group by itemName + select {itemName, quantity: sum(quantity)}; + }; } From ef434dda1662ac59dc90cea0610e771f0682f1f1 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 14 Dec 2023 23:09:40 +0530 Subject: [PATCH 075/209] Fix mishandling of \. in obj type name at codegen --- .../ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index 8efd06fc65e1..fb492b3efa7e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -521,7 +521,9 @@ public static String generateReturnType(BType bType) { static String cleanupObjectTypeName(String typeName) { int index = typeName.lastIndexOf("."); // Internal type names can contain dots hence use the `lastIndexOf` int typeNameLength = typeName.length(); - if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end + if (index - 1 > 0 && typeName.charAt(index - 1) == '\\') { // Methods can contain escaped characters + return typeName; + } else if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end return typeName.substring(index + 1); } else if (index > 0) { // We will reach here for resource methods eg: (MyClient8.$get$.) From da325235ff5c0270ff3579a0713ecacaedb56b2d Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 14 Dec 2023 23:21:08 +0530 Subject: [PATCH 076/209] Add tests for resource access actions --- .../ClientResourceAccessActionTest.java | 3 +- .../action/client_resource_access_action.bal | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionTest.java index dff2707eb0aa..cd9f82d2c15d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/action/ClientResourceAccessActionTest.java @@ -58,7 +58,8 @@ public Object[][] testClientResourceAccessActionData() { {"testResourceAccessOfAnObjectConstructedViaObjectCons"}, {"testResourceAccessContainingSpecialChars"}, {"testClosuresFromPathParams"}, - {"testAccessingResourceWithIncludedRecordParam"} + {"testAccessingResourceWithIncludedRecordParam"}, + {"testAccessingResourceWithEscapedChars"} }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal b/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal index b81c79194e13..48d35f85d5b6 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal @@ -697,6 +697,48 @@ function testAccessingResourceWithIncludedRecordParam() { assertEquality(d, 3); } +client class Client11 { + resource function get v1\.2/greeting1() returns string { + return "Path1"; + } + + resource function get ["v1.2"]/greeting2() returns string { + return "Path2"; + } + + resource function get v1\.2/ab\.c/greeting3() returns string { + return "Path3"; + } + + function abc\.abc() returns string { + return "abc.abc"; + } +} + +function testAccessingResourceWithEscapedChars() { + Client11 cl = new; + string a1 = cl->/v1\.2/greeting1; + assertEquality(a1, "Path1"); + + string a2 = cl->/["v1.2"]/greeting1; + assertEquality(a2, "Path1"); + + string b1 = cl->/["v1.2"]/greeting2; + assertEquality(b1, "Path2"); + + string b2 = cl->/v1\.2/greeting2; + assertEquality(b2, "Path2"); + + string c1 = cl->/v1\.2/ab\.c/greeting3; + assertEquality(c1, "Path3"); + + string c2 = cl->/["v1.2"]/["ab.c"]/greeting3; + assertEquality(c2, "Path3"); + + string d1 = cl.abc\.abc(); + assertEquality(d1, "abc.abc"); +} + function assertEquality(any|error actual, any|error expected) { if expected is anydata && actual is anydata && expected == actual { return; From 2185ac958d86d58e1b93d02dc5003a58dcd31e3b Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 7 Dec 2023 16:10:59 +0530 Subject: [PATCH 077/209] Make function rest param final --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index 1398f14a277d..e80581b6f04f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -497,6 +497,10 @@ public void visit(BLangFunction funcNode, AnalyzerData data) { // TODO: Shouldn't this be done in symbol enter? //set function param flag to final funcNode.symbol.params.forEach(param -> param.flags |= Flags.FUNCTION_FINAL); + + if (funcNode.symbol.restParam != null) { + funcNode.symbol.restParam.flags |= Flags.FUNCTION_FINAL; + } if (!funcNode.flagSet.contains(Flag.WORKER)) { // annotation validation for workers is done for the invocation. From 7c6f5e3afcb912830466e04f5a204cff70ad77fe Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 7 Dec 2023 16:30:51 +0530 Subject: [PATCH 078/209] Add tests for making rest params final --- .../ballerinalang/test/types/finaltypes/FinalAccessTest.java | 4 +++- .../types/finaltypes/test_implicitly_final_negative.bal | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java index db77c3b08be6..e1aa02d9a924 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java @@ -47,7 +47,7 @@ public void setup() { public void testFinalFailCase() { CompileResult compileResultNegative = BCompileUtil.compile( "test-src/types/finaltypes/test_implicitly_final_negative.bal"); - Assert.assertEquals(compileResultNegative.getErrorCount(), 8); + Assert.assertEquals(compileResultNegative.getErrorCount(), 9); BAssertUtil.validateError(compileResultNegative, 0, "cannot assign a value to function argument 'a'", 11, 5); BAssertUtil.validateError(compileResultNegative, 1, "cannot assign a value to function argument 'a'", 17, 5); BAssertUtil.validateError(compileResultNegative, 2, "cannot assign a value to function argument 'f'", 22, 5); @@ -57,6 +57,8 @@ public void testFinalFailCase() { BAssertUtil.validateError(compileResultNegative, 6, "cannot assign a value to function argument 'a'", 38, 5); BAssertUtil.validateError(compileResultNegative, 7, "invalid assignment: 'listener' declaration is final", 45, 5); + BAssertUtil.validateError(compileResultNegative, 8, "cannot assign a value to function argument 'p2'", 49, 5); + } @Test diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal index bc5e6a8db91b..790c6082609a 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal @@ -44,3 +44,7 @@ listener test:MockListener ml = new (8080); public function testChangingListenerVariableAfterDefining() { ml = new test:MockListener(8081); } + +function restFinal(string p1, string... p2) { + p2 = ["a", "b"]; +} From e1f94ba510b75cab2ac1d1b1051d8779394f1858 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Mon, 11 Dec 2023 09:42:52 +0530 Subject: [PATCH 079/209] Add tests for anonymous functions with rest params --- .../types/finaltypes/FinalAccessTest.java | 24 ++++++++++--------- .../test_implicitly_final_negative.bal | 12 +++++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java index e1aa02d9a924..7aa774783043 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java @@ -47,18 +47,20 @@ public void setup() { public void testFinalFailCase() { CompileResult compileResultNegative = BCompileUtil.compile( "test-src/types/finaltypes/test_implicitly_final_negative.bal"); - Assert.assertEquals(compileResultNegative.getErrorCount(), 9); - BAssertUtil.validateError(compileResultNegative, 0, "cannot assign a value to function argument 'a'", 11, 5); - BAssertUtil.validateError(compileResultNegative, 1, "cannot assign a value to function argument 'a'", 17, 5); - BAssertUtil.validateError(compileResultNegative, 2, "cannot assign a value to function argument 'f'", 22, 5); - BAssertUtil.validateError(compileResultNegative, 3, "cannot assign a value to function argument 's'", 23, 5); - BAssertUtil.validateError(compileResultNegative, 4, "cannot assign a value to function argument 'b'", 24, 5); - BAssertUtil.validateError(compileResultNegative, 5, "cannot assign a value to function argument 'j'", 25, 5); - BAssertUtil.validateError(compileResultNegative, 6, "cannot assign a value to function argument 'a'", 38, 5); - BAssertUtil.validateError(compileResultNegative, 7, "invalid assignment: 'listener' declaration is final", + int i = 0; + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'a'", 11, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'a'", 17, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'f'", 22, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 's'", 23, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 24, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'j'", 25, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'a'", 38, 5); + BAssertUtil.validateError(compileResultNegative, i++, "invalid assignment: 'listener' declaration is final", 45, 5); - BAssertUtil.validateError(compileResultNegative, 8, "cannot assign a value to function argument 'p2'", 49, 5); - + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'p2'", 49, 5); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 53, 9); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 58, 9); + Assert.assertEquals(compileResultNegative.getErrorCount(), i); } @Test diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal index 790c6082609a..1ce32d385f8d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal @@ -45,6 +45,16 @@ public function testChangingListenerVariableAfterDefining() { ml = new test:MockListener(8081); } -function restFinal(string p1, string... p2) { +function testRestParamFinal(string p1, string... p2) { p2 = ["a", "b"]; } + +function (int a, int... b) testModuleLevelRestParamFinal = function (int i, int... b) { + b = []; + }; + +public function testLocalLevelRestParamFinal() { + function (int a, int... b) func = function (int i, int... b) { + b = []; + }; +} From e62b265f7003b2fae35e03a97cdd18f86c4ea808 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 3 Jan 2024 10:00:39 +0530 Subject: [PATCH 080/209] Address review suggestions --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 7 ++++--- .../test/types/finaltypes/FinalAccessTest.java | 2 +- .../types/finaltypes/test_implicitly_final_negative.bal | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index e80581b6f04f..f1a30baf5f2d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -497,9 +497,10 @@ public void visit(BLangFunction funcNode, AnalyzerData data) { // TODO: Shouldn't this be done in symbol enter? //set function param flag to final funcNode.symbol.params.forEach(param -> param.flags |= Flags.FUNCTION_FINAL); - - if (funcNode.symbol.restParam != null) { - funcNode.symbol.restParam.flags |= Flags.FUNCTION_FINAL; + + BVarSymbol restParamSym = funcNode.symbol.restParam; + if (restParamSym != null) { + restParamSym.flags |= Flags.FUNCTION_FINAL; } if (!funcNode.flagSet.contains(Flag.WORKER)) { diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java index 7aa774783043..a4f7bae7c03e 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java @@ -59,7 +59,7 @@ public void testFinalFailCase() { 45, 5); BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'p2'", 49, 5); BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 53, 9); - BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 58, 9); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 59, 9); Assert.assertEquals(compileResultNegative.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal index 1ce32d385f8d..66621e0a1a5d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal @@ -54,7 +54,8 @@ function (int a, int... b) testModuleLevelRestParamFinal = function (int i, int. }; public function testLocalLevelRestParamFinal() { + int[] arr = []; function (int a, int... b) func = function (int i, int... b) { - b = []; + b = arr; }; } From bf890dc26035cc346247f1d2154c27869439a44f Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 17 Jan 2024 10:54:50 +0530 Subject: [PATCH 081/209] Add negative tests for rest param being final --- .../test/types/finaltypes/FinalAccessTest.java | 1 + .../types/finaltypes/test_implicitly_final_negative.bal | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java index a4f7bae7c03e..6e2c009e072f 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/finaltypes/FinalAccessTest.java @@ -60,6 +60,7 @@ public void testFinalFailCase() { BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'p2'", 49, 5); BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 53, 9); BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 59, 9); + BAssertUtil.validateError(compileResultNegative, i++, "cannot assign a value to function argument 'b'", 66, 9); Assert.assertEquals(compileResultNegative.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal index 66621e0a1a5d..d7de92a7a443 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/finaltypes/test_implicitly_final_negative.bal @@ -59,3 +59,10 @@ public function testLocalLevelRestParamFinal() { b = arr; }; } + +public function testLocalLevelRestParamFinalWithVar() { + int[] arr = []; + var func = function (int i, int... b) { + b = arr; + }; +} From 9e6acd237f01eb4575e69f137c4f1206ef6ff8f3 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 7 Dec 2023 15:10:01 +0530 Subject: [PATCH 082/209] Make RegExp type inherently immutable --- .../wso2/ballerinalang/compiler/semantics/analyzer/Types.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index e21f15a19e54..0e71020f9c7f 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -1498,6 +1498,7 @@ public boolean isInherentlyImmutableType(BType type) { case TypeTags.INVOKABLE: case TypeTags.TYPEDESC: case TypeTags.HANDLE: + case TypeTags.REGEXP: return true; case TypeTags.XML: return getImpliedType(((BXMLType) type).constraint).tag == TypeTags.NEVER; From 0583d712e4a62c73159e13b41bed5e5b5de559c9 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 7 Dec 2023 15:18:56 +0530 Subject: [PATCH 083/209] Add tests for RegExp readonly intersection --- .../test/resources/test-src/types/regexp/regexp_type_test.bal | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal index edaca3d8ece0..83a5970416a8 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal @@ -13,6 +13,7 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. +import ballerina/lang.regexp; function testBasicRegExp() { string:RegExp _ = re `AB*|[^c-d]{1,5}`; @@ -105,6 +106,9 @@ function testRegExpWithUserDefinedType() { assertEquality(re `AB*|[^c-d]{1,5}`, x7); } +type T1 string:RegExp & readonly; +type T2 regexp:RegExp & readonly; + const ASSERTION_ERROR_REASON = "AssertionError"; function assertEquality(any|error expected, any|error actual) { From ee7d0fe893dda4c4bc22892f280430969de009ee Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Mon, 11 Dec 2023 11:14:43 +0530 Subject: [PATCH 084/209] Make RegExp type inherently immutable at runtime --- .../src/main/java/io/ballerina/runtime/internal/TypeChecker.java | 1 + 1 file changed, 1 insertion(+) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java index 6717bf6a8d1b..66328454a261 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java @@ -1953,6 +1953,7 @@ public static boolean isInherentlyImmutableType(Type sourceType) { case TypeTags.TYPEDESC_TAG: case TypeTags.FUNCTION_POINTER_TAG: case TypeTags.HANDLE_TAG: + case TypeTags.REG_EXP_TYPE_TAG: return true; case TypeTags.XML_TAG: return ((BXmlType) sourceType).constraint.getTag() == TypeTags.NEVER_TAG; From 1c3524db70d8e06188e608a1852e9afe766a2955 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Mon, 11 Dec 2023 11:15:53 +0530 Subject: [PATCH 085/209] Add RegExp readonly intersection tests --- .../readonly/test_inherently_immutable_type.bal | 6 ++++++ .../test-src/types/regexp/regexp_type_test.bal | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal index faaf6de44071..f5e5ad7048b7 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal @@ -163,6 +163,12 @@ function testRuntimeIsTypeForInherentlyImmutableBasicTypes() { 'xml:Text xmlText = xml `xml text`; any n = xmlText; assertTrue(n is readonly); + + any reg1 = re `pattern`; + assertTrue(reg1 is readonly); + + readonly reg2 = re `pattern`; + assertTrue(reg2 is readonly); } function testRuntimeIsTypeForNeverImmutableBasicTypes() { diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal index 83a5970416a8..cdf84de7709d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal @@ -109,6 +109,19 @@ function testRegExpWithUserDefinedType() { type T1 string:RegExp & readonly; type T2 regexp:RegExp & readonly; +type Foo record {| + int e; + readonly regexp:RegExp f; +|}; + +Foo & readonly rf = {e: 1, f: re `test`}; + +function testRegExpReadonlyLocalVars() { + string:RegExp & readonly x1 = re `test`; + T1 & readonly x2 = re `test`; + (T2 & readonly) & string:RegExp x3 = re `test`; +} + const ASSERTION_ERROR_REASON = "AssertionError"; function assertEquality(any|error expected, any|error actual) { From 1be23f58368daefc8ca0812165032a097bd98abf Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 3 Jan 2024 09:26:16 +0530 Subject: [PATCH 086/209] Add test for checking runtime value type --- .../test-src/types/readonly/test_inherently_immutable_type.bal | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal index f5e5ad7048b7..f5a9529587cf 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_inherently_immutable_type.bal @@ -16,6 +16,7 @@ import ballerina/jballerina.java; import ballerina/lang.'xml; +import ballerina/lang.regexp; // readonly-type-descriptor := readonly // A shape belongs to the type readonly if its read-only bit is on. @@ -169,6 +170,8 @@ function testRuntimeIsTypeForInherentlyImmutableBasicTypes() { readonly reg2 = re `pattern`; assertTrue(reg2 is readonly); + + assertTrue(regexp:fromString("pattern") is readonly); } function testRuntimeIsTypeForNeverImmutableBasicTypes() { From 6c0d989173879eca2bb63f3fa733c0c7ed2ee69d Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 17 Jan 2024 11:13:05 +0530 Subject: [PATCH 087/209] Address review suggestions --- .../resources/test-src/types/regexp/regexp_type_test.bal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal index cdf84de7709d..e94175be7a77 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal @@ -117,9 +117,9 @@ type Foo record {| Foo & readonly rf = {e: 1, f: re `test`}; function testRegExpReadonlyLocalVars() { - string:RegExp & readonly x1 = re `test`; - T1 & readonly x2 = re `test`; - (T2 & readonly) & string:RegExp x3 = re `test`; + string:RegExp & readonly _ = re `test`; + T1 & readonly _ = re `test`; + (T2 & readonly) & string:RegExp _ = re `test`; } const ASSERTION_ERROR_REASON = "AssertionError"; From a14d32d460026e651057b7b866b062c7d21febf0 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:29:41 +0530 Subject: [PATCH 088/209] Change sample tool --- cli/ballerina-cli/src/main/java/module-info.java | 1 + .../src/main/java/build/tool/runner/SampleToolRunner.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/module-info.java b/cli/ballerina-cli/src/main/java/module-info.java index 27c54d8c248e..baef3d0bfbe0 100644 --- a/cli/ballerina-cli/src/main/java/module-info.java +++ b/cli/ballerina-cli/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.cli { uses io.ballerina.cli.BLauncherCmd; + uses io.ballerina.cli.tool.CodeGeneratorTool; exports io.ballerina.cli; exports io.ballerina.cli.launcher; exports io.ballerina.cli.utils; diff --git a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java index f5dc918fc1f5..f47e546bc046 100644 --- a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java +++ b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java @@ -44,7 +44,7 @@ public void execute(ToolContext toolContext) { "The provided filePath does not exist", DiagnosticSeverity.ERROR); toolContext.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, new NullLocation())); } - System.out.println("Running sample build tool: " + toolContext.toolType()); + System.out.println("Running sample build tool: " + toolContext.toolId()); System.out.println("Cache created at: " + toolContext.cachePath()); } From 7363c7b5f9a3a93f6d2476f87f4180738866ad65 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:30:07 +0530 Subject: [PATCH 089/209] Improve tool class in packageManifest --- .../ballerina/projects/PackageManifest.java | 59 ++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java index 08bca3b29f52..4efa3c577a82 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java @@ -415,50 +415,79 @@ public Optional location() { } } + /** + * Represents the build tool configurations in Ballerina.toml file. + * + * @since 2201.9.0 + */ public static class Tool { private final String id; private final TomlTableNode optionsTable; + private final String filePath; + private final String targetModule; + private final String type; + private final Toml optionsToml; + private final boolean hasErrorDiagnostic; + + public Tool(String type, String id, String filePath, String targetModule, Toml optionsToml, + TomlTableNode optionsTable, boolean hasErrorDiagnostic) { + this.type = type; + this.id = id; + this.filePath = filePath; + this.targetModule = targetModule; + this.optionsTable = optionsTable; + this.optionsToml = optionsToml; + this.hasErrorDiagnostic = hasErrorDiagnostic; + } + /** + * @return the tool id. + */ public String getId() { return id; } + /** + * @return the filepath. + */ public String getFilePath() { return this.filePath; } + /** + * @return the tool's target module. + */ public String getTargetModule() { return this.targetModule; } + /** + * @return the tool options table. + */ public TomlTableNode getOptionsTable() { return this.optionsTable; } + /** + * @return the tool type. + */ public String getType() { return type; } - private final String filePath; - private final String targetModule; - private final String type; - + /** + * @return the options toml. + */ public Toml getOptionsToml() { return optionsToml; } - private final Toml optionsToml; - - public Tool(String type, String id, String filePath, String targetModule, Toml optionsToml, - TomlTableNode optionsTable) { - this.type = type; - this.id = id; - this.filePath = filePath; - this.targetModule = targetModule; - this.optionsTable = optionsTable; - this.optionsToml = optionsToml; + /** + * @return whether the tool has error diagnostics. + */ + public boolean hasErrorDiagnostic() { + return hasErrorDiagnostic; } - } private List getExport(PackageDescriptor packageDesc, List export) { From c6823139adaa600f49d411a680f8570ef481e7e7 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:30:38 +0530 Subject: [PATCH 090/209] Add hasDiagnostic flag to build tools and improve validations --- .../projects/internal/ManifestBuilder.java | 68 +++++++------------ 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index e5f56405621d..9f60f62a3d84 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -20,6 +20,7 @@ import io.ballerina.projects.BuildOptions; import io.ballerina.projects.DiagnosticResult; +import io.ballerina.projects.Diagnostics; import io.ballerina.projects.PackageDescriptor; import io.ballerina.projects.PackageManifest; import io.ballerina.projects.PackageName; @@ -233,23 +234,21 @@ private PackageManifest parseAsPackageManifest() { } private List getTools() { - TomlTableNode rootNode = ballerinaToml.toml().rootNode(); if (rootNode.entries().isEmpty()) { return Collections.emptyList(); } - TopLevelNode toolEntries = rootNode.entries().get("tool"); - List tools = new ArrayList<>(); if (toolEntries == null || toolEntries.kind() != TomlType.TABLE) { return Collections.emptyList(); } TomlTableNode toolTable = (TomlTableNode) toolEntries; Set toolCodes = toolTable.entries().keySet(); - List toolIds = new ArrayList<>(); - List toolTargetModules = new ArrayList<>(); + Set toolIdsSet = new HashSet<>(); + Set targetModuleSet = new HashSet<>(); + // Gather tool configurations and add the tools to a list for (String toolCode : toolCodes) { TopLevelNode toolCodeNode = toolTable.entries().get(toolCode); if (toolCodeNode.kind() != TomlType.TABLE_ARRAY) { @@ -281,13 +280,28 @@ private List getTools() { if (topLevelNode != null && topLevelNode.kind() == TomlType.TABLE) { optionsNode = (TomlTableNode) topLevelNode; } + + // Validate recurring tool ids and target modules + if (!toolIdsSet.add(id)) { + reportDiagnostic(dependencyNode, "recurring tool id '" + id + "' found in Ballerina.toml. " + + "Tool id must be unique for each tool", + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + DiagnosticSeverity.ERROR); + } + if (!targetModuleSet.add(targetModule)) { + reportDiagnostic(dependencyNode, "recurring target module found in Ballerina.toml. Target " + + "module must be unique for each tool", + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + DiagnosticSeverity.ERROR); + } + + // Add a flag for tools with error diagnostics + boolean hasErrorDiagnostic = !Diagnostics.filterErrors(dependencyNode.diagnostics()).isEmpty(); PackageManifest.Tool tool = new PackageManifest.Tool(toolCode, id, filePath, - targetModule, optionsToml, optionsNode); + targetModule, optionsToml, optionsNode, hasErrorDiagnostic); tools.add(tool); - addIdTargetModuleToLists(id, targetModule, toolIds, toolTargetModules); } } - validateUniqueIdAndTargetModule(toolIds, toolTargetModules, toolTable); return tools; } @@ -823,7 +837,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String + toolCode + "]'. " + "Default module will be taken as the target module", ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY.diagnosticId(), DiagnosticSeverity.WARNING); - return getStringFromTomlTableNode(topLevelNode); + return null; } else if (ToolNodeValueType.NON_STRING.equals(toolNodeValueType)) { reportDiagnostic(toolNode, "incompatible type found for key '[" + key + "]': expected 'STRING'", ProjectDiagnosticErrorCode.INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY.diagnosticId(), @@ -845,42 +859,6 @@ private Toml getToml(TomlTableNode toolNode, String key) { return new Toml(optionsNode); } - private void addIdTargetModuleToLists(String id, String targetModule, List toolIds, - List targetModules) { - if (id != null) { - toolIds.add(id); - } - if (targetModule == null || targetModule.isEmpty()) { - targetModules.add("default"); - return; - } - targetModules.add(targetModule); - } - - private void validateUniqueIdAndTargetModule(List toolIds, List targetModules, - TomlTableNode tomlTableNode) { - Set toolIdsSet = new HashSet<>(); - Set targetModuleSet = new HashSet<>(); - for (String toolId: toolIds) { - if (!toolIdsSet.add(toolId)) { - reportDiagnostic(tomlTableNode, "recurring tool id '" + toolId + "' found in Ballerina.toml. " + - "Tool id must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), - DiagnosticSeverity.ERROR); - break; - } - } - for (String targetModule: targetModules) { - if (!targetModuleSet.add(targetModule)) { - reportDiagnostic(tomlTableNode, "recurring target module '" + targetModule + "' found in " + - "Ballerina.toml. Target module must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), - DiagnosticSeverity.ERROR); - break; - } - } - } - /** * Check file name has {@code .png} extension. * From 2fd6d1a2d92eb7aebdd2cbbed8dd4110d92146e3 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 17 Jan 2024 11:40:35 +0530 Subject: [PATCH 091/209] Fix xml sequence in equals check --- .../main/java/io/ballerina/runtime/internal/TypeChecker.java | 4 ++-- .../io/ballerina/runtime/internal/values/XmlSequence.java | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java index 6717bf6a8d1b..0a1bfc669d47 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java @@ -2980,8 +2980,8 @@ private static boolean checkValueEquals(Object lhsValue, Object rhsValue, List - return PredefinedTypes.TYPE_TEXT; + return new BXmlType(PredefinedTypes.TYPE_TEXT, false); } } From 0f4387130711cef07a7e35e136406aab2637ed5b Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 17 Jan 2024 11:40:48 +0530 Subject: [PATCH 092/209] Add unit test --- .../EqualAndNotEqualOperationsTest.java | 3 ++- .../equal_and_not_equal_operation.bal | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/EqualAndNotEqualOperationsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/EqualAndNotEqualOperationsTest.java index 7d8a82c93589..1a262dff5c35 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/EqualAndNotEqualOperationsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/binaryoperations/EqualAndNotEqualOperationsTest.java @@ -190,7 +190,8 @@ public Object[] getXmlTestFunctions() { "testUnequalXmlIgnoringAttributeOrder", "testEqualXmlWithPI", "testUnequalXmlWithUnequalPI", "testUnequalXmlWithPIInWrongOrder", "testUnequalXmlWithMultiplePIInWrongOrder", "testUnequalXmlWithMissingPI", "testXmlWithNamespacesPositive", "testXmlWithNamespacesNegative", - "testXmlSequenceAndXmlItemEqualityPositive", "testXmlSequenceAndXmlItemEqualityNegative" + "testXmlSequenceAndXmlItemEqualityPositive", "testXmlSequenceAndXmlItemEqualityNegative", + "testXmlSequenceLHSEquals" }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal index 92980fe96b4c..e0b4f291c6d4 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal @@ -1135,6 +1135,18 @@ public function testXmlSequenceAndXmlItemEqualityNegative() { test:assertFalse(x1 == x3 || !(x1 != x3) || x3 == x1 || !(x3 != x1)); } +public function testXmlSequenceLHSEquals() { + string a = "hello"; + xml x1 = xml `AS-${a}`; + xml x2 = xml `AS-${a}`; + test:assertTrue(x1 == x2 && !(x1 != x2)); + + x1 = xml ``; + x2 = xml ``; + test:assertTrue(x1 == x2 && !(x1 != x2)); +} + + function testXmlStringNegative() { anydata x1 = xml `The Lost World`; anydata x2 = "The Lost World"; From b82855a671835fe6b0f4fc5ffd3e65a30312e620 Mon Sep 17 00:00:00 2001 From: dsplayerX Date: Wed, 17 Jan 2024 14:03:46 +0530 Subject: [PATCH 093/209] Set type boolean for isTransactionalCheck --- .../wso2/ballerinalang/compiler/desugar/TransactionDesugar.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java index 886b44eefb74..d89ce5c31b7d 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/TransactionDesugar.java @@ -441,6 +441,7 @@ void createRollbackIfFailed(Location pos, BLangBlockStmt onFailBodyBlock, // transactional BLangTransactionalExpr isTransactionalCheck = TreeBuilder.createTransactionalExpressionNode(); + isTransactionalCheck.setBType(symTable.booleanType); isTransactionalCheck.pos = pos; // if(($trxError$ is error) && !($trxError$ is TransactionError) && transactional) From 5a609cc5d076e50ef0f2d579a0c829be77c79708 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 17 Jan 2024 21:34:24 +0530 Subject: [PATCH 094/209] Move xml types to constants --- .../ballerina/runtime/api/PredefinedTypes.java | 4 ++++ .../runtime/internal/values/XmlSequence.java | 16 ++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java index a9635fbc87d9..1229d2897e4e 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java @@ -151,6 +151,10 @@ public class PredefinedTypes { TYPE_TEXT)), EMPTY_MODULE); public static final Type TYPE_READONLY_XML = ReadOnlyUtils.setImmutableTypeAndGetEffectiveType(TYPE_XML); + public static final Type XML_TYPE_ELEMENT = new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); + public static final Type XML_TYPE_COMMENT = new BXmlType(PredefinedTypes.TYPE_COMMENT, false); + public static final Type XML_TYPE_PI = new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); + public static final Type XML_TYPE_TEXT = new BXmlType(PredefinedTypes.TYPE_TEXT, false); public static final AnyType TYPE_ANY = new BAnyType(TypeConstants.ANY_TNAME, EMPTY_MODULE, false); public static final AnyType TYPE_READONLY_ANY = new BAnyType(TypeConstants.READONLY_ANY_TNAME, EMPTY_MODULE, true); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java index b3cf96903845..6f57f9a8d26f 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java @@ -626,16 +626,12 @@ public Object next() { } private Type getSequenceType(Type tempExprType) { - switch (tempExprType.getTag()) { - case TypeTags.XML_ELEMENT_TAG: - return new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); - case TypeTags.XML_COMMENT_TAG: - return new BXmlType(PredefinedTypes.TYPE_COMMENT, false); - case TypeTags.XML_PI_TAG: - return new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); - default: - return new BXmlType(PredefinedTypes.TYPE_TEXT, false); - } + return switch (tempExprType.getTag()) { + case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.XML_TYPE_ELEMENT; + case TypeTags.XML_COMMENT_TAG -> PredefinedTypes.XML_TYPE_COMMENT; + case TypeTags.XML_PI_TAG -> PredefinedTypes.XML_TYPE_PI; + default -> PredefinedTypes.XML_TYPE_TEXT; + }; } private void initializeIteratorNextReturnType() { From 89a0d63cfa8aaed87c7294c841b13b05aed956e6 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 18 Jan 2024 09:38:56 +0530 Subject: [PATCH 095/209] Fix checkstyle errors --- .../java/io/ballerina/runtime/internal/values/XmlSequence.java | 1 - 1 file changed, 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java index 6f57f9a8d26f..4405b9061f4d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java @@ -34,7 +34,6 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import io.ballerina.runtime.internal.types.BArrayType; import io.ballerina.runtime.internal.types.BUnionType; -import io.ballerina.runtime.internal.types.BXmlType; import java.util.ArrayList; import java.util.HashSet; From 181918e405e1874352f70e40675550de11ab9fe7 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 18 Jan 2024 09:46:10 +0530 Subject: [PATCH 096/209] Address review suggestions --- .../wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index fb492b3efa7e..7a4a564c981a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -521,7 +521,7 @@ public static String generateReturnType(BType bType) { static String cleanupObjectTypeName(String typeName) { int index = typeName.lastIndexOf("."); // Internal type names can contain dots hence use the `lastIndexOf` int typeNameLength = typeName.length(); - if (index - 1 > 0 && typeName.charAt(index - 1) == '\\') { // Methods can contain escaped characters + if (index > 1 && typeName.charAt(index - 1) == '\\') { // Methods can contain escaped characters return typeName; } else if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end return typeName.substring(index + 1); From 4c8db893799cb385962dc543a908d613803baa41 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 18 Jan 2024 09:57:08 +0530 Subject: [PATCH 097/209] Add tests for resource access actions --- .../test-src/action/client_resource_access_action.bal | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal b/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal index 48d35f85d5b6..2fbad10a56b6 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/action/client_resource_access_action.bal @@ -710,6 +710,10 @@ client class Client11 { return "Path3"; } + resource function get v1\.\.2() returns string { + return "Path4"; + } + function abc\.abc() returns string { return "abc.abc"; } @@ -735,8 +739,11 @@ function testAccessingResourceWithEscapedChars() { string c2 = cl->/["v1.2"]/["ab.c"]/greeting3; assertEquality(c2, "Path3"); - string d1 = cl.abc\.abc(); - assertEquality(d1, "abc.abc"); + string d1 = cl->/v1\.\.2; + assertEquality(d1, "Path4"); + + string e1 = cl.abc\.abc(); + assertEquality(e1, "abc.abc"); } function assertEquality(any|error actual, any|error expected) { From 8dc11fe3e8e39af00fec3f6642c4e0202dc41509 Mon Sep 17 00:00:00 2001 From: Nadeeshan96 Date: Thu, 18 Jan 2024 11:59:54 +0530 Subject: [PATCH 098/209] Add tests with cyclic readonly and nilable types --- .../test/resources/test-src/valuelib_test.bal | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal index 5922a16c9503..541815e4a6a2 100644 --- a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal +++ b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal @@ -2455,6 +2455,12 @@ public type code string; public type uri string; +public type ElementReadOnlyCyclic record {| + string id?; + Extension[] extension?; + ((ElementReadOnlyCyclic & readonly)|())...; +|}; + public type Element record {| string id?; Extension[] extension?; @@ -2484,8 +2490,31 @@ public type CodeableConcept record {| string text?; |}; +public type ExtensionExtension2 record {| + *ElementReadOnlyCyclic; + + uri url; + Extension[] extension?; +|}; + +public type CodeableConceptExtension2 record {| + *ElementReadOnlyCyclic; + + uri url; + CodeableConcept valueCodeableConcept; +|}; + +public type CodingExtension2 record {| + *ElementReadOnlyCyclic; + + uri url; + Coding valueCoding; +|}; + public type Extension CodeableConceptExtension|ExtensionExtension|CodingExtension; +public type Extension2 CodeableConceptExtension2|ExtensionExtension2|CodingExtension2; + function testCloneWithTypeToUnion() { int|float|[string, string] unionVar = 2; float|decimal|[string, int]|error tupleValue = unionVar.cloneWithType(UnionTypedesc); @@ -2511,6 +2540,14 @@ function testCloneWithTypeToUnion() { "valueCoding": {"system": "http://loinc.org", "code": "LA29518-0", "display": "he/him/his/himself"} }); assertEquality((typeof ext).toString(), "typedesc CodingExtension"); + + Extension2 ext2 = checkpanic extCoding.cloneWithType(); + assertEquality(ext2, { + "url": + "http://open.epic.com/FHIR/StructureDefinition/extension/calculated-pronouns-to-use-for-text", + "valueCoding": {"system": "http://loinc.org", "code": "LA29518-0", "display": "he/him/his/himself"} + }); + assertEquality((typeof ext2).toString(), "typedesc CodingExtension2"); } type UnionTypedesc typedesc; From 68e7098350917ad9e97d57a03106d7d9a3c499e9 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Thu, 18 Jan 2024 13:05:29 +0530 Subject: [PATCH 099/209] Fix failing formatter tests --- .../query-action/query_action_assert_08.json | 16 ++++++++++++++-- .../query-action/query_action_source_08.bal | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json index 69e1978f9bd6..e08c46727cca 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_assert_08.json @@ -1267,12 +1267,24 @@ "children": [ { "kind": "IDENTIFIER_TOKEN", - "value": "price" + "value": "price", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] } ] }, { - "kind": "ASTERISK_TOKEN" + "kind": "ASTERISK_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] }, { "kind": "SIMPLE_NAME_REFERENCE", diff --git a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal index 0f4543d16156..82face7c525d 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal +++ b/compiler/ballerina-parser/src/test/resources/actions/query-action/query_action_source_08.bal @@ -8,7 +8,7 @@ function foo() { from var i in [1, 2, 3, 4] do { var income = from var {price, quantity} in orders - let var totPrice = price*quantity + let var totPrice = price * quantity collect sum(totPrice); }; } From 1299ee8444042c3d797cb84a51d7e661408d3404 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 18 Jan 2024 14:52:25 +0530 Subject: [PATCH 100/209] Address review suggestions --- .../java/io/ballerina/runtime/api/PredefinedTypes.java | 8 ++++---- .../io/ballerina/runtime/internal/values/XmlSequence.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java index 1229d2897e4e..aef3057465fe 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java @@ -151,10 +151,10 @@ public class PredefinedTypes { TYPE_TEXT)), EMPTY_MODULE); public static final Type TYPE_READONLY_XML = ReadOnlyUtils.setImmutableTypeAndGetEffectiveType(TYPE_XML); - public static final Type XML_TYPE_ELEMENT = new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); - public static final Type XML_TYPE_COMMENT = new BXmlType(PredefinedTypes.TYPE_COMMENT, false); - public static final Type XML_TYPE_PI = new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); - public static final Type XML_TYPE_TEXT = new BXmlType(PredefinedTypes.TYPE_TEXT, false); + public static final Type XML_ELEMENT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); + public static final Type XML_COMMENT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_COMMENT, false); + public static final Type XML_PI_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); + public static final Type XML_TEXT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_TEXT, false); public static final AnyType TYPE_ANY = new BAnyType(TypeConstants.ANY_TNAME, EMPTY_MODULE, false); public static final AnyType TYPE_READONLY_ANY = new BAnyType(TypeConstants.READONLY_ANY_TNAME, EMPTY_MODULE, true); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java index 4405b9061f4d..3bd1e3960812 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java @@ -626,10 +626,10 @@ public Object next() { private Type getSequenceType(Type tempExprType) { return switch (tempExprType.getTag()) { - case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.XML_TYPE_ELEMENT; - case TypeTags.XML_COMMENT_TAG -> PredefinedTypes.XML_TYPE_COMMENT; - case TypeTags.XML_PI_TAG -> PredefinedTypes.XML_TYPE_PI; - default -> PredefinedTypes.XML_TYPE_TEXT; + case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.XML_ELEMENT_SEQUENCE_TYPE; + case TypeTags.XML_COMMENT_TAG -> PredefinedTypes.XML_COMMENT_SEQUENCE_TYPE; + case TypeTags.XML_PI_TAG -> PredefinedTypes.XML_PI_SEQUENCE_TYPE; + default -> PredefinedTypes.XML_TEXT_SEQUENCE_TYPE; }; } From c322e3aeabacd61c04a30f3f6db32acfc3cbfd55 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:12:56 +0530 Subject: [PATCH 101/209] Add toolContextMap to PackageContext --- .../main/java/io/ballerina/projects/Package.java | 13 +++++++++++++ .../java/io/ballerina/projects/PackageContext.java | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index b359c13098e5..03bf68bcb202 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -158,6 +158,10 @@ public PackageResolution getResolution(CompilationOptions compilationOptions) { return this.packageContext.getResolution(compilationOptions); } + public void setPackageContextTools(Map toolContextMap) { + this.packageContext.setToolContextMap(toolContextMap); + } + public DependencyGraph moduleDependencyGraph() { // Each Package should know the packages that it depends on and packages that depends on it // Each Module should know the modules that it depends on and modules that depends on it @@ -172,6 +176,15 @@ public CompilationOptions compilationOptions() { return packageContext.compilationOptions(); } + /** + * returns a map of build tools. + * + * @return map of {@code ToolContext} + */ + public Map toolContextMap() { + return packageContext.toolContextMap(); + } + public Optional ballerinaToml() { if (null == this.ballerinaToml) { this.ballerinaToml = this.packageContext.ballerinaTomlContext().map(c -> diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index 7cfc92426279..cbc3ffee4754 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -52,6 +52,7 @@ class PackageContext { private final CompilationOptions compilationOptions; private ModuleContext defaultModuleContext; + private Map toolContextMap; /** * This variable holds the dependency graph cached in a project. * At the moment, we cache the dependency graph in a bala file. @@ -96,7 +97,6 @@ class PackageContext { this.moduleCompilationMap = new HashMap<>(); this.packageDependencies = Collections.emptySet(); this.pkgDescDependencyGraph = pkgDescDependencyGraph; - } static PackageContext from(Project project, PackageConfig packageConfig, CompilationOptions compilationOptions) { @@ -181,6 +181,10 @@ Collection moduleIds() { return moduleIds; } + Map toolContextMap() { + return toolContextMap; + } + ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } @@ -315,4 +319,8 @@ PackageContext duplicate(Project project) { this.cloudTomlContext, this.compilerPluginTomlContext, this.balToolTomlContext, this.packageMdContext, this.compilationOptions, duplicatedModuleContextMap, this.pkgDescDependencyGraph); } + + void setToolContextMap(Map toolContextMap) { + this.toolContextMap = toolContextMap; + } } From fd8c66d4634ae0bcfbaa698a97141b65bc31844f Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:14:40 +0530 Subject: [PATCH 102/209] Handle build tool execution failures with diagnostics --- .../io/ballerina/cli/task/CompileTask.java | 23 +++++++++++++++---- .../projects/internal/ManifestBuilder.java | 3 ++- .../internal/ProjectDiagnosticErrorCode.java | 5 ++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 7ae41cd32e13..d73ea3616540 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -29,6 +29,7 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.ProjectKind; import io.ballerina.projects.SemanticVersion; +import io.ballerina.projects.ToolContext; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.environment.ResolutionOptions; import io.ballerina.projects.internal.PackageDiagnostic; @@ -185,7 +186,11 @@ public void execute(Project project) { diagnostics.addAll(project.currentPackage().manifest().diagnostics().diagnostics()); // add dependency manifest diagnostics diagnostics.addAll(project.currentPackage().dependencyManifest().diagnostics().diagnostics()); - diagnostics.forEach(d -> err.println(d.toString())); + diagnostics.forEach(d -> { + if (!d.diagnosticInfo().code().startsWith("BCE54")) { + err.println(d); + } + }); throw createLauncherException("package resolution contains errors"); } @@ -205,15 +210,23 @@ public void execute(Project project) { // Report package compilation and backend diagnostics diagnostics.addAll(jBallerinaBackend.diagnosticResult().diagnostics(false)); + diagnostics.forEach(d -> { + if (d.diagnosticInfo().code() == null || (!d.diagnosticInfo().code().equals( + ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId()) && + !d.diagnosticInfo().code().startsWith("BCE54"))) { + err.println(d); + } + }); + + //Report build tool execution diagnostics + for (ToolContext tool: project.currentPackage().toolContextMap().values()) { + diagnostics.addAll(tool.diagnostics()); + } boolean hasErrors = false; for (Diagnostic d : diagnostics) { if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { hasErrors = true; } - if (d.diagnosticInfo().code() == null || !d.diagnosticInfo().code().equals( - ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId())) { - err.println(d); - } } if (hasErrors) { throw createLauncherException("compilation contains errors"); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 9f60f62a3d84..562b8ac69a5e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -607,12 +607,13 @@ private List getLocalRepoDependencies() { return dependencies; } + // TODO: Fix code and messageFormat parameters in usages. private void reportDiagnostic(TopLevelNode tomlTableNode, String message, String messageFormat, DiagnosticSeverity severity) { DiagnosticInfo diagnosticInfo = - new DiagnosticInfo(null, messageFormat, severity); + new DiagnosticInfo(messageFormat, messageFormat, severity); TomlDiagnostic tomlDiagnostic = new TomlDiagnostic( tomlTableNode.location(), diagnosticInfo, diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 15e97c34b9fa..80badbc61d98 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -27,6 +27,7 @@ */ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { + // TODO: Assign specific codes for each error type and sort the error codes. INVALID_BALA_FILE("BCE5000", "invalid.bala.file"), OLD_DEPENDENCIES_TOML("BCE5001", "old.dependencies.toml"), LOCAL_PACKAGES_IN_DEPENDENCIES_TOML("BCE5002", "local.packages.in.dependencies.toml"), @@ -37,11 +38,15 @@ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { DEPRECATED_PACKAGE("BCE5007", "deprecated.package"), BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5008", "built.with.older.sl.update.distribution"), CUSTOM_REPOSITORY_NOT_FOUND("BCE5009", "custom.repository.not.found"), + + // Error codes related to build tools starting from BCE5400. MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5400", "missing.tool.properties"), INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5401", "incompatible.tool.properties"), EMPTY_TOOL_PROPERTY("BCE5402", "empty.tool.properties"), TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5403", "tool.options.validation.skipped"), RECURRING_TOOL_PROPERTIES("BCE5404", "recurring.tool.properties"), + BUILD_TOOL_NOT_FOUND("BCE5405", "build.tool.not.found"), + MODULE_NOT_FOUND("BCE5100", "module.not.found"), UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5200", "unsupported.compiler.plugin.type"), CONFLICTING_PLATFORM_JAR_FILES("BCE5300", "conflicting.platform.jars.type"), From 5b0704617596d5ccab2f1dcb2ba531ed382efe83 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:17:01 +0530 Subject: [PATCH 103/209] Improve diagnostic handling for build tools --- .../task/RunBallerinaPreBuildToolsTask.java | 89 ++++++++++++------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 2eab2bdefbb5..7fdb5fe06e1d 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -20,18 +20,24 @@ import io.ballerina.cli.tool.CodeGeneratorTool; import io.ballerina.cli.utils.FileUtils; +import io.ballerina.projects.Diagnostics; import io.ballerina.projects.Project; -import io.ballerina.projects.ProjectException; import io.ballerina.projects.ToolContext; +import io.ballerina.projects.internal.PackageDiagnostic; +import io.ballerina.projects.internal.ProjectDiagnosticErrorCode; import io.ballerina.toml.api.Toml; import io.ballerina.tools.diagnostics.Diagnostic; +import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import java.io.IOException; import java.io.PrintStream; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; +import java.util.stream.Collectors; import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.PackageManifest.Tool; @@ -42,7 +48,6 @@ * @since 2201.9.0 */ public class RunBallerinaPreBuildToolsTask implements Task { - private final PrintStream outStream; public RunBallerinaPreBuildToolsTask(PrintStream out) { @@ -51,41 +56,61 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { @Override public void execute(Project project) { - Collection toolDiagnostics = project.currentPackage().manifest().diagnostics().diagnostics(); - boolean hasTomlErrors = project.currentPackage().manifest().diagnostics().hasErrors(); - if (hasTomlErrors) { - toolDiagnostics.forEach(outStream::println); - throw createLauncherException("compilation contains errors"); - } + this.outStream.println("\nExecuting pre build tools\n"); + // Print all build tool manifest diagnostics + Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() + .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) + .collect(Collectors.toList()); + toolManifestDiagnostics.forEach(outStream::println); + + //Build tool execution + Map toolContextMap = new HashMap<>(); List tools = project.currentPackage().manifest().tools(); ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); for (Tool tool : tools) { + String commandName = tool.getType(); + boolean hasOptionErrors = false; try { - String commandName = tool.getType(); - CodeGeneratorTool targetTool = getTargetTool(commandName, buildRunners); - if (targetTool == null) { - // TODO: Install tool if not found - outStream.println("Command not found: " + commandName); - return; - } - try { - validateOptionsToml(tool.getOptionsToml(), commandName); - } catch (IOException e) { - outStream.println("WARNING: Skipping the validation of tool options due to: " + + hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); + } catch (IOException e) { + outStream.println("\nWARNING: Skipping the validation of tool options due to: " + e.getMessage()); - } - ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); - targetTool.execute(toolContext); - toolContext.diagnostics().forEach(outStream::println); - for (Diagnostic d : toolContext.diagnostics()) { - if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { - throw new ProjectException("compilation contains errors"); + } + if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { + try { + CodeGeneratorTool targetTool = getTargetTool(commandName, buildRunners); + ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); + if (targetTool == null) { + // TODO: Installing tool if not found to be implemented at a later phase + DiagnosticInfo diagnosticInfo = new DiagnosticInfo( + ProjectDiagnosticErrorCode.BUILD_TOOL_NOT_FOUND.diagnosticId(), + "Build tool '" + tool.getType() + "' not found", + DiagnosticSeverity.ERROR); + PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, + tool.getType()); + this.outStream.println(diagnostic); + toolContext.reportDiagnostic(diagnostic); + toolContextMap.put(tool.getId(), toolContext); + continue; + } + this.outStream.println("\nExecuting build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "'."); + targetTool.execute(toolContext); + toolContext.diagnostics().forEach(outStream::println); + if (!Diagnostics.filterErrors(toolContext.diagnostics()).isEmpty()) { + outStream.println("WARNING: Execution of Build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "' contains errors\n"); } + toolContextMap.put(tool.getId(), toolContext); + } catch (Exception e) { + throw createLauncherException(e.getMessage()); } - } catch (ProjectException e) { - throw createLauncherException(e.getMessage()); + } else { + outStream.println("WARNING: Skipping execution of build tool '" + tool.getType() + + "' as tool configurations in Ballerina.toml contains errors\n"); } } + project.currentPackage().setPackageContextTools(toolContextMap); } private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader buildRunners) { @@ -97,16 +122,12 @@ private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader Date: Fri, 19 Jan 2024 11:32:32 +0530 Subject: [PATCH 104/209] Fix build command test failures --- .../java/io/ballerina/cli/task/CompileTask.java | 8 +++++--- .../cli/task/RunBallerinaPreBuildToolsTask.java | 9 ++++----- .../io/ballerina/cli/cmd/BuildCommandTest.java | 5 ++--- .../build-tool-with-diagnostics/main.bal | 6 ++---- .../main.bal | 6 ++---- .../main.bal | 6 ++---- .../main.bal | 4 ++-- .../unix/build-bal-project-with-build-tool.txt | 7 +++++++ ...tool-with-invalid-missing-toml-properties.txt | 4 ++++ ...build-tool-with-recurring-tool-properties.txt | 16 ++++++++++++++-- .../build-bal-project-with-build-tool.txt | 6 ++++++ ...tool-with-invalid-missing-toml-properties.txt | 4 ++++ ...build-tool-with-recurring-tool-properties.txt | 16 ++++++++++++++-- 13 files changed, 68 insertions(+), 29 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index d73ea3616540..30320fc0c41a 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -217,11 +217,13 @@ public void execute(Project project) { err.println(d); } }); - //Report build tool execution diagnostics - for (ToolContext tool: project.currentPackage().toolContextMap().values()) { - diagnostics.addAll(tool.diagnostics()); + if (project.currentPackage().toolContextMap() != null) { + for (ToolContext tool : project.currentPackage().toolContextMap().values()) { + diagnostics.addAll(tool.diagnostics()); + } } + boolean hasErrors = false; for (Diagnostic d : diagnostics) { if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 7fdb5fe06e1d..d3600f458932 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -56,7 +56,6 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { @Override public void execute(Project project) { - this.outStream.println("\nExecuting pre build tools\n"); // Print all build tool manifest diagnostics Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) @@ -73,8 +72,8 @@ public void execute(Project project) { try { hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); } catch (IOException e) { - outStream.println("\nWARNING: Skipping the validation of tool options due to: " + - e.getMessage()); + outStream.println("WARNING: Skipping validation of tool options for tool '" + tool.getType() + + "' due to: " + e.getMessage()); } if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { try { @@ -93,8 +92,8 @@ public void execute(Project project) { toolContextMap.put(tool.getId(), toolContext); continue; } - this.outStream.println("\nExecuting build tool '" + tool.getType() + - "' for tool configurations '" + tool.getId() + "'."); + this.outStream.println("Executing build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "'.\n"); targetTool.execute(toolContext); toolContext.diagnostics().forEach(outStream::println); if (!Diagnostics.filterErrors(toolContext.diagnostics()).isEmpty()) { diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 540f936c341c..2eacc03977b1 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1203,8 +1203,7 @@ public void testBuildProjectWithBuildToolTomlPropertyDiagnostics(String projectN String buildLog = readOutput(true); Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput(outputFile)); - Assert.assertTrue(e.getDetailedMessages().get(0) - .equals(error)); + Assert.assertEquals(error, e.getDetailedMessages().get(0)); } } @@ -1218,7 +1217,7 @@ public void testBuildProjectWithBuildTool() throws IOException { buildCommand.execute(); String buildLog = readOutput(true); Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-bal-project.txt")); + getOutput("build-bal-project-with-build-tool.txt")); } private String getNewVersionForOldDistWarning() { diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal index 0a995997c547..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal @@ -1,3 +1,3 @@ -public function main() { - return "Hello, World!"; +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt new file mode 100644 index 000000000000..e28b723405ce --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt @@ -0,0 +1,7 @@ +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt index 6d004ad5967f..095355a47e6e 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt @@ -1,2 +1,6 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt index ac6e2e79166d..cfe40f165d2c 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt @@ -1,4 +1,16 @@ -ERROR [Ballerina.toml:(6:1,10:24)] recurring target module 'delivery' found in Ballerina.toml. Target module must be unique for each tool -ERROR [Ballerina.toml:(6:1,10:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool +ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt new file mode 100644 index 000000000000..14e0fea40bdf --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt @@ -0,0 +1,6 @@ +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt index 6d004ad5967f..095355a47e6e 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt @@ -1,2 +1,6 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt index ac6e2e79166d..cfe40f165d2c 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt @@ -1,4 +1,16 @@ -ERROR [Ballerina.toml:(6:1,10:24)] recurring target module 'delivery' found in Ballerina.toml. Target module must be unique for each tool -ERROR [Ballerina.toml:(6:1,10:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool +ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 From e73817f184e400a8dd30dfcb13372385ac08ab1b Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 14:14:04 +0530 Subject: [PATCH 105/209] Add build command test for build tool not found --- .../java/io/ballerina/cli/cmd/BuildCommandTest.java | 12 ++++++++++++ .../build-tool-not-found/Ballerina.toml | 9 +++++++++ .../build-tool-not-found/delivery.json | 0 .../test-resources/build-tool-not-found/main.bal | 3 +++ .../build-bal-project-with-build-tool-not-found.txt | 8 ++++++++ .../build-bal-project-with-build-tool-not-found.txt | 8 ++++++++ .../main/java/io/ballerina/projects/ToolContext.java | 3 +++ 7 files changed, 43 insertions(+) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 2eacc03977b1..dabb75a6c7b1 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1220,6 +1220,18 @@ public void testBuildProjectWithBuildTool() throws IOException { getOutput("build-bal-project-with-build-tool.txt")); } + @Test(description = "Build a project with a build tool not found") + public void testBuildProjectWithBuildToolNotFound() throws IOException { + Path projectPath = this.testResources.resolve("build-tool-not-found"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); + new CommandLine(buildCommand).parseArgs(); + buildCommand.execute(); + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("build-bal-project-with-build-tool-not-found.txt")); + } + private String getNewVersionForOldDistWarning() { SemanticVersion currentDistributionVersion = SemanticVersion.from(RepoUtils.getBallerinaShortVersion()); String currentVersionForDiagnostic = String.valueOf(currentDistributionVersion.minor()); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml new file mode 100644 index 000000000000..c1676c237575 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml @@ -0,0 +1,9 @@ +[package] +org = "foo" +name = "winery" +version = "0.1.0" + +[[tool.grpc]] +id = "generate-grpc-client" +filePath = "delivery_grpc.json" +targetModule = "delivery" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal new file mode 100644 index 000000000000..fd36f05068fe --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal @@ -0,0 +1,3 @@ +public function main() { + return; +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt new file mode 100644 index 000000000000..0cb45eb40745 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt @@ -0,0 +1,8 @@ +WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +ERROR [grpc] Build tool 'grpc' not found +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt new file mode 100644 index 000000000000..0cb45eb40745 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt @@ -0,0 +1,8 @@ +WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +ERROR [grpc] Build tool 'grpc' not found +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java index d84f78e312b0..8b6ba994dfd7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java @@ -132,6 +132,9 @@ public void reportDiagnostic(Diagnostic diagnostic) { private Map getOptions(TomlTableNode optionsTable) { Map options = new HashMap<>(); + if (null == optionsTable) { + return options; + } for (String option: optionsTable.entries().keySet()) { options.put(option, optionsTable.entries().get(option).toNativeObject()); } From 36460aca448dd37c6c4014e49bb343d431b399b8 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 14:22:32 +0530 Subject: [PATCH 106/209] Declare tool diagnostic error code prefix --- .../src/main/java/io/ballerina/cli/task/CompileTask.java | 5 +++-- .../io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java | 5 +++-- .../java/io/ballerina/projects/util/ProjectConstants.java | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 30320fc0c41a..bb503007d2a1 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -48,6 +48,7 @@ import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.util.ProjectConstants.DOT; +import static io.ballerina.projects.util.ProjectConstants.TOOL_DIAGNOSTIC_CODE_PREFIX; /** * Task for compiling a package. @@ -187,7 +188,7 @@ public void execute(Project project) { // add dependency manifest diagnostics diagnostics.addAll(project.currentPackage().dependencyManifest().diagnostics().diagnostics()); diagnostics.forEach(d -> { - if (!d.diagnosticInfo().code().startsWith("BCE54")) { + if (!d.diagnosticInfo().code().startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)) { err.println(d); } }); @@ -213,7 +214,7 @@ public void execute(Project project) { diagnostics.forEach(d -> { if (d.diagnosticInfo().code() == null || (!d.diagnosticInfo().code().equals( ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId()) && - !d.diagnosticInfo().code().startsWith("BCE54"))) { + !d.diagnosticInfo().code().startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX))) { err.println(d); } }); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index d3600f458932..432b3598bc7c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -41,6 +41,7 @@ import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.PackageManifest.Tool; +import static io.ballerina.projects.util.ProjectConstants.TOOL_DIAGNOSTIC_CODE_PREFIX; /** * Task for running tools integrated with the build. @@ -58,8 +59,8 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { public void execute(Project project) { // Print all build tool manifest diagnostics Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() - .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) - .collect(Collectors.toList()); + .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code() + .startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)).collect(Collectors.toList()); toolManifestDiagnostics.forEach(outStream::println); //Build tool execution diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java index 1ced0dd81592..722e6358045e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java @@ -134,4 +134,5 @@ private ProjectConstants() {} public static final String CONFIG_DIR = ".config"; public static final String PROFILER_DIR_NAME = "profiler"; public static final String TOOL_CACHE_DIR = "tool-cache"; + public static final String TOOL_DIAGNOSTIC_CODE_PREFIX = "BCE54"; } From c2d4c56f1a2e2056c4dd7ce908dc2650058f4eb0 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 09:56:06 +0530 Subject: [PATCH 107/209] Change ToolContext getters and implementation --- .../io/ballerina/projects/ToolContext.java | 79 +++++++++++++------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java index 56abbc166512..d84f78e312b0 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java @@ -22,7 +22,9 @@ import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static io.ballerina.projects.util.ProjectConstants.GENERATED_MODULES_ROOT; import static io.ballerina.projects.util.ProjectConstants.TARGET_DIR_NAME; @@ -36,75 +38,104 @@ public class ToolContext { private final Package currentPackage; - private final String toolType; private final String toolId; private final String filePath; private final String targetModule; - private final TomlTableNode optionsTable; - private final Path cachePath; - private final Path outputPath; - private List diagnostics = new ArrayList<>(); + private final Map options; + private final List diagnostics = new ArrayList<>(); - ToolContext(Package currentPackage, String type, String toolId, String filePath, + ToolContext(Package currentPackage, String toolId, String filePath, String targetModule, TomlTableNode optionsTable) { this.currentPackage = currentPackage; - this.toolType = type; this.toolId = toolId; this.filePath = filePath; this.targetModule = targetModule; - this.optionsTable = optionsTable; - Path sourceRoot = currentPackage.project().sourceRoot(); - this.cachePath = sourceRoot.resolve(TARGET_DIR_NAME).resolve(TOOL_CACHE_DIR).resolve(toolId); - if (targetModule == null || targetModule.isEmpty()) { - this.outputPath = sourceRoot.resolve(GENERATED_MODULES_ROOT); - } else { - this.outputPath = sourceRoot.resolve(GENERATED_MODULES_ROOT).resolve(targetModule); - } + this.options = getOptions(optionsTable); } public static ToolContext from(PackageManifest.Tool tool, Package currentPackage) { - return new ToolContext(currentPackage, tool.getType(), tool.getId(), + return new ToolContext(currentPackage, tool.getId(), tool.getFilePath(), tool.getTargetModule(), tool.getOptionsTable()); } + /** + * @return the id of the tool configuration. + */ public String toolId() { return this.toolId; } - public String toolType() { - return this.toolType; - } - + /** + * @return the filepath extracted from tool configuration. + */ public String filePath() { return this.filePath; } + /** + * @return the target module extracted from tool configuration. + */ public String targetModule() { return targetModule; } - public TomlTableNode optionsTable() { - return this.optionsTable; + /** + * @return a map of the optional tool configurations. + */ + public Map options() { + return this.options; } + /** + * @return the cache path derived using the tool id. + */ public Path cachePath() { - return cachePath; + Path sourceRoot = currentPackage.project().sourceRoot(); + return sourceRoot.resolve(TARGET_DIR_NAME).resolve(TOOL_CACHE_DIR).resolve(toolId); } + /** + * @return the output path derived using the target module + */ public Path outputPath() { - return outputPath; + Path sourceRoot = currentPackage.project().sourceRoot(); + if (targetModule == null || targetModule.isEmpty()) { + return sourceRoot.resolve(GENERATED_MODULES_ROOT); + } else { + return sourceRoot.resolve(GENERATED_MODULES_ROOT).resolve(targetModule); + } } + /** + * @return the current package instance. + */ public Package currentPackage() { return currentPackage; } + + /** + * @return a list of tool diagnostics. + */ public List diagnostics() { return diagnostics; } + /** + * Reports a diagnostic against the build tool executed. + * + * @param diagnostic the {@code Diagnostic} to be reported + */ public void reportDiagnostic(Diagnostic diagnostic) { diagnostics.add(diagnostic); } + + private Map getOptions(TomlTableNode optionsTable) { + Map options = new HashMap<>(); + for (String option: optionsTable.entries().keySet()) { + options.put(option, optionsTable.entries().get(option).toNativeObject()); + } + return options; + } } From 94f7b08769d1cddbcd71a51f7e28bf58fc68429f Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:29:41 +0530 Subject: [PATCH 108/209] Change sample tool --- cli/ballerina-cli/src/main/java/module-info.java | 1 + .../src/main/java/build/tool/runner/SampleToolRunner.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/module-info.java b/cli/ballerina-cli/src/main/java/module-info.java index 27c54d8c248e..baef3d0bfbe0 100644 --- a/cli/ballerina-cli/src/main/java/module-info.java +++ b/cli/ballerina-cli/src/main/java/module-info.java @@ -1,5 +1,6 @@ module io.ballerina.cli { uses io.ballerina.cli.BLauncherCmd; + uses io.ballerina.cli.tool.CodeGeneratorTool; exports io.ballerina.cli; exports io.ballerina.cli.launcher; exports io.ballerina.cli.utils; diff --git a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java index f5dc918fc1f5..f47e546bc046 100644 --- a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java +++ b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java @@ -44,7 +44,7 @@ public void execute(ToolContext toolContext) { "The provided filePath does not exist", DiagnosticSeverity.ERROR); toolContext.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, new NullLocation())); } - System.out.println("Running sample build tool: " + toolContext.toolType()); + System.out.println("Running sample build tool: " + toolContext.toolId()); System.out.println("Cache created at: " + toolContext.cachePath()); } From 20d17b1f232cc2a7073bdd7091813fde584bb202 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:30:07 +0530 Subject: [PATCH 109/209] Improve tool class in packageManifest --- .../ballerina/projects/PackageManifest.java | 59 ++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java index 08bca3b29f52..4efa3c577a82 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java @@ -415,50 +415,79 @@ public Optional location() { } } + /** + * Represents the build tool configurations in Ballerina.toml file. + * + * @since 2201.9.0 + */ public static class Tool { private final String id; private final TomlTableNode optionsTable; + private final String filePath; + private final String targetModule; + private final String type; + private final Toml optionsToml; + private final boolean hasErrorDiagnostic; + + public Tool(String type, String id, String filePath, String targetModule, Toml optionsToml, + TomlTableNode optionsTable, boolean hasErrorDiagnostic) { + this.type = type; + this.id = id; + this.filePath = filePath; + this.targetModule = targetModule; + this.optionsTable = optionsTable; + this.optionsToml = optionsToml; + this.hasErrorDiagnostic = hasErrorDiagnostic; + } + /** + * @return the tool id. + */ public String getId() { return id; } + /** + * @return the filepath. + */ public String getFilePath() { return this.filePath; } + /** + * @return the tool's target module. + */ public String getTargetModule() { return this.targetModule; } + /** + * @return the tool options table. + */ public TomlTableNode getOptionsTable() { return this.optionsTable; } + /** + * @return the tool type. + */ public String getType() { return type; } - private final String filePath; - private final String targetModule; - private final String type; - + /** + * @return the options toml. + */ public Toml getOptionsToml() { return optionsToml; } - private final Toml optionsToml; - - public Tool(String type, String id, String filePath, String targetModule, Toml optionsToml, - TomlTableNode optionsTable) { - this.type = type; - this.id = id; - this.filePath = filePath; - this.targetModule = targetModule; - this.optionsTable = optionsTable; - this.optionsToml = optionsToml; + /** + * @return whether the tool has error diagnostics. + */ + public boolean hasErrorDiagnostic() { + return hasErrorDiagnostic; } - } private List getExport(PackageDescriptor packageDesc, List export) { From 4349177a7f5f950703c1dbbc1da7219e12e93075 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 17 Jan 2024 11:30:38 +0530 Subject: [PATCH 110/209] Add hasDiagnostic flag to build tools and improve validations --- .../projects/internal/ManifestBuilder.java | 68 +++++++------------ 1 file changed, 23 insertions(+), 45 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index e5f56405621d..9f60f62a3d84 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -20,6 +20,7 @@ import io.ballerina.projects.BuildOptions; import io.ballerina.projects.DiagnosticResult; +import io.ballerina.projects.Diagnostics; import io.ballerina.projects.PackageDescriptor; import io.ballerina.projects.PackageManifest; import io.ballerina.projects.PackageName; @@ -233,23 +234,21 @@ private PackageManifest parseAsPackageManifest() { } private List getTools() { - TomlTableNode rootNode = ballerinaToml.toml().rootNode(); if (rootNode.entries().isEmpty()) { return Collections.emptyList(); } - TopLevelNode toolEntries = rootNode.entries().get("tool"); - List tools = new ArrayList<>(); if (toolEntries == null || toolEntries.kind() != TomlType.TABLE) { return Collections.emptyList(); } TomlTableNode toolTable = (TomlTableNode) toolEntries; Set toolCodes = toolTable.entries().keySet(); - List toolIds = new ArrayList<>(); - List toolTargetModules = new ArrayList<>(); + Set toolIdsSet = new HashSet<>(); + Set targetModuleSet = new HashSet<>(); + // Gather tool configurations and add the tools to a list for (String toolCode : toolCodes) { TopLevelNode toolCodeNode = toolTable.entries().get(toolCode); if (toolCodeNode.kind() != TomlType.TABLE_ARRAY) { @@ -281,13 +280,28 @@ private List getTools() { if (topLevelNode != null && topLevelNode.kind() == TomlType.TABLE) { optionsNode = (TomlTableNode) topLevelNode; } + + // Validate recurring tool ids and target modules + if (!toolIdsSet.add(id)) { + reportDiagnostic(dependencyNode, "recurring tool id '" + id + "' found in Ballerina.toml. " + + "Tool id must be unique for each tool", + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + DiagnosticSeverity.ERROR); + } + if (!targetModuleSet.add(targetModule)) { + reportDiagnostic(dependencyNode, "recurring target module found in Ballerina.toml. Target " + + "module must be unique for each tool", + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + DiagnosticSeverity.ERROR); + } + + // Add a flag for tools with error diagnostics + boolean hasErrorDiagnostic = !Diagnostics.filterErrors(dependencyNode.diagnostics()).isEmpty(); PackageManifest.Tool tool = new PackageManifest.Tool(toolCode, id, filePath, - targetModule, optionsToml, optionsNode); + targetModule, optionsToml, optionsNode, hasErrorDiagnostic); tools.add(tool); - addIdTargetModuleToLists(id, targetModule, toolIds, toolTargetModules); } } - validateUniqueIdAndTargetModule(toolIds, toolTargetModules, toolTable); return tools; } @@ -823,7 +837,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String + toolCode + "]'. " + "Default module will be taken as the target module", ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY.diagnosticId(), DiagnosticSeverity.WARNING); - return getStringFromTomlTableNode(topLevelNode); + return null; } else if (ToolNodeValueType.NON_STRING.equals(toolNodeValueType)) { reportDiagnostic(toolNode, "incompatible type found for key '[" + key + "]': expected 'STRING'", ProjectDiagnosticErrorCode.INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY.diagnosticId(), @@ -845,42 +859,6 @@ private Toml getToml(TomlTableNode toolNode, String key) { return new Toml(optionsNode); } - private void addIdTargetModuleToLists(String id, String targetModule, List toolIds, - List targetModules) { - if (id != null) { - toolIds.add(id); - } - if (targetModule == null || targetModule.isEmpty()) { - targetModules.add("default"); - return; - } - targetModules.add(targetModule); - } - - private void validateUniqueIdAndTargetModule(List toolIds, List targetModules, - TomlTableNode tomlTableNode) { - Set toolIdsSet = new HashSet<>(); - Set targetModuleSet = new HashSet<>(); - for (String toolId: toolIds) { - if (!toolIdsSet.add(toolId)) { - reportDiagnostic(tomlTableNode, "recurring tool id '" + toolId + "' found in Ballerina.toml. " + - "Tool id must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), - DiagnosticSeverity.ERROR); - break; - } - } - for (String targetModule: targetModules) { - if (!targetModuleSet.add(targetModule)) { - reportDiagnostic(tomlTableNode, "recurring target module '" + targetModule + "' found in " + - "Ballerina.toml. Target module must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), - DiagnosticSeverity.ERROR); - break; - } - } - } - /** * Check file name has {@code .png} extension. * From c4d225592402ca06ec6099300b76050a5201a964 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:12:56 +0530 Subject: [PATCH 111/209] Add toolContextMap to PackageContext --- .../main/java/io/ballerina/projects/Package.java | 13 +++++++++++++ .../java/io/ballerina/projects/PackageContext.java | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index b359c13098e5..03bf68bcb202 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -158,6 +158,10 @@ public PackageResolution getResolution(CompilationOptions compilationOptions) { return this.packageContext.getResolution(compilationOptions); } + public void setPackageContextTools(Map toolContextMap) { + this.packageContext.setToolContextMap(toolContextMap); + } + public DependencyGraph moduleDependencyGraph() { // Each Package should know the packages that it depends on and packages that depends on it // Each Module should know the modules that it depends on and modules that depends on it @@ -172,6 +176,15 @@ public CompilationOptions compilationOptions() { return packageContext.compilationOptions(); } + /** + * returns a map of build tools. + * + * @return map of {@code ToolContext} + */ + public Map toolContextMap() { + return packageContext.toolContextMap(); + } + public Optional ballerinaToml() { if (null == this.ballerinaToml) { this.ballerinaToml = this.packageContext.ballerinaTomlContext().map(c -> diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index 7cfc92426279..cbc3ffee4754 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -52,6 +52,7 @@ class PackageContext { private final CompilationOptions compilationOptions; private ModuleContext defaultModuleContext; + private Map toolContextMap; /** * This variable holds the dependency graph cached in a project. * At the moment, we cache the dependency graph in a bala file. @@ -96,7 +97,6 @@ class PackageContext { this.moduleCompilationMap = new HashMap<>(); this.packageDependencies = Collections.emptySet(); this.pkgDescDependencyGraph = pkgDescDependencyGraph; - } static PackageContext from(Project project, PackageConfig packageConfig, CompilationOptions compilationOptions) { @@ -181,6 +181,10 @@ Collection moduleIds() { return moduleIds; } + Map toolContextMap() { + return toolContextMap; + } + ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } @@ -315,4 +319,8 @@ PackageContext duplicate(Project project) { this.cloudTomlContext, this.compilerPluginTomlContext, this.balToolTomlContext, this.packageMdContext, this.compilationOptions, duplicatedModuleContextMap, this.pkgDescDependencyGraph); } + + void setToolContextMap(Map toolContextMap) { + this.toolContextMap = toolContextMap; + } } From 41767fcdf4d53ef2dde961417b8e8b79ab10933d Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:14:40 +0530 Subject: [PATCH 112/209] Handle build tool execution failures with diagnostics --- .../io/ballerina/cli/task/CompileTask.java | 23 +++++++++++++++---- .../projects/internal/ManifestBuilder.java | 3 ++- .../internal/ProjectDiagnosticErrorCode.java | 5 ++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 7ae41cd32e13..d73ea3616540 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -29,6 +29,7 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.ProjectKind; import io.ballerina.projects.SemanticVersion; +import io.ballerina.projects.ToolContext; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.environment.ResolutionOptions; import io.ballerina.projects.internal.PackageDiagnostic; @@ -185,7 +186,11 @@ public void execute(Project project) { diagnostics.addAll(project.currentPackage().manifest().diagnostics().diagnostics()); // add dependency manifest diagnostics diagnostics.addAll(project.currentPackage().dependencyManifest().diagnostics().diagnostics()); - diagnostics.forEach(d -> err.println(d.toString())); + diagnostics.forEach(d -> { + if (!d.diagnosticInfo().code().startsWith("BCE54")) { + err.println(d); + } + }); throw createLauncherException("package resolution contains errors"); } @@ -205,15 +210,23 @@ public void execute(Project project) { // Report package compilation and backend diagnostics diagnostics.addAll(jBallerinaBackend.diagnosticResult().diagnostics(false)); + diagnostics.forEach(d -> { + if (d.diagnosticInfo().code() == null || (!d.diagnosticInfo().code().equals( + ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId()) && + !d.diagnosticInfo().code().startsWith("BCE54"))) { + err.println(d); + } + }); + + //Report build tool execution diagnostics + for (ToolContext tool: project.currentPackage().toolContextMap().values()) { + diagnostics.addAll(tool.diagnostics()); + } boolean hasErrors = false; for (Diagnostic d : diagnostics) { if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { hasErrors = true; } - if (d.diagnosticInfo().code() == null || !d.diagnosticInfo().code().equals( - ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId())) { - err.println(d); - } } if (hasErrors) { throw createLauncherException("compilation contains errors"); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 9f60f62a3d84..562b8ac69a5e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -607,12 +607,13 @@ private List getLocalRepoDependencies() { return dependencies; } + // TODO: Fix code and messageFormat parameters in usages. private void reportDiagnostic(TopLevelNode tomlTableNode, String message, String messageFormat, DiagnosticSeverity severity) { DiagnosticInfo diagnosticInfo = - new DiagnosticInfo(null, messageFormat, severity); + new DiagnosticInfo(messageFormat, messageFormat, severity); TomlDiagnostic tomlDiagnostic = new TomlDiagnostic( tomlTableNode.location(), diagnosticInfo, diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 15e97c34b9fa..80badbc61d98 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -27,6 +27,7 @@ */ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { + // TODO: Assign specific codes for each error type and sort the error codes. INVALID_BALA_FILE("BCE5000", "invalid.bala.file"), OLD_DEPENDENCIES_TOML("BCE5001", "old.dependencies.toml"), LOCAL_PACKAGES_IN_DEPENDENCIES_TOML("BCE5002", "local.packages.in.dependencies.toml"), @@ -37,11 +38,15 @@ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { DEPRECATED_PACKAGE("BCE5007", "deprecated.package"), BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5008", "built.with.older.sl.update.distribution"), CUSTOM_REPOSITORY_NOT_FOUND("BCE5009", "custom.repository.not.found"), + + // Error codes related to build tools starting from BCE5400. MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5400", "missing.tool.properties"), INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5401", "incompatible.tool.properties"), EMPTY_TOOL_PROPERTY("BCE5402", "empty.tool.properties"), TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5403", "tool.options.validation.skipped"), RECURRING_TOOL_PROPERTIES("BCE5404", "recurring.tool.properties"), + BUILD_TOOL_NOT_FOUND("BCE5405", "build.tool.not.found"), + MODULE_NOT_FOUND("BCE5100", "module.not.found"), UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5200", "unsupported.compiler.plugin.type"), CONFLICTING_PLATFORM_JAR_FILES("BCE5300", "conflicting.platform.jars.type"), From d9b641b529c3ef373aa151460c2f2fc614afa3b5 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 07:17:01 +0530 Subject: [PATCH 113/209] Improve diagnostic handling for build tools --- .../task/RunBallerinaPreBuildToolsTask.java | 89 ++++++++++++------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 2eab2bdefbb5..7fdb5fe06e1d 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -20,18 +20,24 @@ import io.ballerina.cli.tool.CodeGeneratorTool; import io.ballerina.cli.utils.FileUtils; +import io.ballerina.projects.Diagnostics; import io.ballerina.projects.Project; -import io.ballerina.projects.ProjectException; import io.ballerina.projects.ToolContext; +import io.ballerina.projects.internal.PackageDiagnostic; +import io.ballerina.projects.internal.ProjectDiagnosticErrorCode; import io.ballerina.toml.api.Toml; import io.ballerina.tools.diagnostics.Diagnostic; +import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; import java.io.IOException; import java.io.PrintStream; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; +import java.util.stream.Collectors; import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.PackageManifest.Tool; @@ -42,7 +48,6 @@ * @since 2201.9.0 */ public class RunBallerinaPreBuildToolsTask implements Task { - private final PrintStream outStream; public RunBallerinaPreBuildToolsTask(PrintStream out) { @@ -51,41 +56,61 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { @Override public void execute(Project project) { - Collection toolDiagnostics = project.currentPackage().manifest().diagnostics().diagnostics(); - boolean hasTomlErrors = project.currentPackage().manifest().diagnostics().hasErrors(); - if (hasTomlErrors) { - toolDiagnostics.forEach(outStream::println); - throw createLauncherException("compilation contains errors"); - } + this.outStream.println("\nExecuting pre build tools\n"); + // Print all build tool manifest diagnostics + Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() + .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) + .collect(Collectors.toList()); + toolManifestDiagnostics.forEach(outStream::println); + + //Build tool execution + Map toolContextMap = new HashMap<>(); List tools = project.currentPackage().manifest().tools(); ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); for (Tool tool : tools) { + String commandName = tool.getType(); + boolean hasOptionErrors = false; try { - String commandName = tool.getType(); - CodeGeneratorTool targetTool = getTargetTool(commandName, buildRunners); - if (targetTool == null) { - // TODO: Install tool if not found - outStream.println("Command not found: " + commandName); - return; - } - try { - validateOptionsToml(tool.getOptionsToml(), commandName); - } catch (IOException e) { - outStream.println("WARNING: Skipping the validation of tool options due to: " + + hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); + } catch (IOException e) { + outStream.println("\nWARNING: Skipping the validation of tool options due to: " + e.getMessage()); - } - ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); - targetTool.execute(toolContext); - toolContext.diagnostics().forEach(outStream::println); - for (Diagnostic d : toolContext.diagnostics()) { - if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { - throw new ProjectException("compilation contains errors"); + } + if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { + try { + CodeGeneratorTool targetTool = getTargetTool(commandName, buildRunners); + ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); + if (targetTool == null) { + // TODO: Installing tool if not found to be implemented at a later phase + DiagnosticInfo diagnosticInfo = new DiagnosticInfo( + ProjectDiagnosticErrorCode.BUILD_TOOL_NOT_FOUND.diagnosticId(), + "Build tool '" + tool.getType() + "' not found", + DiagnosticSeverity.ERROR); + PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, + tool.getType()); + this.outStream.println(diagnostic); + toolContext.reportDiagnostic(diagnostic); + toolContextMap.put(tool.getId(), toolContext); + continue; + } + this.outStream.println("\nExecuting build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "'."); + targetTool.execute(toolContext); + toolContext.diagnostics().forEach(outStream::println); + if (!Diagnostics.filterErrors(toolContext.diagnostics()).isEmpty()) { + outStream.println("WARNING: Execution of Build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "' contains errors\n"); } + toolContextMap.put(tool.getId(), toolContext); + } catch (Exception e) { + throw createLauncherException(e.getMessage()); } - } catch (ProjectException e) { - throw createLauncherException(e.getMessage()); + } else { + outStream.println("WARNING: Skipping execution of build tool '" + tool.getType() + + "' as tool configurations in Ballerina.toml contains errors\n"); } } + project.currentPackage().setPackageContextTools(toolContextMap); } private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader buildRunners) { @@ -97,16 +122,12 @@ private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader Date: Fri, 19 Jan 2024 11:32:32 +0530 Subject: [PATCH 114/209] Fix build command test failures --- .../java/io/ballerina/cli/task/CompileTask.java | 8 +++++--- .../cli/task/RunBallerinaPreBuildToolsTask.java | 9 ++++----- .../io/ballerina/cli/cmd/BuildCommandTest.java | 5 ++--- .../build-tool-with-diagnostics/main.bal | 6 ++---- .../main.bal | 6 ++---- .../main.bal | 6 ++---- .../main.bal | 4 ++-- .../unix/build-bal-project-with-build-tool.txt | 7 +++++++ ...tool-with-invalid-missing-toml-properties.txt | 4 ++++ ...build-tool-with-recurring-tool-properties.txt | 16 ++++++++++++++-- .../build-bal-project-with-build-tool.txt | 6 ++++++ ...tool-with-invalid-missing-toml-properties.txt | 4 ++++ ...build-tool-with-recurring-tool-properties.txt | 16 ++++++++++++++-- 13 files changed, 68 insertions(+), 29 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index d73ea3616540..30320fc0c41a 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -217,11 +217,13 @@ public void execute(Project project) { err.println(d); } }); - //Report build tool execution diagnostics - for (ToolContext tool: project.currentPackage().toolContextMap().values()) { - diagnostics.addAll(tool.diagnostics()); + if (project.currentPackage().toolContextMap() != null) { + for (ToolContext tool : project.currentPackage().toolContextMap().values()) { + diagnostics.addAll(tool.diagnostics()); + } } + boolean hasErrors = false; for (Diagnostic d : diagnostics) { if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 7fdb5fe06e1d..d3600f458932 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -56,7 +56,6 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { @Override public void execute(Project project) { - this.outStream.println("\nExecuting pre build tools\n"); // Print all build tool manifest diagnostics Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) @@ -73,8 +72,8 @@ public void execute(Project project) { try { hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); } catch (IOException e) { - outStream.println("\nWARNING: Skipping the validation of tool options due to: " + - e.getMessage()); + outStream.println("WARNING: Skipping validation of tool options for tool '" + tool.getType() + + "' due to: " + e.getMessage()); } if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { try { @@ -93,8 +92,8 @@ public void execute(Project project) { toolContextMap.put(tool.getId(), toolContext); continue; } - this.outStream.println("\nExecuting build tool '" + tool.getType() + - "' for tool configurations '" + tool.getId() + "'."); + this.outStream.println("Executing build tool '" + tool.getType() + + "' for tool configurations '" + tool.getId() + "'.\n"); targetTool.execute(toolContext); toolContext.diagnostics().forEach(outStream::println); if (!Diagnostics.filterErrors(toolContext.diagnostics()).isEmpty()) { diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 540f936c341c..2eacc03977b1 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1203,8 +1203,7 @@ public void testBuildProjectWithBuildToolTomlPropertyDiagnostics(String projectN String buildLog = readOutput(true); Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput(outputFile)); - Assert.assertTrue(e.getDetailedMessages().get(0) - .equals(error)); + Assert.assertEquals(error, e.getDetailedMessages().get(0)); } } @@ -1218,7 +1217,7 @@ public void testBuildProjectWithBuildTool() throws IOException { buildCommand.execute(); String buildLog = readOutput(true); Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-bal-project.txt")); + getOutput("build-bal-project-with-build-tool.txt")); } private String getNewVersionForOldDistWarning() { diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal index 31e8785bf98f..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal @@ -1,5 +1,3 @@ -import ballerina/io; - -public function main() { - io:println("Hello, World!"); +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal index 0a995997c547..adbf847790de 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal @@ -1,3 +1,3 @@ -public function main() { - return "Hello, World!"; +public function hello() returns string { + return ("Hello, World!"); } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt new file mode 100644 index 000000000000..e28b723405ce --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt @@ -0,0 +1,7 @@ +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt index 6d004ad5967f..095355a47e6e 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt @@ -1,2 +1,6 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt index ac6e2e79166d..cfe40f165d2c 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt @@ -1,4 +1,16 @@ -ERROR [Ballerina.toml:(6:1,10:24)] recurring target module 'delivery' found in Ballerina.toml. Target module must be unique for each tool -ERROR [Ballerina.toml:(6:1,10:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool +ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt new file mode 100644 index 000000000000..14e0fea40bdf --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt @@ -0,0 +1,6 @@ +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt index 6d004ad5967f..095355a47e6e 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt @@ -1,2 +1,6 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt index ac6e2e79166d..cfe40f165d2c 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt @@ -1,4 +1,16 @@ -ERROR [Ballerina.toml:(6:1,10:24)] recurring target module 'delivery' found in Ballerina.toml. Target module must be unique for each tool -ERROR [Ballerina.toml:(6:1,10:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. +ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool +ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 From ead4427d98ed9589d13c49912707465f7788a736 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 14:14:04 +0530 Subject: [PATCH 115/209] Add build command test for build tool not found --- .../java/io/ballerina/cli/cmd/BuildCommandTest.java | 12 ++++++++++++ .../build-tool-not-found/Ballerina.toml | 9 +++++++++ .../build-tool-not-found/delivery.json | 0 .../test-resources/build-tool-not-found/main.bal | 3 +++ .../build-bal-project-with-build-tool-not-found.txt | 8 ++++++++ .../build-bal-project-with-build-tool-not-found.txt | 8 ++++++++ .../main/java/io/ballerina/projects/ToolContext.java | 3 +++ 7 files changed, 43 insertions(+) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 2eacc03977b1..dabb75a6c7b1 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1220,6 +1220,18 @@ public void testBuildProjectWithBuildTool() throws IOException { getOutput("build-bal-project-with-build-tool.txt")); } + @Test(description = "Build a project with a build tool not found") + public void testBuildProjectWithBuildToolNotFound() throws IOException { + Path projectPath = this.testResources.resolve("build-tool-not-found"); + System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); + BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); + new CommandLine(buildCommand).parseArgs(); + buildCommand.execute(); + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("build-bal-project-with-build-tool-not-found.txt")); + } + private String getNewVersionForOldDistWarning() { SemanticVersion currentDistributionVersion = SemanticVersion.from(RepoUtils.getBallerinaShortVersion()); String currentVersionForDiagnostic = String.valueOf(currentDistributionVersion.minor()); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml new file mode 100644 index 000000000000..c1676c237575 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/Ballerina.toml @@ -0,0 +1,9 @@ +[package] +org = "foo" +name = "winery" +version = "0.1.0" + +[[tool.grpc]] +id = "generate-grpc-client" +filePath = "delivery_grpc.json" +targetModule = "delivery" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal new file mode 100644 index 000000000000..fd36f05068fe --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-not-found/main.bal @@ -0,0 +1,3 @@ +public function main() { + return; +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt new file mode 100644 index 000000000000..0cb45eb40745 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt @@ -0,0 +1,8 @@ +WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +ERROR [grpc] Build tool 'grpc' not found +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt new file mode 100644 index 000000000000..0cb45eb40745 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt @@ -0,0 +1,8 @@ +WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found +ERROR [grpc] Build tool 'grpc' not found +Compiling source + foo/winery:0.1.0 + +Generating executable + target/bin/winery.jar diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java index d84f78e312b0..8b6ba994dfd7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java @@ -132,6 +132,9 @@ public void reportDiagnostic(Diagnostic diagnostic) { private Map getOptions(TomlTableNode optionsTable) { Map options = new HashMap<>(); + if (null == optionsTable) { + return options; + } for (String option: optionsTable.entries().keySet()) { options.put(option, optionsTable.entries().get(option).toNativeObject()); } From 966fad564f08911b4eb145e2d7a049c9f40aed74 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 19 Jan 2024 14:22:32 +0530 Subject: [PATCH 116/209] Declare tool diagnostic error code prefix --- .../src/main/java/io/ballerina/cli/task/CompileTask.java | 5 +++-- .../io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java | 5 +++-- .../java/io/ballerina/projects/util/ProjectConstants.java | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 30320fc0c41a..bb503007d2a1 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -48,6 +48,7 @@ import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.util.ProjectConstants.DOT; +import static io.ballerina.projects.util.ProjectConstants.TOOL_DIAGNOSTIC_CODE_PREFIX; /** * Task for compiling a package. @@ -187,7 +188,7 @@ public void execute(Project project) { // add dependency manifest diagnostics diagnostics.addAll(project.currentPackage().dependencyManifest().diagnostics().diagnostics()); diagnostics.forEach(d -> { - if (!d.diagnosticInfo().code().startsWith("BCE54")) { + if (!d.diagnosticInfo().code().startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)) { err.println(d); } }); @@ -213,7 +214,7 @@ public void execute(Project project) { diagnostics.forEach(d -> { if (d.diagnosticInfo().code() == null || (!d.diagnosticInfo().code().equals( ProjectDiagnosticErrorCode.BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION.diagnosticId()) && - !d.diagnosticInfo().code().startsWith("BCE54"))) { + !d.diagnosticInfo().code().startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX))) { err.println(d); } }); diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index d3600f458932..432b3598bc7c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -41,6 +41,7 @@ import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.projects.PackageManifest.Tool; +import static io.ballerina.projects.util.ProjectConstants.TOOL_DIAGNOSTIC_CODE_PREFIX; /** * Task for running tools integrated with the build. @@ -58,8 +59,8 @@ public RunBallerinaPreBuildToolsTask(PrintStream out) { public void execute(Project project) { // Print all build tool manifest diagnostics Collection toolManifestDiagnostics = project.currentPackage().manifest().diagnostics() - .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code().startsWith("BCE54")) - .collect(Collectors.toList()); + .diagnostics().stream().filter(diagnostic -> diagnostic.diagnosticInfo().code() + .startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)).collect(Collectors.toList()); toolManifestDiagnostics.forEach(outStream::println); //Build tool execution diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java index 8c8d1bb41aa0..491477724520 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java @@ -134,6 +134,7 @@ private ProjectConstants() {} public static final String CONFIG_DIR = ".config"; public static final String PROFILER_DIR_NAME = "profiler"; public static final String TOOL_CACHE_DIR = "tool-cache"; + public static final String TOOL_DIAGNOSTIC_CODE_PREFIX = "BCE54"; public static final String ORG = "org"; public static final String PACKAGE_NAME = "name"; public static final String LOCAL_TOOLS_JSON = "local-tools.json"; From ec0ad0baca52b88c77d7d63760b6e82f4b0a8fd3 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Sat, 20 Jan 2024 17:14:20 +0530 Subject: [PATCH 117/209] Move TooContextMap to Project --- .../io/ballerina/cli/task/CompileTask.java | 4 ++-- .../task/RunBallerinaPreBuildToolsTask.java | 2 +- .../java/io/ballerina/projects/Package.java | 13 ------------- .../io/ballerina/projects/PackageContext.java | 9 --------- .../java/io/ballerina/projects/Project.java | 18 ++++++++++++++++++ 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index bb503007d2a1..7a76192c0cc9 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -219,8 +219,8 @@ public void execute(Project project) { } }); //Report build tool execution diagnostics - if (project.currentPackage().toolContextMap() != null) { - for (ToolContext tool : project.currentPackage().toolContextMap().values()) { + if (project.getToolContextMap() != null) { + for (ToolContext tool : project.getToolContextMap().values()) { diagnostics.addAll(tool.diagnostics()); } } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 432b3598bc7c..e56ea9a8e105 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -110,7 +110,7 @@ public void execute(Project project) { "' as tool configurations in Ballerina.toml contains errors\n"); } } - project.currentPackage().setPackageContextTools(toolContextMap); + project.setToolContextMap(toolContextMap); } private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader buildRunners) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index 03bf68bcb202..b359c13098e5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -158,10 +158,6 @@ public PackageResolution getResolution(CompilationOptions compilationOptions) { return this.packageContext.getResolution(compilationOptions); } - public void setPackageContextTools(Map toolContextMap) { - this.packageContext.setToolContextMap(toolContextMap); - } - public DependencyGraph moduleDependencyGraph() { // Each Package should know the packages that it depends on and packages that depends on it // Each Module should know the modules that it depends on and modules that depends on it @@ -176,15 +172,6 @@ public CompilationOptions compilationOptions() { return packageContext.compilationOptions(); } - /** - * returns a map of build tools. - * - * @return map of {@code ToolContext} - */ - public Map toolContextMap() { - return packageContext.toolContextMap(); - } - public Optional ballerinaToml() { if (null == this.ballerinaToml) { this.ballerinaToml = this.packageContext.ballerinaTomlContext().map(c -> diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index cbc3ffee4754..c83f07c7b7aa 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -52,7 +52,6 @@ class PackageContext { private final CompilationOptions compilationOptions; private ModuleContext defaultModuleContext; - private Map toolContextMap; /** * This variable holds the dependency graph cached in a project. * At the moment, we cache the dependency graph in a bala file. @@ -181,10 +180,6 @@ Collection moduleIds() { return moduleIds; } - Map toolContextMap() { - return toolContextMap; - } - ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } @@ -319,8 +314,4 @@ PackageContext duplicate(Project project) { this.cloudTomlContext, this.compilerPluginTomlContext, this.balToolTomlContext, this.packageMdContext, this.compilationOptions, duplicatedModuleContextMap, this.pkgDescDependencyGraph); } - - void setToolContextMap(Map toolContextMap) { - this.toolContextMap = toolContextMap; - } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java index c539eb65b357..c940e6f07cdb 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java @@ -22,6 +22,7 @@ import org.wso2.ballerinalang.compiler.util.CompilerOptions; import java.nio.file.Path; +import java.util.Map; import java.util.Optional; import static org.ballerinalang.compiler.CompilerOptionName.PROJECT_DIR; @@ -37,6 +38,7 @@ public abstract class Project { private BuildOptions buildOptions; protected ProjectEnvironment projectEnvironment; private final ProjectKind projectKind; + private Map toolContextMap; protected Project(ProjectKind projectKind, Path projectPath, @@ -93,6 +95,22 @@ public BuildOptions buildOptions() { return buildOptions; } + /** + * returns a map of build tools. + * + * @return map of {@code ToolContext} + */public Map getToolContextMap() { + return toolContextMap; + } + + /** + * assigns a map of build tools. + * @param toolContextMap map of {@code ToolContext} + */ + public void setToolContextMap(Map toolContextMap) { + this.toolContextMap = toolContextMap; + } + // Following project path was added to support old compiler extensions. // Currently this method is only called from Build and Single File projects // todo remove after introducing extension model From 32df1c8b54fa2a24ce99e1bdd8412b1a0dfab56a Mon Sep 17 00:00:00 2001 From: ShammiL Date: Sat, 20 Jan 2024 20:18:12 +0530 Subject: [PATCH 118/209] Revert package context changes --- .../main/java/io/ballerina/projects/Package.java | 13 ------------- .../java/io/ballerina/projects/PackageContext.java | 10 +--------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java index 03bf68bcb202..b359c13098e5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Package.java @@ -158,10 +158,6 @@ public PackageResolution getResolution(CompilationOptions compilationOptions) { return this.packageContext.getResolution(compilationOptions); } - public void setPackageContextTools(Map toolContextMap) { - this.packageContext.setToolContextMap(toolContextMap); - } - public DependencyGraph moduleDependencyGraph() { // Each Package should know the packages that it depends on and packages that depends on it // Each Module should know the modules that it depends on and modules that depends on it @@ -176,15 +172,6 @@ public CompilationOptions compilationOptions() { return packageContext.compilationOptions(); } - /** - * returns a map of build tools. - * - * @return map of {@code ToolContext} - */ - public Map toolContextMap() { - return packageContext.toolContextMap(); - } - public Optional ballerinaToml() { if (null == this.ballerinaToml) { this.ballerinaToml = this.packageContext.ballerinaTomlContext().map(c -> diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java index cbc3ffee4754..9cfb76791adf 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageContext.java @@ -52,7 +52,7 @@ class PackageContext { private final CompilationOptions compilationOptions; private ModuleContext defaultModuleContext; - private Map toolContextMap; + /** * This variable holds the dependency graph cached in a project. * At the moment, we cache the dependency graph in a bala file. @@ -181,10 +181,6 @@ Collection moduleIds() { return moduleIds; } - Map toolContextMap() { - return toolContextMap; - } - ModuleContext moduleContext(ModuleId moduleId) { return moduleContextMap.get(moduleId); } @@ -319,8 +315,4 @@ PackageContext duplicate(Project project) { this.cloudTomlContext, this.compilerPluginTomlContext, this.balToolTomlContext, this.packageMdContext, this.compilationOptions, duplicatedModuleContextMap, this.pkgDescDependencyGraph); } - - void setToolContextMap(Map toolContextMap) { - this.toolContextMap = toolContextMap; - } } From 053ad372a5099b8b2eb7e1dc10a32c90859214d8 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Sun, 21 Jan 2024 07:57:49 +0530 Subject: [PATCH 119/209] Fix test for no tools found --- .../java/io/ballerina/cli/cmd/BuildCommandTest.java | 13 +++++++++---- .../build-bal-project-with-build-tool-not-found.txt | 3 --- .../unix/build-tool-with-diagnostics.txt | 5 ++++- .../build-bal-project-with-build-tool-not-found.txt | 3 --- .../windows/build-tool-with-diagnostics.txt | 5 ++++- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index dabb75a6c7b1..18f0fcee96e4 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1226,10 +1226,15 @@ public void testBuildProjectWithBuildToolNotFound() throws IOException { System.setProperty(USER_DIR_PROPERTY, projectPath.toString()); BuildCommand buildCommand = new BuildCommand(projectPath, printStream, printStream, false); new CommandLine(buildCommand).parseArgs(); - buildCommand.execute(); - String buildLog = readOutput(true); - Assert.assertEquals(buildLog.replaceAll("\r", ""), - getOutput("build-bal-project-with-build-tool-not-found.txt")); + try { + buildCommand.execute(); + } catch (BLauncherException e) { + String buildLog = readOutput(true); + Assert.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("build-bal-project-with-build-tool-not-found.txt")); + Assert.assertEquals("error: compilation contains errors", e.getDetailedMessages().get(0)); + + } } private String getNewVersionForOldDistWarning() { diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt index 0cb45eb40745..b216624c696a 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt @@ -3,6 +3,3 @@ WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool opt ERROR [grpc] Build tool 'grpc' not found Compiling source foo/winery:0.1.0 - -Generating executable - target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt index c2ca71c46587..16e2cc641dcd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt @@ -1 +1,4 @@ -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt index 0cb45eb40745..b216624c696a 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt @@ -3,6 +3,3 @@ WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool opt ERROR [grpc] Build tool 'grpc' not found Compiling source foo/winery:0.1.0 - -Generating executable - target/bin/winery.jar diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt index c2ca71c46587..16e2cc641dcd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt @@ -1 +1,4 @@ -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Compiling source + foo/winery:0.1.0 From 28c4aa92fcaa5541ad7c42dd14c61fc8f035ad5e Mon Sep 17 00:00:00 2001 From: ShammiL Date: Sun, 21 Jan 2024 15:02:03 +0530 Subject: [PATCH 120/209] Fix test for build tools with diagnostics --- .../command-outputs/unix/build-tool-with-diagnostics.txt | 5 ++++- .../command-outputs/windows/build-tool-with-diagnostics.txt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt index 16e2cc641dcd..cfa2fa7a2cc5 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt @@ -1,4 +1,7 @@ -openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt index 16e2cc641dcd..cfa2fa7a2cc5 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt @@ -1,4 +1,7 @@ -openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors + Compiling source foo/winery:0.1.0 From ca16acce778fa63f53fc217488d327b5dfccf189 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Mon, 22 Jan 2024 09:42:44 +0530 Subject: [PATCH 121/209] Include changes for improvment #42023 --- .../projects/internal/ManifestBuilder.java | 38 ++++++++-------- .../internal/ProjectDiagnosticErrorCode.java | 43 +++++++++++-------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 562b8ac69a5e..534d5dab87f7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -272,7 +272,7 @@ private List getTools() { } catch (IOException e) { reportDiagnostic(dependencyNode, "tool options validation skipped due to: " + e.getMessage(), - ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_SKIPPED.diagnosticId(), + ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_SKIPPED, DiagnosticSeverity.WARNING); } } @@ -285,13 +285,13 @@ private List getTools() { if (!toolIdsSet.add(id)) { reportDiagnostic(dependencyNode, "recurring tool id '" + id + "' found in Ballerina.toml. " + "Tool id must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES, DiagnosticSeverity.ERROR); } if (!targetModuleSet.add(targetModule)) { reportDiagnostic(dependencyNode, "recurring target module found in Ballerina.toml. Target " + "module must be unique for each tool", - ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES.diagnosticId(), + ProjectDiagnosticErrorCode.RECURRING_TOOL_PROPERTIES, DiagnosticSeverity.ERROR); } @@ -311,7 +311,7 @@ private void validateEmptyOptionsToml(TomlTableNode toolNode, String toolName) t if (!requiredFields.isEmpty()) { for (String field: requiredFields) { reportDiagnostic(toolNode, "missing required field '" + field + "'", - ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY.diagnosticId(), DiagnosticSeverity.ERROR); + ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, DiagnosticSeverity.ERROR); } } } @@ -330,7 +330,7 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { if (tomlTableNode.entries().isEmpty()) { reportDiagnostic(tomlTableNode, errorMessage, - ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); return PackageDescriptor.from(defaultOrg(), defaultName(this.projectPath), defaultVersion()); } @@ -338,7 +338,7 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { TopLevelNode topLevelPkgNode = tomlTableNode.entries().get(PACKAGE); if (topLevelPkgNode == null || topLevelPkgNode.kind() != TomlType.TABLE) { reportDiagnostic(tomlTableNode, errorMessage, - ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); return PackageDescriptor.from(defaultOrg(), defaultName(this.projectPath), defaultVersion()); } @@ -350,7 +350,7 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { org = defaultOrg().value(); reportDiagnostic(pkgNode, "missing key 'org' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'org = \"" + org + "\"'", - ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); } name = getStringValueFromTomlTableNode(pkgNode, "name"); @@ -358,7 +358,7 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { name = defaultName(this.projectPath).value(); reportDiagnostic(pkgNode, "missing key 'name' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'name = \"" + name + "\"'", - ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); } version = getStringValueFromTomlTableNode(pkgNode, VERSION); @@ -366,7 +366,7 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { version = defaultVersion().value().toString(); reportDiagnostic(pkgNode, "missing key 'version' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'version = \"" + version + "\"'", - ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); } @@ -404,7 +404,7 @@ private void validateIconPathForPng(String icon, TomlTableNode pkgNode) { // if file path does not exist, throw this error reportDiagnostic(pkgNode.entries().get(ICON), "could not locate icon path '" + icon + "'", - "error.invalid.path", DiagnosticSeverity.ERROR); + ProjectDiagnosticErrorCode.INVALID_PATH, DiagnosticSeverity.ERROR); } else { // validate file content // if other file types renamed as png, throw this error @@ -412,7 +412,7 @@ private void validateIconPathForPng(String icon, TomlTableNode pkgNode) { if (!FileUtils.isValidPng(iconPath)) { reportDiagnostic(pkgNode.entries().get("icon"), "invalid 'icon' under [package]: 'icon' can only have 'png' images", - "error.invalid.icon", DiagnosticSeverity.ERROR); + ProjectDiagnosticErrorCode.INVALID_ICON, DiagnosticSeverity.ERROR); } } catch (IOException e) { // should not reach to this line @@ -533,7 +533,7 @@ private PackageManifest.Platform getDependencyPlatform(TopLevelNode dependencyNo if (Files.notExists(path)) { reportDiagnostic(platformEntryTable.entries().get("path"), "could not locate dependency path '" + pathValue + "'", - "error.invalid.path", DiagnosticSeverity.ERROR); + ProjectDiagnosticErrorCode.INVALID_PATH, DiagnosticSeverity.ERROR); } } platformEntryMap.put("path", @@ -610,10 +610,10 @@ private List getLocalRepoDependencies() { // TODO: Fix code and messageFormat parameters in usages. private void reportDiagnostic(TopLevelNode tomlTableNode, String message, - String messageFormat, + ProjectDiagnosticErrorCode errorCode, DiagnosticSeverity severity) { DiagnosticInfo diagnosticInfo = - new DiagnosticInfo(messageFormat, messageFormat, severity); + new DiagnosticInfo(errorCode.diagnosticId(), errorCode.messageKey(), severity); TomlDiagnostic tomlDiagnostic = new TomlDiagnostic( tomlTableNode.location(), diagnosticInfo, @@ -814,12 +814,12 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String if (topLevelNode == null) { if (!key.equals("targetModule")) { reportDiagnostic(toolNode, errorMessage, - ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML, DiagnosticSeverity.ERROR); return null; } reportDiagnostic(toolNode, errorMessage + " Default module will be taken as target module.", - ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML.diagnosticId(), + ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML, DiagnosticSeverity.WARNING); return null; } @@ -830,18 +830,18 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String if (!key.equals("targetModule")) { reportDiagnostic(toolNode, "empty string found for key '[" + key + "]' in table '[tool." + toolCode + "]'.", - ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY.diagnosticId(), + ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, DiagnosticSeverity.ERROR); return null; } reportDiagnostic(toolNode, "empty string found for key '[" + key + "]' in table '[tool." + toolCode + "]'. " + "Default module will be taken as the target module", - ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY.diagnosticId(), + ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, DiagnosticSeverity.WARNING); return null; } else if (ToolNodeValueType.NON_STRING.equals(toolNodeValueType)) { reportDiagnostic(toolNode, "incompatible type found for key '[" + key + "]': expected 'STRING'", - ProjectDiagnosticErrorCode.INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY.diagnosticId(), + ProjectDiagnosticErrorCode.INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY, DiagnosticSeverity.ERROR); return null; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 80badbc61d98..92d608934df9 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -27,29 +27,36 @@ */ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { - // TODO: Assign specific codes for each error type and sort the error codes. - INVALID_BALA_FILE("BCE5000", "invalid.bala.file"), + // Error codes used in DependencyManifestBuilder. OLD_DEPENDENCIES_TOML("BCE5001", "old.dependencies.toml"), LOCAL_PACKAGES_IN_DEPENDENCIES_TOML("BCE5002", "local.packages.in.dependencies.toml"), CORRUPTED_DEPENDENCIES_TOML("BCE5003", "corrupted.dependencies.toml"), - INCOMPATIBLE_DEPENDENCY_VERSIONS("BCE5004", "incompatible.dependency.versions"), - PACKAGE_NOT_FOUND("BCE5005", "package.not.found"), - MISSING_PKG_INFO_IN_BALLERINA_TOML("BCE5006", "missing.package.info"), - DEPRECATED_PACKAGE("BCE5007", "deprecated.package"), - BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5008", "built.with.older.sl.update.distribution"), - CUSTOM_REPOSITORY_NOT_FOUND("BCE5009", "custom.repository.not.found"), - // Error codes related to build tools starting from BCE5400. - MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5400", "missing.tool.properties"), - INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5401", "incompatible.tool.properties"), - EMPTY_TOOL_PROPERTY("BCE5402", "empty.tool.properties"), - TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5403", "tool.options.validation.skipped"), - RECURRING_TOOL_PROPERTIES("BCE5404", "recurring.tool.properties"), - BUILD_TOOL_NOT_FOUND("BCE5405", "build.tool.not.found"), + // Error codes used during dependency resolution. + INCOMPATIBLE_DEPENDENCY_VERSIONS("BCE5101", "incompatible.dependency.versions"), + PACKAGE_NOT_FOUND("BCE5102", "package.not.found"), + DEPRECATED_PACKAGE("BCE5103", "deprecated.package"), + BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5104", "built.with.older.sl.update.distribution"), + CUSTOM_REPOSITORY_NOT_FOUND("BCE5105", "custom.repository.not.found"), - MODULE_NOT_FOUND("BCE5100", "module.not.found"), - UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5200", "unsupported.compiler.plugin.type"), - CONFLICTING_PLATFORM_JAR_FILES("BCE5300", "conflicting.platform.jars.type"), + // Error codes used in the ManifestBuilder + MISSING_PKG_INFO_IN_BALLERINA_TOML("BCE5201", "missing.package.info"), + INVALID_PATH("BCE5202", "error.invalid.path"), + INVALID_ICON("BCE5203", "error.invalid.icon"), + + // Error codes related to build tools. + MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5401", "missing.tool.properties"), + INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5402", "incompatible.tool.properties"), + EMPTY_TOOL_PROPERTY("BCE5403", "empty.tool.properties"), + TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5404", "tool.options.validation.skipped"), + RECURRING_TOOL_PROPERTIES("BCE5405", "recurring.tool.properties"), + BUILD_TOOL_NOT_FOUND("BCE5406", "build.tool.not.found"), + + // Error codes used for compiler plugins. + UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5301", "unsupported.compiler.plugin.type"), + + // Error codes used for Jar resolving. + CONFLICTING_PLATFORM_JAR_FILES("BCE5501", "conflicting.platform.jars.type"), ; private final String diagnosticId; From 1ba08aca87e95244c31ae102f846d3e57fdb34d9 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 22 Jan 2024 15:15:54 +0530 Subject: [PATCH 122/209] Fix NPE from daemon strand --- .../io/ballerina/runtime/internal/scheduling/Scheduler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index 1a82952d48f8..174e66dfe1c9 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -455,7 +455,9 @@ public void unblockStrand(Strand strand) { } private void cleanUp(Strand justCompleted) { - justCompleted.scheduler = null; + if (daemonStrand != null && !daemonStrand.scheduler.equals(justCompleted.scheduler)) { + justCompleted.scheduler = null; + } justCompleted.frames = null; justCompleted.waitingContexts = null; From abbe8839e2efcc836638f248082bb1a045149fe0 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Mon, 22 Jan 2024 19:54:16 +0530 Subject: [PATCH 123/209] Fail compilation for validation failure in tool options --- .../cli/task/RunBallerinaPreBuildToolsTask.java | 12 +++++++++++- .../Ballerina.toml | 5 +++++ .../build-tool-with-invalid-missing-optional.txt | 8 ++++++++ .../build-tool-with-invalid-missing-optional.txt | 8 ++++++++ .../internal/ProjectDiagnosticErrorCode.java | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index e56ea9a8e105..ff634cfd0f52 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -69,9 +69,20 @@ public void execute(Project project) { ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); for (Tool tool : tools) { String commandName = tool.getType(); + ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); boolean hasOptionErrors = false; try { hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); + if (hasOptionErrors) { + DiagnosticInfo diagnosticInfo = new DiagnosticInfo( + ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_FAILED.diagnosticId(), + ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_FAILED.messageKey(), + DiagnosticSeverity.ERROR); + PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, + tool.getType()); + toolContext.reportDiagnostic(diagnostic); + toolContextMap.put(tool.getId(), toolContext); + } } catch (IOException e) { outStream.println("WARNING: Skipping validation of tool options for tool '" + tool.getType() + "' due to: " + e.getMessage()); @@ -79,7 +90,6 @@ public void execute(Project project) { if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { try { CodeGeneratorTool targetTool = getTargetTool(commandName, buildRunners); - ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); if (targetTool == null) { // TODO: Installing tool if not found to be implemented at a later phase DiagnosticInfo diagnosticInfo = new DiagnosticInfo( diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/Ballerina.toml index 9026646c5944..93319729eac8 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/Ballerina.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/Ballerina.toml @@ -8,3 +8,8 @@ id = "generate-delivery-client" filePath = "delivery.json" targetModule = "delivery" options.limit = "2" + +[[tool.openapi]] +id = "generate-delivery-client-1" +filePath = "delivery.json" +targetModule = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt index c0b09dd05759..415d890d5c30 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt @@ -1,2 +1,10 @@ +ERROR [Ballerina.toml:(12:1,15:24)] missing required field 'mode' ERROR [Ballerina.toml:(10:1,10:20)] missing required field 'mode' ERROR [Ballerina.toml:(10:17,10:20)] incompatible type for key 'limit': expected 'INTEGER', found 'STRING' +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'openapi' due to: No tool options found +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt index c0b09dd05759..415d890d5c30 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt @@ -1,2 +1,10 @@ +ERROR [Ballerina.toml:(12:1,15:24)] missing required field 'mode' ERROR [Ballerina.toml:(10:1,10:20)] missing required field 'mode' ERROR [Ballerina.toml:(10:17,10:20)] incompatible type for key 'limit': expected 'INTEGER', found 'STRING' +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +WARNING: Skipping validation of tool options for tool 'openapi' due to: No tool options found +WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Compiling source + foo/winery:0.1.0 diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 92d608934df9..2ff17bfefee6 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -51,6 +51,7 @@ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5404", "tool.options.validation.skipped"), RECURRING_TOOL_PROPERTIES("BCE5405", "recurring.tool.properties"), BUILD_TOOL_NOT_FOUND("BCE5406", "build.tool.not.found"), + TOOL_OPTIONS_VALIDATION_FAILED("BCE5407", "tool.options.validation.failed"), // Error codes used for compiler plugins. UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5301", "unsupported.compiler.plugin.type"), From 5d3a330a6dd18f7e1017e64320e7e76d1226fff2 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 23 Jan 2024 10:30:17 +0530 Subject: [PATCH 124/209] Improve fix logic --- .../io/ballerina/runtime/internal/scheduling/Scheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index 174e66dfe1c9..18727c685509 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -455,7 +455,7 @@ public void unblockStrand(Strand strand) { } private void cleanUp(Strand justCompleted) { - if (daemonStrand != null && !daemonStrand.scheduler.equals(justCompleted.scheduler)) { + if (daemonStrand != null && !daemonStrand.equals(justCompleted)) { justCompleted.scheduler = null; } justCompleted.frames = null; From 131204c36c6fecb9beb2abd63948ac7dbf3080db Mon Sep 17 00:00:00 2001 From: mindula Date: Tue, 23 Jan 2024 15:15:24 +0530 Subject: [PATCH 125/209] Fix rename position in extract to local variable and constant code actions --- .../providers/ExtractToConstantCodeAction.java | 12 ++++++------ .../providers/ExtractToLocalVarCodeAction.java | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToConstantCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToConstantCodeAction.java index deda1261b1d4..e0b8080d23f7 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToConstantCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToConstantCodeAction.java @@ -117,7 +117,7 @@ public List getCodeActions(CodeActionContext context, CodeAction codeAction = CodeActionUtil.createCodeAction(CommandConstants.EXTRACT_TO_CONSTANT, textEdits, context.fileUri(), CodeActionKind.RefactorExtract); CodeActionUtil.addRenamePopup(context, codeAction, CommandConstants.RENAME_COMMAND_TITLE_FOR_CONSTANT, - getRenamePosition(textEdits.get(1).getRange().getStart(), addNewLineAtStart)); + getRenamePosition(textEdits.get(1).getRange(), addNewLineAtStart)); return Collections.singletonList(codeAction); } @@ -127,7 +127,7 @@ public List getCodeActions(CodeActionContext context, CodeAction codeAction = CodeActionUtil.createCodeAction(CommandConstants.EXTRACT_TO_CONSTANT, textEdits, context.fileUri(), CodeActionKind.RefactorExtract); CodeActionUtil.addRenamePopup(context, codeAction, CommandConstants.RENAME_COMMAND_TITLE_FOR_CONSTANT, - getRenamePosition(textEdits.get(1).getRange().getStart(), addNewLineAtStart)); + getRenamePosition(textEdits.get(1).getRange(), addNewLineAtStart)); return Collections.singletonList(codeAction); } @@ -141,7 +141,7 @@ public List getCodeActions(CodeActionContext context, LinkedHashMap renamePositionMap = new LinkedHashMap<>(); nodeList.forEach(extractableNode -> renamePositionMap.put(extractableNode.toSourceCode().strip(), - getRenamePosition(PositionUtil.toRange(extractableNode.lineRange()).getStart(), + getRenamePosition(PositionUtil.toRange(extractableNode.lineRange()), addNewLineAtStart))); return Collections.singletonList( CodeActionUtil.createCodeAction(CommandConstants.EXTRACT_TO_CONSTANT, @@ -171,13 +171,13 @@ private boolean isExpressionNode(Node node) { return node instanceof StatementNode || node instanceof ModuleMemberDeclarationNode; } - private Position getRenamePosition(Position replacePosition, boolean addNewLineAtStart) { + private Position getRenamePosition(Range range, boolean addNewLineAtStart) { // line position will increment by one due to const declaration statement - int line = replacePosition.getLine() + 1; + int line = range.getEnd().getLine() + 1; if (addNewLineAtStart) { line += 1; } - return new Position(line, replacePosition.getCharacter()); + return new Position(line, range.getStart().getCharacter()); } @Override diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java index 6620d250667d..732500a47293 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/ExtractToLocalVarCodeAction.java @@ -139,7 +139,7 @@ public List getCodeActions(CodeActionContext context, CodeAction codeAction = CodeActionUtil.createCodeAction(CommandConstants.EXTRACT_TO_VARIABLE, textEdits, context.fileUri(), CodeActionKind.RefactorExtract); CodeActionUtil.addRenamePopup(context, codeAction, CommandConstants.RENAME_COMMAND_TITLE_FOR_VARIABLE, - getRenamePosition(textEdits.get(1).getRange().getStart())); + getRenamePosition(textEdits.get(1).getRange())); return Collections.singletonList(codeAction); } @@ -165,7 +165,7 @@ public List getCodeActions(CodeActionContext context, String key = extractableNode.toSourceCode().strip(); textEditMap.put(key, getTextEdits(context, tSymbol.get(), extractableNode, statementNode)); - renamePositionMap.put(key, getRenamePosition(PositionUtil.toRange(extractableNode.lineRange()).getStart())); + renamePositionMap.put(key, getRenamePosition(PositionUtil.toRange(extractableNode.lineRange()))); }); if (lsClientCapabilities.getInitializationOptions().isPositionalRefactorRenameSupported()) { @@ -198,8 +198,8 @@ private List getTextEdits(CodeActionContext context, TypeSymbol typeSy return List.of(varDeclEdit, replaceEdit); } - private Position getRenamePosition(Position position) { - return new Position(position.getLine() + 1, position.getCharacter()); + private Position getRenamePosition(Range range) { + return new Position(range.getEnd().getLine() + 1, range.getStart().getCharacter()); } private static List getPossibleExpressionNodes(Node node) { From d147b64b7837380fe0036171eabfe7e5307f76c0 Mon Sep 17 00:00:00 2001 From: mindula Date: Tue, 23 Jan 2024 15:15:42 +0530 Subject: [PATCH 126/209] Add tests --- .../codeaction/ExtractToConstantTest.java | 3 +- .../config/extractTwoLinesToConstant.json | 59 +++++++++++++++++++ .../source/extractToConstant.bal | 3 + 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/config/extractTwoLinesToConstant.json diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ExtractToConstantTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ExtractToConstantTest.java index c76a79ebd2d5..cefff718e58c 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ExtractToConstantTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ExtractToConstantTest.java @@ -71,7 +71,8 @@ public Object[][] dataProvider() { {"extractNumericLiteralInUnaryExprToConstant.json"}, {"extractNumericLiteralInUnaryExprToConstant2.json"}, {"extractExprToConstant1.json"}, - {"extractExprToConstant2.json"} + {"extractExprToConstant2.json"}, + {"extractTwoLinesToConstant.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/config/extractTwoLinesToConstant.json b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/config/extractTwoLinesToConstant.json new file mode 100644 index 000000000000..a8e7bd7b2599 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/config/extractTwoLinesToConstant.json @@ -0,0 +1,59 @@ +{ + "range": { + "start": { + "line": 26, + "character": 13 + }, + "end": { + "line": 27, + "character": 18 + } + }, + "source": "extractToConstant.bal", + "expected": [ + { + "title": "Extract to constant", + "kind": "refactor.extract", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "const string CONST = \"abc\"\n + \"def\";\n" + }, + { + "range": { + "start": { + "line": 26, + "character": 13 + }, + "end": { + "line": 27, + "character": 18 + } + }, + "newText": "CONST" + } + ], + "command": { + "title": "Rename constant", + "command": "ballerina.action.positional.rename", + "arguments": [ + "extractToConstant.bal", + { + "line": 28, + "character": 13 + } + ] + }, + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/source/extractToConstant.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/source/extractToConstant.bal index c17dffb96115..d66d4c56ccf7 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/source/extractToConstant.bal +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-constant/source/extractToConstant.bal @@ -23,3 +23,6 @@ const int CONST1 = 10 + 20; int unaryNumericExpr = -100; boolean unaryLogicalExpr = !true; + +string str = "abc" + + "def"; From 4ba5b8d6f3644e9e8f312a661ea7b41ba77933a2 Mon Sep 17 00:00:00 2001 From: mindula Date: Tue, 23 Jan 2024 15:16:12 +0530 Subject: [PATCH 127/209] Fix failing tests --- .../config/extractToVariableInQueryExpression.json | 2 +- .../config/extractToVariableInTableConstructor.json | 2 +- .../config/extractToVariableInTableConstructor2.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInQueryExpression.json b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInQueryExpression.json index f2be908fbbca..c5a1e8d06e4b 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInQueryExpression.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInQueryExpression.json @@ -48,7 +48,7 @@ "arguments": [ "extractToVariableInQueryExpression.bal", { - "line": 3, + "line": 4, "character": 24 } ] diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor.json b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor.json index 3b7b1bb47622..975f9b02f3bf 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor.json @@ -48,7 +48,7 @@ "arguments": [ "extractToVariableInTableConstructor.bal", { - "line": 6, + "line": 9, "character": 30 } ] diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor2.json index 59c6e0b0eb49..a16420363e2a 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor2.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/extract-to-local-variable/config/extractToVariableInTableConstructor2.json @@ -48,7 +48,7 @@ "arguments": [ "extractToVariableInTableConstructor.bal", { - "line": 13, + "line": 16, "character": 21 } ] From f44d2ecab8832bce5c197693b5be2834d8c1dd32 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 23 Jan 2024 15:56:18 +0530 Subject: [PATCH 128/209] Address suggestions --- .../io/ballerina/runtime/internal/scheduling/Scheduler.java | 3 ++- .../java/io/ballerina/runtime/internal/scheduling/Strand.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index 18727c685509..c90dfd7dd84a 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -89,6 +89,7 @@ public class Scheduler { public static void setDaemonStrand(Strand strand) { daemonStrand = strand; + daemonStrand.isDaemon = true; } public static Strand getDaemonStrand() { @@ -455,7 +456,7 @@ public void unblockStrand(Strand strand) { } private void cleanUp(Strand justCompleted) { - if (daemonStrand != null && !daemonStrand.equals(justCompleted)) { + if (!justCompleted.isDaemon) { justCompleted.scheduler = null; } justCompleted.frames = null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java index 652795c5b68c..58cf3e00ccb4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java @@ -90,6 +90,7 @@ public class Strand { public Stack trxContexts; private State state; private final ReentrantLock strandLock; + public boolean isDaemon = false; public Strand(String name, StrandMetadata metadata, Scheduler scheduler, Strand parent, Map properties) { From d4f514b63dce28a4904ac3e21cc278607893631f Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 23 Jan 2024 20:58:07 +0530 Subject: [PATCH 129/209] Update tests to have assertions --- .../test/types/regexp/RegExpTypeTest.java | 3 ++- .../test-src/types/regexp/regexp_type_test.bal | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/regexp/RegExpTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/regexp/RegExpTypeTest.java index 432b9fd55425..fcda49704652 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/regexp/RegExpTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/regexp/RegExpTypeTest.java @@ -49,7 +49,8 @@ public Object[] dataToTestRegExp() { "testAssignabilityWithRegExp", "testSubtypingWithRegExp", "testRegExpWithVar", - "testRegExpWithUserDefinedType" + "testRegExpWithUserDefinedType", + "testRegExpReadonlyLocalVars" }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal index e94175be7a77..00f785e2f7b0 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/regexp/regexp_type_test.bal @@ -117,9 +117,14 @@ type Foo record {| Foo & readonly rf = {e: 1, f: re `test`}; function testRegExpReadonlyLocalVars() { - string:RegExp & readonly _ = re `test`; - T1 & readonly _ = re `test`; - (T2 & readonly) & string:RegExp _ = re `test`; + string:RegExp & readonly r1 = re `test`; + assertEquality(true, r1 is readonly); + + T1 & readonly r2 = re `test`; + assertEquality(true, r2 is readonly); + + (T2 & readonly) & string:RegExp r3 = re `test`; + assertEquality(true, r3 is readonly); } const ASSERTION_ERROR_REASON = "AssertionError"; From 0ae6e361aead9db6235956d2a6dd141a62ca8396 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 23 Jan 2024 20:58:32 +0530 Subject: [PATCH 130/209] Add negative tests --- .../test/types/intersection/IntersectionTypeTest.java | 2 ++ .../types/intersection/test_intersection_type_negative.bal | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java index c10ccccee212..cb93a1b34b6f 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java @@ -86,6 +86,8 @@ public void testImmutableTypesNegative() { validateError(result, index++, "invalid intersection type '(Baz & readonly)': no intersection", 32, 45); validateError(result, index++, "incompatible types: 'Y' is not a record", 42, 6); + validateError(result, index++, "incompatible types: expected " + + "'((stream|ballerina/lang.string:0.0.0:RegExp) & readonly)', found 'stream'", 48, 48); assertEquals(result.getErrorCount(), index); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal index f972c6678f52..9f6d17c1eaea 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal @@ -43,3 +43,9 @@ type Z record { X x; Y y; }; + +function testUnsupportedIntersectionWithReadonly(stream strm) { + (stream|string:RegExp) & readonly x = strm; +} + + From 4fd2d81f4297ddcd6300a721cd6ef28529211834 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 23 Jan 2024 21:18:34 +0530 Subject: [PATCH 131/209] Log error for query actions with collect clause --- .../internal/diagnostics/DiagnosticErrorCode.java | 3 ++- .../compiler/internal/parser/BallerinaParser.java | 9 +++++++-- .../main/resources/syntax_diagnostic_message.properties | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/DiagnosticErrorCode.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/DiagnosticErrorCode.java index c4ccdc215f19..b19909575930 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/DiagnosticErrorCode.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/diagnostics/DiagnosticErrorCode.java @@ -359,7 +359,8 @@ public enum DiagnosticErrorCode implements DiagnosticCode { ERROR_ANNOTATIONS_NOT_ALLOWED_FOR_TUPLE_REST_DESCRIPTOR("BCE0684", "error.annotations.not.allowed.for.tuple.rest.descriptor"), ERROR_INVALID_RE_SYNTAX_CHAR("BCE0685", "error.invalid.syntax.char"), - ERROR_MORE_CLAUSES_AFTER_COLLECT_CLAUSE("BCE0686", "error.more.clauses.after.collect.clause") + ERROR_MORE_CLAUSES_AFTER_COLLECT_CLAUSE("BCE0686", "error.more.clauses.after.collect.clause"), + ERROR_COLLECT_CLAUSE_IN_QUERY_ACTION("BCE0687", "error.collect.clause.in.query.action") ; String diagnosticId; diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java index d306a0148dd5..fe2e35187276 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java @@ -11953,7 +11953,7 @@ private STNode parseQueryExprRhs(STNode queryConstructType, boolean isRhsExpr, b (!isNestedQueryExpr() || (selectClause == null && collectClause == null))) { STNode intermediateClauses = STNodeFactory.createNodeList(clauses); STNode queryPipeline = STNodeFactory.createQueryPipelineNode(fromClause, intermediateClauses); - return parseQueryAction(queryConstructType, queryPipeline, selectClause); + return parseQueryAction(queryConstructType, queryPipeline, selectClause, collectClause); } if (selectClause == null && collectClause == null) { @@ -13554,7 +13554,8 @@ private STNode parseFieldAccessIdentifier(boolean isInConditionalExpr) { * @param selectClause Select clause if any This is only for validation. * @return Query action node */ - private STNode parseQueryAction(STNode queryConstructType, STNode queryPipeline, STNode selectClause) { + private STNode parseQueryAction(STNode queryConstructType, STNode queryPipeline, STNode selectClause, + STNode collectClause) { if (queryConstructType != null) { queryPipeline = SyntaxErrors.cloneWithLeadingInvalidNodeMinutiae(queryPipeline, queryConstructType, DiagnosticErrorCode.ERROR_QUERY_CONSTRUCT_TYPE_IN_QUERY_ACTION); @@ -13563,6 +13564,10 @@ private STNode parseQueryAction(STNode queryConstructType, STNode queryPipeline, queryPipeline = SyntaxErrors.cloneWithTrailingInvalidNodeMinutiae(queryPipeline, selectClause, DiagnosticErrorCode.ERROR_SELECT_CLAUSE_IN_QUERY_ACTION); } + if (collectClause != null) { + queryPipeline = SyntaxErrors.cloneWithTrailingInvalidNodeMinutiae(queryPipeline, collectClause, + DiagnosticErrorCode.ERROR_COLLECT_CLAUSE_IN_QUERY_ACTION); + } startContext(ParserRuleContext.DO_CLAUSE); STNode doKeyword = parseDoKeyword(); diff --git a/compiler/ballerina-parser/src/main/resources/syntax_diagnostic_message.properties b/compiler/ballerina-parser/src/main/resources/syntax_diagnostic_message.properties index 45c38e5854ab..8845c0b8f47c 100644 --- a/compiler/ballerina-parser/src/main/resources/syntax_diagnostic_message.properties +++ b/compiler/ballerina-parser/src/main/resources/syntax_diagnostic_message.properties @@ -275,6 +275,7 @@ error.invalid.token=invalid token ''{0}'' error.invalid.expression.statement=invalid expression statement error.invalid.array.length=invalid array length: array length should be a non-negative integer error.select.clause.in.query.action=select clause in query action +error.collect.clause.in.query.action=collect clause in query action error.more.clauses.after.select.clause=more clauses after select clause error.more.clauses.after.collect.clause=more clauses after collect clause error.query.construct.type.in.query.action= query construct type in query action From 445546bf2e1cb9396ec6405f72135b50615d54f4 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 23 Jan 2024 21:27:57 +0530 Subject: [PATCH 132/209] Add negative tests for query actions --- .../test/query/QueryNegativeTests.java | 11 +++++++++ ...uery_action_with_final_clause_negative.bal | 23 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_with_final_clause_negative.bal diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryNegativeTests.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryNegativeTests.java index 30d72d802dc4..29c4fcdc886b 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryNegativeTests.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryNegativeTests.java @@ -189,4 +189,15 @@ public void testQueryExpressionWithMismatchedReturnType() { validateError(compileResult, index++, "missing non-defaultable required record field 'x'", 47, 24); Assert.assertEquals(compileResult.getDiagnostics().length, index); } + + @Test(description = "Test the query actions having select or collect clauses") + public void testQueryActionsWithInvalidFinalClause() { + CompileResult compileResult = BCompileUtil.compile( + "test-src/query/query_action_with_final_clause_negative.bal"); + int index = 0; + validateError(compileResult, index++, "select clause in query action", 3, 5); + validateError(compileResult, index++, "collect clause in query action", 11, 5); + validateError(compileResult, index++, "collect clause in query action", 19, 5); + Assert.assertEquals(compileResult.getDiagnostics().length, index); + } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_with_final_clause_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_with_final_clause_negative.bal new file mode 100644 index 000000000000..3f1e885c9be9 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_with_final_clause_negative.bal @@ -0,0 +1,23 @@ +function queryActionWithSelectClause() { + from var i in [1, 2, 3, 4] + select i + do { + + }; +} + +function queryActionWithCollectClasue1() { + from var i in [1, 2, 3, 4] + collect i + do { + + }; +} + +function queryActionWithCollectClasue2() { + from var i in [1, 2, 3, 4] + collect sum(i) + do { + + }; +} From 1fef70fa85331963fa1090e3de179fb45723f13d Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 24 Jan 2024 12:50:59 +0530 Subject: [PATCH 133/209] Reorder error diagnostic codes --- .../io/ballerina/cli/task/CompileTask.java | 2 +- .../internal/ProjectDiagnosticErrorCode.java | 42 +++++++++---------- .../projects/util/ProjectConstants.java | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index 7a76192c0cc9..f18876ba76e4 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -218,7 +218,7 @@ public void execute(Project project) { err.println(d); } }); - //Report build tool execution diagnostics + // Report build tool execution diagnostics if (project.getToolContextMap() != null) { for (ToolContext tool : project.getToolContextMap().values()) { diagnostics.addAll(tool.diagnostics()); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java index 2ff17bfefee6..5981655136e8 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectDiagnosticErrorCode.java @@ -27,34 +27,34 @@ */ public enum ProjectDiagnosticErrorCode implements DiagnosticCode { + // Error codes used in the ManifestBuilder + MISSING_PKG_INFO_IN_BALLERINA_TOML("BCE5001", "missing.package.info"), + INVALID_PATH("BCE5002", "error.invalid.path"), + INVALID_ICON("BCE5003", "error.invalid.icon"), + // Error codes used in DependencyManifestBuilder. - OLD_DEPENDENCIES_TOML("BCE5001", "old.dependencies.toml"), - LOCAL_PACKAGES_IN_DEPENDENCIES_TOML("BCE5002", "local.packages.in.dependencies.toml"), - CORRUPTED_DEPENDENCIES_TOML("BCE5003", "corrupted.dependencies.toml"), + OLD_DEPENDENCIES_TOML("BCE5101", "old.dependencies.toml"), + LOCAL_PACKAGES_IN_DEPENDENCIES_TOML("BCE5102", "local.packages.in.dependencies.toml"), + CORRUPTED_DEPENDENCIES_TOML("BCE5103", "corrupted.dependencies.toml"), // Error codes used during dependency resolution. - INCOMPATIBLE_DEPENDENCY_VERSIONS("BCE5101", "incompatible.dependency.versions"), - PACKAGE_NOT_FOUND("BCE5102", "package.not.found"), - DEPRECATED_PACKAGE("BCE5103", "deprecated.package"), - BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5104", "built.with.older.sl.update.distribution"), - CUSTOM_REPOSITORY_NOT_FOUND("BCE5105", "custom.repository.not.found"), - - // Error codes used in the ManifestBuilder - MISSING_PKG_INFO_IN_BALLERINA_TOML("BCE5201", "missing.package.info"), - INVALID_PATH("BCE5202", "error.invalid.path"), - INVALID_ICON("BCE5203", "error.invalid.icon"), + INCOMPATIBLE_DEPENDENCY_VERSIONS("BCE5201", "incompatible.dependency.versions"), + PACKAGE_NOT_FOUND("BCE5202", "package.not.found"), + DEPRECATED_PACKAGE("BCE5203", "deprecated.package"), + BUILT_WITH_OLDER_SL_UPDATE_DISTRIBUTION("BCE5204", "built.with.older.sl.update.distribution"), + CUSTOM_REPOSITORY_NOT_FOUND("BCE5205", "custom.repository.not.found"), // Error codes related to build tools. - MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5401", "missing.tool.properties"), - INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5402", "incompatible.tool.properties"), - EMPTY_TOOL_PROPERTY("BCE5403", "empty.tool.properties"), - TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5404", "tool.options.validation.skipped"), - RECURRING_TOOL_PROPERTIES("BCE5405", "recurring.tool.properties"), - BUILD_TOOL_NOT_FOUND("BCE5406", "build.tool.not.found"), - TOOL_OPTIONS_VALIDATION_FAILED("BCE5407", "tool.options.validation.failed"), + MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML("BCE5301", "missing.tool.properties"), + INCOMPATIBLE_TYPE_FOR_TOOL_PROPERTY("BCE5302", "incompatible.tool.properties"), + EMPTY_TOOL_PROPERTY("BCE5303", "empty.tool.properties"), + TOOL_OPTIONS_VALIDATION_SKIPPED("BCE5304", "tool.options.validation.skipped"), + RECURRING_TOOL_PROPERTIES("BCE5305", "recurring.tool.properties"), + BUILD_TOOL_NOT_FOUND("BCE5306", "build.tool.not.found"), + TOOL_OPTIONS_VALIDATION_FAILED("BCE5307", "tool.options.validation.failed"), // Error codes used for compiler plugins. - UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5301", "unsupported.compiler.plugin.type"), + UNSUPPORTED_COMPILER_PLUGIN_TYPE("BCE5401", "unsupported.compiler.plugin.type"), // Error codes used for Jar resolving. CONFLICTING_PLATFORM_JAR_FILES("BCE5501", "conflicting.platform.jars.type"), diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java index 491477724520..149440120bc3 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/util/ProjectConstants.java @@ -134,7 +134,7 @@ private ProjectConstants() {} public static final String CONFIG_DIR = ".config"; public static final String PROFILER_DIR_NAME = "profiler"; public static final String TOOL_CACHE_DIR = "tool-cache"; - public static final String TOOL_DIAGNOSTIC_CODE_PREFIX = "BCE54"; + public static final String TOOL_DIAGNOSTIC_CODE_PREFIX = "BCE53"; public static final String ORG = "org"; public static final String PACKAGE_NAME = "name"; public static final String LOCAL_TOOLS_JSON = "local-tools.json"; From 9e9f56a3ab11be8b8024c6999f26284995fb4868 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Fri, 26 Jan 2024 10:45:08 +0530 Subject: [PATCH 134/209] Remove setting scheduler null --- .../io/ballerina/runtime/internal/scheduling/Scheduler.java | 4 ---- .../java/io/ballerina/runtime/internal/scheduling/Strand.java | 1 - 2 files changed, 5 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java index c90dfd7dd84a..112832b002bf 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Scheduler.java @@ -89,7 +89,6 @@ public class Scheduler { public static void setDaemonStrand(Strand strand) { daemonStrand = strand; - daemonStrand.isDaemon = true; } public static Strand getDaemonStrand() { @@ -456,9 +455,6 @@ public void unblockStrand(Strand strand) { } private void cleanUp(Strand justCompleted) { - if (!justCompleted.isDaemon) { - justCompleted.scheduler = null; - } justCompleted.frames = null; justCompleted.waitingContexts = null; diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java index 58cf3e00ccb4..652795c5b68c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/scheduling/Strand.java @@ -90,7 +90,6 @@ public class Strand { public Stack trxContexts; private State state; private final ReentrantLock strandLock; - public boolean isDaemon = false; public Strand(String name, StrandMetadata metadata, Scheduler scheduler, Strand parent, Map properties) { From 4e1ee93f9c189dfea8f98518d36a509f778ed3fd Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 26 Jan 2024 11:08:02 +0530 Subject: [PATCH 135/209] Improve diagnostic logging --- .../task/RunBallerinaPreBuildToolsTask.java | 40 ++++++++++++++----- .../projects/internal/ManifestBuilder.java | 30 -------------- 2 files changed, 29 insertions(+), 41 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index ff634cfd0f52..f38d9ac2b35c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -26,6 +26,7 @@ import io.ballerina.projects.internal.PackageDiagnostic; import io.ballerina.projects.internal.ProjectDiagnosticErrorCode; import io.ballerina.toml.api.Toml; +import io.ballerina.toml.validator.schema.Schema; import io.ballerina.tools.diagnostics.Diagnostic; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; @@ -64,6 +65,7 @@ public void execute(Project project) { toolManifestDiagnostics.forEach(outStream::println); //Build tool execution + this.outStream.println("Executing Build Tools"); Map toolContextMap = new HashMap<>(); List tools = project.currentPackage().manifest().tools(); ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); @@ -84,8 +86,8 @@ public void execute(Project project) { toolContextMap.put(tool.getId(), toolContext); } } catch (IOException e) { - outStream.println("WARNING: Skipping validation of tool options for tool '" + tool.getType() + - "' due to: " + e.getMessage()); + outStream.println(String.format("WARNING: Skipping validation of tool options for tool %s(%s) " + + "due to: %s", tool.getType(), tool.getId(), e.getMessage())); } if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { try { @@ -103,21 +105,16 @@ public void execute(Project project) { toolContextMap.put(tool.getId(), toolContext); continue; } - this.outStream.println("Executing build tool '" + tool.getType() + - "' for tool configurations '" + tool.getId() + "'.\n"); + this.outStream.println(String.format("\n\t%s(%s)\n", tool.getType(), tool.getId())); targetTool.execute(toolContext); toolContext.diagnostics().forEach(outStream::println); - if (!Diagnostics.filterErrors(toolContext.diagnostics()).isEmpty()) { - outStream.println("WARNING: Execution of Build tool '" + tool.getType() + - "' for tool configurations '" + tool.getId() + "' contains errors\n"); - } toolContextMap.put(tool.getId(), toolContext); } catch (Exception e) { throw createLauncherException(e.getMessage()); } } else { - outStream.println("WARNING: Skipping execution of build tool '" + tool.getType() + - "' as tool configurations in Ballerina.toml contains errors\n"); + outStream.println(String.format("WARNING: Skipping execution of build tool %s(%s) as Ballerina.toml " + + "contains errors\n", tool.getType(), tool.getId() != null ? tool.getId() : "")); } } project.setToolContextMap(toolContextMap); @@ -134,10 +131,31 @@ private CodeGeneratorTool getTargetTool(String commandName, ServiceLoader requiredFields = schema.required(); + if (!requiredFields.isEmpty()) { + for (String field: requiredFields) { + DiagnosticInfo diagnosticInfo = new DiagnosticInfo( + ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML.diagnosticId(), + String.format("missing required optional field '%s'", field), + DiagnosticSeverity.ERROR); + PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, + toolName); + this.outStream.println(diagnostic); + } + return true; + } + this.outStream.println(String.format("WARNING: Skipping validation of tool options for tool %s due to: " + + "No tool options found", toolName)); + return false; + } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 534d5dab87f7..3a83a03792d2 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -266,16 +266,6 @@ private List getTools() { "targetModule", toolCode); Toml optionsToml = getToml(dependencyNode, "options"); TopLevelNode topLevelNode = dependencyNode.entries().get("options"); - if (topLevelNode == null) { - try { - validateEmptyOptionsToml(dependencyNode, toolCode); - } catch (IOException e) { - reportDiagnostic(dependencyNode, - "tool options validation skipped due to: " + e.getMessage(), - ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_SKIPPED, - DiagnosticSeverity.WARNING); - } - } TomlTableNode optionsNode = null; if (topLevelNode != null && topLevelNode.kind() == TomlType.TABLE) { optionsNode = (TomlTableNode) topLevelNode; @@ -305,17 +295,6 @@ private List getTools() { return tools; } - private void validateEmptyOptionsToml(TomlTableNode toolNode, String toolName) throws IOException { - Schema schema = Schema.from(FileUtils.readFileAsString(toolName + "-options-schema.json")); - List requiredFields = schema.required(); - if (!requiredFields.isEmpty()) { - for (String field: requiredFields) { - reportDiagnostic(toolNode, "missing required field '" + field + "'", - ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, DiagnosticSeverity.ERROR); - } - } - } - private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { // set defaults String org; @@ -816,11 +795,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String reportDiagnostic(toolNode, errorMessage, ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML, DiagnosticSeverity.ERROR); - return null; } - reportDiagnostic(toolNode, errorMessage + " Default module will be taken as target module.", - ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML, - DiagnosticSeverity.WARNING); return null; } ToolNodeValueType toolNodeValueType = getBuildToolTomlValueType(topLevelNode); @@ -832,12 +807,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String + toolCode + "]'.", ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, DiagnosticSeverity.ERROR); - return null; } - reportDiagnostic(toolNode, "empty string found for key '[" + key + "]' in table '[tool." - + toolCode + "]'. " + "Default module will be taken as the target module", - ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, - DiagnosticSeverity.WARNING); return null; } else if (ToolNodeValueType.NON_STRING.equals(toolNodeValueType)) { reportDiagnostic(toolNode, "incompatible type found for key '[" + key + "]': expected 'STRING'", From 11e04e1c8f5a7d1ecd9feacb5497b7f9bedb6bf2 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 26 Jan 2024 11:38:17 +0530 Subject: [PATCH 136/209] Update build command tests --- .../cli/task/RunBallerinaPreBuildToolsTask.java | 4 +++- ...uild-bal-project-with-build-tool-not-found.txt | 5 +++-- .../unix/build-bal-project-with-build-tool.txt | 5 ++++- .../unix/build-tool-with-diagnostics.txt | 7 ++++--- .../build-tool-with-invalid-missing-optional.txt | 9 +++++---- ...-tool-with-invalid-missing-toml-properties.txt | 5 +++-- .../build-tool-with-recurring-tool-properties.txt | 15 +++++++-------- ...uild-bal-project-with-build-tool-not-found.txt | 5 +++-- .../windows/build-bal-project-with-build-tool.txt | 6 +++++- .../windows/build-tool-with-diagnostics.txt | 7 ++++--- .../build-tool-with-invalid-missing-optional.txt | 9 +++++---- ...-tool-with-invalid-missing-toml-properties.txt | 5 +++-- .../build-tool-with-recurring-tool-properties.txt | 15 +++++++-------- 13 files changed, 56 insertions(+), 41 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index f38d9ac2b35c..706c0337de1b 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -65,9 +65,11 @@ public void execute(Project project) { toolManifestDiagnostics.forEach(outStream::println); //Build tool execution - this.outStream.println("Executing Build Tools"); Map toolContextMap = new HashMap<>(); List tools = project.currentPackage().manifest().tools(); + if (!tools.isEmpty()) { + this.outStream.println("\nExecuting Build Tools"); + } ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); for (Tool tool : tools) { String commandName = tool.getType(); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt index b216624c696a..44095dec267f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool-not-found.txt @@ -1,5 +1,6 @@ -WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json -WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found + +Executing Build Tools +WARNING: Skipping validation of tool options for tool grpc(generate-grpc-client) due to: Schema file not found: grpc-options-schema.json ERROR [grpc] Build tool 'grpc' not found Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt index e28b723405ce..6f3ef6b75b25 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt @@ -1,4 +1,7 @@ -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +Executing Build Tools + + openapi(generate-delivery-client) Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt index cfa2fa7a2cc5..6a396eb0dabd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt @@ -1,7 +1,8 @@ -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist -WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Executing Build Tools + + openapi(generate-delivery-client) +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt index 415d890d5c30..0294e2a26a97 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-optional.txt @@ -1,10 +1,11 @@ -ERROR [Ballerina.toml:(12:1,15:24)] missing required field 'mode' + +Executing Build Tools ERROR [Ballerina.toml:(10:1,10:20)] missing required field 'mode' ERROR [Ballerina.toml:(10:17,10:20)] incompatible type for key 'limit': expected 'INTEGER', found 'STRING' -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors -WARNING: Skipping validation of tool options for tool 'openapi' due to: No tool options found -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +ERROR [openapi] missing required optional field 'mode' +WARNING: Skipping execution of build tool openapi(generate-delivery-client-1) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt index 095355a47e6e..3c1973af6a65 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt @@ -1,6 +1,7 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. -WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Executing Build Tools +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt index cfe40f165d2c..7ea0d267e5b6 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt @@ -1,16 +1,15 @@ -WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool -WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist -WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Executing Build Tools + + openapi(generate-delivery-client) -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors -WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found -WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors +WARNING: Skipping validation of tool options for tool grpc(generate-grpc-client) due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping execution of build tool grpc(generate-grpc-client) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt index b216624c696a..44095dec267f 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool-not-found.txt @@ -1,5 +1,6 @@ -WARNING [Ballerina.toml:(6:1,9:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json -WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found + +Executing Build Tools +WARNING: Skipping validation of tool options for tool grpc(generate-grpc-client) due to: Schema file not found: grpc-options-schema.json ERROR [grpc] Build tool 'grpc' not found Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt index 14e0fea40bdf..6f3ef6b75b25 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt @@ -1,4 +1,8 @@ -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. + +Executing Build Tools + + openapi(generate-delivery-client) + Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt index cfa2fa7a2cc5..6a396eb0dabd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt @@ -1,7 +1,8 @@ -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist -WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Executing Build Tools + + openapi(generate-delivery-client) +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt index 415d890d5c30..0294e2a26a97 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-optional.txt @@ -1,10 +1,11 @@ -ERROR [Ballerina.toml:(12:1,15:24)] missing required field 'mode' + +Executing Build Tools ERROR [Ballerina.toml:(10:1,10:20)] missing required field 'mode' ERROR [Ballerina.toml:(10:17,10:20)] incompatible type for key 'limit': expected 'INTEGER', found 'STRING' -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors -WARNING: Skipping validation of tool options for tool 'openapi' due to: No tool options found -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +ERROR [openapi] missing required optional field 'mode' +WARNING: Skipping execution of build tool openapi(generate-delivery-client-1) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt index 095355a47e6e..3c1973af6a65 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-invalid-missing-toml-properties.txt @@ -1,6 +1,7 @@ ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. -WARNING [Ballerina.toml:(6:1,9:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors + +Executing Build Tools +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt index cfe40f165d2c..7ea0d267e5b6 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt @@ -1,16 +1,15 @@ -WARNING [Ballerina.toml:(12:1,15:24)] missing key '[targetModule]' in table '[tool.openapi]'. Default module will be taken as target module. ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool -WARNING [Ballerina.toml:(17:1,20:26)] tool options validation skipped due to: Schema file not found: grpc-options-schema.json -Executing build tool 'openapi' for tool configurations 'generate-delivery-client'. -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist -WARNING: Execution of Build tool 'openapi' for tool configurations 'generate-delivery-client' contains errors +Executing Build Tools + + openapi(generate-delivery-client) -WARNING: Skipping execution of build tool 'openapi' as tool configurations in Ballerina.toml contains errors +ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors -WARNING: Skipping validation of tool options for tool 'grpc' due to: No tool options found -WARNING: Skipping execution of build tool 'grpc' as tool configurations in Ballerina.toml contains errors +WARNING: Skipping validation of tool options for tool grpc(generate-grpc-client) due to: Schema file not found: grpc-options-schema.json +WARNING: Skipping execution of build tool grpc(generate-grpc-client) as Ballerina.toml contains errors Compiling source foo/winery:0.1.0 From 7c72eb51de65dc2c1c895a5bd0f8fb717d1e82df Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 26 Jan 2024 12:08:14 +0530 Subject: [PATCH 137/209] replace newlines in string formatting --- .../io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 706c0337de1b..f818740a3630 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -107,7 +107,7 @@ public void execute(Project project) { toolContextMap.put(tool.getId(), toolContext); continue; } - this.outStream.println(String.format("\n\t%s(%s)\n", tool.getType(), tool.getId())); + this.outStream.println(String.format("%n\t%s(%s)%n", tool.getType(), tool.getId())); targetTool.execute(toolContext); toolContext.diagnostics().forEach(outStream::println); toolContextMap.put(tool.getId(), toolContext); @@ -116,7 +116,7 @@ public void execute(Project project) { } } else { outStream.println(String.format("WARNING: Skipping execution of build tool %s(%s) as Ballerina.toml " + - "contains errors\n", tool.getType(), tool.getId() != null ? tool.getId() : "")); + "contains errors%n", tool.getType(), tool.getId() != null ? tool.getId() : "")); } } project.setToolContextMap(toolContextMap); From 02810a6c516d140f23830a6c3c42c7f9433e7e29 Mon Sep 17 00:00:00 2001 From: NipunaMadhushan Date: Fri, 26 Jan 2024 22:30:36 +0530 Subject: [PATCH 138/209] Filter configurable variables under separate category --- .../main/java/org/ballerinalang/docgen/Generator.java | 10 ++++++++-- .../ballerinalang/docgen/generator/model/Module.java | 6 ++++-- 2 files changed, 12 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 eb3a3f1182a9..ef1ef58691d7 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/Generator.java @@ -167,8 +167,14 @@ public static boolean setModuleFromSyntaxTree(Module module, SyntaxTree syntaxTr ((ModuleVariableDeclarationNode) node).visibilityQualifier().isPresent() && ((ModuleVariableDeclarationNode) node).visibilityQualifier().get().kind() .equals(SyntaxKind.PUBLIC_KEYWORD)) { - module.variables.add(getModuleVariable((ModuleVariableDeclarationNode) node, semanticModel, - module)); + DefaultableVariable defaultableVariable = getModuleVariable((ModuleVariableDeclarationNode) node, + semanticModel, module); + if (containsToken(((ModuleVariableDeclarationNode) node).qualifiers(), + SyntaxKind.CONFIGURABLE_KEYWORD)) { + module.configurables.add(defaultableVariable); + } else { + module.variables.add(defaultableVariable); + } } } } diff --git a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Module.java b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Module.java index 1f6d4a57619e..0a626c879580 100644 --- a/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Module.java +++ b/misc/docerina/src/main/java/org/ballerinalang/docgen/generator/model/Module.java @@ -76,7 +76,7 @@ public class Module extends ModuleMetaData { public List anyDataTypes = new ArrayList<>(); @Expose public List anyTypes = new ArrayList<>(); - + @Expose public List stringTypes = new ArrayList<>(); @Expose public List integerTypes = new ArrayList<>(); @@ -88,6 +88,8 @@ public class Module extends ModuleMetaData { public List enums = new ArrayList<>(); @Expose public List variables = new ArrayList<>(); - + @Expose + public List configurables = new ArrayList<>(); + @Expose public List resources = new ArrayList<>(); } From 04b52108f77b13f46e6d002c4f9243b113e9c860 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Sun, 28 Jan 2024 09:51:07 +0530 Subject: [PATCH 139/209] Update semver command help text --- .../src/main/resources/cli-help/ballerina-semver.help | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-semver.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-semver.help index a889a7fed04f..0e5b6ba1b156 100755 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-semver.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-semver.help @@ -6,14 +6,14 @@ SYNOPSIS DESCRIPTION - Compare the local package changes with any previously released package + Compare the local changes in the package with any previously released package version available in Ballerina Central. Provide suggestions for the next version based on the source code compatibility between the local changes and any specified previous release version. - Note: Validating SemVer compliance of standalone '.bal' files is not allowed. - + Note: This feature is experimental and has limited support for some advanced + language constructs. OPTIONS -d, --show-diff From 7c654d72aeb3fabbe421d1b85754494d0106a382 Mon Sep 17 00:00:00 2001 From: Dilhasha Date: Fri, 26 Jan 2024 14:40:08 +0530 Subject: [PATCH 140/209] Update bal deprecate command help --- .../src/main/resources/cli-help/ballerina-deprecate.help | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help index 93fba94ff9fd..861322ffc0cb 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help @@ -25,5 +25,8 @@ OPTIONS EXAMPLES - Deprecates the package ballerina/io:1.1.1 - bal deprecate ballerina/io:1.1.1 + Deprecate all versions of the package ballerina/io + $ bal deprecate ballerina/io + + Deprecate a specific version of the package ballerina/io + $ bal deprecate ballerina/io:1.1.1 From 1ab3b659fc2270422525e6f73826f81ec0b0b850 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 29 Jan 2024 12:11:29 +0530 Subject: [PATCH 141/209] Fix CustomToolClassLoader linkage issue --- .../cli/launcher/CustomToolClassLoader.java | 71 ++++++++++++++++--- 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java index 12acd8baa60a..a2f89511243f 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java @@ -18,8 +18,13 @@ package io.ballerina.cli.launcher; +import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.List; /** * Custom class loader used to load the tool implementation classes. @@ -28,23 +33,71 @@ * @since 2201.8.0 */ public class CustomToolClassLoader extends URLClassLoader { + private final ClassLoader system; public CustomToolClassLoader(URL[] urls, ClassLoader parent) { super(urls, parent); + system = getSystemClassLoader(); } @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - try { - // Load from parent if cli or picocli classes. This is to avoid SPI and class loading issues - if (name.startsWith("io.ballerina.cli") || name.startsWith("picocli")) { - return super.loadClass(name, resolve); + Class loadedClass = findLoadedClass(name); + if (loadedClass == null) { + try { + // First, try to load the class from the URLs + loadedClass = findClass(name); + } catch (ClassNotFoundException e) { + try { + // If not found, delegate to the parent + loadedClass = super.loadClass(name, resolve); + } catch (ClassNotFoundException e2) { + // If not found, delegate to the system class loader + if (system != null) { + loadedClass = system.loadClass(name); + } + } } - // First, try to load the class from the URLs - return findClass(name); - } catch (ClassNotFoundException e) { - // If not found, delegate to the parent - return super.loadClass(name, resolve); } + if (resolve) { + resolveClass(loadedClass); + } + return loadedClass; + } + + @Override + public Enumeration getResources(String name) throws IOException { + List allResources = new LinkedList<>(); + Enumeration sysResource; + if (system != null) { + sysResource = system.getResources(name); + while (sysResource.hasMoreElements()) { + allResources.add(sysResource.nextElement()); + } + } + Enumeration thisResource = findResources(name); + while (thisResource.hasMoreElements()) { + allResources.add(thisResource.nextElement()); + } + Enumeration parentResource; + if (getParent() != null) { + parentResource = getParent().getResources(name); + while (parentResource.hasMoreElements()) { + allResources.add(parentResource.nextElement()); + } + } + return Collections.enumeration(allResources); + } + + @Override + public URL getResource(String name) { + URL resource = findResource(name); + if (resource == null) { + resource = super.getResource(name); + } + if (resource == null && system != null) { + resource = system.getResource(name); + } + return resource; } } From 52d09dff64cddfe82b4606a2dff66a1232d013df Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 29 Jan 2024 13:51:18 +0530 Subject: [PATCH 142/209] Require non null for loadedClass --- .../java/io/ballerina/cli/launcher/CustomToolClassLoader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java index a2f89511243f..6869c8361663 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java @@ -25,6 +25,7 @@ import java.util.Enumeration; import java.util.LinkedList; import java.util.List; +import java.util.Objects; /** * Custom class loader used to load the tool implementation classes. @@ -60,7 +61,7 @@ protected Class loadClass(String name, boolean resolve) throws ClassNotFoundE } } if (resolve) { - resolveClass(loadedClass); + resolveClass(Objects.requireNonNull(loadedClass)); } return loadedClass; } From 11499fbc91e39b4cf10f6f75824fd727ffec68e5 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 29 Jan 2024 21:45:43 +0530 Subject: [PATCH 143/209] Add unit test --- .../java/org/ballerinalang/test/BRunUtil.java | 25 ++++++- .../test/runtime/api/RuntimeAPITest.java | 46 +++++++++++++ .../runtime/api/no_strand/Ballerina.toml | 4 ++ .../test-src/runtime/api/no_strand/main.bal | 66 +++++++++++++++++++ 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/Ballerina.toml create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal diff --git a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BRunUtil.java b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BRunUtil.java index 3be624a79cdb..dfc7680ac7e7 100644 --- a/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BRunUtil.java +++ b/tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BRunUtil.java @@ -373,8 +373,8 @@ public static void runInit(CompileResult compileResult) throws ClassNotFoundExce directRun(compileResult.getClassLoader().loadClass(configClassName), "$configureInit", new Class[]{String[].class, Path[].class, String.class}, new Object[]{new String[]{}, configurationDetails.paths, configurationDetails.configContent}); - runOnSchedule(initClazz, ASTBuilderUtil.createIdentifier(null, "$moduleInit"), scheduler); - runOnSchedule(initClazz, ASTBuilderUtil.createIdentifier(null, "$moduleStart"), scheduler); + runOnSchedule(initClazz, "$moduleInit", scheduler); + runOnSchedule(initClazz, "$moduleStart", scheduler); // if (temp) { // scheduler.immortal = true; // new Thread(scheduler::start).start(); @@ -397,6 +397,26 @@ private static void directRun(Class initClazz, String functionName, Class[] p } } + public static void runOnSchedule(CompileResult compileResult, String functionName, Scheduler scheduler) { + BIRNode.BIRFunction function = getInvokedFunction(compileResult, functionName); + PackageManifest packageManifest = compileResult.packageManifest(); + String funcClassName = JarResolver.getQualifiedClassName(packageManifest.org().toString(), + packageManifest.name().toString(), + packageManifest.version().toString(), + getClassName(function.pos.lineRange().fileName())); + Class funcClass = null; + try { + funcClass = compileResult.getClassLoader().loadClass(funcClassName); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Error while invoking function '" + functionName + "'", e); + } + runOnSchedule(funcClass, functionName, scheduler); + } + + private static void runOnSchedule(Class initClazz, String name, Scheduler scheduler) { + runOnSchedule(initClazz, ASTBuilderUtil.createIdentifier(null, name), scheduler); + } + private static void runOnSchedule(Class initClazz, BLangIdentifier name, Scheduler scheduler) { String funcName = JvmCodeGenUtil.cleanupFunctionName(name.value); try { @@ -418,6 +438,7 @@ private static void runOnSchedule(Class initClazz, BLangIdentifier name, Sche }; final FutureValue out = scheduler .schedule(new Object[1], func, null, null, null, PredefinedTypes.TYPE_ANY, null, null); + Scheduler.setDaemonStrand(out.strand); scheduler.start(); final Throwable t = out.panic; if (t != null) { diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java index 7ca9edaca1d8..09508f6986cb 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java @@ -17,12 +17,21 @@ */ package org.ballerinalang.test.runtime.api; +import io.ballerina.runtime.api.Module; +import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.internal.scheduling.Scheduler; import org.ballerinalang.test.BCompileUtil; import org.ballerinalang.test.BRunUtil; import org.ballerinalang.test.CompileResult; +import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.util.concurrent.atomic.AtomicReference; + /** * Test cases for runtime api. * @@ -49,4 +58,41 @@ public Object[] packageNameProvider() { "environment" }; } + + @Test + public void testRecordNoStrandDefaultValue() { + CompileResult strand_result = BCompileUtil.compile("test-src/runtime/api/no_strand"); + final Scheduler scheduler = new Scheduler(false); + AtomicReference exceptionRef = new AtomicReference<>(); + Thread thread1 = new Thread(() -> { + BRunUtil.runOnSchedule(strand_result, "main", scheduler); + }); + Thread thread2 = new Thread(() -> { + try { + Thread.sleep(1000); + BMap recordValue = ValueCreator.createRecordValue(new Module("testorg", + "no_strand", "1"), "MutualSslHandshake"); + Assert.assertEquals(recordValue.getType().getName(), "MutualSslHandshake"); + Assert.assertEquals(recordValue.get(StringUtils.fromString("status")), + StringUtils.fromString("passed")); + Assert.assertNull(recordValue.get(StringUtils.fromString("base64EncodedCert"))); + } catch (Throwable e) { + exceptionRef.set(e); + } finally { + scheduler.poison(); + } + }); + try { + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); + Throwable storedException = exceptionRef.get(); + if (storedException != null) { + throw new AssertionError("Test failed due to an exception in a thread", storedException); + } + } catch (InterruptedException e) { + throw new RuntimeException("Error while invoking function 'main'", e); + } + } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/Ballerina.toml b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/Ballerina.toml new file mode 100644 index 000000000000..7c01db43e064 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org= "testorg" +name="no_strand" +version= "1.0.0" diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal new file mode 100644 index 000000000000..2678ca4b057e --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal @@ -0,0 +1,66 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/lang.runtime; + +public class Listener { + + private string name = ""; + + public function init(string name){ + self.name = name; + } + + public function 'start() returns error? { + + } + + public function gracefulStop() returns error? { + + } + + public function immediateStop() returns error? { + } + + public function attach(service object {} s, string[]|string? name = ()) returns error? { + } + + public function detach(service object {} s) returns error? { + } +} + +public function main() { + Listener l = new("TestListener"); + runtime:registerListener(l); + +} + +public type MutualSslHandshake record {| + MutualSslStatus status = PASSED; + string? base64EncodedCert = (); +|}; + +# Defines the possible values for the mutual ssl status. +# +# `passed`: Mutual SSL handshake is successful. +# `failed`: Mutual SSL handshake has failed. +public type MutualSslStatus PASSED|FAILED|(); + +# Mutual SSL handshake is successful. +public const PASSED = "passed"; + +# Mutual SSL handshake has failed. +public const FAILED = "failed"; From a42a9bc54e2b05116be05a928e146f64f55a259b Mon Sep 17 00:00:00 2001 From: Hinduja Balasubramaniyam <28644893+HindujaB@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:48:51 +0530 Subject: [PATCH 144/209] Update tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal Co-authored-by: Chiran Sachintha <33259160+chiranSachintha@users.noreply.github.com> --- .../binaryoperations/equal_and_not_equal_operation.bal | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal index e0b4f291c6d4..10ec84ff2ec7 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/equal_and_not_equal_operation.bal @@ -1146,7 +1146,6 @@ public function testXmlSequenceLHSEquals() { test:assertTrue(x1 == x2 && !(x1 != x2)); } - function testXmlStringNegative() { anydata x1 = xml `The Lost World`; anydata x2 = "The Lost World"; From 9261d1288da410e87c93c5db44604c99b45334e2 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 30 Jan 2024 06:24:32 +0530 Subject: [PATCH 145/209] Fix checkstyle error --- .../org/ballerinalang/test/runtime/api/RuntimeAPITest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java index 09508f6986cb..83e50996f2a2 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/runtime/api/RuntimeAPITest.java @@ -61,11 +61,11 @@ public Object[] packageNameProvider() { @Test public void testRecordNoStrandDefaultValue() { - CompileResult strand_result = BCompileUtil.compile("test-src/runtime/api/no_strand"); + CompileResult strandResult = BCompileUtil.compile("test-src/runtime/api/no_strand"); final Scheduler scheduler = new Scheduler(false); AtomicReference exceptionRef = new AtomicReference<>(); Thread thread1 = new Thread(() -> { - BRunUtil.runOnSchedule(strand_result, "main", scheduler); + BRunUtil.runOnSchedule(strandResult, "main", scheduler); }); Thread thread2 = new Thread(() -> { try { From 1662512cc1c96614ecdb2bef156081838708e5ef Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 30 Jan 2024 10:50:08 +0530 Subject: [PATCH 146/209] Remove new lines --- .../resources/test-src/runtime/api/no_strand/main.bal | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal index 2678ca4b057e..96d3a1c5e4e8 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/no_strand/main.bal @@ -25,11 +25,9 @@ public class Listener { } public function 'start() returns error? { - } public function gracefulStop() returns error? { - } public function immediateStop() returns error? { @@ -45,7 +43,6 @@ public class Listener { public function main() { Listener l = new("TestListener"); runtime:registerListener(l); - } public type MutualSslHandshake record {| @@ -53,14 +50,6 @@ public type MutualSslHandshake record {| string? base64EncodedCert = (); |}; -# Defines the possible values for the mutual ssl status. -# -# `passed`: Mutual SSL handshake is successful. -# `failed`: Mutual SSL handshake has failed. public type MutualSslStatus PASSED|FAILED|(); - -# Mutual SSL handshake is successful. public const PASSED = "passed"; - -# Mutual SSL handshake has failed. public const FAILED = "failed"; From 6a874e59e68693a504d7c7906ba435b670868fa9 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Tue, 30 Jan 2024 10:58:14 +0530 Subject: [PATCH 147/209] Improve doc comments and getters --- .../task/RunBallerinaPreBuildToolsTask.java | 24 ++++++++--------- .../ballerina/projects/PackageManifest.java | 26 ++++++++++++++----- .../java/io/ballerina/projects/Project.java | 7 ++--- .../io/ballerina/projects/ToolContext.java | 22 +++++++++++++--- .../projects/BallerinaTomlTests.java | 8 +++--- 5 files changed, 59 insertions(+), 28 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index f818740a3630..072d29131513 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -64,7 +64,7 @@ public void execute(Project project) { .startsWith(TOOL_DIAGNOSTIC_CODE_PREFIX)).collect(Collectors.toList()); toolManifestDiagnostics.forEach(outStream::println); - //Build tool execution + // Build tool execution Map toolContextMap = new HashMap<>(); List tools = project.currentPackage().manifest().tools(); if (!tools.isEmpty()) { @@ -72,24 +72,24 @@ public void execute(Project project) { } ServiceLoader buildRunners = ServiceLoader.load(CodeGeneratorTool.class); for (Tool tool : tools) { - String commandName = tool.getType(); + String commandName = tool.type(); ToolContext toolContext = ToolContext.from(tool, project.currentPackage()); boolean hasOptionErrors = false; try { - hasOptionErrors = validateOptionsToml(tool.getOptionsToml(), commandName); + hasOptionErrors = validateOptionsToml(tool.optionsToml(), commandName); if (hasOptionErrors) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo( ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_FAILED.diagnosticId(), ProjectDiagnosticErrorCode.TOOL_OPTIONS_VALIDATION_FAILED.messageKey(), DiagnosticSeverity.ERROR); PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, - tool.getType()); + tool.type()); toolContext.reportDiagnostic(diagnostic); - toolContextMap.put(tool.getId(), toolContext); + toolContextMap.put(tool.id(), toolContext); } } catch (IOException e) { outStream.println(String.format("WARNING: Skipping validation of tool options for tool %s(%s) " + - "due to: %s", tool.getType(), tool.getId(), e.getMessage())); + "due to: %s", tool.type(), tool.id(), e.getMessage())); } if (!tool.hasErrorDiagnostic() && !hasOptionErrors) { try { @@ -98,25 +98,25 @@ public void execute(Project project) { // TODO: Installing tool if not found to be implemented at a later phase DiagnosticInfo diagnosticInfo = new DiagnosticInfo( ProjectDiagnosticErrorCode.BUILD_TOOL_NOT_FOUND.diagnosticId(), - "Build tool '" + tool.getType() + "' not found", + "Build tool '" + tool.type() + "' not found", DiagnosticSeverity.ERROR); PackageDiagnostic diagnostic = new PackageDiagnostic(diagnosticInfo, - tool.getType()); + tool.type()); this.outStream.println(diagnostic); toolContext.reportDiagnostic(diagnostic); - toolContextMap.put(tool.getId(), toolContext); + toolContextMap.put(tool.id(), toolContext); continue; } - this.outStream.println(String.format("%n\t%s(%s)%n", tool.getType(), tool.getId())); + this.outStream.println(String.format("\t%s(%s)%n", tool.type(), tool.id())); targetTool.execute(toolContext); toolContext.diagnostics().forEach(outStream::println); - toolContextMap.put(tool.getId(), toolContext); + toolContextMap.put(tool.id(), toolContext); } catch (Exception e) { throw createLauncherException(e.getMessage()); } } else { outStream.println(String.format("WARNING: Skipping execution of build tool %s(%s) as Ballerina.toml " + - "contains errors%n", tool.getType(), tool.getId() != null ? tool.getId() : "")); + "contains errors%n", tool.type(), tool.id() != null ? tool.id() : "")); } } project.setToolContextMap(toolContextMap); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java index 4efa3c577a82..7dcac8382206 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/PackageManifest.java @@ -441,48 +441,62 @@ public Tool(String type, String id, String filePath, String targetModule, Toml o } /** + * Returns the tool id. + * * @return the tool id. */ - public String getId() { + public String id() { return id; } /** + * Returns the filepath. + * * @return the filepath. */ - public String getFilePath() { + public String filePath() { return this.filePath; } /** + * Returns the target module. + * * @return the tool's target module. */ - public String getTargetModule() { + public String targetModule() { return this.targetModule; } /** + * Returns the tool-specific options as a TomlTableNode. + * * @return the tool options table. */ - public TomlTableNode getOptionsTable() { + public TomlTableNode optionsTable() { return this.optionsTable; } /** + * Returns the type of the tool. + * * @return the tool type. */ - public String getType() { + public String type() { return type; } /** + * Returns the tool-specific options as a Toml. + * * @return the options toml. */ - public Toml getOptionsToml() { + public Toml optionsToml() { return optionsToml; } /** + * Returns a flag indicating whether the tool has error diagnostics. + * * @return whether the tool has error diagnostics. */ public boolean hasErrorDiagnostic() { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java index c940e6f07cdb..d822633f1aa5 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java @@ -96,15 +96,16 @@ public BuildOptions buildOptions() { } /** - * returns a map of build tools. + * Returns a map of build tools. * * @return map of {@code ToolContext} - */public Map getToolContextMap() { + */ + public Map getToolContextMap() { return toolContextMap; } /** - * assigns a map of build tools. + * Assigns a map of build tools. * @param toolContextMap map of {@code ToolContext} */ public void setToolContextMap(Map toolContextMap) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java index 8b6ba994dfd7..cddc26f24127 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java @@ -54,12 +54,14 @@ public class ToolContext { } public static ToolContext from(PackageManifest.Tool tool, Package currentPackage) { - return new ToolContext(currentPackage, tool.getId(), - tool.getFilePath(), tool.getTargetModule(), - tool.getOptionsTable()); + return new ToolContext(currentPackage, tool.id(), + tool.filePath(), tool.targetModule(), + tool.optionsTable()); } /** + * Returns the tool id. + * * @return the id of the tool configuration. */ public String toolId() { @@ -67,6 +69,8 @@ public String toolId() { } /** + * Returns the filepath. + * * @return the filepath extracted from tool configuration. */ public String filePath() { @@ -74,6 +78,8 @@ public String filePath() { } /** + * Returns the target module. + * * @return the target module extracted from tool configuration. */ public String targetModule() { @@ -81,6 +87,8 @@ public String targetModule() { } /** + * Returns the tool-specific configurations. + * * @return a map of the optional tool configurations. */ public Map options() { @@ -88,6 +96,8 @@ public Map options() { } /** + * Returns the cache path. + * * @return the cache path derived using the tool id. */ public Path cachePath() { @@ -96,6 +106,8 @@ public Path cachePath() { } /** + * Returns the output path. + * * @return the output path derived using the target module */ public Path outputPath() { @@ -108,6 +120,8 @@ public Path outputPath() { } /** + * Returns the current package instance. + * * @return the current package instance. */ public Package currentPackage() { @@ -115,6 +129,8 @@ public Package currentPackage() { } /** + * Returns the tool diagnostics list. + * * @return a list of tool diagnostics. */ public List diagnostics() { diff --git a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/BallerinaTomlTests.java b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/BallerinaTomlTests.java index 46c017cee78b..cfdcbd7d1064 100644 --- a/compiler/ballerina-lang/src/test/java/io/ballerina/projects/BallerinaTomlTests.java +++ b/compiler/ballerina-lang/src/test/java/io/ballerina/projects/BallerinaTomlTests.java @@ -145,10 +145,10 @@ public void testBallerinaTomlWithTool() throws IOException { Assert.assertFalse(packageManifest.diagnostics().hasErrors()); PackageManifest.Tool tool = packageManifest.tools().get(0); - Assert.assertEquals(tool.getType(), "openapi"); - Assert.assertEquals(tool.getId(), "generate-delivery-client"); - Assert.assertEquals(tool.getFilePath(), "delivery.json"); - Assert.assertEquals(tool.getTargetModule(), "delivery"); + Assert.assertEquals(tool.type(), "openapi"); + Assert.assertEquals(tool.id(), "generate-delivery-client"); + Assert.assertEquals(tool.filePath(), "delivery.json"); + Assert.assertEquals(tool.targetModule(), "delivery"); } // Negative tests From 35f0804455ec218409d429be4093e9f583ff78b8 Mon Sep 17 00:00:00 2001 From: gabilang Date: Tue, 30 Jan 2024 13:18:00 +0530 Subject: [PATCH 148/209] Use sets to simplify the logic --- .../langlib/array/utils/ArrayUtils.java | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java index ea3419c98d58..1f30f1cd2706 100644 --- a/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java +++ b/langlib/lang.array/src/main/java/org/ballerinalang/langlib/array/utils/ArrayUtils.java @@ -34,7 +34,9 @@ import io.ballerina.runtime.internal.errors.ErrorHelper; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static io.ballerina.runtime.api.constants.RuntimeConstants.ARRAY_LANG_LIB; import static io.ballerina.runtime.internal.errors.ErrorReasons.OPERATION_NOT_SUPPORTED_IDENTIFIER; @@ -104,33 +106,21 @@ public static BArray createEmptyArrayFromTuple(BArray arr) { TupleType tupleType = (TupleType) arrType; List tupleTypes = tupleType.getTupleTypes(); Type restType = tupleType.getRestType(); - boolean isSameType = true; - Type sameType = null; - if (!tupleTypes.isEmpty()) { - sameType = tupleTypes.get(0); - for (int i = 1; i < tupleTypes.size(); i++) { - if (tupleTypes.get(i) != sameType) { - isSameType = false; - break; - } - } - } - List memTypes = new ArrayList<>(tupleTypes); - // If there's a tuple-rest-descriptor the array will not be of the same type even if other types are the same + Set uniqueTypes = new HashSet<>(tupleTypes); if (restType != null) { - isSameType = false; - memTypes.add(restType); + uniqueTypes.add(restType); } - // Create an array of one type if the member-type-descriptors are the same - if (isSameType) { - if (sameType == null) { - // Return an array with never type - return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); - } - ArrayType type = TypeCreator.createArrayType(sameType); - return ValueCreator.createArrayValue(type); + if (uniqueTypes.isEmpty()) { + // Return an array with never type + return ValueCreator.createArrayValue(TypeCreator.createArrayType(PredefinedTypes.TYPE_NEVER)); + } else if (uniqueTypes.size() == 1) { + // Return an array with the member type + Type type = uniqueTypes.iterator().next(); + ArrayType arrayType = TypeCreator.createArrayType(type); + return ValueCreator.createArrayValue(arrayType); } - UnionType unionType = TypeCreator.createUnionType(memTypes); + // Return an array with the union of member types + UnionType unionType = TypeCreator.createUnionType(new ArrayList<>(uniqueTypes)); ArrayType slicedArrType = TypeCreator.createArrayType(unionType); return ValueCreator.createArrayValue(slicedArrType); } From de1917b4d9e2c5fc2f5724f3e522d84812f79700 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Tue, 30 Jan 2024 13:41:23 +0530 Subject: [PATCH 149/209] Change test output logs to align with changes --- .../command-outputs/unix/build-bal-project-with-build-tool.txt | 1 - .../command-outputs/unix/build-tool-with-diagnostics.txt | 1 - .../unix/build-tool-with-recurring-tool-properties.txt | 1 - .../windows/build-bal-project-with-build-tool.txt | 1 - .../command-outputs/windows/build-tool-with-diagnostics.txt | 1 - .../windows/build-tool-with-recurring-tool-properties.txt | 1 - 6 files changed, 6 deletions(-) diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt index 6f3ef6b75b25..ae435fd052a3 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-bal-project-with-build-tool.txt @@ -1,6 +1,5 @@ Executing Build Tools - openapi(generate-delivery-client) Compiling source diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt index 6a396eb0dabd..0919dc3c6b45 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt @@ -1,6 +1,5 @@ Executing Build Tools - openapi(generate-delivery-client) ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt index 7ea0d267e5b6..6e99dd72e6cd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt @@ -2,7 +2,6 @@ ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool Executing Build Tools - openapi(generate-delivery-client) ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt index 6f3ef6b75b25..ae435fd052a3 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-bal-project-with-build-tool.txt @@ -1,6 +1,5 @@ Executing Build Tools - openapi(generate-delivery-client) Compiling source diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt index 6a396eb0dabd..0919dc3c6b45 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-diagnostics.txt @@ -1,6 +1,5 @@ Executing Build Tools - openapi(generate-delivery-client) ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt index 7ea0d267e5b6..6e99dd72e6cd 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/build-tool-with-recurring-tool-properties.txt @@ -2,7 +2,6 @@ ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool Executing Build Tools - openapi(generate-delivery-client) ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist From cde4813b5fcee2c81f74f2373e3550e0930c416d Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Tue, 30 Jan 2024 14:57:54 +0530 Subject: [PATCH 150/209] Fix review suggestion --- .../compiler/semantics/analyzer/SemanticAnalyzer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java index bca1dfb473cf..2bdc7896c3b5 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/SemanticAnalyzer.java @@ -1735,6 +1735,7 @@ public void visit(BLangErrorVariable varNode, AnalyzerData data) { if (varNode.getBType() == null) { varNode.setBType(symResolver.resolveTypeNode(varNode.typeNode, currentEnv)); } + analyzeNode(varNode.typeNode, data); // match err1 { error(reason,....) => ... } // reason must be a const of subtype of string. From dc0792bb2c0a6e5a8d2ff18846dd99398134a6cc Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Tue, 30 Jan 2024 14:58:03 +0530 Subject: [PATCH 151/209] Add unit tests --- .../test/annotations/AnnotationAttachmentNegativeTest.java | 4 +++- .../test-src/annotations/annot_attachments_negative.bal | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index 85d4fd13a537..e4a120b43f9d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 283); + Assert.assertEquals(compileResult.getErrorCount(), 285); } @Test @@ -529,6 +529,8 @@ public void testInvalidAnnotationAttachmentOnField() { validateError(compileResult, index++, "undefined annotation 'annot'", line += 1, 14); validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 13, 2); validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 17); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 12); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 16); } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index 77c94c86db03..a4b8895e6efb 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -995,4 +995,8 @@ function getPerson() returns Person { [@UndefinedAnnotation int, int] [w, e] = [1, 2]; -error err = error("hi", i = 33); +error err = error("err", i = 33); + +error> error () = error("err"); + +error error () = error("err"); From 513ef527d10e58fd193ef8874ca0865eb574fe52 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 30 Jan 2024 15:22:07 +0530 Subject: [PATCH 152/209] Change let expr desuagr order in query --- .../org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java index 3d256e83b017..707d664861a6 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/QueryDesugar.java @@ -2103,8 +2103,8 @@ public void visit(BLangGroupExpr groupExpr) { @Override public void visit(BLangLetExpression letExpr) { - letExpr.expr = rewrite(letExpr.expr); letExpr.letVarDeclarations.forEach(var -> this.acceptNode((BLangNode) var.definitionNode)); + letExpr.expr = rewrite(letExpr.expr); result = letExpr; } From a47cb53077af07b0bd9705fe85020ecb3255e4fd Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Tue, 30 Jan 2024 15:26:37 +0530 Subject: [PATCH 153/209] Add tests for query actions with let exprs --- .../test/query/QueryActionOrExprTest.java | 3 +- .../test-src/query/query_action_or_expr.bal | 37 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionOrExprTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionOrExprTest.java index ee5cb48fc591..078b4267e901 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionOrExprTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryActionOrExprTest.java @@ -80,7 +80,8 @@ public Object[] dataToTestQueryActionOrExpr() { "testQueryActionOrExpressionWithUnionRecordResultType", "testQueryActionOrExprWithAnyOrErrResultType", "testNestedQueryActionOrExprWithClientResourceAccessAction", - "testQueryActionWithQueryExpression" + "testQueryActionWithQueryExpression", + "testQueryActionWithLetExpression" }; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal index d37d6d8c5ac3..90e6f1338b74 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal @@ -988,11 +988,7 @@ type Student record { function calGraduationYear(int year) returns int => year + 5; function getBestStudents() returns any|error { - Student s1 = {firstName: "Martin", lastName: "Sadler", intakeYear: 1990, gpa: 3.5}; - Student s2 = {firstName: "Ranjan", lastName: "Fonseka", intakeYear: 2001, gpa: 1.9}; - Student s3 = {firstName: "Michelle", lastName: "Guthrie", intakeYear: 2002, gpa: 3.7}; - Student s4 = {firstName: "George", lastName: "Fernando", intakeYear: 2005, gpa: 4.0}; - Student[] studentList = [s1, s2, s3]; + Student[] studentList = getStudents(); return from var student in studentList where student.gpa >= 2.0 @@ -1006,6 +1002,37 @@ function testQueryActionOrExprWithAnyOrErrResultType() { assertTrue(getBestStudents() is record {|string name; string degree; int graduationYear;|}[]); } +function getStudents() returns Student[] { + return [ + {firstName: "Martin", lastName: "Sadler", intakeYear: 1990, gpa: 3.5}, + {firstName: "Ranjan", lastName: "Fonseka", intakeYear: 2001, gpa: 1.9}, + {firstName: "Michelle", lastName: "Guthrie", intakeYear: 2002, gpa: 3.7}, + {firstName: "George", lastName: "Fernando", intakeYear: 2005, gpa: 4.0} + ]; +} + +function testQueryActionWithLetExpression() { + Student[] studentList = getStudents(); + float[] actualGpaList = []; + _ = from var {gpa} in studentList + do { + float gpaVal = let var sGpa = gpa in sGpa; + actualGpaList.push(gpaVal); + }; + float[] expectedGpaList = [3.5, 1.9, 3.7, 4.0]; + assertEquality(expectedGpaList, actualGpaList); + + int[] actualValues = []; + int weight = 2; + _ = from var i in [1, 2, 3, 4] + do { + int gpaVal = let var sGpa = i in weight * i; + actualValues.push(gpaVal); + }; + int[] expectedValues = [2, 4, 6, 8]; + assertEquality(actualValues, expectedValues); +} + const ASSERTION_ERROR_REASON = "AssertionError"; function assertEquality(anydata expected, anydata actual) { From 3e00dba866436ce741d084c9566eb0cfbed7b710 Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Tue, 30 Jan 2024 16:27:02 +0530 Subject: [PATCH 154/209] Fix review suggestions --- .../AnnotationAttachmentNegativeTest.java | 20 +++++++++------- .../annot_attachments_negative.bal | 23 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index e4a120b43f9d..22607cabfd92 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -38,7 +38,7 @@ public class AnnotationAttachmentNegativeTest { @BeforeClass public void setup() { compileResult = BCompileUtil.compile("test-src/annotations/annot_attachments_negative.bal"); - Assert.assertEquals(compileResult.getErrorCount(), 285); + Assert.assertEquals(compileResult.getErrorCount(), 289); } @Test @@ -522,15 +522,19 @@ public void testInvalidConstAnnotElements() { public void testInvalidAnnotationAttachmentOnField() { int index = 277; - int line = 980; - validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line, 6); - validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 6); - validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 7); - validateError(compileResult, index++, "undefined annotation 'annot'", line += 1, 14); - validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 13, 2); - validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 17); + int line = 989; + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line, 2); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 10); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 16); validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 12); validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 2, 16); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 3, 6); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 6); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 7); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 14); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 20); + validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line += 1, 16); + validateError(compileResult, index, "undefined annotation 'UndefinedAnnotation'", line += 1, 20); } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index a4b8895e6efb..fa69dcd53842 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -976,13 +976,6 @@ type F5 record {| int x; |}; -function testInvalidAnnotationAttachmentOnField() { - [@UndefinedAnnotation int, int] [first, second] = [1, 2]; - [@UndefinedAnnotation int, int, int] [a, b, c] = [1, 2, 3]; - [[@UndefinedAnnotation int, int], int] [[a1, b1], c1] = [[1, 2], 3]; - record {|@annot string fname; string lname;|} {fname, lname} = getPerson(); -} - type Person record {| string fname; string lname; @@ -993,10 +986,22 @@ function getPerson() returns Person { return person; } -[@UndefinedAnnotation int, int] [w, e] = [1, 2]; +[@UndefinedAnnotation int, int] [f1, s2] = [1, 2]; + +record {|@UndefinedAnnotation string fname; string lname;|} {fname, lname} = getPerson(); -error err = error("err", i = 33); +error err = error("err", i = 33); error> error () = error("err"); error error () = error("err"); + +function testInvalidAnnotationAttachmentOnTypeBindingPatterns() { + [@UndefinedAnnotation int, int] [first, second] = [1, 2]; + [@UndefinedAnnotation int, int, int] [a, b, c] = [1, 2, 3]; + [[@UndefinedAnnotation int, int], int] [[a1, b1], c1] = [[1, 2], 3]; + record {|@UndefinedAnnotation string fname; string lname;|} {fname, lname} = getPerson(); + error err = error("err", i = 33); + error> error () = error("err"); + error error () = error("err"); +} From 6f8cd3857971872ba1c12e95f60ebb0d4709452b Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 31 Jan 2024 15:17:32 +0530 Subject: [PATCH 155/209] Address review suggestions --- .../test/types/intersection/IntersectionTypeTest.java | 2 -- .../test/types/readonly/SelectivelyImmutableTypeTest.java | 2 ++ .../types/intersection/test_intersection_type_negative.bal | 5 ----- .../types/readonly/test_selectively_immutable_type.bal | 5 +++++ .../readonly/test_selectively_immutable_type_negative.bal | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java index cb93a1b34b6f..c10ccccee212 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/intersection/IntersectionTypeTest.java @@ -86,8 +86,6 @@ public void testImmutableTypesNegative() { validateError(result, index++, "invalid intersection type '(Baz & readonly)': no intersection", 32, 45); validateError(result, index++, "incompatible types: 'Y' is not a record", 42, 6); - validateError(result, index++, "incompatible types: expected " + - "'((stream|ballerina/lang.string:0.0.0:RegExp) & readonly)', found 'stream'", 48, 48); assertEquals(result.getErrorCount(), index); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/readonly/SelectivelyImmutableTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/readonly/SelectivelyImmutableTypeTest.java index d0d075190cbc..6f44bf47867b 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/readonly/SelectivelyImmutableTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/readonly/SelectivelyImmutableTypeTest.java @@ -193,6 +193,8 @@ public void testImmutableTypesNegative() { "'(json & readonly)[]'", 407, 28); validateError(result, index++, "incompatible types: expected '(json & readonly)[]', found " + "'(xml & readonly)[]'", 408, 29); + validateError(result, index++, "incompatible types: expected " + + "'((stream|ballerina/lang.string:0.0.0:RegExp) & readonly)', found 'stream'", 412, 48); assertEquals(result.getErrorCount(), index); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal index 9f6d17c1eaea..3ebaf4ab9f58 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal @@ -44,8 +44,3 @@ type Z record { Y y; }; -function testUnsupportedIntersectionWithReadonly(stream strm) { - (stream|string:RegExp) & readonly x = strm; -} - - diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type.bal index ebae240dc5b2..89489482b63d 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type.bal @@ -1197,6 +1197,11 @@ function testReadOnlyIntersectionWithJsonAndAnydata() { assertFalse(l is (string|error)[]); } +function testSelectivelyImmutabilityWithRegexp() { + (stream|string:RegExp) & readonly x = re `pattern`; + assertTrue(x is (string:RegExp & readonly)); +} + const ASSERTION_ERROR_REASON = "AssertionError"; function assertTrue(any|error actual) { diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type_negative.bal index 62657323d06a..65eafecc2bbd 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/readonly/test_selectively_immutable_type_negative.bal @@ -407,3 +407,7 @@ function testReadOnlyIntersectionWithJsonAndAnydataNegative() { (xml & readonly)[] n = k; // error (json & readonly)[] _ = n; // error } + +function testUnsupportedIntersectionWithReadonly(stream strm) { + (stream|string:RegExp) & readonly _ = strm; +} From cfa09606e9ca2e662735683b04a17229ec6180c0 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 31 Jan 2024 16:40:08 +0530 Subject: [PATCH 156/209] Fix toJson API for string --- .../java/io/ballerina/runtime/internal/JsonInternalUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java index fc5a48f60dce..8487c7254435 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/JsonInternalUtils.java @@ -326,7 +326,7 @@ public static Object convertJSON(Object jsonValue, Type targetType) { if (jsonValue instanceof BString) { return jsonValue; } - return jsonValue.toString(); + return StringUtils.fromString(jsonValue.toString()); case TypeTags.BOOLEAN_TAG: return jsonNodeToBoolean(jsonValue); case TypeTags.JSON_TAG: From 09766b182d5d0f02e29bc170532bc327ae1a4a1d Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 31 Jan 2024 16:40:27 +0530 Subject: [PATCH 157/209] Add unit test --- .../test-src/runtime/api/utils/modules/jsons/jsons.bal | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/utils/modules/jsons/jsons.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/utils/modules/jsons/jsons.bal index a06820f826a2..9e1e9ed47280 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/utils/modules/jsons/jsons.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/utils/modules/jsons/jsons.bal @@ -118,6 +118,10 @@ function testConvertJSON() { jval = null; jval_result = trap convertJSON(jval, typeof ()); test:assertEquals(jval_result, ()); + + handle val = java:fromString("apple"); + jval_result = trap convertJSON(val, string); + test:assertEquals(jval_result, "apple"); } function convertJSONToRecord(anydata v, typedesc t) returns map = @java:Method { @@ -125,7 +129,7 @@ function convertJSONToRecord(anydata v, typedesc t) returns map t) returns anydata = @java:Method { +function convertJSON(any v, typedesc t) returns anydata = @java:Method { 'class: "org.ballerinalang.nativeimpl.jvm.runtime.api.tests.JsonValues", name: "testConvertJSON" } external; From 7ecb2777fe9d00b5bb16130772bfc457b0226910 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Wed, 31 Jan 2024 21:44:41 +0530 Subject: [PATCH 158/209] Address review suggestions --- .../test/resources/test-src/query/query_action_or_expr.bal | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal index 90e6f1338b74..f5aa6e3e4461 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query_action_or_expr.bal @@ -1019,8 +1019,7 @@ function testQueryActionWithLetExpression() { float gpaVal = let var sGpa = gpa in sGpa; actualGpaList.push(gpaVal); }; - float[] expectedGpaList = [3.5, 1.9, 3.7, 4.0]; - assertEquality(expectedGpaList, actualGpaList); + assertEquality([3.5, 1.9, 3.7, 4.0], actualGpaList); int[] actualValues = []; int weight = 2; @@ -1029,8 +1028,7 @@ function testQueryActionWithLetExpression() { int gpaVal = let var sGpa = i in weight * i; actualValues.push(gpaVal); }; - int[] expectedValues = [2, 4, 6, 8]; - assertEquality(actualValues, expectedValues); + assertEquality([2, 4, 6, 8], actualValues); } const ASSERTION_ERROR_REASON = "AssertionError"; From 025f8004a31386773e1bdd37820e9814eec09450 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Thu, 1 Feb 2024 16:45:40 +0530 Subject: [PATCH 159/209] Eliminate the bad sad error --- .../compiler/desugar/MockDesugar.java | 32 +++---------------- .../compiler/tree/BLangTestablePackage.java | 10 ++++++ .../core/MockAnnotationProcessor.java | 4 +++ 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java index 5bd74cd596cd..a257687b582e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java @@ -115,35 +115,13 @@ public void generateMockFunctions(BLangPackage pkgNode) { // Get the Mock Function map from the pkgNode Map mockFunctionMap = pkgNode.getTestablePkg().getMockFunctionNamesMap(); - // Get all the imports symbols from the testable package - Set mockFunctionSet = mockFunctionMap.keySet(); - ArrayList importsList = new ArrayList<>(); - for (BLangImportPackage importPkg : pkgNode.getTestablePkg().getImports()) { - if (importPkg.symbol == null) { - continue; - } - if (!importPkg.symbol.toString().contains(testPackageSymbol)) { - importsList.add(importPkg.symbol.toString()); - } - } - - // Get all the imports from the current package - for (BLangImportPackage importPkg : pkgNode.getImports()) { - if (importPkg.symbol == null) { - continue; - } - if (importsList.contains(importPkg.symbol.toString())) { - continue; - } - if (!importPkg.symbol.toString().contains(testPackageSymbol)) { - importsList.add(importPkg.symbol.toString()); - } - } + // Get the mock function type map from the pkgNode + Map mockFunctionTypeMap = pkgNode.getTestablePkg().getMockFunctionTypeMap(); + // Get the set of functions to generate + Set mockFunctionSet = mockFunctionMap.keySet(); for (String function : mockFunctionSet) { - if (function.contains(pkgNode.packageID.toString()) ? !function.split(pkgNode.packageID.toString())[1]. - startsWith(MOCK_LEGACY_DELIMITER) : - !startsWithMockLegacyDelimiterForImportedMockFunctions(function, importsList)) { + if ("LATEST".equals(mockFunctionTypeMap.get(function))) { pkgNode.getTestablePkg().functions.add(generateMockFunction(function)); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java index 412743a7b36c..58dea1f2e209 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java @@ -29,6 +29,8 @@ public class BLangTestablePackage extends BLangPackage { // Semantic Data //Map to maintain all the mock functions private Map mockFunctionNamesMap = new HashMap<>(); + + private final Map mockFunctionTypeMap = new HashMap<>(); public Map getMockFunctionNamesMap() { return mockFunctionNamesMap; } @@ -46,4 +48,12 @@ public void accept(BLangNodeAnalyzer analyzer, T props) { public R apply(BLangNodeTransformer modifier, T props) { return modifier.transform(this, props); } + + public Map getMockFunctionTypeMap() { + return mockFunctionTypeMap; + } + + public void addMockFunctionType(String id, String type) { + this.mockFunctionTypeMap.put(id, type); + } } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java index 4535ce9d2173..7d82a0d40815 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java @@ -149,6 +149,8 @@ public void process(SimpleVariableNode simpleVariableNode, List # --> ` to registry @@ -257,6 +259,8 @@ public void process(FunctionNode functionNode, List an (BLangTestablePackage) ((BLangFunction) functionNode).parent; // parent -> BLangPackage bLangTestablePackage.addMockFunction(functionToMockID + MOCK_LEGACY_DELIMITER + vals[1], functionName); + bLangTestablePackage.addMockFunctionType(functionToMockID + MOCK_LEGACY_DELIMITER + vals[1], + "LEGACY"); // Adding ` # --> ` to registry String className = getQualifiedClassName(bLangTestablePackage, From 08cbf5ffcf301d798cf603b85870b6a40c3ef81b Mon Sep 17 00:00:00 2001 From: hindujaB Date: Thu, 1 Feb 2024 17:04:56 +0530 Subject: [PATCH 160/209] Set builtin pos for redundant positions --- .../org/wso2/ballerinalang/compiler/desugar/Desugar.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index 8a2f42b8e1b0..082222b9cee2 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -9758,9 +9758,9 @@ private BLangAssignment createStructFieldUpdate(BLangFunction function, BLangExp BLangAssignment assignmentStmt = (BLangAssignment) TreeBuilder.createAssignmentNode(); // position information is not passed to remove code coverage for record/class definition - expr.pos = null; - fieldName.pos = null; - fieldSymbol.pos = null; + expr.pos = this.symTable.builtinPos; + fieldName.pos = this.symTable.builtinPos; + fieldSymbol.pos = this.symTable.builtinPos; assignmentStmt.expr = expr; assignmentStmt.pos = function.pos; assignmentStmt.setVariable(fieldAccess); From 98399e6b026b8e4cd874b580071f4bef435dedbe Mon Sep 17 00:00:00 2001 From: dilhasha Date: Thu, 1 Feb 2024 18:43:01 +0500 Subject: [PATCH 161/209] Improve bal deprecate command help --- .../resources/cli-help/ballerina-deprecate.help | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help index 861322ffc0cb..b7c5d8a98102 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help @@ -2,11 +2,14 @@ NAME ballerina-deprecate - Deprecates a published package SYNOPSIS - bal deprecate [OPTIONS] + bal deprecate [OPTIONS] /[:] DESCRIPTION - The deprecate command marks the specified package as deprecated in Ballerina central. + Deprecate a package published in Ballerina central. + + If a specific version of a package is provided, that version will be deprecated. + Alternatively, if no version is specified, all versions of the package will be deprecated. A deprecated package will not be used as a dependency of a package unless the deprecated package is already recorded in the `Dependencies.toml` and the `--sticky` option is used to build the package. Also, a deprecated package will be used as @@ -14,14 +17,14 @@ DESCRIPTION A warning diagnostic will be issued whenever a deprecated package is used as a dependency. - This command does not delete the package from Ballerina central, and the package can be undeprecated using the `--undo` option. + This command does not delete the package from Ballerina central, and the package deprecation can be undone using the `--undo` option. OPTIONS --message= Use the given as the deprecation message --undo - Undeprecate a deprecated package + Undo deprecation of package EXAMPLES @@ -30,3 +33,9 @@ EXAMPLES Deprecate a specific version of the package ballerina/io $ bal deprecate ballerina/io:1.1.1 + + Deprecate a specific version of the package with an optional warning message + $ bal deprecate ballerina/io:1.1.1 --message="deprecated due to a security vulnerability" + + Undo deprecation of a package + $ bal deprecate ballerina/io --undo From 6a5b90ba4ffa558353c03ade9f049e998abc5b7f Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Thu, 1 Feb 2024 18:05:16 +0530 Subject: [PATCH 162/209] Support create fn for worker and explicit fn --- .../FunctionCallExpressionTypeFinder.java | 17 +++++- .../codeaction/CreateFunctionTest.java | 10 ++++ ...ction_in_explicit_anonymous_function1.json | 57 +++++++++++++++++++ ...ction_in_explicit_anonymous_function2.json | 57 +++++++++++++++++++ ...ction_in_explicit_anonymous_function3.json | 57 +++++++++++++++++++ ...ction_in_explicit_anonymous_function4.json | 57 +++++++++++++++++++ .../config/create_function_in_worker1.json | 57 +++++++++++++++++++ .../config/create_function_in_worker2.json | 57 +++++++++++++++++++ .../config/create_function_in_worker3.json | 57 +++++++++++++++++++ .../config/create_function_in_worker4.json | 57 +++++++++++++++++++ ...unction_in_explicit_anonymous_function.bal | 20 +++++++ .../source/create_function_in_worker.bal | 20 +++++++ 12 files changed, 521 insertions(+), 2 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java index f846bba1b8f2..d5f51c174fb5 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java @@ -36,12 +36,14 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.api.symbols.UnionTypeSymbol; import io.ballerina.compiler.api.symbols.VariableSymbol; +import io.ballerina.compiler.api.symbols.WorkerSymbol; import io.ballerina.compiler.syntax.tree.AssignmentStatementNode; import io.ballerina.compiler.syntax.tree.BinaryExpressionNode; import io.ballerina.compiler.syntax.tree.BlockStatementNode; import io.ballerina.compiler.syntax.tree.CheckExpressionNode; import io.ballerina.compiler.syntax.tree.ConditionalExpressionNode; import io.ballerina.compiler.syntax.tree.ErrorConstructorExpressionNode; +import io.ballerina.compiler.syntax.tree.ExplicitAnonymousFunctionExpressionNode; import io.ballerina.compiler.syntax.tree.ExplicitNewExpressionNode; import io.ballerina.compiler.syntax.tree.FailStatementNode; import io.ballerina.compiler.syntax.tree.FunctionArgumentNode; @@ -57,6 +59,7 @@ import io.ballerina.compiler.syntax.tree.MethodCallExpressionNode; import io.ballerina.compiler.syntax.tree.ModuleVariableDeclarationNode; import io.ballerina.compiler.syntax.tree.NamedArgumentNode; +import io.ballerina.compiler.syntax.tree.NamedWorkerDeclarationNode; import io.ballerina.compiler.syntax.tree.Node; import io.ballerina.compiler.syntax.tree.NodeVisitor; import io.ballerina.compiler.syntax.tree.ObjectFieldNode; @@ -402,6 +405,12 @@ public void visit(BlockStatementNode node) { node.parent().accept(this); } + @Override + public void visit(NamedWorkerDeclarationNode namedWorkerDeclarationNode) { + Optional symbol = semanticModel.symbol(namedWorkerDeclarationNode); + symbol.ifPresent(value -> checkAndSetTypeResult(((WorkerSymbol) value).returnType())); + } + @Override public void visit(ReturnStatementNode returnStatementNode) { this.semanticModel.typeOf(returnStatementNode).ifPresent(this::checkAndSetTypeResult); @@ -414,8 +423,6 @@ public void visit(ReturnStatementNode returnStatementNode) { if (resultFound && returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) { FunctionTypeSymbol functionTypeSymbol = (FunctionTypeSymbol) returnTypeSymbol; functionTypeSymbol.returnTypeDescriptor().ifPresentOrElse(this::checkAndSetTypeResult, this::resetResult); - } else { - resetResult(); } } @@ -512,6 +519,12 @@ public void visit(ImplicitAnonymousFunctionExpressionNode expr) { } } + @Override + public void visit(ExplicitAnonymousFunctionExpressionNode explicitAnonymousFunctionExpressionNode) { + Optional typeSymbol = semanticModel.typeOf(explicitAnonymousFunctionExpressionNode); + typeSymbol.ifPresent(this::checkAndSetTypeResult); + } + @Override public void visit(PanicStatementNode panicStatementNode) { checkAndSetTypeResult(semanticModel.types().ERROR); diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java index a451910e5282..f43bd32095c5 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java @@ -186,6 +186,16 @@ public Object[][] dataProvider() { {"create_function_in_anonymous_function1.json"}, {"create_function_in_anonymous_function2.json"}, + + {"create_function_in_worker1.json"}, + {"create_function_in_worker2.json"}, + {"create_function_in_worker3.json"}, + {"create_function_in_worker4.json"}, + + {"create_function_in_explicit_anonymous_function1.json"}, + {"create_function_in_explicit_anonymous_function2.json"}, + {"create_function_in_explicit_anonymous_function3.json"}, + {"create_function_in_explicit_anonymous_function4.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json new file mode 100644 index 000000000000..4a8c71c24a41 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 4, + "character": 16 + }, + "source": "create_function_in_explicit_anonymous_function.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns int {\n return 0;\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_explicit_anonymous_function.bal", + "range": { + "start": { + "line": 4, + "character": 15 + }, + "end": { + "line": 4, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 4.0, + "character": 15.0 + }, + "end": { + "line": 4.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json new file mode 100644 index 000000000000..a5f597a29138 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 8, + "character": 10 + }, + "source": "create_function_in_explicit_anonymous_function.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo(int i) {\n \n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_explicit_anonymous_function.bal", + "range": { + "start": { + "line": 8, + "character": 8 + }, + "end": { + "line": 8, + "character": 15 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 8.0, + "character": 8.0 + }, + "end": { + "line": 8.0, + "character": 15.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json new file mode 100644 index 000000000000..0979e3fd65db --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 13, + "character": 17 + }, + "source": "create_function_in_explicit_anonymous_function.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() {\n \n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_explicit_anonymous_function.bal", + "range": { + "start": { + "line": 13, + "character": 15 + }, + "end": { + "line": 13, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 13.0, + "character": 15.0 + }, + "end": { + "line": 13.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json new file mode 100644 index 000000000000..14e0b507940b --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 17, + "character": 17 + }, + "source": "create_function_in_explicit_anonymous_function.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns module1:TestRecord2 {\n return {};\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_explicit_anonymous_function.bal", + "range": { + "start": { + "line": 17, + "character": 15 + }, + "end": { + "line": 17, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 17.0, + "character": 15.0 + }, + "end": { + "line": 17.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json new file mode 100644 index 000000000000..91b39c7b4caa --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 4, + "character": 16 + }, + "source": "create_function_in_worker.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns int {\n return 0;\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_worker.bal", + "range": { + "start": { + "line": 4, + "character": 15 + }, + "end": { + "line": 4, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 4.0, + "character": 15.0 + }, + "end": { + "line": 4.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json new file mode 100644 index 000000000000..87ef73466419 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 8, + "character": 10 + }, + "source": "create_function_in_worker.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo(int i) {\n \n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_worker.bal", + "range": { + "start": { + "line": 8, + "character": 8 + }, + "end": { + "line": 8, + "character": 15 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 8.0, + "character": 8.0 + }, + "end": { + "line": 8.0, + "character": 15.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json new file mode 100644 index 000000000000..a57c1855fc2c --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 13, + "character": 17 + }, + "source": "create_function_in_worker.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() {\n \n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_worker.bal", + "range": { + "start": { + "line": 13, + "character": 15 + }, + "end": { + "line": 13, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 13.0, + "character": 15.0 + }, + "end": { + "line": 13.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json new file mode 100644 index 000000000000..fbe259630b85 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 17, + "character": 17 + }, + "source": "create_function_in_worker.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 19, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns module1:TestRecord2 {\n return {};\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_worker.bal", + "range": { + "start": { + "line": 17, + "character": 15 + }, + "end": { + "line": 17, + "character": 20 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 17.0, + "character": 15.0 + }, + "end": { + "line": 17.0, + "character": 20.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal new file mode 100644 index 000000000000..48e0ab89bfb9 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal @@ -0,0 +1,20 @@ +import ballerina/module1; + +function createFunctionInWorker() { + var fn1 = function() returns int { + return foo(); + }; + + var fn2 = function() returns string { + foo(32); + return "bar"; + }; + + var fn3 = function() { + return foo(); + }; + + var fn4 = function() returns module1:TestRecord2 { + return foo(); + }; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal new file mode 100644 index 000000000000..709711a300ef --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal @@ -0,0 +1,20 @@ +import ballerina/module1; + +function createFunctionInWorker() { + worker A returns int { + return foo(); + } + + worker B returns string { + foo(32); + return "bar"; + } + + worker C { + return foo(); + } + + worker D returns module1:TestRecord2 { + return foo(); + } +} From fc425a76d8fa95303394804cc6cf8b7c1a05b530 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Fri, 2 Feb 2024 04:37:26 +0530 Subject: [PATCH 163/209] Add module table to the visited set --- .../internal/configurable/providers/toml/TomlProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java index c372c8be93d1..949ebf33b0d1 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/configurable/providers/toml/TomlProvider.java @@ -618,14 +618,14 @@ private List getRootModuleNode(Toml baseToml) { Optional table = baseToml.getTable(moduleKey); List moduleNodes = new ArrayList<>(); if (table.isPresent()) { - moduleNodes.add(table.get().rootNode()); + addToModuleNodesList(table.get(), moduleNodes); } else if (moduleInfo.hasModuleAmbiguity()) { throw new ConfigException(ErrorCodes.CONFIG_TOML_MODULE_AMBIGUITY, getLineRange(baseToml.rootNode()), moduleName, moduleKey); } table = baseToml.getTable(moduleName); table.ifPresent(toml -> addToModuleNodesList(toml, moduleNodes)); - moduleNodes.add(baseToml.rootNode()); + addToModuleNodesList(baseToml, moduleNodes); return moduleNodes; } From 1fb7c9d8e95c7925655512267322763297ab0ddf Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 2 Feb 2024 06:57:14 +0530 Subject: [PATCH 164/209] Change printing tool diagnostics --- .../main/java/io/ballerina/cli/task/CompileTask.java | 1 - .../cli/task/RunBallerinaPreBuildToolsTask.java | 8 +++++++- .../ballerina/projects/internal/ManifestBuilder.java | 12 +++++++----- .../projects/internal/PackageDiagnostic.java | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index f18876ba76e4..df92855d41cf 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -224,7 +224,6 @@ public void execute(Project project) { diagnostics.addAll(tool.diagnostics()); } } - boolean hasErrors = false; for (Diagnostic d : diagnostics) { if (d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) { diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index 072d29131513..f80dfd083b0a 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -109,7 +109,13 @@ public void execute(Project project) { } this.outStream.println(String.format("\t%s(%s)%n", tool.type(), tool.id())); targetTool.execute(toolContext); - toolContext.diagnostics().forEach(outStream::println); + for (Diagnostic d : toolContext.diagnostics()) { + if (d.toString().contains("(1:1,1:1)")) { + outStream.println(new PackageDiagnostic(d.diagnosticInfo(), toolContext.toolId())); + } else { + outStream.println(new PackageDiagnostic(d.diagnosticInfo(), d.location())); + } + } toolContextMap.put(tool.id(), toolContext); } catch (Exception e) { throw createLauncherException(e.getMessage()); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 3a83a03792d2..a3bfc0096175 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -107,6 +107,8 @@ public class ManifestBuilder { private static final String URL = "url"; private static final String DEPENDENCY = "dependency"; private static final String ID = "id"; + private static final String TARGETMODULE = "targetModule"; + private static final String OPTIONS = "options"; private ManifestBuilder(TomlDocument ballerinaToml, TomlDocument compilerPluginToml, @@ -263,9 +265,9 @@ private List getTools() { String filePath = getStringValueFromPreBuildToolNode(dependencyNode, "filePath", toolCode); String targetModule = getStringValueFromPreBuildToolNode(dependencyNode, - "targetModule", toolCode); - Toml optionsToml = getToml(dependencyNode, "options"); - TopLevelNode topLevelNode = dependencyNode.entries().get("options"); + TARGETMODULE, toolCode); + Toml optionsToml = getToml(dependencyNode, OPTIONS); + TopLevelNode topLevelNode = dependencyNode.entries().get(OPTIONS); TomlTableNode optionsNode = null; if (topLevelNode != null && topLevelNode.kind() == TomlType.TABLE) { optionsNode = (TomlTableNode) topLevelNode; @@ -791,7 +793,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String TopLevelNode topLevelNode = toolNode.entries().get(key); String errorMessage = "missing key '[" + key + "]' in table '[tool." + toolCode + "]'."; if (topLevelNode == null) { - if (!key.equals("targetModule")) { + if (!key.equals(TARGETMODULE)) { reportDiagnostic(toolNode, errorMessage, ProjectDiagnosticErrorCode.MISSING_TOOL_PROPERTIES_IN_BALLERINA_TOML, DiagnosticSeverity.ERROR); @@ -802,7 +804,7 @@ private String getStringValueFromPreBuildToolNode(TomlTableNode toolNode, String if (ToolNodeValueType.STRING.equals(toolNodeValueType)) { return getStringFromTomlTableNode(topLevelNode); } else if (ToolNodeValueType.EMPTY.equals(toolNodeValueType)) { - if (!key.equals("targetModule")) { + if (!key.equals(TARGETMODULE)) { reportDiagnostic(toolNode, "empty string found for key '[" + key + "]' in table '[tool." + toolCode + "]'.", ProjectDiagnosticErrorCode.EMPTY_TOOL_PROPERTY, diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDiagnostic.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDiagnostic.java index a8fd54d1a7b3..ec1502a9bb37 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDiagnostic.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageDiagnostic.java @@ -52,7 +52,7 @@ public class PackageDiagnostic extends Diagnostic { protected Project project; protected ModuleDescriptor moduleDescriptor; - protected PackageDiagnostic(DiagnosticInfo diagnosticInfo, Location location) { + public PackageDiagnostic(DiagnosticInfo diagnosticInfo, Location location) { this.diagnostic = DiagnosticFactory.createDiagnostic(diagnosticInfo, location); this.location = location; } From daecdc093a581c4b567470ec7ae5108380e0cded Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 2 Feb 2024 06:57:46 +0530 Subject: [PATCH 165/209] Adjust tests for new changes --- .../test-resources/build-tool-with-diagnostics/main.bal | 2 +- .../main.bal | 2 +- .../Ballerina.toml | 5 +++++ .../main.bal | 2 +- .../Ballerina.toml | 9 +++------ .../delivery.json | 0 .../delivery.yml | 0 .../build-tool-with-recurring-tool-properties/main.bal | 2 +- .../command-outputs/unix/build-tool-with-diagnostics.txt | 2 +- .../build-tool-with-invalid-missing-toml-properties.txt | 5 ++++- .../unix/build-tool-with-recurring-tool-properties.txt | 6 +----- 11 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.json create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.yml diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal index adbf847790de..06a591055bc7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-diagnostics/main.bal @@ -1,3 +1,3 @@ public function hello() returns string { - return ("Hello, World!"); + return "Hello, World!"; } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal index adbf847790de..06a591055bc7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-optional-toml-properties/main.bal @@ -1,3 +1,3 @@ public function hello() returns string { - return ("Hello, World!"); + return "Hello, World!"; } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/Ballerina.toml index 34a80d602b2e..df3adfc52c0d 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/Ballerina.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/Ballerina.toml @@ -6,4 +6,9 @@ version = "0.1.0" [[tool.openapi]] id = "generate-delivery-client" filePath = "" +targetModule = "delivery" +options.mode = "client" + +[[tool.openapi]] +id = "generate-client" options.mode = "client" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal index adbf847790de..06a591055bc7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-invalid-missing-toml-properties/main.bal @@ -1,3 +1,3 @@ public function hello() returns string { - return ("Hello, World!"); + return "Hello, World!"; } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/Ballerina.toml index 137618bdc710..8377990902fe 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/Ballerina.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/Ballerina.toml @@ -6,15 +6,12 @@ version = "0.1.0" [[tool.openapi]] id = "generate-delivery-client" filePath = "delivery.json" -targetModule = "delivery" +targetModule = "" options.mode = "client" [[tool.openapi]] id = "generate-delivery-client" -filePath = "delivery1.json" +filePath = "delivery.yml" options.mode = "client" -[[tool.grpc]] -id = "generate-grpc-client" -filePath = "delivery2.json" -targetModule = "delivery" + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.json b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.yml b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/delivery.yml new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal index adbf847790de..06a591055bc7 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal +++ b/cli/ballerina-cli/src/test/resources/test-resources/build-tool-with-recurring-tool-properties/main.bal @@ -1,3 +1,3 @@ public function hello() returns string { - return ("Hello, World!"); + return "Hello, World!"; } diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt index 0919dc3c6b45..fe850a2e70fe 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-diagnostics.txt @@ -2,6 +2,6 @@ Executing Build Tools openapi(generate-delivery-client) -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist +ERROR [generate-delivery-client] The provided filePath does not exist Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt index 3c1973af6a65..ebfb9b7e0c04 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-invalid-missing-toml-properties.txt @@ -1,7 +1,10 @@ -ERROR [Ballerina.toml:(6:1,9:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. +ERROR [Ballerina.toml:(6:1,10:24)] empty string found for key '[filePath]' in table '[tool.openapi]'. +ERROR [Ballerina.toml:(12:1,14:24)] missing key '[filePath]' in table '[tool.openapi]'. Executing Build Tools WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors +WARNING: Skipping execution of build tool openapi(generate-client) as Ballerina.toml contains errors + Compiling source foo/winery:0.1.0 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt index 6e99dd72e6cd..20cfc5ad2359 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/build-tool-with-recurring-tool-properties.txt @@ -1,14 +1,10 @@ +ERROR [Ballerina.toml:(12:1,15:24)] recurring target module found in Ballerina.toml. Target module must be unique for each tool ERROR [Ballerina.toml:(12:1,15:24)] recurring tool id 'generate-delivery-client' found in Ballerina.toml. Tool id must be unique for each tool -ERROR [Ballerina.toml:(17:1,20:26)] recurring target module found in Ballerina.toml. Target module must be unique for each tool Executing Build Tools openapi(generate-delivery-client) -ERROR [openAPI sample build tool:(1:1,1:1)] The provided filePath does not exist WARNING: Skipping execution of build tool openapi(generate-delivery-client) as Ballerina.toml contains errors -WARNING: Skipping validation of tool options for tool grpc(generate-grpc-client) due to: Schema file not found: grpc-options-schema.json -WARNING: Skipping execution of build tool grpc(generate-grpc-client) as Ballerina.toml contains errors - Compiling source foo/winery:0.1.0 From 62feca786b9ce2109c66143a1386a0cf8edfa89c Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 2 Feb 2024 07:09:38 +0530 Subject: [PATCH 166/209] Address comments --- .../io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java | 2 +- .../src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index f80dfd083b0a..c8d6e118229c 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -163,7 +163,7 @@ private boolean validateEmptyOptionsToml(String toolName) throws IOException { return true; } this.outStream.println(String.format("WARNING: Skipping validation of tool options for tool %s due to: " + - "No tool options found", toolName)); + "No tool options found for", toolName)); return false; } } diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java index 18f0fcee96e4..564e2e9008a3 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/BuildCommandTest.java @@ -1204,7 +1204,6 @@ public void testBuildProjectWithBuildToolTomlPropertyDiagnostics(String projectN Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput(outputFile)); Assert.assertEquals(error, e.getDetailedMessages().get(0)); - } } @@ -1233,7 +1232,6 @@ public void testBuildProjectWithBuildToolNotFound() throws IOException { Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("build-bal-project-with-build-tool-not-found.txt")); Assert.assertEquals("error: compilation contains errors", e.getDetailedMessages().get(0)); - } } From ef0fc467445c85fdbe56a9810b1572f5ac988205 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Fri, 2 Feb 2024 12:46:52 +0530 Subject: [PATCH 167/209] Address the review comment --- .../ballerinalang/compiler/desugar/MockDesugar.java | 4 ++-- .../compiler/tree/BLangTestablePackage.java | 10 +++++----- .../testerina/core/MockAnnotationProcessor.java | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java index a257687b582e..d9ce5313f26e 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java @@ -116,12 +116,12 @@ public void generateMockFunctions(BLangPackage pkgNode) { Map mockFunctionMap = pkgNode.getTestablePkg().getMockFunctionNamesMap(); // Get the mock function type map from the pkgNode - Map mockFunctionTypeMap = pkgNode.getTestablePkg().getMockFunctionTypeMap(); + Map isLegacyMockingMap = pkgNode.getTestablePkg().getIsLegacyMockingMap(); // Get the set of functions to generate Set mockFunctionSet = mockFunctionMap.keySet(); for (String function : mockFunctionSet) { - if ("LATEST".equals(mockFunctionTypeMap.get(function))) { + if (!isLegacyMockingMap.get(function)) { pkgNode.getTestablePkg().functions.add(generateMockFunction(function)); } } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java index 58dea1f2e209..87c9d4a9c3fa 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/tree/BLangTestablePackage.java @@ -30,7 +30,7 @@ public class BLangTestablePackage extends BLangPackage { //Map to maintain all the mock functions private Map mockFunctionNamesMap = new HashMap<>(); - private final Map mockFunctionTypeMap = new HashMap<>(); + private final Map isLegacyMockingMap = new HashMap<>(); public Map getMockFunctionNamesMap() { return mockFunctionNamesMap; } @@ -49,11 +49,11 @@ public R apply(BLangNodeTransformer modifier, T props) { return modifier.transform(this, props); } - public Map getMockFunctionTypeMap() { - return mockFunctionTypeMap; + public Map getIsLegacyMockingMap() { + return isLegacyMockingMap; } - public void addMockFunctionType(String id, String type) { - this.mockFunctionTypeMap.put(id, type); + public void addIsLegacyMockingMap(String id, Boolean isLegacy) { + this.isLegacyMockingMap.put(id, isLegacy); } } diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java index 7d82a0d40815..1a60b64447c9 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/core/MockAnnotationProcessor.java @@ -149,8 +149,8 @@ public void process(SimpleVariableNode simpleVariableNode, List # --> ` to registry @@ -259,8 +259,8 @@ public void process(FunctionNode functionNode, List an (BLangTestablePackage) ((BLangFunction) functionNode).parent; // parent -> BLangPackage bLangTestablePackage.addMockFunction(functionToMockID + MOCK_LEGACY_DELIMITER + vals[1], functionName); - bLangTestablePackage.addMockFunctionType(functionToMockID + MOCK_LEGACY_DELIMITER + vals[1], - "LEGACY"); + bLangTestablePackage.addIsLegacyMockingMap(functionToMockID + MOCK_LEGACY_DELIMITER + vals[1], + true); // Adding ` # --> ` to registry String className = getQualifiedClassName(bLangTestablePackage, From 1e296dcf960e68defdbca3434f2e6bd092dd9a08 Mon Sep 17 00:00:00 2001 From: LakshanWeerasinghe Date: Fri, 2 Feb 2024 13:19:46 +0530 Subject: [PATCH 168/209] Remove unwanted new line --- .../types/intersection/test_intersection_type_negative.bal | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal index 3ebaf4ab9f58..f972c6678f52 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/intersection/test_intersection_type_negative.bal @@ -43,4 +43,3 @@ type Z record { X x; Y y; }; - From f2fdb27071307f08681d6d89d4ccdbacb189b396 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Mon, 29 Jan 2024 13:47:53 +0530 Subject: [PATCH 169/209] Set the determine type for conditional expr --- .../semantics/analyzer/TypeChecker.java | 34 +++--- .../typeof/TypeOfConditionalExprTest.java | 105 ++++++++++++++++++ .../symbols_in_conditional_exprs_test.bal | 59 ++++++++++ .../src/test/resources/testng.xml | 1 + 4 files changed, 184 insertions(+), 15 deletions(-) create mode 100644 tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfConditionalExprTest.java create mode 100644 tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 819367516b7f..9e8ef7d33364 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -5013,30 +5013,37 @@ private boolean isReferencingNonWorker(BLangExpression expression, AnalyzerData return true; } - public void visit(BLangTernaryExpr ternaryExpr, AnalyzerData data) { BType condExprType = checkExpr(ternaryExpr.expr, this.symTable.booleanType, data); SymbolEnv thenEnv = typeNarrower.evaluateTruth(ternaryExpr.expr, ternaryExpr.thenExpr, data.env); + BType thenActualType = silentTypeCheckExpr(ternaryExpr.thenExpr, symTable.noType, data); BType thenType = checkExpr(ternaryExpr.thenExpr, thenEnv, data.expType, data); SymbolEnv elseEnv = typeNarrower.evaluateFalsity(ternaryExpr.expr, ternaryExpr.elseExpr, data.env, false); + BType elseActualType = silentTypeCheckExpr(ternaryExpr.elseExpr, symTable.noType, data); BType elseType = checkExpr(ternaryExpr.elseExpr, elseEnv, data.expType, data); if (condExprType == symTable.semanticError || thenType == symTable.semanticError || elseType == symTable.semanticError) { data.resultType = symTable.semanticError; } else if (data.expType == symTable.noType) { - if (types.isAssignable(elseType, thenType)) { - data.resultType = thenType; - } else if (types.isAssignable(thenType, elseType)) { - data.resultType = elseType; - } else { - data.resultType = BUnionType.create(null, thenType, elseType); - } + data.resultType = getConditionalExprType(thenType, elseType); } else { data.resultType = data.expType; } + + ternaryExpr.setDeterminedType(getConditionalExprType(thenActualType, elseActualType)); + } + + private BType getConditionalExprType(BType lhsType, BType rhsType) { + if (types.isAssignable(rhsType, lhsType)) { + return lhsType; + } + if (types.isAssignable(lhsType, rhsType)) { + return rhsType; + } + return BUnionType.create(null, lhsType, rhsType); } public void visit(BLangWaitExpr waitExpr, AnalyzerData data) { @@ -5288,22 +5295,19 @@ public void visit(BLangElvisExpr elvisExpr, AnalyzerData data) { BType lhsType = checkExpr(elvisExpr.lhsExpr, data); BType actualType = lhsType == symTable.semanticError ? symTable.semanticError : validateElvisExprLhsExpr(elvisExpr, lhsType); + BType rhsActualType = silentTypeCheckExpr(elvisExpr.rhsExpr, symTable.noType, data); BType rhsReturnType = checkExpr(elvisExpr.rhsExpr, data.expType, data); BType lhsReturnType = types.checkType(elvisExpr.lhsExpr.pos, actualType, data.expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES); if (rhsReturnType == symTable.semanticError || lhsReturnType == symTable.semanticError) { data.resultType = symTable.semanticError; } else if (data.expType == symTable.noType) { - if (types.isAssignable(rhsReturnType, lhsReturnType)) { - data.resultType = lhsReturnType; - } else if (types.isAssignable(lhsReturnType, rhsReturnType)) { - data.resultType = rhsReturnType; - } else { - data.resultType = BUnionType.create(null, lhsReturnType, rhsReturnType); - } + data.resultType = getConditionalExprType(lhsReturnType, rhsReturnType); } else { data.resultType = data.expType; } + + elvisExpr.setDeterminedType(getConditionalExprType(actualType, rhsActualType)); } @Override diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfConditionalExprTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfConditionalExprTest.java new file mode 100644 index 000000000000..10b596f22de3 --- /dev/null +++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfConditionalExprTest.java @@ -0,0 +1,105 @@ +package io.ballerina.semantic.api.test.typeof; + +import io.ballerina.compiler.api.SemanticModel; +import io.ballerina.compiler.api.symbols.TypeDescKind; +import io.ballerina.compiler.api.symbols.TypeSymbol; +import io.ballerina.compiler.api.symbols.UnionTypeSymbol; +import io.ballerina.semantic.api.test.util.SemanticAPITestUtils; +import io.ballerina.tools.text.LinePosition; +import io.ballerina.tools.text.LineRange; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +import static io.ballerina.compiler.api.symbols.TypeDescKind.BOOLEAN; +import static io.ballerina.compiler.api.symbols.TypeDescKind.FLOAT; +import static io.ballerina.compiler.api.symbols.TypeDescKind.INT; +import static io.ballerina.compiler.api.symbols.TypeDescKind.STRING; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * Tests cases for testing typeOf() with conditional expressions. + * + * @since 2201.9.0 + */ +public class TypeOfConditionalExprTest { + + private SemanticModel model; + + @BeforeClass + public void setup() { + model = SemanticAPITestUtils.getDefaultModulesSemanticModel( + "test-src/symbols/symbols_in_conditional_exprs_test.bal"); + } + + @Test(dataProvider = "TernaryExprsPos") + public void testTernaryExprs(int sLine, int sCol, int eLine, int eCol, List kinds) { + assertType(sLine, sCol, eLine, eCol, kinds); + } + + @DataProvider(name = "TernaryExprsPos") + public Object[][] getTernaryExprPos() { + return new Object[][]{ + {3, 10, 3, 36, List.of(BOOLEAN)}, + {4, 11, 4, 39, List.of(STRING, BOOLEAN)}, + {5, 15, 5, 43, List.of(STRING, BOOLEAN)}, + {6, 14, 6, 60, List.of(STRING, BOOLEAN, INT)}, + {9, 11, 9, 30, List.of(BOOLEAN)}, + {13, 11, 13, 32, List.of(STRING, BOOLEAN)}, + {17, 11, 17, 46, List.of(STRING, BOOLEAN, INT)}, + {21, 11, 21, 45, List.of(STRING, BOOLEAN, INT)}, + {25, 11, 25, 85, List.of(STRING, INT)}, + {29, 11, 29, 79, List.of(BOOLEAN, STRING, INT)}, + }; + } + + @Test(dataProvider = "ElvisExprsPos") + public void testElvisExprs(int sLine, int sCol, int eLine, int eCol, List kinds) { + assertType(sLine, sCol, eLine, eCol, kinds); + } + + @DataProvider(name = "ElvisExprsPos") + public Object[][] getElvisExprPos() { + return new Object[][]{ + {35, 10, 35, 38, List.of(STRING)}, + {36, 10, 36, 36, List.of(STRING, BOOLEAN)}, + {37, 11, 37, 58, List.of(STRING, INT, BOOLEAN)}, + {40, 11, 40, 33, List.of(STRING)}, + {44, 11, 44, 31, List.of(STRING, BOOLEAN)}, + {52, 11, 52, 72, List.of(STRING, INT, BOOLEAN, FLOAT)}, + {56, 11, 57, 33, List.of(BOOLEAN, INT, STRING)}, + }; + } + + private TypeSymbol assertType(int sLine, int sCol, int eLine, int eCol, List kinds) { + Optional type = model.typeOf( + LineRange.from("symbols_in_conditional_exprs_test.bal", LinePosition.from(sLine, sCol), + LinePosition.from(eLine, eCol))); + + if (kinds == null) { + assertTrue(type.isEmpty()); + return null; + } + assertFalse(type.isEmpty()); + + TypeSymbol typeSymbol = type.get(); + if (Objects.requireNonNull(type.get().typeKind()) == TypeDescKind.UNION) { + UnionTypeSymbol unionTypeSymbol = (UnionTypeSymbol) typeSymbol; + assertEquals(unionTypeSymbol.memberTypeDescriptors().size(), kinds.size()); + for (int i = 0; i < kinds.size(); i++) { + assertEquals(unionTypeSymbol.memberTypeDescriptors().get(i).typeKind(), kinds.get(i)); + } + } else { + assertEquals(type.get().typeKind(), kinds.get(0)); + } + + return type.get(); + } + +} diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal new file mode 100644 index 000000000000..d167328aad57 --- /dev/null +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal @@ -0,0 +1,59 @@ +boolean moduleFlag1 = false; +boolean moduleFlag2 = true; + +() var1 = moduleFlag1 ? true : false; +int var2 = moduleFlag1 ? "True" : false; +boolean var3 = moduleFlag1 ? "True" : false; +string var4 = moduleFlag1 ? "True" : moduleFlag2 ? false : 0; + +function testTernaryExprWithSameType(boolean flag) { + return flag ? true : false; +} + +function testTernaryExprWithDifferentType(boolean flag) { + return flag ? "True" : false; +} + +function testNestedTernaryExpr1(boolean flag1, boolean flag2) { + return flag1 ? flag2 ? "True " : false : 0; +} + +function testNestedTernaryExpr2(boolean flag1, boolean flag2) { + return flag1 ? "True" : flag2 ? false : 0; +} + +function testNestedTernaryExpr3(boolean flag1, boolean flag2, boolean flag3) { + return (flag1 == flag3 ? moduleFlag1 && flag2 : flag1 || flag3) ? "True" : 0 + 32; +} + +function testNestedTernaryExpr4(boolean flag1, boolean flag2, boolean flag3) { + return flag1 == flag3 ? flag1 && flag2 : moduleFlag2 ? "True" + "False" : 0; +} + +string? moduleNullableStr = (); +int? moduleNullableInt = 1; + +() var5 = moduleNullableStr ?: "False"; +() var6 = moduleNullableStr ?: false; +int var7 = moduleNullableStr ?: moduleNullableInt ?: false; + +function testElvisExprWithSameType(string? nullableStr) { + return nullableStr ?: "False"; +} + +function testElvisExprWithDifferentType(string? nullableStr) { + return nullableStr ?: false; +} + +function testNestedElvisExpr1(string? nullableStr, int? nullableInt) { + return moduleNullableStr ?: moduleNullableInt ?: false; +} + +function testNestedElvisExpr2(string? nullableStr, int? nullableInt, boolean? nullableBool) { + return moduleNullableStr ?: moduleNullableInt ?: nullableBool ?: 0.0; +} + +function testNestedElvisExpr3(string? nullableStr, int? nullableInt, boolean? nullableBool) { + return moduleNullableStr ?: (nullableBool is boolean ? nullableBool || moduleFlag1 + : nullableInt ?: "False"); +} \ No newline at end of file diff --git a/tests/ballerina-compiler-api-test/src/test/resources/testng.xml b/tests/ballerina-compiler-api-test/src/test/resources/testng.xml index b9b7eef9676f..1e21a251f440 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/testng.xml +++ b/tests/ballerina-compiler-api-test/src/test/resources/testng.xml @@ -200,6 +200,7 @@ + From 23ca2442427db9f14db015bf9e93e5ff4a22fdd8 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 30 Jan 2024 10:40:53 +0530 Subject: [PATCH 170/209] Set the determine type for query expr --- .../semantics/analyzer/QueryTypeChecker.java | 2 + .../api/test/typeof/TypeOfQueryExprTest.java | 48 ++++++++++++++++++ .../symbols/symbols_in_query_exprs_test.bal | 50 +++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java index 4aa6aa675130..7ec274881c0a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/QueryTypeChecker.java @@ -183,6 +183,7 @@ public void checkQueryType(BLangQueryExpr queryExpr, TypeChecker.AnalyzerData da if (finalClause.getKind() == NodeKind.SELECT) { actualType = resolveQueryType(commonAnalyzerData.queryEnvs.peek(), ((BLangSelectClause) finalClause).expression, data.expType, queryExpr, clauses, data); + queryExpr.setDeterminedType(actualType); actualType = (actualType == symTable.semanticError) ? actualType : types.checkType(queryExpr.pos, actualType, data.expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES); } else { @@ -196,6 +197,7 @@ public void checkQueryType(BLangQueryExpr queryExpr, TypeChecker.AnalyzerData da if (completionType != null) { queryType = BUnionType.create(null, queryType, completionType); } + queryExpr.setDeterminedType(queryType); actualType = types.checkType(finalClauseExpr.pos, queryType, data.expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES); } diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfQueryExprTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfQueryExprTest.java index c8e678abbd0d..d3ec6b0f922b 100644 --- a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfQueryExprTest.java +++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/typeof/TypeOfQueryExprTest.java @@ -20,6 +20,7 @@ import io.ballerina.compiler.api.SemanticModel; import io.ballerina.compiler.api.symbols.ArrayTypeSymbol; +import io.ballerina.compiler.api.symbols.StreamTypeSymbol; import io.ballerina.compiler.api.symbols.TypeDescKind; import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.TypeSymbol; @@ -35,13 +36,16 @@ import static io.ballerina.compiler.api.symbols.TypeDescKind.ARRAY; import static io.ballerina.compiler.api.symbols.TypeDescKind.ERROR; +import static io.ballerina.compiler.api.symbols.TypeDescKind.FLOAT; import static io.ballerina.compiler.api.symbols.TypeDescKind.INT; import static io.ballerina.compiler.api.symbols.TypeDescKind.RECORD; +import static io.ballerina.compiler.api.symbols.TypeDescKind.STREAM; import static io.ballerina.compiler.api.symbols.TypeDescKind.STRING; import static io.ballerina.compiler.api.symbols.TypeDescKind.TABLE; import static io.ballerina.compiler.api.symbols.TypeDescKind.TYPE_REFERENCE; import static io.ballerina.compiler.api.symbols.TypeDescKind.UNION; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; /** @@ -123,6 +127,50 @@ public Object[][] getExprPos2() { }; } + @Test(dataProvider = "ExprPos3") + public void testQueryExprWithInvalidExpectedType(int sLine, int sCol, int eLine, int eCol, + TypeDescKind expectedKind, TypeDescKind expectedMemberKind, + String expectedMemberName) { + TypeSymbol type = assertType(sLine, sCol, eLine, eCol, expectedKind); + assertNotNull(type); + + switch (type.typeKind()) { + case ARRAY -> { + ArrayTypeSymbol arrayType = (ArrayTypeSymbol) type; + assertEquals(arrayType.memberTypeDescriptor().typeKind(), expectedMemberKind); + if (expectedMemberName != null) { + assertTrue(arrayType.memberTypeDescriptor().getName().isPresent()); + assertEquals(arrayType.memberTypeDescriptor().getName().get(), expectedMemberName); + } + } + case STREAM -> { + StreamTypeSymbol streamType = (StreamTypeSymbol) type; + assertEquals(streamType.typeParameter().typeKind(), expectedMemberKind); + if (expectedMemberName != null) { + assertTrue(streamType.typeParameter().getName().isPresent()); + assertEquals(streamType.typeParameter().getName().get(), expectedMemberName); + } + } + default -> assertEquals(type.typeKind(), expectedKind); + } + } + + @DataProvider(name = "ExprPos3") + public Object[][] getExprPos3() { + return new Object[][]{ + {98, 9, 99, 51, ARRAY, RECORD, null}, + {100, 9, 101, 59, ARRAY, TYPE_REFERENCE, "Person"}, + {104, 14, 106, 27, ARRAY, RECORD, null}, + {109, 13, 111, 34, ARRAY, RECORD, null}, + {114, 13, 116, 36, ARRAY, RECORD, null}, + {119, 13, 121, 13, ARRAY, TYPE_REFERENCE, "Student"}, + {124, 9, 126, 13, ARRAY, TYPE_REFERENCE, "Student"}, + {129, 9, 131, 53, STREAM, TYPE_REFERENCE, "Person"}, + {134, 14, 136, 14, ARRAY, UNION, null}, + {139, 11, 141, 29, FLOAT, null, null}, + }; + } + @Test public void testTableKeySpecifier() { UnionTypeSymbol type = (UnionTypeSymbol) assertType(50, 37, 52, 80, UNION); diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal index e4874dff3721..4e38c2130d23 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal @@ -89,3 +89,53 @@ function getPeople() returns Person[] { Person p2 = {id: 2, name: "Jane Doe"}; return [p1, p2]; } + +Student[] moduleStudents = getStudents(); +Person[] modulePeople = getPeople(); + +// basic/minimal +() v11 = from var st in moduleStudents + select {id: st.id, name: st.fname, age: st.age}; +() v12 = from var st in moduleStudents + select {id: st.id, name: st.fname, age: st.age}; + +// where clause +Student v13 = from var st in moduleStudents + where st.fname == "Jon" + select {name: st.fname}; + +// let clause +Person v14 = from var st in moduleStudents + let string name = st.fname + " " + st.lname + select {id: st.id, name: name}; + +// join clause +Person v15 = from var st in moduleStudents + join var {id, name} in modulePeople on st.id equals id + select {name: name, gpa: st.gpa}; + +// order by clause +Person v16 = from var st in moduleStudents + order by st.id + select st; + +// limit clause +() v17 = from var st in moduleStudents + limit LIMIT + select st; + +// on conflict clause +() v18 = table key(id) from var st in moduleStudents.toStream() + select {id: st.id, name: st.fname, age: st.age} + on conflict error("Conflicted Key", cKey = st.id); + +// group by clause +Student v19 = from var {name, age} in modulePeople + group by age + select age; + +function testQueryExprWithCollect() { + return from var {age, gpa} in getStudents() + let var ageScore = (50 - age) * gpa + collect sum(ageScore); +} From 42aff87b4a0a085107b754fe49b337ff8c47929a Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 30 Jan 2024 16:58:14 +0530 Subject: [PATCH 171/209] Remove redundant test case --- .../semantics/analyzer/TypeChecker.java | 6 +- .../changetype/FixReturnTypeCodeAction.java | 33 +++++++-- .../codeaction/FixReturnTypeTest.java | 14 +++- .../fixReturnTypeForConditionalExpr1.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr2.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr3.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr4.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr5.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr6.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr7.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr8.json | 29 ++++++++ .../config/fixReturnTypeForQueryExpr1.json | 69 +++++++++++++++++++ .../config/fixReturnTypeForQueryExpr2.json | 29 ++++++++ .../config/fixReturnTypeForQueryExpr3.json | 29 ++++++++ .../config/fixReturnTypeForQueryExpr4.json | 29 ++++++++ .../fixReturnTypeForConditionalExpr.bal | 25 +++++++ .../source/fixReturnTypeForQueryExpr.bal | 51 ++++++++++++++ .../symbols_in_conditional_exprs_test.bal | 2 +- .../symbols/symbols_in_query_exprs_test.bal | 2 + 19 files changed, 511 insertions(+), 10 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr5.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr6.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr7.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr8.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForConditionalExpr.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForQueryExpr.bal diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 9e8ef7d33364..1daf42ab31c3 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -5293,11 +5293,11 @@ private BType getXMLConstituents(BType bType) { public void visit(BLangElvisExpr elvisExpr, AnalyzerData data) { BType lhsType = checkExpr(elvisExpr.lhsExpr, data); - BType actualType = lhsType == symTable.semanticError ? + BType lhsActualType = lhsType == symTable.semanticError ? symTable.semanticError : validateElvisExprLhsExpr(elvisExpr, lhsType); BType rhsActualType = silentTypeCheckExpr(elvisExpr.rhsExpr, symTable.noType, data); BType rhsReturnType = checkExpr(elvisExpr.rhsExpr, data.expType, data); - BType lhsReturnType = types.checkType(elvisExpr.lhsExpr.pos, actualType, data.expType, + BType lhsReturnType = types.checkType(elvisExpr.lhsExpr.pos, lhsActualType, data.expType, DiagnosticErrorCode.INCOMPATIBLE_TYPES); if (rhsReturnType == symTable.semanticError || lhsReturnType == symTable.semanticError) { data.resultType = symTable.semanticError; @@ -5307,7 +5307,7 @@ public void visit(BLangElvisExpr elvisExpr, AnalyzerData data) { data.resultType = data.expType; } - elvisExpr.setDeterminedType(getConditionalExprType(actualType, rhsActualType)); + elvisExpr.setDeterminedType(getConditionalExprType(lhsActualType, rhsActualType)); } @Override diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/FixReturnTypeCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/FixReturnTypeCodeAction.java index 37cf178ef4c3..c687ae6e2c3f 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/FixReturnTypeCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/changetype/FixReturnTypeCodeAction.java @@ -69,14 +69,37 @@ public boolean validate(Diagnostic diagnostic, DiagBasedPositionDetails position return false; } - //Suggest the code action only if the immediate parent of the matched node is either of return statement, - //check expression, check action. + // Suggest code action if the node is aligned with a check keyword. NonTerminalNode matchedNode = positionDetails.matchedNode(); - if (matchedNode.parent() != null && matchedNode.parent().kind() != SyntaxKind.RETURN_STATEMENT && - matchedNode.kind() != SyntaxKind.CHECK_EXPRESSION && - matchedNode.kind() != SyntaxKind.CHECK_ACTION) { + if (matchedNode.kind() == SyntaxKind.CHECK_ACTION || matchedNode.kind() == SyntaxKind.CHECK_EXPRESSION) { + return CodeActionNodeValidator.validate(context.nodeAtRange()); + } + + // Suggest code action if the node is an expression inside a return statement. + NonTerminalNode parentNode = matchedNode.parent(); + if (parentNode == null) { + return false; + } + if (parentNode.kind() == SyntaxKind.RETURN_KEYWORD) { + return CodeActionNodeValidator.validate(context.nodeAtRange()); + } + + // Suggest code action if the node is an expression nested into a return statement. + NonTerminalNode grandParentNode = parentNode.parent(); + if (grandParentNode == null) { return false; } + if (grandParentNode.kind() == SyntaxKind.RETURN_STATEMENT) { + return CodeActionNodeValidator.validate(context.nodeAtRange()); + } + + // Suggest code action if the node is an expression inside a collect clause. + if (matchedNode.kind() == SyntaxKind.COLLECT_CLAUSE) { + NonTerminalNode ancestorNode = grandParentNode.parent(); + if (ancestorNode == null || ancestorNode.kind() != SyntaxKind.RETURN_STATEMENT) { + return false; + } + } return CodeActionNodeValidator.validate(context.nodeAtRange()); } diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/FixReturnTypeTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/FixReturnTypeTest.java index 7f937a9541e4..c3389c5ca4b9 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/FixReturnTypeTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/FixReturnTypeTest.java @@ -67,7 +67,19 @@ public Object[][] dataProvider() { {"fixReturnTypeInUnionContext3.json"}, {"fixReturnTypeInUnionContext4.json"}, {"fixReturnTypeInCommitAction.json"}, - {"fixReturnTypeInMain1.json"} + {"fixReturnTypeInMain1.json"}, + {"fixReturnTypeForConditionalExpr1.json"}, + {"fixReturnTypeForConditionalExpr2.json"}, + {"fixReturnTypeForConditionalExpr3.json"}, + {"fixReturnTypeForConditionalExpr4.json"}, + {"fixReturnTypeForConditionalExpr5.json"}, + {"fixReturnTypeForConditionalExpr6.json"}, + {"fixReturnTypeForConditionalExpr7.json"}, + {"fixReturnTypeForConditionalExpr8.json"}, + {"fixReturnTypeForQueryExpr1.json"}, + {"fixReturnTypeForQueryExpr2.json"}, + {"fixReturnTypeForQueryExpr3.json"}, + {"fixReturnTypeForQueryExpr4.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr1.json new file mode 100644 index 000000000000..fc6b045f0a45 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr1.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 6, + "character": 39 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'boolean|int'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 5, + "character": 76 + }, + "end": { + "line": 5, + "character": 76 + } + }, + "newText": " returns boolean|int" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr2.json new file mode 100644 index 000000000000..036ff255608e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr2.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 6, + "character": 51 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'boolean|int'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 5, + "character": 76 + }, + "end": { + "line": 5, + "character": 76 + } + }, + "newText": " returns boolean|int" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr3.json new file mode 100644 index 000000000000..b50259462922 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr3.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 11, + "character": 72 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'module1:TestRecord1|int'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 9, + "character": 76 + }, + "end": { + "line": 9, + "character": 76 + } + }, + "newText": " returns module1:TestRecord1|int" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr4.json new file mode 100644 index 000000000000..1e4a2b4bc402 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr4.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 11, + "character": 81 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'module1:TestRecord1|int'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 9, + "character": 76 + }, + "end": { + "line": 9, + "character": 76 + } + }, + "newText": " returns module1:TestRecord1|int" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr5.json new file mode 100644 index 000000000000..a8151ae1e05d --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr5.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 18, + "character": 18 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'string|boolean'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 17, + "character": 50 + }, + "end": { + "line": 17, + "character": 50 + } + }, + "newText": " returns string|boolean" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr6.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr6.json new file mode 100644 index 000000000000..00cbb777ecf6 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr6.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 18, + "character": 28 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'string|boolean'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 17, + "character": 50 + }, + "end": { + "line": 17, + "character": 50 + } + }, + "newText": " returns string|boolean" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr7.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr7.json new file mode 100644 index 000000000000..ea5c8625404e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr7.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 23, + "character": 74 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'string|int|boolean|module1:TestRecord1|float'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 91 + }, + "end": { + "line": 21, + "character": 91 + } + }, + "newText": " returns string|int|boolean|module1:TestRecord1|float" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr8.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr8.json new file mode 100644 index 000000000000..5916087bcef2 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForConditionalExpr8.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 23, + "character": 86 + }, + "source": "fixReturnTypeForConditionalExpr.bal", + "expected": [ + { + "title": "Change return type to 'string|int|boolean|module1:TestRecord1|float'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 21, + "character": 91 + }, + "end": { + "line": 21, + "character": 91 + } + }, + "newText": " returns string|int|boolean|module1:TestRecord1|float" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr1.json new file mode 100644 index 000000000000..317f8dfc1279 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr1.json @@ -0,0 +1,69 @@ +{ + "position": { + "line": 29, + "character": 11 + }, + "source": "fixReturnTypeForQueryExpr.bal", + "expected": [ + { + "title": "Change return type to 'map[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 28, + "character": 32 + }, + "end": { + "line": 28, + "character": 32 + } + }, + "newText": " returns map[]" + } + ], + "resolvable": false + }, + { + "title": "Change return type to 'record {|string name; float gpa;|}[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 28, + "character": 32 + }, + "end": { + "line": 28, + "character": 32 + } + }, + "newText": " returns record {|string name; float gpa;|}[]" + } + ], + "resolvable": false + }, + { + "title": "Change return type to 'json[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 28, + "character": 32 + }, + "end": { + "line": 28, + "character": 32 + } + }, + "newText": " returns json[]" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr2.json new file mode 100644 index 000000000000..ebc954fefb84 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr2.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 36, + "character": 24 + }, + "source": "fixReturnTypeForQueryExpr.bal", + "expected": [ + { + "title": "Change return type to 'stream'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 34, + "character": 38 + }, + "end": { + "line": 34, + "character": 38 + } + }, + "newText": " returns stream" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr3.json new file mode 100644 index 000000000000..1a967ad049da --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr3.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 42, + "character": 12 + }, + "source": "fixReturnTypeForQueryExpr.bal", + "expected": [ + { + "title": "Change return type to '(int?)[]'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 40, + "character": 35 + }, + "end": { + "line": 40, + "character": 35 + } + }, + "newText": " returns (int?)[]" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr4.json new file mode 100644 index 000000000000..094ffcd0fa60 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/config/fixReturnTypeForQueryExpr4.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 49, + "character": 18 + }, + "source": "fixReturnTypeForQueryExpr.bal", + "expected": [ + { + "title": "Change return type to 'float'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 46, + "character": 35 + }, + "end": { + "line": 46, + "character": 35 + } + }, + "newText": " returns float" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForConditionalExpr.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForConditionalExpr.bal new file mode 100644 index 000000000000..0e3ef9079b05 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForConditionalExpr.bal @@ -0,0 +1,25 @@ +import ballerina/module1; + +boolean moduleFlag1 = false; +boolean moduleFlag2 = true; + +function testNestedTernaryExpr2(boolean flag1, boolean flag2, boolean flag3) { + return flag1 == flag3 ? flag1 && moduleFlag2 : 0; +} + +function testNestedTernaryExpr3(boolean flag1, boolean flag2, boolean flag3) { + module1:TestRecord1 rec1 = {}; + return (flag1 == flag3 ? moduleFlag1 && flag2 : flag1 || flag3) ? rec1 : 0 + 32; +} + +string? moduleNullableStr = (); +int? moduleNullableInt = 1; + +function testNestedElvisExpr1(string? nullableStr) { + return nullableStr ?: false; +} + +function testNestedElvisExpr2(string? nullableStr, int? nullableInt, boolean? nullableBool) { + module1:TestRecord1? nullableRec = {}; + return moduleNullableStr ?: moduleNullableInt ?: nullableBool ?: nullableRec ?: 0.0; +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForQueryExpr.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForQueryExpr.bal new file mode 100644 index 000000000000..5f862e6b5f0e --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/fix-return-type/source/fixReturnTypeForQueryExpr.bal @@ -0,0 +1,51 @@ +type Person record {| + readonly int id; + string name; + int age?; + Person parent?; +|}; + +type Student record { + int id; + string fname; + string lname; + int age; + float gpa; +}; + +function getStudents() returns Student[] { + Student s3 = {id: 3, fname: "Amy", lname: "Melina", age: 30, gpa: 1.3}; + Student s1 = {id: 1, fname: "Jon", lname: "Doe", age: 21, gpa: 2.1}; + Student s2 = {id: 2, fname: "Jane", lname: "Doe", age: 25, gpa: 3.2}; + return [s1, s2, s3]; +} + +function getPeople() returns Person[] { + Person p1 = {id: 1, name: "Jon Doe"}; + Person p2 = {id: 2, name: "Jane Doe"}; + return [p1, p2]; +} + +function testQueryExprWithJoin() { + return from var st in getStudents() + join var {id, name} in getPeople() on st.id equals id + select {name: name, gpa: st.gpa}; +} + +function testQueryExprWithOnConflict() { + return table key(id) from var st in getStudents().toStream() + select {id: st.id, name: st.fname, age: st.age} + on conflict error("Conflicted Key", cKey = st.id); +} + +function testQueryExprWithGroupBy() { + return from var {name, age} in getPeople() + group by age + select age; +} + +function testQueryExprWithCollect() { + return from var {age, gpa} in getStudents() + let var ageScore = (50 - age) * gpa + collect sum(ageScore); +} diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal index d167328aad57..26d927fb74fa 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_conditional_exprs_test.bal @@ -56,4 +56,4 @@ function testNestedElvisExpr2(string? nullableStr, int? nullableInt, boolean? nu function testNestedElvisExpr3(string? nullableStr, int? nullableInt, boolean? nullableBool) { return moduleNullableStr ?: (nullableBool is boolean ? nullableBool || moduleFlag1 : nullableInt ?: "False"); -} \ No newline at end of file +} diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal index 4e38c2130d23..6af6c601503d 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/symbols_in_query_exprs_test.bal @@ -90,6 +90,8 @@ function getPeople() returns Person[] { return [p1, p2]; } + + Student[] moduleStudents = getStudents(); Person[] modulePeople = getPeople(); From c96ee0115b72ba6c1d43ec4c45a88daa91f75046 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Fri, 2 Feb 2024 15:00:27 +0530 Subject: [PATCH 172/209] Fix failing unit tests --- .../wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java index aea21af2282a..18e2d95e4743 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmPackageGen.java @@ -567,7 +567,7 @@ private void linkModuleFunctions(BIRPackage birPackage, String initClass, boolea // link the bir function for lookup String birFuncName = birFunc.name.value; String balFileName; - if (birFunc.pos == null) { + if (birFunc.pos == null || birFunc.pos == symbolTable.builtinPos) { balFileName = MODULE_INIT_CLASS_NAME; } else { balFileName = birFunc.pos.lineRange().fileName(); From e045782201e738a25def927d5db3b7fd7a00043f Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Sat, 20 Jan 2024 09:53:07 +0530 Subject: [PATCH 173/209] Fix coverage mapping logic for modified sources When a code modifier modifies the source code, the generated coverage report is for the modified source code. Then this is mapped to the original source code. That logic has been rewritten to fix prevailing bugs. --- .../test/runtime/entity/CoverageReport.java | 111 +++++++--------- tests/testerina-integration-test/build.gradle | 12 ++ .../test/CodegenCodeCoverageTest.java | 124 +++++++++++------- ..._comp_plugin_code_modify_add_function.bala | Bin 9826 -> 0 bytes .../Ballerina.toml | 4 + .../CompilerPlugin.toml | 8 ++ .../Dependencies.toml | 17 +++ .../main.bal | 3 + 8 files changed, 170 insertions(+), 109 deletions(-) delete mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/balas/package_comp_plugin_code_modify_add_function.bala create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Ballerina.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/main.bal diff --git a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java index b9f6ad5b7527..5fa822659155 100644 --- a/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java +++ b/misc/testerina/modules/testerina-runtime/src/main/java/org/ballerinalang/test/runtime/entity/CoverageReport.java @@ -77,17 +77,16 @@ public class CoverageReport { private final String title; private final Path coverageDir; - private Path executionDataFile; - private Path classesDirectory; - private ExecFileLoader execFileLoader; - private Module module; - private Target target; - private Map moduleCoverageMap; - private List packageNativeClassCoverageList; - private List packageBalClassCoverageList; - private List packageSourceCoverageList; - private List packageExecData; - private List sessionInfoList; + private final Path executionDataFile; + private final Path classesDirectory; + private final ExecFileLoader execFileLoader; + private final Module module; + private final Map moduleCoverageMap; + private final List packageNativeClassCoverageList; + private final List packageBalClassCoverageList; + private final List packageSourceCoverageList; + private final List packageExecData; + private final List sessionInfoList; public CoverageReport(Module module, Map moduleCoverageMap, List packageNativeClassCoverageList, @@ -95,7 +94,7 @@ public CoverageReport(Module module, Map moduleCoverageM List packageSourceCoverageList, List packageExecData, List sessionInfoList) throws IOException { this.module = module; - this.target = new Target(module.project().targetDir()); + Target target = new Target(module.project().targetDir()); this.coverageDir = target.getTestsCachePath().resolve(TesterinaConstants.COVERAGE_DIR); this.title = coverageDir.toFile().getName(); this.classesDirectory = coverageDir.resolve(TesterinaConstants.BIN_DIR); @@ -115,7 +114,7 @@ public CoverageReport(Module module, Map moduleCoverageM * @param jBallerinaBackend JBallerinaBackend * @param includesInCoverage boolean * @param exclusionClassList list of classes to be excluded - * @throws IOException + * @throws IOException if an error occurs while generating the report */ public void generateReport(JBallerinaBackend jBallerinaBackend, String includesInCoverage, String reportFormat, Module originalModule, Set exclusionClassList) @@ -182,7 +181,7 @@ private List getDependenciesForJacocoXML(JBallerinaBackend jBallerinaBacke * @param originalModule Module * @param exclusionClassList list of classes to be excluded * @return CoverageBuilder - * @throws IOException + * @throws IOException if an error occurs while generating the report */ private CoverageBuilder generateTesterinaCoverageReport(String orgName, String packageName, List filteredPathList, @@ -200,12 +199,8 @@ private CoverageBuilder generateTesterinaCoverageReport(String orgName, String p private List getGeneratedFilesToExclude(Module originalModules) { List excludedDocumentIds = new ArrayList<>(this.module.documentIds()); - List oldDocuementIds = new ArrayList<>(); - // Add all old document ids - for (DocumentId documentId : originalModules.documentIds()) { - oldDocuementIds.add(documentId); - } - excludedDocumentIds.removeAll(oldDocuementIds); + List oldDocumentIds = new ArrayList<>(originalModules.documentIds()); + excludedDocumentIds.removeAll(oldDocumentIds); return excludedDocumentIds; } @@ -247,9 +242,7 @@ private void updatePackageLevelCoverage(CoverageBuilder coverageBuilder) { } // Jacoco is capable of handling duplicated execution data, // so it is not needed to remove duplicates. - for (ExecutionData executionData : execFileLoader.getExecutionDataStore().getContents()) { - packageExecData.add(executionData); - } + packageExecData.addAll(execFileLoader.getExecutionDataStore().getContents()); } private boolean isExistingSessionInfo(SessionInfo sessionInfo) { @@ -276,7 +269,7 @@ private void removeFromCoverageList(IClassCoverage classCoverage) { coverageToRemove = coverage; } } - if (isExists && coverageToRemove != null) { + if (isExists) { packageNativeClassCoverageList.remove(coverageToRemove); } } @@ -336,7 +329,7 @@ private void createReport(final IBundleCoverage bundleCoverage, Map> coveredLinesList = moduleCoverage.getCoveredLinesList( sourceFileCoverage.getName()); - if (!missedLinesList.isEmpty() && !coveredLinesList.isEmpty()) { + if (missedLinesList.isPresent() && coveredLinesList.isPresent()) { List missedLines = missedLinesList.get(); List coveredLines = coveredLinesList.get(); List existingMissedLines = new ArrayList<>(missedLines); @@ -388,8 +381,8 @@ private void createReport(final IBundleCoverage bundleCoverage, Map moduleCoverageM modifiedDocument.textDocument().textLines()); if (!stringPatch.getDeltas().isEmpty()) { List> patchDeltas = stringPatch.getDeltas(); - List insertedLines = new ArrayList(); + List insertedLines = new ArrayList<>(); List modifiedLines = new ArrayList<>(); List deletedLines = new ArrayList<>(); for (AbstractDelta delta : patchDeltas) { @@ -463,7 +456,10 @@ private void filterGeneratedCoverage(Map moduleCoverageM } } else if (delta.getType().equals(DeltaType.DELETE)) { int lineNumber = delta.getSource().getPosition(); - deletedLines.add(lineNumber); + int size = delta.getSource().size(); + for (int i = lineNumber; i < lineNumber + size; i++) { + deletedLines.add(i); + } } } @@ -471,47 +467,43 @@ private void filterGeneratedCoverage(Map moduleCoverageM List coveredLinesList = moduleCoverage.getCoveredLinesList(modifiedDocument.name()).get(); List missedLinesList = moduleCoverage.getMissedLinesList(modifiedDocument.name()).get(); - // Populate lineStatus with zeroes - List lineStatus = new ArrayList<>(); + // create the modified document coverage list + List modifiedDocLineStatus = new ArrayList<>(); for (int i = 0; i < modifiedDocument.textDocument().textLines().size(); i++) { - lineStatus.add(0); - } - - // Replace line status with respective covered and missed statuses - for (Integer coveredLine : coveredLinesList) { - lineStatus.remove(coveredLine); - lineStatus.add(coveredLine, FULLY_COVERED); - } - for (Integer missedLine : missedLinesList) { - lineStatus.remove(missedLine); - lineStatus.add(missedLine, NOT_COVERED); + if (coveredLinesList.contains(i + 1)) { + modifiedDocLineStatus.add(FULLY_COVERED); + } else if (missedLinesList.contains(i + 1)) { + modifiedDocLineStatus.add(NOT_COVERED); + } else { + modifiedDocLineStatus.add(EMPTY); + } } - List newLineStatus = new ArrayList<>(); - for (int i = 0; i < lineStatus.size(); i++) { - if (insertedLines.contains(i)) { - continue; + // iterate the modified coverage list and map to the original document + List originalDocLineStatus = new ArrayList<>(); + for (int i = 0; i < modifiedDocument.textDocument().textLines().size(); i++) { + while (deletedLines.contains(originalDocLineStatus.size() + 1)) { + // if the next line is deleted in the source, we add the line status as empty + originalDocLineStatus.add(EMPTY); } - // If an empty line was modified or deleted, add the line status as empty if (modifiedLines.contains(i)) { - newLineStatus.add(EMPTY); - } else { - newLineStatus.add(lineStatus.get(i)); - } - // If a deleted line exists - if (deletedLines.contains(i)) { - newLineStatus.add(EMPTY); + // if the line is modified, we add the line status as empty + originalDocLineStatus.add(EMPTY); + } else if (!insertedLines.contains(i)) { + // if the line is not modified, nor inserted, we add the line status as it is + originalDocLineStatus.add(modifiedDocLineStatus.get(i)); } + // if the line is inserted, we ignore it } List newCoveredLines = new ArrayList<>(); List newMissedLines = new ArrayList<>(); // Go through line status and get the new covered and missed lines - for (int i = 0; i < newLineStatus.size(); i++) { - if (newLineStatus.get(i).equals(FULLY_COVERED)) { + for (int i = 0; i < originalDocLineStatus.size(); i++) { + if (originalDocLineStatus.get(i).equals(FULLY_COVERED)) { newCoveredLines.add(i + 1); - } else if (newLineStatus.get(i).equals(NOT_COVERED)) { + } else if (originalDocLineStatus.get(i).equals(NOT_COVERED)) { newMissedLines.add(i + 1); } } @@ -526,7 +518,6 @@ private void filterGeneratedCoverage(Map moduleCoverageM // Diff exception caught when diff cannot be calculated properly // NullPointer caught when a Generated Source File is passed or if its an empty file // continue to consider other files in the coverage - continue; } } } @@ -604,7 +595,6 @@ private List getPlatformLibsList(JBallerinaBackend jBallerinaBackend, Pack return platformLibsList; } - private List getDependencyJarList(JBallerinaBackend jBallerinaBackend) { List dependencyPathList = new ArrayList<>(); module.packageInstance().getResolution().allDependencies() @@ -630,5 +620,4 @@ private List getDependencyJarList(JBallerinaBackend jBallerinaBackend) { }); return dependencyPathList; } - } diff --git a/tests/testerina-integration-test/build.gradle b/tests/testerina-integration-test/build.gradle index cc39c16409d3..67c50c427d63 100644 --- a/tests/testerina-integration-test/build.gradle +++ b/tests/testerina-integration-test/build.gradle @@ -23,6 +23,9 @@ def extractedDist = "$buildDir/extractedDistribution/jballerina-tools-${project. configurations { jballerinaTools + compilerPluginJar { + transitive false + } } dependencies { @@ -48,12 +51,20 @@ dependencies { implementation group: 'org.ow2.asm', name: 'asm-commons', version: "${project.ow2AsmCommonsVersion}" implementation group: 'org.ow2.asm', name: 'asm-tree', version: "${project.ow2AsmTreeVersion}" implementation group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: "${project.javaDiffUtilsVersion}" + + compilerPluginJar project(':project-api-test-artifact:init-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:diagnostic-utils-lib') } jacoco { toolVersion = "${project.jacocoVersion}" } +task copyCompilerPluginJars(type: Copy) { + from configurations.compilerPluginJar + into "$buildDir/compiler-plugin-jars" +} + task extractDistribution(type: Copy) { dependsOn ':jballerina-tools:build' from zipTree(configurations.jballerinaTools.asPath) @@ -72,6 +83,7 @@ test { mustRunAfter ':jballerina-integration-test:test' dependsOn extractDistribution dependsOn testUtilsJar + dependsOn copyCompilerPluginJars systemProperty 'enableTesterinaTests', 'true' maxParallelForks = 1 diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java index 97c145ff8974..76b6d8c69e39 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java @@ -25,8 +25,10 @@ import org.ballerinalang.test.context.BMainInstance; import org.ballerinalang.test.context.BallerinaTestException; import org.ballerinalang.test.context.LogLeecher; +import org.ballerinalang.testerina.test.utils.FileUtils; import org.testng.Assert; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.BufferedReader; @@ -36,6 +38,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Map; /** * Test class to test report for Codegen ballerina projects. @@ -43,12 +46,18 @@ public class CodegenCodeCoverageTest extends BaseTestCase { private BMainInstance balClient; private String projectPath; + Path repoBalaPath; private Path resultsJsonPath; private JsonObject resultObj; - private static final int TOTAL_TESTS = 0; - private static final int PASSED = 1; - private static final int SKIPPED = 2; - private static final int FAILED = 3; + + private static final String TOTAL_TESTS = "totalTests"; + private static final String PASSED_TESTS = "passed"; + private static final String FAILED_TESTS = "failed"; + private static final String SKIPPED_TESTS = "skipped"; + private static final String FOO_COVERED = "fooCovered"; + private static final String FOO_MISSED = "fooMissed"; + private static final String MAIN_COVERED = "mainCovered"; + private static final String MAIN_MISSED = "mainMissed"; @BeforeClass public void setup() throws BallerinaTestException, IOException { @@ -56,37 +65,69 @@ public void setup() throws BallerinaTestException, IOException { projectPath = projectBasedTestsPath.resolve("codegen-coverage-test").toString(); resultsJsonPath = projectBasedTestsPath.resolve("codegen-coverage-test").resolve("target").resolve("report") .resolve("test_results.json"); - Path repoBalaPath = Paths.get(balServer.getServerHome()).resolve("repo"); - Path balaPath = projectBasedTestsPath.resolve( - "codegen-coverage-test/balas/package_comp_plugin_code_modify_add_function.bala"); - BCompileUtil.copyBalaToExtractedDist(balaPath, - "samjs", - "package_comp_plugin_code_modify_add_function", - "0.1.0", - repoBalaPath); + FileUtils.copyFolder(Paths.get("build").resolve("compiler-plugin-jars"), + projectBasedTestsPath.resolve("compiler-plugin-jars")); + repoBalaPath = Paths.get(balServer.getServerHome()).resolve("repo"); + } + + @DataProvider(name = "provideCoverageData") + public Object[][] provideCoverageData() { + return new Object[][]{ + { + "package_comp_plugin_code_modify_add_function", + Map.of(TOTAL_TESTS, 2, PASSED_TESTS, 2, FAILED_TESTS, 0, SKIPPED_TESTS, 0), + Map.of( + FOO_COVERED, new int[]{3, 4}, + FOO_MISSED, new int[]{8, 11, 12}, + MAIN_COVERED, new int[]{8, 9}, + MAIN_MISSED, new int[]{3, 4, 5} + ) + } + }; } - @Test(enabled = false) - public void codegenCoverageTest() throws BallerinaTestException { + @Test(description = "Test code coverage report generation for a codegen project", dataProvider = "provideCoverageData") + public void codegenCoverageTest(String compilerPluginName, Map status, Map coverage) throws BallerinaTestException, IOException { + publishCompilerPlugin(compilerPluginName); String[] args = new String[] {"--code-coverage"}; runCommand(args); - int total = 2, passed = 2, failed = 0, skipped = 0; - int[] status = {total, passed, failed, skipped}; - validateStatus(status, "codegen_coverage_test"); - validateCoverage(); + validateStatus(status); + validateCoverage(coverage); + } + + private void publishCompilerPlugin(String compilerPluginName) throws BallerinaTestException, IOException { + String compilerPluginBalaPath = projectBasedTestsPath.resolve("compiler-plugins") + .resolve(compilerPluginName).toString(); + balClient.runMain("pack", new String[]{}, null, null, new LogLeecher[]{}, compilerPluginBalaPath); + Path balaPath = projectBasedTestsPath.resolve(compilerPluginBalaPath).resolve("target").resolve("bala") + .resolve("samjs-" + compilerPluginName + "-java17-0.1.0.bala"); + BCompileUtil.copyBalaToExtractedDist(balaPath, "samjs", compilerPluginName, "0.1.0", repoBalaPath); + } + + + private void validateStatus(Map status) { + String moduleName = "codegen_coverage_test"; + for (JsonElement obj : resultObj.get("moduleStatus").getAsJsonArray()) { + JsonObject moduleObj = ((JsonObject) obj); + if (moduleName.equals(moduleObj.get("name").getAsString())) { + String msg = "Status check failed for module : " + moduleName + "."; + validateStatus(status, moduleObj, msg); + return; + } + } + Assert.fail("Module status for " + moduleName + " could not be found"); } - private void validateCoverage() { - JsonParser parser = new JsonParser(); + private void validateCoverage(Map coverage) { // foo file - int[] fooCovered = new int[] {3, 4}, fooMissed = new int[] {8, 11, 12}; + int[] fooCovered = coverage.get(FOO_COVERED), fooMissed = coverage.get(FOO_MISSED); float fooPercentageVal = (float) (fooCovered.length) / (fooCovered.length + fooMissed.length) * 100; float fooPercentage = (float) (Math.round(fooPercentageVal * 100.0) / 100.0); int fooCoveredVal = fooCovered.length, fooMissedVal = fooMissed.length; // main file - int[] mainCovered = new int[] {8, 9}, mainMissed = new int[] {3, 4, 5}; + int[] mainCovered = coverage.get(MAIN_COVERED), mainMissed = coverage.get(MAIN_MISSED); float mainPercentageVal = (float) (mainCovered.length) / (mainCovered.length + mainMissed.length) * 100; float mainPercentage = @@ -105,16 +146,16 @@ private void validateCoverage() { for (JsonElement sourceFiles : moduleObj.get("sourceFiles").getAsJsonArray()) { JsonObject fileObj = (JsonObject) sourceFiles; if ("foo.bal".equals(fileObj.get("name").getAsString())) { - Assert.assertEquals(parser.parse(Arrays.toString(fooCovered)), - parser.parse(fileObj.get("coveredLines").getAsJsonArray().toString())); - Assert.assertEquals(parser.parse(Arrays.toString(fooMissed)), - parser.parse(fileObj.get("missedLines").getAsJsonArray().toString())); + Assert.assertEquals(JsonParser.parseString(Arrays.toString(fooCovered)), + JsonParser.parseString(fileObj.get("coveredLines").getAsJsonArray().toString())); + Assert.assertEquals(JsonParser.parseString(Arrays.toString(fooMissed)), + JsonParser.parseString(fileObj.get("missedLines").getAsJsonArray().toString())); Assert.assertEquals(fooPercentage, fileObj.get("coveragePercentage").getAsFloat()); } else if ("main.bal".equals(fileObj.get("name").getAsString())) { - Assert.assertEquals(parser.parse(Arrays.toString(mainCovered)), - parser.parse(fileObj.get("coveredLines").getAsJsonArray().toString())); - Assert.assertEquals(parser.parse(Arrays.toString(mainMissed)), - parser.parse(fileObj.get("missedLines").getAsJsonArray().toString())); + Assert.assertEquals(JsonParser.parseString(Arrays.toString(mainCovered)), + JsonParser.parseString(fileObj.get("coveredLines").getAsJsonArray().toString())); + Assert.assertEquals(JsonParser.parseString(Arrays.toString(mainMissed)), + JsonParser.parseString(fileObj.get("missedLines").getAsJsonArray().toString())); Assert.assertEquals(mainPercentage, fileObj.get("coveragePercentage").getAsFloat()); } } @@ -125,24 +166,11 @@ private void validateCoverage() { } - - private void validateStatus(int[] status, String moduleName) { - for (JsonElement obj : resultObj.get("moduleStatus").getAsJsonArray()) { - JsonObject moduleObj = ((JsonObject) obj); - if (moduleName.equals(moduleObj.get("name").getAsString())) { - String msg = "Status check failed for module : " + moduleName + "."; - validateStatus(status, moduleObj, msg); - return; - } - } - Assert.fail("Module status for " + moduleName + " could not be found"); - } - - private void validateStatus(int[] status, JsonObject obj, String msg) { - Assert.assertEquals(obj.get("totalTests").getAsInt(), status[TOTAL_TESTS], msg); - Assert.assertEquals(obj.get("passed").getAsInt(), status[PASSED], msg); - Assert.assertEquals(obj.get("failed").getAsInt(), status[FAILED], msg); - Assert.assertEquals(obj.get("skipped").getAsInt(), status[SKIPPED], msg); + private void validateStatus(Map status, JsonObject obj, String msg) { + Assert.assertEquals(obj.get("totalTests").getAsInt(), status.get(TOTAL_TESTS), msg); + Assert.assertEquals(obj.get("passed").getAsInt(), status.get(PASSED_TESTS), msg); + Assert.assertEquals(obj.get("failed").getAsInt(), status.get(FAILED_TESTS), msg); + Assert.assertEquals(obj.get("skipped").getAsInt(), status.get(SKIPPED_TESTS), msg); } private void runCommand(String[] args) throws BallerinaTestException { diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/balas/package_comp_plugin_code_modify_add_function.bala b/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/balas/package_comp_plugin_code_modify_add_function.bala deleted file mode 100644 index 9946074ea5b0f8fa081b9c47a1efcbb825e2a9d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9826 zcmcI~1yCK?*6u-qyIT$<1P$)4!QI_05ZocSg%I4`-3jjQ?!n#N9Ujcwyvd!KsWKV|vr-^QNjhN62uJg1Ea&(Lk?21Rmq`#HYloThofdAo>2o1Y@nrY|wy{pH3gQ#Y zE}X%n#UP;;&v6M8pW}Ur`FAv4;55x<`ZsLR{{jtDV_loy0k(Dh2LRLjqOu7B0HFUn zmHNgyM&=eaw#IstcDBZ*Hk8kXC~2u^o(~fp>)-GOe>TYL{+BBXdu(X9qN}~UtSzl+ zh|vcC7l%V?f$nH3eiK}m>}GyD00%+}!#qjf7y&^Z3a*Q+@7omYmTX?!`o_7*JjHc5 z@$zJ9vc6}psKD-U;AW5)LMafR!}UB8dXPq6EzXmL9>1N-_6tZ98p)<1`kDf%S0T;& zGEx%yJkqjUloB91p0g|+>iF5|H!->hF)=zDnuDl$<@v{?Fi&3ZD9_e#VS4rDdub#s zYF3i68b>o>^QzJeo}`%}lIp-u@HQp)P@fMt+4mV^WXC(|c!+ag?=chH44Rf0rBp5M z{0`!^Cftvo!tN`r!}u1MuZ9Mvqew&zJ{*`OvtJo*G{i9*9VR!sYrVdM^qdYXu;*}2 zoFqW&LbGvHc=}Y&;f-`N`G(nMF5r8_9HJsMxf16-TGRRXFepgLFfV0dSc$FyyWBic zvK#C9>ZU`{dH`%%`B(&1Vu^ps%GfSbhW(OB3~R|yVP6ka(z#Xb=~7;d#hI;CqT}|2 zP*?kd&fG%0JYqC-P&o-LJwo*fXLvC8If;O6zjnhZ5?R zEH?1FDknr2@9p=$iS)>y?q-FM(@l|OH|w^JEX-Q8B5eA zUW2ug(=Nplp*m(`HnKOSATu()uG0*+g^vxW@FWvO65iU(iQLTGHQdbF;FlHo=#jIe z1L?^afU3%zi^ZuM?6getc?fJO$u~sVAjG19$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?dvW zFSh>Liy;sI;DrU&H?TA?*EcZNbD}h|*0KEfk36aj9foNqfctXf3Uk6C>ab7{_=b0U zRWakE8dla((~o9v4G6uM)FmNZw_sl+IuADH|L3d#MuG#cQdRptE2n*0ftN)TY- zykqt%XH~dv1r|yymeCAG7OCZA=Mx&_zCAZdrj&IgXi-QaeFDlolr%=9~ zf=85Ae1bY4>&Bbw{ziG6sZjdfZmJucd%W0rB!RrU^YoQ!h7$Pd655c;90#-MLStit zLrJ}BTyEg_$I#W&26+Nw*CG76*VM@H43ak(tvc>G`ibtQqCLj`-WS9+skJTs#Ao*c zVA~!Ad+;w9Z8Vj$_B~_tf`qgf2q+rZ-_K$^zxJCv@V@;0i46M(-|_F-f6iw7I;Ze5 zoAFaBJSG1^`=6}+qm}wKp1+!Z_-XNhSN%EqKUtvuhtm*$1oc8N{z^T*%tQQ?3eS?i zGx7g79q}{97gS#y_%-FfFq}W7!c+5^4gJd){}=eqpI*IK|26Zy+`p8YpYp(K^cwIV z6raD}pD*R-r#$c${i5}MxETGh-Y@HQ@SJ~k4QwAicX TT@C=iJ|At*6955kUhe)6xKslv diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Ballerina.toml new file mode 100644 index 000000000000..f0f026dc457b --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "samjs" +name = "package_comp_plugin_code_modify_add_function" +version = "0.1.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml new file mode 100644 index 000000000000..3ac66eaa133b --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml @@ -0,0 +1,8 @@ +[plugin] +class = "io.samjs.plugins.init.codemodify.CodeModifyFunctionPlugin" + +[[dependency]] +path = "../../compiler-plugin-jars/init-function-code-modify-compiler-plugin-1.0.0.jar" + +[[dependency]] +path = "../../compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml new file mode 100644 index 000000000000..62d792fdd7d6 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.4" + +[[package]] +org = "samjs" +name = "package_comp_plugin_code_modify_add_function" +version = "0.1.0" +modules = [ + {org = "samjs", packageName = "package_comp_plugin_code_modify_add_function", moduleName = "package_comp_plugin_code_modify_add_function"} +] + diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/main.bal new file mode 100644 index 000000000000..41a101b1c439 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/main.bal @@ -0,0 +1,3 @@ +public function doSomething() { + // Do nothing +} From c37796623f55ec1167a7121e1958bf19c9d1f612 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 29 Jan 2024 14:18:33 +0530 Subject: [PATCH 174/209] Improve CodegenCodeCoverageTest --- project-api/project-api-test/build.gradle | 2 + .../build.gradle | 39 +++++ .../AddRemoveFunctionsCodeModifier.java | 148 ++++++++++++++++++ .../codemodify/CodeModifyFunctionPlugin.java | 33 ++++ .../src/main/java/module-info.java | 8 + .../build.gradle | 39 +++++ .../codemodify/CodeModifyFunctionPlugin.java | 33 ++++ .../RemoveFunctionCodeModifier.java | 69 ++++++++ .../src/main/java/module-info.java | 8 + settings.gradle | 4 + tests/testerina-integration-test/build.gradle | 2 + .../test/CodegenCodeCoverageTest.java | 64 +++++--- .../Ballerina.toml | 0 .../line-insert-and-remove-test/foo.bal | 10 ++ .../line-insert-and-remove-test/main.bal | 18 +++ .../tests/main_test.bal | 0 .../line-insert-test/Ballerina.toml | 4 + .../line-insert-test}/foo.bal | 0 .../line-insert-test}/main.bal | 0 .../line-insert-test/tests/main_test.bal | 11 ++ .../line-remove-test/Ballerina.toml | 4 + .../line-remove-test/foo.bal | 12 ++ .../line-remove-test/main.bal | 9 ++ .../line-remove-test/tests/main_test.bal | 11 ++ .../Dependencies.toml | 17 -- .../Ballerina.toml | 4 + .../CompilerPlugin.toml | 8 + .../main.bal | 3 + .../Ballerina.toml | 4 + .../CompilerPlugin.toml | 8 + .../main.bal | 3 + 31 files changed, 538 insertions(+), 37 deletions(-) create mode 100644 project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/build.gradle create mode 100644 project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/AddRemoveFunctionsCodeModifier.java create mode 100644 project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/CodeModifyFunctionPlugin.java create mode 100644 project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/module-info.java create mode 100644 project-api/test-artifacts/remove-function-code-modify-compiler-plugin/build.gradle create mode 100644 project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/CodeModifyFunctionPlugin.java create mode 100644 project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/RemoveFunctionCodeModifier.java create mode 100644 project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/module-info.java rename tests/testerina-integration-test/src/test/resources/project-based-tests/{codegen-coverage-test => code-coverage-report-test/line-insert-and-remove-test}/Ballerina.toml (100%) create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/foo.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/main.bal rename tests/testerina-integration-test/src/test/resources/project-based-tests/{codegen-coverage-test => code-coverage-report-test/line-insert-and-remove-test}/tests/main_test.bal (100%) create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/Ballerina.toml rename tests/testerina-integration-test/src/test/resources/project-based-tests/{codegen-coverage-test => code-coverage-report-test/line-insert-test}/foo.bal (100%) rename tests/testerina-integration-test/src/test/resources/project-based-tests/{codegen-coverage-test => code-coverage-report-test/line-insert-test}/main.bal (100%) create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/tests/main_test.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/Ballerina.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/foo.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/tests/main_test.bal delete mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/Ballerina.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/CompilerPlugin.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/main.bal create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/Ballerina.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/CompilerPlugin.toml create mode 100644 tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/main.bal diff --git a/project-api/project-api-test/build.gradle b/project-api/project-api-test/build.gradle index 2223fb792c02..9f3519c92800 100644 --- a/project-api/project-api-test/build.gradle +++ b/project-api/project-api-test/build.gradle @@ -65,6 +65,8 @@ dependencies { compilerPluginJar project(':project-api-test-artifact:bad-sad-compiler-plugin') compilerPluginJar project(':project-api-test-artifact:init-function-codegen-compiler-plugin') compilerPluginJar project(':project-api-test-artifact:init-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:remove-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:add-remove-function-code-modify-compiler-plugin') compilerPluginJar project(':compiler-plugins:package-semantic-analyzer') compilerPluginJar project(':project-api-test-artifact:init-function-diagnostic-compiler-plugin') compilerPluginJar project(':project-api-test-artifact:compiler-plugin-with-analyzer-generator-modifier') diff --git a/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/build.gradle b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/build.gradle new file mode 100644 index 000000000000..34b3532abb7d --- /dev/null +++ b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/build.gradle @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +apply from: "$rootDir/gradle/javaProject.gradle" + +description = 'Compiler Plugin Tests - Code Modify Add And Remove Function' +version = '1.0.0' + +dependencies { + implementation project(':ballerina-lang') + implementation project(':ballerina-parser') + implementation project(':ballerina-tools-api') + implementation project(':project-api-test-artifact:diagnostic-utils-lib') +} + +ext.moduleName = 'compiler.plugin.test.addremove.func.codemodify' + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} diff --git a/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/AddRemoveFunctionsCodeModifier.java b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/AddRemoveFunctionsCodeModifier.java new file mode 100644 index 000000000000..ea873d9f983b --- /dev/null +++ b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/AddRemoveFunctionsCodeModifier.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.samjs.plugins.addremove.codemodify; + +import io.ballerina.compiler.syntax.tree.FunctionBodyBlockNode; +import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; +import io.ballerina.compiler.syntax.tree.FunctionSignatureNode; +import io.ballerina.compiler.syntax.tree.MinutiaeList; +import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode; +import io.ballerina.compiler.syntax.tree.ModulePartNode; +import io.ballerina.compiler.syntax.tree.NodeList; +import io.ballerina.compiler.syntax.tree.OptionalTypeDescriptorNode; +import io.ballerina.compiler.syntax.tree.RequiredParameterNode; +import io.ballerina.compiler.syntax.tree.ReturnTypeDescriptorNode; +import io.ballerina.compiler.syntax.tree.SimpleNameReferenceNode; +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.compiler.syntax.tree.SyntaxTree; +import io.ballerina.compiler.syntax.tree.Token; +import io.ballerina.projects.Document; +import io.ballerina.projects.DocumentId; +import io.ballerina.projects.ModuleId; +import io.ballerina.projects.plugins.CodeModifier; +import io.ballerina.projects.plugins.CodeModifierContext; + +import java.util.ArrayList; +import java.util.List; + +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createEmptyMinutiaeList; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createEmptyNodeList; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createIdentifierToken; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createMinutiaeList; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createNodeList; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createSeparatedNodeList; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createToken; +import static io.ballerina.compiler.syntax.tree.AbstractNodeFactory.createWhitespaceMinutiae; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createFunctionBodyBlockNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createFunctionDefinitionNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createFunctionSignatureNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createOptionalTypeDescriptorNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createParameterizedTypeDescriptorNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createRequiredParameterNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createReturnTypeDescriptorNode; +import static io.ballerina.compiler.syntax.tree.NodeFactory.createSimpleNameReferenceNode; + +/** + * A {@code CodeModifier} implementation that modify each bal file by adding a specific function to the end. + * + * @since 2201.9.0 + */ +public class AddRemoveFunctionsCodeModifier extends CodeModifier { + + @Override + public void init(CodeModifierContext modifierContext) { + modifierContext.addSourceModifierTask(context -> { + for (ModuleId moduleId : context.currentPackage().moduleIds()) { + io.ballerina.projects.Module module = context.currentPackage().module(moduleId); + for (DocumentId documentId : module.documentIds()) { + Document document = module.document(documentId); + ModulePartNode rootNode = document.syntaxTree().rootNode(); + + // Remove empty functions + List emptyFunctionNodes = rootNode.members().stream() + .filter(member -> member.kind() == SyntaxKind.FUNCTION_DEFINITION) + .filter(member -> ((FunctionDefinitionNode) member).functionBody().children().size() < 3) + .toList(); + NodeList updatedMembers = + rootNode.members().removeAll(emptyFunctionNodes); + + // Add new function + updatedMembers = updatedMembers.add(createFunctionDefNode(document)); + ModulePartNode newModulePart = rootNode.modify( + rootNode.imports(), updatedMembers, rootNode.eofToken()); + SyntaxTree updatedSyntaxTree = document.syntaxTree().modifyWith(newModulePart); + context.modifySourceFile(updatedSyntaxTree.textDocument(), documentId); + } + } + }); + } + + private static FunctionDefinitionNode createFunctionDefNode(Document document) { + List qualifierList = new ArrayList<>(); + Token publicToken = createToken(SyntaxKind.PUBLIC_KEYWORD, generateMinutiaeListWithTwoNewline(), + generateMinutiaeListWithWhitespace()); + qualifierList.add(publicToken); + SimpleNameReferenceNode simpleNameRefNode = createSimpleNameReferenceNode( + createIdentifierToken("string", createEmptyMinutiaeList(), + generateMinutiaeListWithWhitespace())); + RequiredParameterNode requiredParameterNode = + createRequiredParameterNode(createEmptyNodeList(), simpleNameRefNode, + createIdentifierToken("params")); + OptionalTypeDescriptorNode optionalErrorTypeDescriptorNode = + createOptionalTypeDescriptorNode( + createParameterizedTypeDescriptorNode(SyntaxKind.ERROR_TYPE_DESC, + createToken(SyntaxKind.ERROR_KEYWORD), null), + createToken(SyntaxKind.QUESTION_MARK_TOKEN, createEmptyMinutiaeList(), + generateMinutiaeListWithWhitespace())); + ReturnTypeDescriptorNode returnTypeDescriptorNode = + createReturnTypeDescriptorNode(createToken(SyntaxKind.RETURNS_KEYWORD, + createEmptyMinutiaeList(), generateMinutiaeListWithWhitespace()), + createEmptyNodeList(), optionalErrorTypeDescriptorNode); + FunctionSignatureNode functionSignatureNode = + createFunctionSignatureNode(createToken(SyntaxKind.OPEN_PAREN_TOKEN), + createSeparatedNodeList(requiredParameterNode), + createToken(SyntaxKind.CLOSE_PAREN_TOKEN, + createEmptyMinutiaeList(), generateMinutiaeListWithWhitespace()), + returnTypeDescriptorNode); + FunctionBodyBlockNode emptyFunctionBodyNode = + createFunctionBodyBlockNode( + createToken(SyntaxKind.OPEN_BRACE_TOKEN, createEmptyMinutiaeList(), + generateMinutiaeListWithNewline()), null, + createEmptyNodeList(), createToken(SyntaxKind.CLOSE_BRACE_TOKEN), null); + return createFunctionDefinitionNode( + SyntaxKind.FUNCTION_DEFINITION, null, createNodeList(qualifierList), + createToken(SyntaxKind.FUNCTION_KEYWORD, createEmptyMinutiaeList(), + generateMinutiaeListWithWhitespace()), + createIdentifierToken("newFunctionByCodeModifier" + + document.name().replace(".bal", "").replace("/", "_") + .replace("-", "_")), + createEmptyNodeList(), functionSignatureNode, emptyFunctionBodyNode); + } + + private static MinutiaeList generateMinutiaeListWithWhitespace() { + return createMinutiaeList(createWhitespaceMinutiae(" ")); + } + + private static MinutiaeList generateMinutiaeListWithNewline() { + return createMinutiaeList(createWhitespaceMinutiae("\n")); + } + + private static MinutiaeList generateMinutiaeListWithTwoNewline() { + return createMinutiaeList(createWhitespaceMinutiae("\n\n")); + } +} diff --git a/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/CodeModifyFunctionPlugin.java b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/CodeModifyFunctionPlugin.java new file mode 100644 index 000000000000..a28881f24edf --- /dev/null +++ b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/addremove/codemodify/CodeModifyFunctionPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.samjs.plugins.addremove.codemodify; + +import io.ballerina.projects.plugins.CompilerPlugin; +import io.ballerina.projects.plugins.CompilerPluginContext; + +/** + * A sample {@code CompilerPlugin} that modifies source files by removing empty functions and adding new function. + * + * @since 2201.9.0 + */ +public class CodeModifyFunctionPlugin extends CompilerPlugin { + @Override + public void init(CompilerPluginContext pluginContext) { + pluginContext.addCodeModifier(new AddRemoveFunctionsCodeModifier()); + } +} diff --git a/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/module-info.java b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/module-info.java new file mode 100644 index 000000000000..03c5aa00d214 --- /dev/null +++ b/project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module compiler.plugin.test.addremove.func.codemodify { + requires io.ballerina.lang; + requires io.ballerina.parser; + requires io.ballerina.tools.api; + requires compiler.plugin.test.diagnostic.utils.lib; + + exports io.samjs.plugins.addremove.codemodify; +} diff --git a/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/build.gradle b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/build.gradle new file mode 100644 index 000000000000..86455f3cacb8 --- /dev/null +++ b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/build.gradle @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +apply from: "$rootDir/gradle/javaProject.gradle" + +description = 'Compiler Plugin Tests - Code Modify Remove Function' +version = '1.0.0' + +dependencies { + implementation project(':ballerina-lang') + implementation project(':ballerina-parser') + implementation project(':ballerina-tools-api') + implementation project(':project-api-test-artifact:diagnostic-utils-lib') +} + +ext.moduleName = 'compiler.plugin.test.remove.func.codemodify' + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} diff --git a/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/CodeModifyFunctionPlugin.java b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/CodeModifyFunctionPlugin.java new file mode 100644 index 000000000000..fd28a4b25a47 --- /dev/null +++ b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/CodeModifyFunctionPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.samjs.plugins.remove.codemodify; + +import io.ballerina.projects.plugins.CompilerPlugin; +import io.ballerina.projects.plugins.CompilerPluginContext; + +/** + * A sample {@code CompilerPlugin} that modifies source files. + * + * @since 2201.9.0 + */ +public class CodeModifyFunctionPlugin extends CompilerPlugin { + @Override + public void init(CompilerPluginContext pluginContext) { + pluginContext.addCodeModifier(new RemoveFunctionCodeModifier()); + } +} diff --git a/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/RemoveFunctionCodeModifier.java b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/RemoveFunctionCodeModifier.java new file mode 100644 index 000000000000..4ec36b235ad0 --- /dev/null +++ b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/io/samjs/plugins/remove/codemodify/RemoveFunctionCodeModifier.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.samjs.plugins.remove.codemodify; + +import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; +import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode; +import io.ballerina.compiler.syntax.tree.ModulePartNode; +import io.ballerina.compiler.syntax.tree.NodeList; +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.compiler.syntax.tree.SyntaxTree; +import io.ballerina.projects.Document; +import io.ballerina.projects.DocumentId; +import io.ballerina.projects.ModuleId; +import io.ballerina.projects.Package; +import io.ballerina.projects.plugins.CodeModifier; +import io.ballerina.projects.plugins.CodeModifierContext; + +import java.util.Optional; + +/** + * A {@code CodeModifier} implementation that modify each bal file by removing empty functions. + * + * @since 2201.9.0 + */ +public class RemoveFunctionCodeModifier extends CodeModifier { + + @Override + public void init(CodeModifierContext modifierContext) { + modifierContext.addSourceModifierTask(sourceModifierContext -> { + // Look for the first function with name "bar" in each bal file and remove if available + Package currentPackage = sourceModifierContext.currentPackage(); + for (ModuleId moduleId : currentPackage.moduleIds()) { + io.ballerina.projects.Module module = currentPackage.module(moduleId); + for (DocumentId documentId : module.documentIds()) { + Document document = module.document(documentId); + ModulePartNode rootNode = document.syntaxTree().rootNode(); + Optional barFunctionNode = rootNode.members().stream() + .filter(member -> member.kind() == SyntaxKind.FUNCTION_DEFINITION + && "bar".equals(((FunctionDefinitionNode) member).functionName().text())) + .findFirst(); + if (barFunctionNode.isEmpty()) { + continue; + } + NodeList updatedMembers = + rootNode.members().remove(barFunctionNode.get()); + ModulePartNode newModulePart = + rootNode.modify(rootNode.imports(), updatedMembers, rootNode.eofToken()); + SyntaxTree updatedSyntaxTree = document.syntaxTree().modifyWith(newModulePart); + sourceModifierContext.modifySourceFile(updatedSyntaxTree.textDocument(), documentId); + } + } + }); + } +} diff --git a/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/module-info.java b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/module-info.java new file mode 100644 index 000000000000..494df1a7b82f --- /dev/null +++ b/project-api/test-artifacts/remove-function-code-modify-compiler-plugin/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module compiler.plugin.test.remove.func.codemodify { + requires io.ballerina.lang; + requires io.ballerina.parser; + requires io.ballerina.tools.api; + requires compiler.plugin.test.diagnostic.utils.lib; + + exports io.samjs.plugins.remove.codemodify; +} diff --git a/settings.gradle b/settings.gradle index e5d32276bcfc..758a7ef3a5d7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -129,6 +129,8 @@ include(':project-api-test-artifact:bad-sad-compiler-plugin') include(':project-api-test-artifact:logging-file-appender-plugin') include(':project-api-test-artifact:init-function-codegen-compiler-plugin') include(':project-api-test-artifact:init-function-code-modify-compiler-plugin') +include(':project-api-test-artifact:remove-function-code-modify-compiler-plugin') +include(':project-api-test-artifact:add-remove-function-code-modify-compiler-plugin') include(':project-api-test-artifact:log-creator-in-built-code-modifier') include(':project-api-test-artifact:log-creator-in-built-code-generator') include(':project-api-test-artifact:log-creator-in-built-code-analyzer') @@ -163,6 +165,8 @@ project(':project-api-test-artifact:bad-sad-compiler-plugin').projectDir = file( project(':project-api-test-artifact:logging-file-appender-plugin').projectDir = file('project-api/test-artifacts/logging-file-appender-plugin') project(':project-api-test-artifact:init-function-codegen-compiler-plugin').projectDir = file('project-api/test-artifacts/init-function-codegen-compiler-plugin') project(':project-api-test-artifact:init-function-code-modify-compiler-plugin').projectDir = file('project-api/test-artifacts/init-function-code-modify-compiler-plugin') +project(':project-api-test-artifact:remove-function-code-modify-compiler-plugin').projectDir = file('project-api/test-artifacts/remove-function-code-modify-compiler-plugin') +project(':project-api-test-artifact:add-remove-function-code-modify-compiler-plugin').projectDir = file('project-api/test-artifacts/add-remove-function-code-modify-compiler-plugin') project(':project-api-test-artifact:log-creator-in-built-code-modifier').projectDir = file('project-api/test-artifacts/log-creator-in-built-code-modifier') project(':project-api-test-artifact:log-creator-in-built-code-generator').projectDir = file('project-api/test-artifacts/log-creator-in-built-code-generator') project(':project-api-test-artifact:log-creator-in-built-code-analyzer').projectDir = file('project-api/test-artifacts/log-creator-in-built-code-analyzer') diff --git a/tests/testerina-integration-test/build.gradle b/tests/testerina-integration-test/build.gradle index 67c50c427d63..d91c3ecc8800 100644 --- a/tests/testerina-integration-test/build.gradle +++ b/tests/testerina-integration-test/build.gradle @@ -53,6 +53,8 @@ dependencies { implementation group: 'io.github.java-diff-utils', name: 'java-diff-utils', version: "${project.javaDiffUtilsVersion}" compilerPluginJar project(':project-api-test-artifact:init-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:remove-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:add-remove-function-code-modify-compiler-plugin') compilerPluginJar project(':project-api-test-artifact:diagnostic-utils-lib') } diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java index 76b6d8c69e39..4e321b2e1171 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/CodegenCodeCoverageTest.java @@ -44,12 +44,6 @@ * Test class to test report for Codegen ballerina projects. */ public class CodegenCodeCoverageTest extends BaseTestCase { - private BMainInstance balClient; - private String projectPath; - Path repoBalaPath; - private Path resultsJsonPath; - private JsonObject resultObj; - private static final String TOTAL_TESTS = "totalTests"; private static final String PASSED_TESTS = "passed"; private static final String FAILED_TESTS = "failed"; @@ -58,13 +52,13 @@ public class CodegenCodeCoverageTest extends BaseTestCase { private static final String FOO_MISSED = "fooMissed"; private static final String MAIN_COVERED = "mainCovered"; private static final String MAIN_MISSED = "mainMissed"; + Path repoBalaPath; + private BMainInstance balClient; + private JsonObject resultObj; @BeforeClass public void setup() throws BallerinaTestException, IOException { balClient = new BMainInstance(balServer); - projectPath = projectBasedTestsPath.resolve("codegen-coverage-test").toString(); - resultsJsonPath = projectBasedTestsPath.resolve("codegen-coverage-test").resolve("target").resolve("report") - .resolve("test_results.json"); FileUtils.copyFolder(Paths.get("build").resolve("compiler-plugin-jars"), projectBasedTestsPath.resolve("compiler-plugin-jars")); repoBalaPath = Paths.get(balServer.getServerHome()).resolve("repo"); @@ -74,7 +68,9 @@ public void setup() throws BallerinaTestException, IOException { public Object[][] provideCoverageData() { return new Object[][]{ { - "package_comp_plugin_code_modify_add_function", + // adds a new function to all files + "line-insert-test", + "package_comp_plugin_code_modify_add_function", Map.of(TOTAL_TESTS, 2, PASSED_TESTS, 2, FAILED_TESTS, 0, SKIPPED_TESTS, 0), Map.of( FOO_COVERED, new int[]{3, 4}, @@ -82,15 +78,41 @@ public Object[][] provideCoverageData() { MAIN_COVERED, new int[]{8, 9}, MAIN_MISSED, new int[]{3, 4, 5} ) + }, + { + // remove "bar" function if available from all files + "line-remove-test", + "package_comp_plugin_code_modify_remove_function", + Map.of(TOTAL_TESTS, 2, PASSED_TESTS, 2, FAILED_TESTS, 0, SKIPPED_TESTS, 0), + Map.of( + FOO_COVERED, new int[]{3, 4}, + FOO_MISSED, new int[]{11, 12}, + MAIN_COVERED, new int[]{8, 9}, + MAIN_MISSED, new int[]{3, 4, 5} + ) + }, + { + // remove empty functions and add a new function. + "line-insert-and-remove-test", + "package_comp_plugin_code_modify_add_remove_function", + Map.of(TOTAL_TESTS, 2, PASSED_TESTS, 2, FAILED_TESTS, 0, SKIPPED_TESTS, 0), + Map.of( + FOO_COVERED, new int[]{3, 4}, + FOO_MISSED, new int[]{9, 10}, + MAIN_COVERED, new int[]{17, 18}, + MAIN_MISSED, new int[]{3, 4, 5} + ) } }; } - @Test(description = "Test code coverage report generation for a codegen project", dataProvider = "provideCoverageData") - public void codegenCoverageTest(String compilerPluginName, Map status, Map coverage) throws BallerinaTestException, IOException { + @Test(description = "Test code coverage report generation for a codegen project", + dataProvider = "provideCoverageData") + public void codegenCoverageTest(String projectName, String compilerPluginName, Map status, Map coverage) throws BallerinaTestException, IOException { publishCompilerPlugin(compilerPluginName); - String[] args = new String[] {"--code-coverage"}; - runCommand(args); + String[] args = new String[]{"--code-coverage"}; + runCommand(projectName, args); validateStatus(status); validateCoverage(coverage); } @@ -167,14 +189,16 @@ private void validateCoverage(Map coverage) { } private void validateStatus(Map status, JsonObject obj, String msg) { - Assert.assertEquals(obj.get("totalTests").getAsInt(), status.get(TOTAL_TESTS), msg); - Assert.assertEquals(obj.get("passed").getAsInt(), status.get(PASSED_TESTS), msg); - Assert.assertEquals(obj.get("failed").getAsInt(), status.get(FAILED_TESTS), msg); - Assert.assertEquals(obj.get("skipped").getAsInt(), status.get(SKIPPED_TESTS), msg); + Assert.assertEquals(obj.get(TOTAL_TESTS).getAsInt(), status.get(TOTAL_TESTS), msg); + Assert.assertEquals(obj.get(PASSED_TESTS).getAsInt(), status.get(PASSED_TESTS), msg); + Assert.assertEquals(obj.get(FAILED_TESTS).getAsInt(), status.get(FAILED_TESTS), msg); + Assert.assertEquals(obj.get(SKIPPED_TESTS).getAsInt(), status.get(SKIPPED_TESTS), msg); } - private void runCommand(String[] args) throws BallerinaTestException { - balClient.runMain("test", args, null, new String[]{}, new LogLeecher[]{}, projectPath); + private void runCommand(String projectName, String[] args) throws BallerinaTestException { + Path projectPath = projectBasedTestsPath.resolve("code-coverage-report-test").resolve(projectName); + Path resultsJsonPath = projectPath.resolve("target").resolve("report").resolve("test_results.json"); + balClient.runMain("test", args, null, new String[]{}, new LogLeecher[]{}, projectPath.toString()); Gson gson = new Gson(); try (BufferedReader bufferedReader = Files.newBufferedReader(resultsJsonPath, StandardCharsets.UTF_8)) { resultObj = gson.fromJson(bufferedReader, JsonObject.class); diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/Ballerina.toml similarity index 100% rename from tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/Ballerina.toml rename to tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/Ballerina.toml diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/foo.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/foo.bal new file mode 100644 index 000000000000..61ac58edf3d0 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/foo.bal @@ -0,0 +1,10 @@ + +function foo(int a) returns (int) { + return a; +} + +function bar() {} + +function foobar(int a) returns (int) { + return a + 2; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/main.bal new file mode 100644 index 000000000000..f2c9aea8d584 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/main.bal @@ -0,0 +1,18 @@ +import samjs/package_comp_plugin_code_modify_add_remove_function as _; + +public function main() { + _ = intAdd(1,2); +} + +function baz () { + +} + +function qux () { + + +} + +function intAdd(int a, int b) returns (int) { + return a + b; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/tests/main_test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/tests/main_test.bal similarity index 100% rename from tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/tests/main_test.bal rename to tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-and-remove-test/tests/main_test.bal diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/Ballerina.toml new file mode 100644 index 000000000000..fea366370c8f --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "intg_tests" +name = "codegen_coverage_test" +version = "0.0.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/foo.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/foo.bal similarity index 100% rename from tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/foo.bal rename to tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/foo.bal diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/main.bal similarity index 100% rename from tests/testerina-integration-test/src/test/resources/project-based-tests/codegen-coverage-test/main.bal rename to tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/main.bal diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/tests/main_test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/tests/main_test.bal new file mode 100644 index 000000000000..04e384917881 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-insert-test/tests/main_test.bal @@ -0,0 +1,11 @@ +import ballerina/test; + +@test:Config {} +public function test1() { + test:assertEquals(intAdd(4, 5), 9); +} + +@test:Config {} +public function test2() { + test:assertEquals(foo(2), 2); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/Ballerina.toml new file mode 100644 index 000000000000..fea366370c8f --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "intg_tests" +name = "codegen_coverage_test" +version = "0.0.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/foo.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/foo.bal new file mode 100644 index 000000000000..aecd08b517a1 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/foo.bal @@ -0,0 +1,12 @@ + +function foo(int a) returns (int) { + return a; +} + +function bar() { + +} + +function foobar(int a) returns (int) { + return a + 2; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/main.bal new file mode 100644 index 000000000000..8abd872f04da --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/main.bal @@ -0,0 +1,9 @@ +import samjs/package_comp_plugin_code_modify_remove_function as _; + +public function main() { + _ = intAdd(1,2); +} + +function intAdd(int a, int b) returns (int) { + return a + b; +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/tests/main_test.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/tests/main_test.bal new file mode 100644 index 000000000000..04e384917881 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/code-coverage-report-test/line-remove-test/tests/main_test.bal @@ -0,0 +1,11 @@ +import ballerina/test; + +@test:Config {} +public function test1() { + test:assertEquals(intAdd(4, 5), 9); +} + +@test:Config {} +public function test2() { + test:assertEquals(foo(2), 2); +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml deleted file mode 100644 index 62d792fdd7d6..000000000000 --- a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_function/Dependencies.toml +++ /dev/null @@ -1,17 +0,0 @@ -# AUTO-GENERATED FILE. DO NOT MODIFY. - -# This file is auto-generated by Ballerina for managing dependency versions. -# It should not be modified by hand. - -[ballerina] -dependencies-toml-version = "2" -distribution-version = "2201.8.4" - -[[package]] -org = "samjs" -name = "package_comp_plugin_code_modify_add_function" -version = "0.1.0" -modules = [ - {org = "samjs", packageName = "package_comp_plugin_code_modify_add_function", moduleName = "package_comp_plugin_code_modify_add_function"} -] - diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/Ballerina.toml new file mode 100644 index 000000000000..0c831a1d9817 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "samjs" +name = "package_comp_plugin_code_modify_add_remove_function" +version = "0.1.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/CompilerPlugin.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/CompilerPlugin.toml new file mode 100644 index 000000000000..4d3b6c8c3be4 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/CompilerPlugin.toml @@ -0,0 +1,8 @@ +[plugin] +class = "io.samjs.plugins.addremove.codemodify.CodeModifyFunctionPlugin" + +[[dependency]] +path = "../../compiler-plugin-jars/add-remove-function-code-modify-compiler-plugin-1.0.0.jar" + +[[dependency]] +path = "../../compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/main.bal new file mode 100644 index 000000000000..41a101b1c439 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_add_remove_function/main.bal @@ -0,0 +1,3 @@ +public function doSomething() { + // Do nothing +} diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/Ballerina.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/Ballerina.toml new file mode 100644 index 000000000000..c220c0f5d8db --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "samjs" +name = "package_comp_plugin_code_modify_remove_function" +version = "0.1.0" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/CompilerPlugin.toml b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/CompilerPlugin.toml new file mode 100644 index 000000000000..e96b55fd8c4b --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/CompilerPlugin.toml @@ -0,0 +1,8 @@ +[plugin] +class = "io.samjs.plugins.remove.codemodify.CodeModifyFunctionPlugin" + +[[dependency]] +path = "../../compiler-plugin-jars/remove-function-code-modify-compiler-plugin-1.0.0.jar" + +[[dependency]] +path = "../../compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar" diff --git a/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/main.bal b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/main.bal new file mode 100644 index 000000000000..41a101b1c439 --- /dev/null +++ b/tests/testerina-integration-test/src/test/resources/project-based-tests/compiler-plugins/package_comp_plugin_code_modify_remove_function/main.bal @@ -0,0 +1,3 @@ +public function doSomething() { + // Do nothing +} From 42cd8d6cc095d11a7c001048795ac79c0e971117 Mon Sep 17 00:00:00 2001 From: dilhasha Date: Fri, 2 Feb 2024 18:56:33 +0500 Subject: [PATCH 175/209] Improve bal deprecate command help --- .../src/main/resources/cli-help/ballerina-deprecate.help | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help index b7c5d8a98102..8242045cdb3a 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-deprecate.help @@ -9,7 +9,7 @@ DESCRIPTION Deprecate a package published in Ballerina central. If a specific version of a package is provided, that version will be deprecated. - Alternatively, if no version is specified, all versions of the package will be deprecated. + If no version is specified, all versions of the package will be deprecated. A deprecated package will not be used as a dependency of a package unless the deprecated package is already recorded in the `Dependencies.toml` and the `--sticky` option is used to build the package. Also, a deprecated package will be used as @@ -24,7 +24,7 @@ OPTIONS --message= Use the given as the deprecation message --undo - Undo deprecation of package + Undo deprecation of a package EXAMPLES From 88d067328c19b61f2e2b21284324a582a03c2044 Mon Sep 17 00:00:00 2001 From: chiranSachintha Date: Tue, 6 Feb 2024 11:11:46 +0530 Subject: [PATCH 176/209] Fix review suggestions --- .../test/annotations/AnnotationAttachmentNegativeTest.java | 2 +- .../test-src/annotations/annot_attachments_negative.bal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java index 22607cabfd92..6092023810bd 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentNegativeTest.java @@ -520,7 +520,7 @@ public void testInvalidConstAnnotElements() { validateError(compileResult, index, "expression is not a constant expression", line + 7, 16); } - public void testInvalidAnnotationAttachmentOnField() { + public void testInvalidAnnotationAttachmentsOnMembersOfStructuredTypedBindingPatterns() { int index = 277; int line = 989; validateError(compileResult, index++, "undefined annotation 'UndefinedAnnotation'", line, 2); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal index fa69dcd53842..be611517bc48 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments_negative.bal @@ -996,7 +996,7 @@ error> error () = error("err"); error error () = error("err"); -function testInvalidAnnotationAttachmentOnTypeBindingPatterns() { +function testInvalidAnnotationAttachmentsOnMembersOfStructuredTypedBindingPatterns() { [@UndefinedAnnotation int, int] [first, second] = [1, 2]; [@UndefinedAnnotation int, int, int] [a, b, c] = [1, 2, 3]; [[@UndefinedAnnotation int, int], int] [[a1, b1], c1] = [[1, 2], 3]; From f1eb8ad6312281a1e9bbee7958a4c4e2bb9a830d Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Tue, 6 Feb 2024 15:48:56 +0530 Subject: [PATCH 177/209] Allow ddt filters to work without single quotes --- .../src/main/ballerina/execute.bal | 3 --- .../testerina/test/DataProviderTest.java | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/misc/testerina/modules/testerina-core/src/main/ballerina/execute.bal b/misc/testerina/modules/testerina-core/src/main/ballerina/execute.bal index 4b1d86a679f1..adda3d0293a8 100644 --- a/misc/testerina/modules/testerina-core/src/main/ballerina/execute.bal +++ b/misc/testerina/modules/testerina-core/src/main/ballerina/execute.bal @@ -293,13 +293,10 @@ function skipDataDrivenTest(TestFunction testFunction, string suffix, TestType t if (!suffixMatch) { string[] subTests = filterSubTests.get(functionKey); foreach string subFilter in subTests { - string updatedSubFilter = subFilter; if (testType == DATA_DRIVEN_MAP_OF_TUPLE) { if (subFilter.startsWith(SINGLE_QUOTE) && subFilter.endsWith(SINGLE_QUOTE)) { updatedSubFilter = subFilter.substring(1, subFilter.length() - 1); - } else { - continue; } } string|error decodedSubFilter = escapeSpecialCharacters(updatedSubFilter); diff --git a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java index 606ffb07c369..b2497259b6ec 100644 --- a/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java +++ b/tests/testerina-integration-test/src/test/java/org/ballerinalang/testerina/test/DataProviderTest.java @@ -83,6 +83,15 @@ public void testValidDataProviderCase() throws BallerinaTestException, IOExcepti AssertionUtils.assertOutput("DataProviderTest-testValidDataProviderCase.txt", output); } + @Test (dependsOnMethods = "testValidDataProviderWithFail") + public void testValidDataProviderCaseWithoutQuotes() throws BallerinaTestException, IOException { + String[] args = mergeCoverageArgs(new String[]{"--tests", "dataproviders:jsonDataProviderTest#json1", + "data-providers"}); + String output = balClient.runMainAndReadStdOut("test", args, + new HashMap<>(), projectPath, false); + AssertionUtils.assertOutput("DataProviderTest-testValidDataProviderCase.txt", output); + } + @Test (dependsOnMethods = "testValidDataProviderCase") public void testDataProviderWithMixedType() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction1#'CaseNew*'", @@ -92,6 +101,15 @@ public void testDataProviderWithMixedType() throws BallerinaTestException, IOExc AssertionUtils.assertOutput("DataProviderTest-testDataProviderWithMixedType.txt", output); } + @Test (dependsOnMethods = "testValidDataProviderCase") + public void testDataProviderWithMixedTypeWithoutQuotes() throws BallerinaTestException, IOException { + String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction1#CaseNew*", + "data-providers"}); + String output = balClient.runMainAndReadStdOut("test", args, + new HashMap<>(), projectPath, false); + AssertionUtils.assertOutput("DataProviderTest-testDataProviderWithMixedType.txt", output); + } + @Test (dependsOnMethods = "testDataProviderWithMixedType") public void testWithSpecialKeys() throws BallerinaTestException, IOException { String[] args = mergeCoverageArgs(new String[]{"--tests", "testFunction2", From 631f85e27252962ec2febf339710ae94f8c900c1 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Tue, 6 Feb 2024 18:44:25 +0530 Subject: [PATCH 178/209] Fix line numbers in test output files --- .../unix/DataProviderTest-testDataProviderSingleFailure.txt | 2 +- .../InvalidDataProviderTestCase-testInvalidDataProvider.txt | 4 ++-- .../InvalidDataProviderTestCase-testInvalidDataProvider2.txt | 4 ++-- ...validDataProviderTestCase-testInvalidTupleDataProvider.txt | 4 ++-- .../DataProviderTest-testDataProviderSingleFailure.txt | 2 +- .../InvalidDataProviderTestCase-testInvalidDataProvider.txt | 4 ++-- .../InvalidDataProviderTestCase-testInvalidDataProvider2.txt | 4 ++-- ...validDataProviderTestCase-testInvalidTupleDataProvider.txt | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/DataProviderTest-testDataProviderSingleFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/DataProviderTest-testDataProviderSingleFailure.txt index 48139cc61cf4..67999415aec0 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/DataProviderTest-testDataProviderSingleFailure.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/DataProviderTest-testDataProviderSingleFailure.txt @@ -19,7 +19,7 @@ Running Tests with Coverage callableName: testDividingValuesNegative moduleName: intg_tests.dataproviders$test.0.tests.new-data-provider-tests fileName: tests/new-data-provider-tests.bal lineNumber: 191 callableName: testDividingValuesNegative$lambda14$ moduleName: intg_tests.dataproviders$test.0.tests.test_execute-generated_*****lineNumber: 18 ",functionName="testDividingValuesNegative") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider.txt index a27ffae1b440..8714477b5792 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider.txt @@ -13,7 +13,7 @@ Running Tests [fail data provider for the function testInvalidDataProvider] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(int)' cannot be passed to function expecting parameter list '(string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -21,7 +21,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test.bal lineNumber: 37 ",functionName="testInvalidDataProvider") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider2.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider2.txt index 921212fb9f70..4138232d0ce0 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider2.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidDataProvider2.txt @@ -15,7 +15,7 @@ Running Tests [fail data provider for the function testInvalidDataProvider2] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(int,int,int)' cannot be passed to function expecting parameter list '(string,string,string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -23,7 +23,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test2.bal lineNumber: 39 ",functionName="testInvalidDataProvider2") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt index 068ebba3b51e..5811136fd5b6 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/unix/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt @@ -12,7 +12,7 @@ Running Tests [fail data provider for the function testInvalidTupleDataProvider] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(string,int)' cannot be passed to function expecting parameter list '(string,string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -20,7 +20,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test3.bal lineNumber: 36 ",functionName="testInvalidTupleDataProvider") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/DataProviderTest-testDataProviderSingleFailure.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/DataProviderTest-testDataProviderSingleFailure.txt index c63c5bc8af00..08db5f4bd30c 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/DataProviderTest-testDataProviderSingleFailure.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/DataProviderTest-testDataProviderSingleFailure.txt @@ -19,7 +19,7 @@ Running Tests with Coverage callableName: testDividingValuesNegative moduleName: intg_tests.dataproviders$test.0.tests.new-data-provider-tests fileName: tests/new-data-provider-tests.bal lineNumber: 191 callableName: testDividingValuesNegative$lambda14$ moduleName: intg_tests.dataproviders$test.0.tests.test_execute-generated_*****lineNumber: 18 ",functionName="testDividingValuesNegative") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider.txt index ba73eb492805..b843eb1c0939 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider.txt @@ -13,7 +13,7 @@ Running Tests [fail data provider for the function testInvalidDataProvider] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(int)' cannot be passed to function expecting parameter list '(string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -21,7 +21,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test.bal lineNumber: 37 ",functionName="testInvalidDataProvider") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider2.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider2.txt index 95f28ab15b5a..76b7ee13ddf5 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider2.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidDataProvider2.txt @@ -15,7 +15,7 @@ Running Tests [fail data provider for the function testInvalidDataProvider2] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(int,int,int)' cannot be passed to function expecting parameter list '(string,string,string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -23,7 +23,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test2.bal lineNumber: 39 ",functionName="testInvalidDataProvider2") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 diff --git a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt index 43fb04a46c97..e1f62e2ac8ad 100644 --- a/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt +++ b/tests/testerina-integration-test/src/test/resources/command-outputs/windows/InvalidDataProviderTestCase-testInvalidTupleDataProvider.txt @@ -12,7 +12,7 @@ Running Tests [fail data provider for the function testInvalidTupleDataProvider] error {ballerina/test:0}ExecutionError ("error("{ballerina/lang.function}IncompatibleArguments",message="arguments of incompatible types: argument list '(string,int)' cannot be passed to function expecting parameter list '(string,string)'") callableName: call moduleName: ballerina.lang.function.0 fileName: function.bal lineNumber: 37 - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 339 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 336 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 @@ -20,7 +20,7 @@ Running Tests callableName: startSuite moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 48 callableName: __execute__ fileName: invalid-data-provider-test3.bal lineNumber: 36 ",functionName="testInvalidTupleDataProvider") - callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 349 + callableName: executeTestFunction moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 346 callableName: executeDataDrivenTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 136 callableName: executeDataDrivenTestSet moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 123 callableName: executeTest moduleName: ballerina.test.0 fileName: execute.bal lineNumber: 83 From 43a099ea5f5a8298f3a70a7dd84a71f3ca534262 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 6 Feb 2024 22:24:05 +0530 Subject: [PATCH 179/209] Add tests to create function CA --- .../FunctionCallExpressionTypeFinder.java | 14 +++-- .../codeaction/CreateFunctionTest.java | 4 +- ...ction_in_explicit_anonymous_function1.json | 4 +- ...ction_in_explicit_anonymous_function2.json | 4 +- ...ction_in_explicit_anonymous_function3.json | 4 +- ...ction_in_explicit_anonymous_function4.json | 4 +- ...ction_in_explicit_anonymous_function5.json | 57 +++++++++++++++++++ .../config/create_function_in_worker1.json | 4 +- .../config/create_function_in_worker2.json | 4 +- .../config/create_function_in_worker3.json | 4 +- .../config/create_function_in_worker4.json | 4 +- .../config/create_function_in_worker5.json | 57 +++++++++++++++++++ ...unction_in_explicit_anonymous_function.bal | 6 ++ .../source/create_function_in_worker.bal | 6 ++ 14 files changed, 154 insertions(+), 22 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function5.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker5.json diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java index d5f51c174fb5..18d52939201d 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/command/visitors/FunctionCallExpressionTypeFinder.java @@ -407,8 +407,8 @@ public void visit(BlockStatementNode node) { @Override public void visit(NamedWorkerDeclarationNode namedWorkerDeclarationNode) { - Optional symbol = semanticModel.symbol(namedWorkerDeclarationNode); - symbol.ifPresent(value -> checkAndSetTypeResult(((WorkerSymbol) value).returnType())); + semanticModel.symbol(namedWorkerDeclarationNode) + .ifPresent(value -> checkAndSetTypeResult(((WorkerSymbol) value).returnType())); } @Override @@ -420,7 +420,12 @@ public void visit(ReturnStatementNode returnStatementNode) { // Get function type symbol and get return type descriptor from it returnStatementNode.parent().accept(this); - if (resultFound && returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) { + + if (!resultFound) { + resetResult(); + return; + } + if (returnTypeSymbol.typeKind() == TypeDescKind.FUNCTION) { FunctionTypeSymbol functionTypeSymbol = (FunctionTypeSymbol) returnTypeSymbol; functionTypeSymbol.returnTypeDescriptor().ifPresentOrElse(this::checkAndSetTypeResult, this::resetResult); } @@ -521,8 +526,7 @@ public void visit(ImplicitAnonymousFunctionExpressionNode expr) { @Override public void visit(ExplicitAnonymousFunctionExpressionNode explicitAnonymousFunctionExpressionNode) { - Optional typeSymbol = semanticModel.typeOf(explicitAnonymousFunctionExpressionNode); - typeSymbol.ifPresent(this::checkAndSetTypeResult); + semanticModel.typeOf(explicitAnonymousFunctionExpressionNode).ifPresent(this::checkAndSetTypeResult); } @Override diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java index f43bd32095c5..3f80af11e19d 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/CreateFunctionTest.java @@ -191,11 +191,13 @@ public Object[][] dataProvider() { {"create_function_in_worker2.json"}, {"create_function_in_worker3.json"}, {"create_function_in_worker4.json"}, + {"create_function_in_worker5.json"}, {"create_function_in_explicit_anonymous_function1.json"}, {"create_function_in_explicit_anonymous_function2.json"}, {"create_function_in_explicit_anonymous_function3.json"}, - {"create_function_in_explicit_anonymous_function4.json"} + {"create_function_in_explicit_anonymous_function4.json"}, + {"create_function_in_explicit_anonymous_function5.json"} }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json index 4a8c71c24a41..8a5bd5ce911e 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function1.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json index a5f597a29138..cb29a4c1db21 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function2.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json index 0979e3fd65db..578f6dfa919f 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function3.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json index 14e0b507940b..4d499c7f50d1 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function4.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function5.json new file mode 100644 index 000000000000..008a88e1e092 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_explicit_anonymous_function5.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 22, + "character": 22 + }, + "source": "create_function_in_explicit_anonymous_function.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 25, + "character": 1 + }, + "end": { + "line": 25, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns int {\n return 0;\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_explicit_anonymous_function.bal", + "range": { + "start": { + "line": 22, + "character": 19 + }, + "end": { + "line": 22, + "character": 24 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 22.0, + "character": 19.0 + }, + "end": { + "line": 22.0, + "character": 24.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json index 91b39c7b4caa..d7dd1dd1e95b 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker1.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json index 87ef73466419..7374fb76cf78 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker2.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json index a57c1855fc2c..641f38fc3fb9 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker3.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json index fbe259630b85..55276910a9b4 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker4.json @@ -12,11 +12,11 @@ { "range": { "start": { - "line": 19, + "line": 25, "character": 1 }, "end": { - "line": 19, + "line": 25, "character": 1 } }, diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker5.json new file mode 100644 index 000000000000..fd4ff61bc968 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/config/create_function_in_worker5.json @@ -0,0 +1,57 @@ +{ + "position": { + "line": 22, + "character": 22 + }, + "source": "create_function_in_worker.bal", + "expected": [ + { + "title": "Create function 'foo(...)'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 25, + "character": 1 + }, + "end": { + "line": 25, + "character": 1 + } + }, + "newText": "\n\nfunction foo() returns int {\n return 0;\n}" + } + ], + "resolvable": true, + "data": { + "extName": "org.ballerinalang.langserver.codeaction.BallerinaCodeActionExtension", + "codeActionName": "Create Function", + "fileUri": "create_function_in_worker.bal", + "range": { + "start": { + "line": 22, + "character": 19 + }, + "end": { + "line": 22, + "character": 24 + } + }, + "actionData": { + "key": "node.range", + "value": { + "start": { + "line": 22.0, + "character": 19.0 + }, + "end": { + "line": 22.0, + "character": 24.0 + } + } + } + } + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal index 48e0ab89bfb9..19bee2900b25 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_explicit_anonymous_function.bal @@ -17,4 +17,10 @@ function createFunctionInWorker() { var fn4 = function() returns module1:TestRecord2 { return foo(); }; + + var fn5 = function() returns function () returns int { + return function () returns int { + return foo(); + }; + }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal index 709711a300ef..d889e6371fc8 100644 --- a/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/create-function/source/create_function_in_worker.bal @@ -17,4 +17,10 @@ function createFunctionInWorker() { worker D returns module1:TestRecord2 { return foo(); } + + fork { + worker E returns int { + return foo(); + } + } } From 0f4251ba40d7cc4dbac6d86c90742884fe7a467f Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 6 Feb 2024 15:42:09 +0530 Subject: [PATCH 180/209] Fix invalid import CA for multiple usages --- .../imports/ImportModuleCodeAction.java | 19 ++++- .../ImportModuleCodeActionTest.java | 8 ++- .../config/importMultipleModules1.json | 69 +++++++++++++++++++ .../config/importMultipleModules2.json | 69 +++++++++++++++++++ .../config/importMultipleModules3.json | 29 ++++++++ .../config/importMultipleModules4.json | 49 +++++++++++++ .../config/importMultipleModules5.json | 29 ++++++++ .../config/importMultipleModules6.json | 29 ++++++++ .../source/project/importMultipleModules1.bal | 8 +++ .../source/project/importMultipleModules2.bal | 5 ++ .../source/project/importMultipleModules3.bal | 5 ++ .../source/project/importMultipleModules4.bal | 5 ++ .../source/project/modules/module2/mod.bal | 5 ++ 13 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules1.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules2.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules3.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules4.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules5.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules6.json create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules1.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules2.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules3.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules4.bal create mode 100644 language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/modules/module2/mod.bal diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/imports/ImportModuleCodeAction.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/imports/ImportModuleCodeAction.java index fa10cf60b3c4..9d0392dafa5f 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/imports/ImportModuleCodeAction.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/codeaction/providers/imports/ImportModuleCodeAction.java @@ -36,12 +36,14 @@ import org.ballerinalang.langserver.commons.codeaction.spi.DiagBasedPositionDetails; import org.ballerinalang.langserver.commons.codeaction.spi.DiagnosticBasedCodeActionProvider; import org.ballerinalang.langserver.completions.util.ItemResolverConstants; +import org.ballerinalang.model.Name; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Position; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.TextEdit; +import org.wso2.ballerinalang.compiler.tree.BLangIdentifier; import java.util.ArrayList; import java.util.Collections; @@ -79,7 +81,7 @@ public List getCodeActions(Diagnostic diagnostic, // Find the qualified name reference node within the diagnostic location Range diagRange = PositionUtil.toRange(diagnostic.location().lineRange()); NonTerminalNode node = CommonUtil.findNode(diagRange, context.currentSyntaxTree().get()); - QNameRefFinder finder = new QNameRefFinder(); + QNameRefFinder finder = new QNameRefFinder(diagnostic.properties().get(0).value()); node.accept(finder); Optional qNameReferenceNode = finder.getQNameReferenceNode(); if (qNameReferenceNode.isEmpty()) { @@ -169,12 +171,25 @@ public String getName() { * A visitor to find the qualified name reference node within an expression. */ static class QNameRefFinder extends NodeVisitor { + private final String moduleName; + + public QNameRefFinder(Object nameObj) { + if (nameObj instanceof Name name) { + this.moduleName = name.getValue(); + } else if (nameObj instanceof BLangIdentifier identifier) { + this.moduleName = identifier.getValue(); + } else { + this.moduleName = nameObj.toString(); + } + } private QualifiedNameReferenceNode qualifiedNameReferenceNode; @Override public void visit(QualifiedNameReferenceNode qualifiedNameReferenceNode) { - this.qualifiedNameReferenceNode = qualifiedNameReferenceNode; + if (qualifiedNameReferenceNode.modulePrefix().text().equals(moduleName)) { + this.qualifiedNameReferenceNode = qualifiedNameReferenceNode; + } } Optional getQNameReferenceNode() { diff --git a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ImportModuleCodeActionTest.java b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ImportModuleCodeActionTest.java index 766cece200a1..6a0a6dcabe60 100644 --- a/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ImportModuleCodeActionTest.java +++ b/language-server/modules/langserver-core/src/test/java/org/ballerinalang/langserver/codeaction/ImportModuleCodeActionTest.java @@ -67,7 +67,13 @@ public Object[][] dataProvider() { {"importModuleWithLicenceHeader1.json"}, {"importModuleWithLicenceHeader2.json"}, {"importModuleWithIgnoredImport.json"}, - {"importModuleWithTopLevelComment.json"} + {"importModuleWithTopLevelComment.json"}, + {"importMultipleModules1.json"}, + {"importMultipleModules2.json"}, + {"importMultipleModules3.json"}, + {"importMultipleModules4.json"}, + {"importMultipleModules5.json"}, + {"importMultipleModules6.json"}, }; } diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules1.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules1.json new file mode 100644 index 000000000000..2972d2f259ef --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules1.json @@ -0,0 +1,69 @@ +{ + "position": { + "line": 2, + "character": 30 + }, + "source": "project/importMultipleModules1.bal", + "expected": [ + { + "title": "Import module 'ballerina/lang.array'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import ballerina/lang.array;\n" + } + ], + "resolvable": false + }, + { + "title": "Import module 'project.array'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.array;\n" + } + ], + "resolvable": false + }, + { + "title": "Import module 'project.module2'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.module2;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules2.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules2.json new file mode 100644 index 000000000000..0907878ba866 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules2.json @@ -0,0 +1,69 @@ +{ + "position": { + "line": 6, + "character": 32 + }, + "source": "project/importMultipleModules1.bal", + "expected": [ + { + "title": "Import module 'ballerina/module1'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import ballerina/module1;\n" + } + ], + "resolvable": false + }, + { + "title": "Import module 'project.module1'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.module1;\n" + } + ], + "resolvable": false + }, + { + "title": "Import module 'project.module2'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.module2;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules3.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules3.json new file mode 100644 index 000000000000..01b03b10a716 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules3.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 3, + "character": 30 + }, + "source": "project/importMultipleModules2.bal", + "expected": [ + { + "title": "Import module 'project.module2'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "newText": "import project.module2;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules4.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules4.json new file mode 100644 index 000000000000..645b5665888f --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules4.json @@ -0,0 +1,49 @@ +{ + "position": { + "line": 3, + "character": 30 + }, + "source": "project/importMultipleModules3.bal", + "expected": [ + { + "title": "Import module 'ballerina/module1'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "newText": "import ballerina/module1;\n" + } + ], + "resolvable": false + }, + { + "title": "Import module 'project.module1'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 1, + "character": 0 + }, + "end": { + "line": 1, + "character": 0 + } + }, + "newText": "import project.module1;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules5.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules5.json new file mode 100644 index 000000000000..edbb6dd659a5 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules5.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 2, + "character": 25 + }, + "source": "project/importMultipleModules4.bal", + "expected": [ + { + "title": "Import module 'project.module2'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.module2;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules6.json b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules6.json new file mode 100644 index 000000000000..bfb5c68b65a3 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/config/importMultipleModules6.json @@ -0,0 +1,29 @@ +{ + "position": { + "line": 3, + "character": 25 + }, + "source": "project/importMultipleModules4.bal", + "expected": [ + { + "title": "Import module 'project.module2'", + "kind": "quickfix", + "edits": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "newText": "import project.module2;\n" + } + ], + "resolvable": false + } + ] +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules1.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules1.bal new file mode 100644 index 000000000000..de63db1f4dfb --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules1.bal @@ -0,0 +1,8 @@ + +function testSubModuleWithNoImports() { + _ = module2:isIntArray(array:size()); +} + +function testExternalModuleWithNoImports() { + _ = module2:isIntArray(module1:function1()); +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules2.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules2.bal new file mode 100644 index 000000000000..2d18a6f51360 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules2.bal @@ -0,0 +1,5 @@ +import project.array; + +function testSubModuleWithOneImport() { + _ = module2:isIntArray(array:size()); +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules3.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules3.bal new file mode 100644 index 000000000000..1cf190cd79ef --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules3.bal @@ -0,0 +1,5 @@ +import project.module2; + +function testExternalModuleWithOneImport() { + _ = module2:isIntArray(module1:function1()); +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules4.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules4.bal new file mode 100644 index 000000000000..02391141ddc8 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/importMultipleModules4.bal @@ -0,0 +1,5 @@ + +public function testLangLib() { + module2:assertEquals(3, 3); + module2:assertEquals("x", "x"); +} diff --git a/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/modules/module2/mod.bal b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/modules/module2/mod.bal new file mode 100644 index 000000000000..33c61412d5c8 --- /dev/null +++ b/language-server/modules/langserver-core/src/test/resources/codeaction/import-module/source/project/modules/module2/mod.bal @@ -0,0 +1,5 @@ +public function first(int[] arr) returns int => arr[0]; + +public function assertEquals(anydata expected, anydata actual) {} + +public function isIntArray(any value) returns boolean => value is int[]; From 31939a7b66cea47e1cc86901c7ea2e1cc6659013 Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Fri, 2 Feb 2024 16:49:40 +0530 Subject: [PATCH 181/209] Add location to field in intersected records --- .../compiler/semantics/analyzer/Types.java | 2 +- .../api/test/symbols/ErrorTypeSymbolTest.java | 46 +++++++++++++++++++ .../symbols/error_type_symbol_test.bal | 20 ++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index 0e71020f9c7f..0e015c126916 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -5619,7 +5619,7 @@ private boolean populateFields(IntersectionContext intersectionContext, BRecordT intersectionFieldType, newTypeSymbol, lhsRecordField.pos, SOURCE); } - newTypeFields.put(key, new BField(name, null, recordFieldSymbol)); + newTypeFields.put(key, new BField(name, recordFieldSymbol.pos, recordFieldSymbol)); newTypeSymbol.scope.define(name, recordFieldSymbol); } return true; diff --git a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/symbols/ErrorTypeSymbolTest.java b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/symbols/ErrorTypeSymbolTest.java index f14143d90a0b..c497f4573ccc 100644 --- a/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/symbols/ErrorTypeSymbolTest.java +++ b/tests/ballerina-compiler-api-test/src/test/java/io/ballerina/semantic/api/test/symbols/ErrorTypeSymbolTest.java @@ -19,10 +19,15 @@ package io.ballerina.semantic.api.test.symbols; import io.ballerina.compiler.api.SemanticModel; +import io.ballerina.compiler.api.impl.symbols.BallerinaErrorTypeSymbol; +import io.ballerina.compiler.api.impl.symbols.BallerinaIntersectionTypeSymbol; +import io.ballerina.compiler.api.impl.symbols.BallerinaRecordTypeSymbol; +import io.ballerina.compiler.api.impl.symbols.BallerinaTypeReferenceTypeSymbol; import io.ballerina.compiler.api.symbols.Documentable; import io.ballerina.compiler.api.symbols.Documentation; import io.ballerina.compiler.api.symbols.ErrorTypeSymbol; import io.ballerina.compiler.api.symbols.ModuleSymbol; +import io.ballerina.compiler.api.symbols.RecordFieldSymbol; import io.ballerina.compiler.api.symbols.Symbol; import io.ballerina.compiler.api.symbols.SymbolKind; import io.ballerina.compiler.api.symbols.TypeDefinitionSymbol; @@ -41,6 +46,7 @@ import org.wso2.ballerinalang.compiler.util.Names; import java.util.List; +import java.util.Map; import java.util.Optional; import static io.ballerina.semantic.api.test.util.SemanticAPITestUtils.getDefaultModulesSemanticModel; @@ -133,6 +139,46 @@ public Object[][] getTypeRefErrorType() { }; } + @Test(dataProvider = "IntersectionErrorTypeProvider") + public void testFieldDescriptorsOfErrorIntersection(int line, int offset, String expectedErrorType, + List expectedFieldNames) { + Optional symbol = model.symbol(srcFile, LinePosition.from(line, offset)); + assertTrue(symbol.isPresent()); + + Symbol ballerinaTypeDefinitionSymbol = symbol.get(); + assertEquals(ballerinaTypeDefinitionSymbol.kind(), SymbolKind.TYPE); + assertTrue(ballerinaTypeDefinitionSymbol.getName().isPresent()); + assertEquals(ballerinaTypeDefinitionSymbol.getName().get(), expectedErrorType); + + TypeSymbol ballerinaIntersectionTypeSymbol = + ((BallerinaTypeReferenceTypeSymbol) ballerinaTypeDefinitionSymbol).typeDescriptor(); + assertEquals(ballerinaIntersectionTypeSymbol.kind(), SymbolKind.TYPE); + + TypeSymbol ballerinaErrorTypeSymbol = + ((BallerinaIntersectionTypeSymbol) ballerinaIntersectionTypeSymbol).effectiveTypeDescriptor(); + assertEquals(ballerinaErrorTypeSymbol.kind(), SymbolKind.TYPE); + + TypeSymbol ballerinaRecordTypeSymbol = + ((BallerinaErrorTypeSymbol) ballerinaErrorTypeSymbol).detailTypeDescriptor(); + assertEquals(ballerinaRecordTypeSymbol.kind(), SymbolKind.TYPE); + + Map stringRecordFieldSymbolMap = + ((BallerinaRecordTypeSymbol) ballerinaRecordTypeSymbol).fieldDescriptors(); + List actualFieldNames = stringRecordFieldSymbolMap.keySet().stream().toList(); + assertEquals(actualFieldNames.size(), expectedFieldNames.size()); + for (int i = 0; i < actualFieldNames.size(); i++) { + assertEquals(actualFieldNames.get(i), expectedFieldNames.get(i)); + } + } + + @DataProvider(name = "IntersectionErrorTypeProvider") + public Object[][] getIntersectionErrorType() { + return new Object[][]{ + {62, 4, "SimpleIntersectionError", List.of("msg", "value")}, + {63, 4, "MultipleIntersectionError", List.of("flag", "msg", "value")} + }; + } + private void assertModuleInfo(ModuleSymbol module) { assertEquals(module.id().orgName(), Names.ANON_ORG.toString()); assertEquals(module.id().moduleName(), PackageID.DEFAULT.toString()); diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal index aa5194d7aa0c..48b257f558ba 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal @@ -43,3 +43,23 @@ function test() { CancelledError distinctErr; IntersectionError intersectionErr; } + +type ErrorDetail1 record { + string msg; + int value?; +}; + +type ErrorDetail2 record {| + *ErrorDetail1; + boolean flag; +|}; + +type SimpleError error; +type InclusionError error; + +type SimpleIntersectionError distinct error & error & error; +type MultipleIntersectionError InclusionError & error & SimpleError & error; +function testMultipleIntersectionError() { + SimpleIntersectionError simpleErr; + MultipleIntersectionError multipleErr; +} From 39110258ca6cb3f48e8a8a538c5ed90c91d7d6bc Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Tue, 6 Feb 2024 09:29:36 +0530 Subject: [PATCH 182/209] Add union type to error symbol test --- .../test/resources/test-src/symbols/error_type_symbol_test.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal index 48b257f558ba..1ca615fd2154 100644 --- a/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal +++ b/tests/ballerina-compiler-api-test/src/test/resources/test-src/symbols/error_type_symbol_test.bal @@ -51,7 +51,7 @@ type ErrorDetail1 record { type ErrorDetail2 record {| *ErrorDetail1; - boolean flag; + boolean|int flag; |}; type SimpleError error; From f9b150ab1d4e385004eb5a8008d52891c9b502de Mon Sep 17 00:00:00 2001 From: Nipuna Fernando Date: Wed, 7 Feb 2024 14:09:06 +0530 Subject: [PATCH 183/209] Use field position of the symbol for intersection --- .../wso2/ballerinalang/compiler/semantics/analyzer/Types.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index 0e015c126916..3f3639bb13ae 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -5616,7 +5616,7 @@ private boolean populateFields(IntersectionContext intersectionContext, BRecordT invokableSymbol.flags = tsymbol.flags; } else { recordFieldSymbol = new BVarSymbol(intersectionFlags, name, env.enclPkg.packageID, - intersectionFieldType, newTypeSymbol, lhsRecordField.pos, SOURCE); + intersectionFieldType, newTypeSymbol, lhsRecordField.symbol.pos, SOURCE); } newTypeFields.put(key, new BField(name, recordFieldSymbol.pos, recordFieldSymbol)); From fe43e44aebbe078ecdfdb2d7cc2e859fead937bc Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 8 Feb 2024 09:46:50 +0530 Subject: [PATCH 184/209] Move build tool related classes to new projects.buildtools package --- .../src/main/java/io/ballerina/cli/task/CompileTask.java | 2 +- .../io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java | 4 ++-- cli/ballerina-cli/src/main/java/module-info.java | 2 -- .../src/main/java/io/ballerina/projects/Project.java | 1 + .../io/ballerina/projects/buildtools}/CodeGeneratorTool.java | 4 +--- .../io/ballerina/projects/{ => buildtools}/ToolContext.java | 4 +++- compiler/ballerina-lang/src/main/java/module-info.java | 1 + .../src/main/java/build/tool/runner/SampleToolRunner.java | 4 ++-- ...ool => io.ballerina.projects.buildtools.CodeGeneratorTool} | 0 9 files changed, 11 insertions(+), 11 deletions(-) rename {cli/ballerina-cli/src/main/java/io/ballerina/cli/tool => compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools}/CodeGeneratorTool.java (84%) rename compiler/ballerina-lang/src/main/java/io/ballerina/projects/{ => buildtools}/ToolContext.java (97%) rename project-api/test-artifacts/sample-openapi-build-tool/src/main/resources/META-INF/services/{io.ballerina.cli.tool.CodeGeneratorTool => io.ballerina.projects.buildtools.CodeGeneratorTool} (100%) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java index df92855d41cf..b05b681c99fa 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CompileTask.java @@ -29,7 +29,7 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.ProjectKind; import io.ballerina.projects.SemanticVersion; -import io.ballerina.projects.ToolContext; +import io.ballerina.projects.buildtools.ToolContext; import io.ballerina.projects.directory.SingleFileProject; import io.ballerina.projects.environment.ResolutionOptions; import io.ballerina.projects.internal.PackageDiagnostic; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java index c8d6e118229c..5ed6a6144e56 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBallerinaPreBuildToolsTask.java @@ -18,11 +18,11 @@ package io.ballerina.cli.task; -import io.ballerina.cli.tool.CodeGeneratorTool; import io.ballerina.cli.utils.FileUtils; import io.ballerina.projects.Diagnostics; import io.ballerina.projects.Project; -import io.ballerina.projects.ToolContext; +import io.ballerina.projects.buildtools.CodeGeneratorTool; +import io.ballerina.projects.buildtools.ToolContext; import io.ballerina.projects.internal.PackageDiagnostic; import io.ballerina.projects.internal.ProjectDiagnosticErrorCode; import io.ballerina.toml.api.Toml; diff --git a/cli/ballerina-cli/src/main/java/module-info.java b/cli/ballerina-cli/src/main/java/module-info.java index baef3d0bfbe0..40fddd6af9aa 100644 --- a/cli/ballerina-cli/src/main/java/module-info.java +++ b/cli/ballerina-cli/src/main/java/module-info.java @@ -1,11 +1,9 @@ module io.ballerina.cli { uses io.ballerina.cli.BLauncherCmd; - uses io.ballerina.cli.tool.CodeGeneratorTool; exports io.ballerina.cli; exports io.ballerina.cli.launcher; exports io.ballerina.cli.utils; exports io.ballerina.cli.cmd; - exports io.ballerina.cli.tool; requires io.ballerina.runtime; requires io.ballerina.lang; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java index d822633f1aa5..bfb31196a631 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/Project.java @@ -17,6 +17,7 @@ */ package io.ballerina.projects; +import io.ballerina.projects.buildtools.ToolContext; import io.ballerina.projects.environment.ProjectEnvironment; import org.wso2.ballerinalang.compiler.util.CompilerContext; import org.wso2.ballerinalang.compiler.util.CompilerOptions; diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/tool/CodeGeneratorTool.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java similarity index 84% rename from cli/ballerina-cli/src/main/java/io/ballerina/cli/tool/CodeGeneratorTool.java rename to compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java index 123e9d4fc183..a1985d99ce03 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/tool/CodeGeneratorTool.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java @@ -1,6 +1,4 @@ -package io.ballerina.cli.tool; - -import io.ballerina.projects.ToolContext; +package io.ballerina.projects.buildtools; /** * {@code CodeGeneratorTool} represents a Ballerina build tool. diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java similarity index 97% rename from compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java rename to compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java index cddc26f24127..fc954b06719f 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java @@ -15,8 +15,10 @@ * specific language governing permissions and limitations * under the License. */ -package io.ballerina.projects; +package io.ballerina.projects.buildtools; +import io.ballerina.projects.Package; +import io.ballerina.projects.PackageManifest; import io.ballerina.toml.semantic.ast.TomlTableNode; import io.ballerina.tools.diagnostics.Diagnostic; diff --git a/compiler/ballerina-lang/src/main/java/module-info.java b/compiler/ballerina-lang/src/main/java/module-info.java index 89c5534e5d54..8fb194dc243c 100644 --- a/compiler/ballerina-lang/src/main/java/module-info.java +++ b/compiler/ballerina-lang/src/main/java/module-info.java @@ -82,4 +82,5 @@ exports io.ballerina.projects.internal.configschema to org.ballerinalang.config.schema.generator, io.ballerina.language.server.core; exports io.ballerina.projects.plugins.completion; + exports io.ballerina.projects.buildtools; } diff --git a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java index f47e546bc046..357e76a885f6 100644 --- a/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java +++ b/project-api/test-artifacts/sample-openapi-build-tool/src/main/java/build/tool/runner/SampleToolRunner.java @@ -18,8 +18,8 @@ package build.tool.runner; -import io.ballerina.cli.tool.CodeGeneratorTool; -import io.ballerina.projects.ToolContext; +import io.ballerina.projects.buildtools.CodeGeneratorTool; +import io.ballerina.projects.buildtools.ToolContext; import io.ballerina.tools.diagnostics.DiagnosticFactory; import io.ballerina.tools.diagnostics.DiagnosticInfo; import io.ballerina.tools.diagnostics.DiagnosticSeverity; diff --git a/project-api/test-artifacts/sample-openapi-build-tool/src/main/resources/META-INF/services/io.ballerina.cli.tool.CodeGeneratorTool b/project-api/test-artifacts/sample-openapi-build-tool/src/main/resources/META-INF/services/io.ballerina.projects.buildtools.CodeGeneratorTool similarity index 100% rename from project-api/test-artifacts/sample-openapi-build-tool/src/main/resources/META-INF/services/io.ballerina.cli.tool.CodeGeneratorTool rename to project-api/test-artifacts/sample-openapi-build-tool/src/main/resources/META-INF/services/io.ballerina.projects.buildtools.CodeGeneratorTool From b9b7f2c600f8b5c516893251c1133afe76dbb945 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 8 Feb 2024 23:04:41 +0530 Subject: [PATCH 185/209] Fix emit diagnostics to print lifecycle plugin diagnostics --- .../cli/task/CreateExecutableTask.java | 13 +++--------- .../ballerina/projects/JBallerinaBackend.java | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index d4c9835a940e..107c88e4c7b3 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -127,16 +127,9 @@ public void execute(Project project) { } } - List diagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); - if (!diagnostics.isEmpty()) { - // TODO: When deprecating the lifecycle compiler plugin, we can remove this check for duplicates - // in JBallerinaBackend diagnostics and the diagnostics added to EmitResult. - diagnostics = diagnostics.stream() - .filter(diagnostic -> !jBallerinaBackend.diagnosticResult().diagnostics().contains(diagnostic)) - .collect(Collectors.toList()); - if (!diagnostics.isEmpty()) { - diagnostics.forEach(d -> out.println("\n" + d.toString())); - } + List emitDiagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); + if (!emitDiagnostics.isEmpty()) { + emitDiagnostics.forEach(d -> out.println("\n" + d.toString())); } } catch (ProjectException e) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 2bba26323976..97ff8b0ba202 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -205,12 +205,11 @@ public DiagnosticResult diagnosticResult() { return diagnosticResult; } - // TODO EmitResult should not contain compilation diagnostics. public EmitResult emit(OutputType outputType, Path filePath) { Path generatedArtifact = null; if (diagnosticResult.hasErrors()) { - return new EmitResult(false, diagnosticResult, generatedArtifact); + return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), generatedArtifact); } switch (outputType) { @@ -227,19 +226,23 @@ public EmitResult emit(OutputType outputType, Path filePath) { throw new RuntimeException("Unexpected output type: " + outputType); } - ArrayList diagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); + ArrayList allDiagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); + List emitResultDiagnostics = new ArrayList<>(); + // Add lifecycle plugin diagnostics. List pluginDiagnostics = packageCompilation.notifyCompilationCompletion(filePath); if (!pluginDiagnostics.isEmpty()) { - diagnostics.addAll(pluginDiagnostics); + emitResultDiagnostics.addAll(pluginDiagnostics); } - diagnosticResult = new DefaultDiagnosticResult(diagnostics); - - List allDiagnostics = new ArrayList<>(diagnostics); + // Add jar resolver diagnostics. jarResolver().diagnosticResult().diagnostics().stream().forEach( - diagnostic -> allDiagnostics.add(diagnostic)); + diagnostic -> emitResultDiagnostics.add(diagnostic)); + allDiagnostics.addAll(emitResultDiagnostics); + // JBallerinaBackend diagnostics contains all diagnostics. + // EmitResult will only contain diagnostics related to emitting the executable. + diagnosticResult = new DefaultDiagnosticResult(allDiagnostics); // TODO handle the EmitResult properly - return new EmitResult(true, new DefaultDiagnosticResult(allDiagnostics), generatedArtifact); + return new EmitResult(true, new DefaultDiagnosticResult(emitResultDiagnostics), generatedArtifact); } private Path emitBala(Path filePath) { From b893dc9fbe98965d1fe187f7d51a84db642bf708 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 8 Feb 2024 23:05:49 +0530 Subject: [PATCH 186/209] Revert "Fix emit diagnostics to print lifecycle plugin diagnostics" This reverts commit b9b7f2c600f8b5c516893251c1133afe76dbb945. --- .../cli/task/CreateExecutableTask.java | 13 +++++++++--- .../ballerina/projects/JBallerinaBackend.java | 21 ++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index 107c88e4c7b3..d4c9835a940e 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -127,9 +127,16 @@ public void execute(Project project) { } } - List emitDiagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); - if (!emitDiagnostics.isEmpty()) { - emitDiagnostics.forEach(d -> out.println("\n" + d.toString())); + List diagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); + if (!diagnostics.isEmpty()) { + // TODO: When deprecating the lifecycle compiler plugin, we can remove this check for duplicates + // in JBallerinaBackend diagnostics and the diagnostics added to EmitResult. + diagnostics = diagnostics.stream() + .filter(diagnostic -> !jBallerinaBackend.diagnosticResult().diagnostics().contains(diagnostic)) + .collect(Collectors.toList()); + if (!diagnostics.isEmpty()) { + diagnostics.forEach(d -> out.println("\n" + d.toString())); + } } } catch (ProjectException e) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 97ff8b0ba202..2bba26323976 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -205,11 +205,12 @@ public DiagnosticResult diagnosticResult() { return diagnosticResult; } + // TODO EmitResult should not contain compilation diagnostics. public EmitResult emit(OutputType outputType, Path filePath) { Path generatedArtifact = null; if (diagnosticResult.hasErrors()) { - return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), generatedArtifact); + return new EmitResult(false, diagnosticResult, generatedArtifact); } switch (outputType) { @@ -226,23 +227,19 @@ public EmitResult emit(OutputType outputType, Path filePath) { throw new RuntimeException("Unexpected output type: " + outputType); } - ArrayList allDiagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); - List emitResultDiagnostics = new ArrayList<>(); - // Add lifecycle plugin diagnostics. + ArrayList diagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); List pluginDiagnostics = packageCompilation.notifyCompilationCompletion(filePath); if (!pluginDiagnostics.isEmpty()) { - emitResultDiagnostics.addAll(pluginDiagnostics); + diagnostics.addAll(pluginDiagnostics); } - // Add jar resolver diagnostics. + diagnosticResult = new DefaultDiagnosticResult(diagnostics); + + List allDiagnostics = new ArrayList<>(diagnostics); jarResolver().diagnosticResult().diagnostics().stream().forEach( - diagnostic -> emitResultDiagnostics.add(diagnostic)); - allDiagnostics.addAll(emitResultDiagnostics); - // JBallerinaBackend diagnostics contains all diagnostics. - // EmitResult will only contain diagnostics related to emitting the executable. - diagnosticResult = new DefaultDiagnosticResult(allDiagnostics); + diagnostic -> allDiagnostics.add(diagnostic)); // TODO handle the EmitResult properly - return new EmitResult(true, new DefaultDiagnosticResult(emitResultDiagnostics), generatedArtifact); + return new EmitResult(true, new DefaultDiagnosticResult(allDiagnostics), generatedArtifact); } private Path emitBala(Path filePath) { From de57a6ee37f51703d5a160effa61305846b3f131 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 8 Feb 2024 23:10:49 +0530 Subject: [PATCH 187/209] Fix emit diagnostics to print lifecycle plugin diagnostics --- .../cli/task/CreateExecutableTask.java | 13 +++--------- .../ballerina/projects/JBallerinaBackend.java | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index d4c9835a940e..107c88e4c7b3 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -127,16 +127,9 @@ public void execute(Project project) { } } - List diagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); - if (!diagnostics.isEmpty()) { - // TODO: When deprecating the lifecycle compiler plugin, we can remove this check for duplicates - // in JBallerinaBackend diagnostics and the diagnostics added to EmitResult. - diagnostics = diagnostics.stream() - .filter(diagnostic -> !jBallerinaBackend.diagnosticResult().diagnostics().contains(diagnostic)) - .collect(Collectors.toList()); - if (!diagnostics.isEmpty()) { - diagnostics.forEach(d -> out.println("\n" + d.toString())); - } + List emitDiagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); + if (!emitDiagnostics.isEmpty()) { + emitDiagnostics.forEach(d -> out.println("\n" + d.toString())); } } catch (ProjectException e) { diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index 2bba26323976..97ff8b0ba202 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -205,12 +205,11 @@ public DiagnosticResult diagnosticResult() { return diagnosticResult; } - // TODO EmitResult should not contain compilation diagnostics. public EmitResult emit(OutputType outputType, Path filePath) { Path generatedArtifact = null; if (diagnosticResult.hasErrors()) { - return new EmitResult(false, diagnosticResult, generatedArtifact); + return new EmitResult(false, new DefaultDiagnosticResult(new ArrayList<>()), generatedArtifact); } switch (outputType) { @@ -227,19 +226,23 @@ public EmitResult emit(OutputType outputType, Path filePath) { throw new RuntimeException("Unexpected output type: " + outputType); } - ArrayList diagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); + ArrayList allDiagnostics = new ArrayList<>(diagnosticResult.allDiagnostics); + List emitResultDiagnostics = new ArrayList<>(); + // Add lifecycle plugin diagnostics. List pluginDiagnostics = packageCompilation.notifyCompilationCompletion(filePath); if (!pluginDiagnostics.isEmpty()) { - diagnostics.addAll(pluginDiagnostics); + emitResultDiagnostics.addAll(pluginDiagnostics); } - diagnosticResult = new DefaultDiagnosticResult(diagnostics); - - List allDiagnostics = new ArrayList<>(diagnostics); + // Add jar resolver diagnostics. jarResolver().diagnosticResult().diagnostics().stream().forEach( - diagnostic -> allDiagnostics.add(diagnostic)); + diagnostic -> emitResultDiagnostics.add(diagnostic)); + allDiagnostics.addAll(emitResultDiagnostics); + // JBallerinaBackend diagnostics contains all diagnostics. + // EmitResult will only contain diagnostics related to emitting the executable. + diagnosticResult = new DefaultDiagnosticResult(allDiagnostics); // TODO handle the EmitResult properly - return new EmitResult(true, new DefaultDiagnosticResult(allDiagnostics), generatedArtifact); + return new EmitResult(true, new DefaultDiagnosticResult(emitResultDiagnostics), generatedArtifact); } private Path emitBala(Path filePath) { From 127679c28b7e343a58c47d75c91cab38c9eb1573 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 8 Feb 2024 23:30:12 +0530 Subject: [PATCH 188/209] Remove unused imports --- .../main/java/io/ballerina/cli/task/CreateExecutableTask.java | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index 107c88e4c7b3..d8fb1db88f99 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -41,7 +41,6 @@ import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; -import java.util.stream.Collectors; import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; import static io.ballerina.cli.utils.FileUtils.getFileNameWithoutExtension; From 91326970dee1c562d2d8b107f3951fc739840f99 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 9 Feb 2024 13:52:53 +0530 Subject: [PATCH 189/209] Improve code generated for bal add command --- .../src/main/resources/create_cmd_templates/lib/lib.bal | 6 +++--- .../resources/create_cmd_templates/lib/tests/lib_test.bal | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal index 7a0681e5344c..a5b1af96448c 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal @@ -1,9 +1,9 @@ # Returns the string `Hello` with the input string name. # -# + name - name as a string +# + name - name as a string or nil # + return - "Hello, " with the input string name -public function hello(string name) returns string { - if !(name is "") { +public function hello(string? name) returns string { + if name !is () { return "Hello, " + name; } return "Hello, World!"; diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal index 31ce10dfbb64..4b725d91de93 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/tests/lib_test.bal @@ -21,8 +21,7 @@ function testFunction() { @test:Config {} function negativeTestFunction() { - string name = ""; - string welcomeMsg = hello(name); + string welcomeMsg = hello(()); test:assertEquals("Hello, World!", welcomeMsg); } From 1e7b5bcf681640d83034f58a23fc98315e800a5d Mon Sep 17 00:00:00 2001 From: ShammiL Date: Mon, 12 Feb 2024 10:41:51 +0530 Subject: [PATCH 190/209] Apply improvement to service template --- .../resources/create_cmd_templates/service/service.bal | 8 ++++---- .../create_cmd_templates/service/tests/service_test.bal | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal index 90f6a0cc7979..293489862114 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal @@ -7,11 +7,11 @@ service / on new http:Listener(9090) { # A resource for generating greetings # + name - the input string name # + return - string name with hello message or error - resource function get greeting(string name) returns string|error { + resource function get greeting(string? name) returns string|error { // Send a response back to the caller. - if name is "" { + if name is () { return error("name should not be empty!"); } - return "Hello, " + name; - } + return string `Hello, ${name}`; + } } diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal index 1e2c013c0280..0d85eb25166e 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/tests/service_test.bal @@ -23,7 +23,7 @@ function testServiceWithProperName() { @test:Config {} function testServiceWithEmptyName() returns error? { - http:Response response = check testClient->get("/greeting/?name="); + http:Response response = check testClient->get("/greeting/"); test:assertEquals(response.statusCode, 500); json errorPayload = check response.getJsonPayload(); test:assertEquals(errorPayload.message, "name should not be empty!"); From 1dfeddb98cecd2323f5e97e55bf55da24d672175 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Mon, 12 Feb 2024 10:42:12 +0530 Subject: [PATCH 191/209] Use string templates in templates --- .../src/main/resources/create_cmd_templates/lib/lib.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal index a5b1af96448c..ae6ddb6448cb 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/lib/lib.bal @@ -4,7 +4,7 @@ # + return - "Hello, " with the input string name public function hello(string? name) returns string { if name !is () { - return "Hello, " + name; + return string `Hello, ${name}`; } return "Hello, World!"; } From dff4f9356c82fd9fa2d8dc5cadfc1391d910339e Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Mon, 12 Feb 2024 11:19:06 +0530 Subject: [PATCH 192/209] Address review suggestions --- .../test/annotations/AnnotationAttachmentSymbolsTest.java | 5 +---- .../resources/test-src/annotations/annot_attachments.bal | 2 -- .../annotations/service_remote_method_annotations.bal | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java index 7c55a82b99fc..68fda5c98431 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/annotations/AnnotationAttachmentSymbolsTest.java @@ -400,10 +400,7 @@ public void testAnnotWithServiceRemoteMethodAttachmentPoint() { List attachments = function.symbol.getAnnotations(); Assert.assertEquals(attachments.size(), 2); - AnnotationAttachmentSymbol v31 = attachments.get(0); - Assert.assertFalse(v31.isConstAnnotation()); - assertAttachmentSymbol(v31, "v31"); - + assertAttachmentSymbol(attachments.get(0), "v31"); assertAttachmentSymbol(attachments.get(1), "v32", true, "increment", 1112L); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal index 020aeecb26ac..f8ab75fa1ed2 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/annot_attachments.bal @@ -349,7 +349,6 @@ service class ServiceClass { increment: 1112 } remote function serviceRemoteFn1() { - } } @@ -365,6 +364,5 @@ service /ser2 on new Listener() { increment: 1114 } remote function serviceRemoteFn3() { - } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal index feef5089aa67..31e80ce8dd18 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/annotations/service_remote_method_annotations.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.org). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except From af06b9d9a6a034a595b4ee471eb2df568a4437e3 Mon Sep 17 00:00:00 2001 From: Heshan Padmasiri Date: Sun, 4 Feb 2024 18:19:28 +0530 Subject: [PATCH 193/209] Cache repeated type calculations --- .../io/ballerina/runtime/api/types/Type.java | 36 +++++++++++++++++++ .../runtime/api/utils/TypeUtils.java | 23 +++++++++--- .../runtime/internal/types/BType.java | 17 +++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java index 54f15bf537a3..c1d4fbdadfe4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java @@ -31,6 +31,42 @@ */ public interface Type { + /** + * Set the referred type for this type once it has been calculated. This must be called the first time this + * calculation is done in order for {@code Type#getReferredTypeCache()} to work properly. This is non-blocking and + * will become eventually consistent. Expect {@code TypeUtils#getReferredType(Type)} tobe referentially transparent. + * + * @param type Type referred by this type. For non-reference types, this is the same type. + */ + void setReferredTypeCache(Type type); + + /** + * Get the type referred by this type if it has been already calculated. If it has not been already calculated will + * return null. For non-reference types, this will return the same type. This is non-blocking and will become + * eventually consistent. Expect {@code TypeUtils#getReferredType(Type)} tobe referentially transparent. + * + * @return Referred type of the type + */ + Type getReferredTypeCache(); + + /** + * Set the implied type for this type once it has been calculated. This must be called the first time this + * calculation is done in order for {@code Type#getImpliedTypeCache()} to work properly. This is non-blocking and + * will become eventually consistent. Expect {@code TypeUtils#getImpliedType(Type)} tobe referentially transparent. + * + * @param type Type implied by this type. For non-intersection types, this is the same type. + */ + void setImpliedTypeCache(Type type); + + /** + * Get the type implied by this type if it has been already calculated. If it has not been already calculated will + * return null. For non-intersection types, this will return the same type. This is non-blocking and will become + * eventually consistent. Expect {@code TypeUtils#getImpliedType(Type)} tobe referentially transparent. + * + * @return Implied type of the type + */ + Type getImpliedTypeCache(); + /** * Get the default value of the type. This is the value of an uninitialized variable of this type. * For value types, this is same as the value get from {@code BType#getInitValue()}. diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java index 9485472eafcf..0d9a30030a34 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java @@ -152,10 +152,17 @@ public static boolean isSameType(Type sourceType, Type targetType) { * @return the referred type if provided with a type reference type, else returns the original type */ public static Type getReferredType(Type type) { + Type referredType = type.getReferredTypeCache(); + if (referredType != null) { + return referredType; + } if (type.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG) { - return getReferredType(((ReferenceType) type).getReferredType()); + referredType = getReferredType(((ReferenceType) type).getReferredType()); + } else { + referredType = type; } - return type; + type.setReferredTypeCache(referredType); + return referredType; } /** @@ -167,12 +174,18 @@ public static Type getReferredType(Type type) { * else returns the original type */ public static Type getImpliedType(Type type) { + Type impliedType = type.getImpliedTypeCache(); + if (impliedType != null) { + return impliedType; + } type = getReferredType(type); if (type.getTag() == TypeTags.INTERSECTION_TAG) { - return getImpliedType(((IntersectionType) type).getEffectiveType()); + impliedType = getImpliedType(((IntersectionType) type).getEffectiveType()); + } else { + impliedType = type; } - - return type; + type.setImpliedTypeCache(impliedType); + return impliedType; } } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java index d83b84517f7f..211b7a990758 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java @@ -42,6 +42,8 @@ public abstract class BType implements Type { protected Module pkg; protected Class valueClass; private int hashCode; + private Type referredTypeCache = null; + private Type impliedType = null; protected BType(String typeName, Module pkg, Class valueClass) { this.typeName = typeName; @@ -195,4 +197,19 @@ public long getFlags() { return 0; } + public void setReferredTypeCache(Type type) { + this.referredTypeCache = type; + } + + public Type getReferredTypeCache() { + return this.referredTypeCache; + } + + public void setImpliedTypeCache(Type type) { + this.impliedType = type; + } + + public Type getImpliedTypeCache() { + return this.impliedType; + } } From fa96700914fec788938336065702e26cd19674a1 Mon Sep 17 00:00:00 2001 From: Heshan Padmasiri Date: Mon, 5 Feb 2024 09:17:39 +0530 Subject: [PATCH 194/209] Add default implementations for type caches --- .../io/ballerina/runtime/api/types/Type.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java index c1d4fbdadfe4..24cd32c1386b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java @@ -31,6 +31,7 @@ */ public interface Type { + // TODO: remove default implementations when standard library types are updated /** * Set the referred type for this type once it has been calculated. This must be called the first time this * calculation is done in order for {@code Type#getReferredTypeCache()} to work properly. This is non-blocking and @@ -38,8 +39,8 @@ public interface Type { * * @param type Type referred by this type. For non-reference types, this is the same type. */ - void setReferredTypeCache(Type type); - + default void setReferredTypeCache(Type type) { + } /** * Get the type referred by this type if it has been already calculated. If it has not been already calculated will * return null. For non-reference types, this will return the same type. This is non-blocking and will become @@ -47,7 +48,9 @@ public interface Type { * * @return Referred type of the type */ - Type getReferredTypeCache(); + default Type getReferredTypeCache() { + return null; + } /** * Set the implied type for this type once it has been calculated. This must be called the first time this @@ -56,7 +59,8 @@ public interface Type { * * @param type Type implied by this type. For non-intersection types, this is the same type. */ - void setImpliedTypeCache(Type type); + default void setImpliedTypeCache(Type type) { + } /** * Get the type implied by this type if it has been already calculated. If it has not been already calculated will @@ -65,7 +69,9 @@ public interface Type { * * @return Implied type of the type */ - Type getImpliedTypeCache(); + default Type getImpliedTypeCache() { + return null; + } /** * Get the default value of the type. This is the value of an uninitialized variable of this type. From c0c17f82b23240c289fabbbb9ebf5b9c894cd4aa Mon Sep 17 00:00:00 2001 From: Heshan Padmasiri Date: Wed, 7 Feb 2024 07:00:35 +0530 Subject: [PATCH 195/209] Fix accessor names --- .../io/ballerina/runtime/api/types/Type.java | 8 ++++---- .../runtime/api/utils/TypeUtils.java | 8 ++++---- .../runtime/internal/types/BType.java | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java index 24cd32c1386b..d035b0ce090d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java @@ -39,7 +39,7 @@ public interface Type { * * @param type Type referred by this type. For non-reference types, this is the same type. */ - default void setReferredTypeCache(Type type) { + default void setCachedReferredType(Type type) { } /** * Get the type referred by this type if it has been already calculated. If it has not been already calculated will @@ -48,7 +48,7 @@ default void setReferredTypeCache(Type type) { * * @return Referred type of the type */ - default Type getReferredTypeCache() { + default Type getCachedReferredType() { return null; } @@ -59,7 +59,7 @@ default Type getReferredTypeCache() { * * @param type Type implied by this type. For non-intersection types, this is the same type. */ - default void setImpliedTypeCache(Type type) { + default void setCachedImpliedType(Type type) { } /** @@ -69,7 +69,7 @@ default void setImpliedTypeCache(Type type) { * * @return Implied type of the type */ - default Type getImpliedTypeCache() { + default Type getCachedImpliedType() { return null; } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java index 0d9a30030a34..731b73b35e2d 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/utils/TypeUtils.java @@ -152,7 +152,7 @@ public static boolean isSameType(Type sourceType, Type targetType) { * @return the referred type if provided with a type reference type, else returns the original type */ public static Type getReferredType(Type type) { - Type referredType = type.getReferredTypeCache(); + Type referredType = type.getCachedReferredType(); if (referredType != null) { return referredType; } @@ -161,7 +161,7 @@ public static Type getReferredType(Type type) { } else { referredType = type; } - type.setReferredTypeCache(referredType); + type.setCachedReferredType(referredType); return referredType; } @@ -174,7 +174,7 @@ public static Type getReferredType(Type type) { * else returns the original type */ public static Type getImpliedType(Type type) { - Type impliedType = type.getImpliedTypeCache(); + Type impliedType = type.getCachedImpliedType(); if (impliedType != null) { return impliedType; } @@ -185,7 +185,7 @@ public static Type getImpliedType(Type type) { } else { impliedType = type; } - type.setImpliedTypeCache(impliedType); + type.setCachedImpliedType(impliedType); return impliedType; } } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java index 211b7a990758..866432570c59 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/types/BType.java @@ -42,8 +42,8 @@ public abstract class BType implements Type { protected Module pkg; protected Class valueClass; private int hashCode; - private Type referredTypeCache = null; - private Type impliedType = null; + private Type cachedReferredType = null; + private Type cachedImpliedType = null; protected BType(String typeName, Module pkg, Class valueClass) { this.typeName = typeName; @@ -197,19 +197,19 @@ public long getFlags() { return 0; } - public void setReferredTypeCache(Type type) { - this.referredTypeCache = type; + public void setCachedReferredType(Type type) { + this.cachedReferredType = type; } - public Type getReferredTypeCache() { - return this.referredTypeCache; + public Type getCachedReferredType() { + return this.cachedReferredType; } - public void setImpliedTypeCache(Type type) { - this.impliedType = type; + public void setCachedImpliedType(Type type) { + this.cachedImpliedType = type; } - public Type getImpliedTypeCache() { - return this.impliedType; + public Type getCachedImpliedType() { + return this.cachedImpliedType; } } From b044eba099c61bc50430d0d749b7f22294a984c3 Mon Sep 17 00:00:00 2001 From: Heshan Padmasiri Date: Mon, 12 Feb 2024 13:20:02 +0530 Subject: [PATCH 196/209] Fix wording in doc comments Co-authored-by: Hinduja Balasubramaniyam <28644893+HindujaB@users.noreply.github.com> --- .../io/ballerina/runtime/api/types/Type.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java index d035b0ce090d..6d1abcd9e60b 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/Type.java @@ -34,17 +34,18 @@ public interface Type { // TODO: remove default implementations when standard library types are updated /** * Set the referred type for this type once it has been calculated. This must be called the first time this - * calculation is done in order for {@code Type#getReferredTypeCache()} to work properly. This is non-blocking and - * will become eventually consistent. Expect {@code TypeUtils#getReferredType(Type)} tobe referentially transparent. + * calculation is done for {@code Type#getReferredTypeCache()} to work properly. This is non-blocking and + * will eventually become consistent. Expect {@code TypeUtils#getReferredType(Type)} to be referentially + * transparent. * * @param type Type referred by this type. For non-reference types, this is the same type. */ default void setCachedReferredType(Type type) { } /** - * Get the type referred by this type if it has been already calculated. If it has not been already calculated will - * return null. For non-reference types, this will return the same type. This is non-blocking and will become - * eventually consistent. Expect {@code TypeUtils#getReferredType(Type)} tobe referentially transparent. + * Get the type referred by this type if it has been already calculated. If it has not been already calculated, it + * will return null. For non-reference types, this will return the same type. This is non-blocking and will + * eventually become consistent. Expect {@code TypeUtils#getReferredType(Type)} to be referentially transparent. * * @return Referred type of the type */ @@ -54,8 +55,8 @@ default Type getCachedReferredType() { /** * Set the implied type for this type once it has been calculated. This must be called the first time this - * calculation is done in order for {@code Type#getImpliedTypeCache()} to work properly. This is non-blocking and - * will become eventually consistent. Expect {@code TypeUtils#getImpliedType(Type)} tobe referentially transparent. + * calculation is done for {@code Type#getImpliedTypeCache()} to work properly. This is non-blocking and + * will eventually become consistent. Expect {@code TypeUtils#getImpliedType(Type)} to be referentially transparent. * * @param type Type implied by this type. For non-intersection types, this is the same type. */ @@ -63,9 +64,9 @@ default void setCachedImpliedType(Type type) { } /** - * Get the type implied by this type if it has been already calculated. If it has not been already calculated will - * return null. For non-intersection types, this will return the same type. This is non-blocking and will become - * eventually consistent. Expect {@code TypeUtils#getImpliedType(Type)} tobe referentially transparent. + * Get the type implied by this type if it has been already calculated. If it has not been already calculated, it + * will return null. For non-intersection types, this will return the same type. This is non-blocking and will + * eventually become consistent. Expect {@code TypeUtils#getImpliedType(Type)} to be referentially transparent. * * @return Implied type of the type */ From 00bc64ec01c6524e14b11df66a0c5f5242c56957 Mon Sep 17 00:00:00 2001 From: DimuthuMadushan Date: Tue, 13 Feb 2024 11:21:03 +0530 Subject: [PATCH 197/209] Update GraphQL help text --- .../resources/cli-help/ballerina-graphql.help | 60 ++++++++++--------- .../resources/cli-help/ballerina-help.help | 5 +- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help index aabe22b09a7d..7b866880b920 100644 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-graphql.help @@ -1,10 +1,10 @@ NAME - ballerina-graphql - Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and Ballerina service sources for a GraphQL schema. + ballerina-graphql - Generate the GraphQL schema for a Ballerina GraphQL service, + generate the Ballerina service sources for a GraphQL schema, and + generate the Ballerina client sources for a GraphQL config file [Experimental]. SYNOPSIS - bal graphql [-i | --input] - [-o | --output] bal graphql [-i | --input] [-o | --output] [-s | --service] @@ -12,25 +12,28 @@ SYNOPSIS [-o | --output] [-m | --mode] [-r | --use-records-for-objects] + bal graphql [-i | --input] + [-o | --output] DESCRIPTION + Export a GraphQL schema (SDL) for a given Ballerina GraphQL service or generate the + Ballerina sources for a given GraphQL schema. The generated Ballerina sources or + GraphQL schema files will be written into the provided output location. + Generate the Ballerina GraphQL client sources for a given GraphQL config file configured with GraphQL schemas specified by GraphQL Schema Definition Language(SDL) and GraphQL - queries or export a GraphQL schema (SDL) for a given Ballerina GraphQL service. - - The generated Ballerina sources or GraphQL schema files will be written into the provided - output location. + queries. GraphQL client generation is an experimental feature which supports only a limited + set of functionality. OPTIONS - -i, --input - This is mandatory input. The given GraphQL config file which is configured with - GraphQL schemas (SDL) and queries, will generate the Ballerina GraphQL client sources. - The given Ballerina GraphQL service file will generate the GraphQL schema (SDL) file - relevant to the service. + -i, --input + This is mandatory input. The given Ballerina GraphQL service file will generate + the GraphQL schema (SDL) file relevant to the service. The given GraphQL schema file will generate the Ballerina GraphQL service sources. + The given GraphQL config file which is configured with GraphQL schemas (SDL) + and queries, will generate the Ballerina GraphQL client sources. -o, --output Location of the generated Ballerina source code or GraphQL schema. If this path is not specified, the output will be written to the same directory from which the command is @@ -41,31 +44,32 @@ OPTIONS If this base path is not specified, schemas will be generated for each of the GraphQL services in the input file. -m, --mode - This mode is used to identify the operation mode. It can be `client`, `schema`, or - `service`. The `client` argument indicates the Ballerina client source code - generation, the `schema` argument indicates the GraphQL schema generation, and the - `service` argument indicates the Ballerina GraphQL service source code generation. - If the `mode` flag is not specified, the `graphql` tool will infer the mode from the + This mode is used to identify the operation mode. It can be `schema`, `service`, + or `client`. The `schema` argument indicates the GraphQL schema generation, + the `service` argument indicates the Ballerina GraphQL service source code generation, + and the `client` argument indicates the Ballerina client source code generation. + If the `mode` flag is not specified, the `graphql` tool will infer the mode from the `input` file extension. -r, --use-records-for-objects - This flag is used without an argument. It is used only in the Ballerina GraphQL - service generation. It will make the Ballerina CLI tool to use record types for + This flag is used without an argument. It is used only in the Ballerina GraphQL + service generation. It will make the Ballerina CLI tool to use record types for GraphQL object types whenever possible. EXAMPLES - Generate Ballerina Graphql clients using a GraphQL config file (`graphql.config.yaml`). - $ bal graphql -i graphql.config.yaml - - Generate Ballerina Graphql clients using a GraphQL config file (`graphql.config.yaml`) - and write the output to the given directory. - $ bal graphql -i graphql.config.yaml -o ./output_path - Generate a GraphQL schema for a selected GraphQL service from the given input file. $ bal graphql -i graphql_service.bal -o ./output_path -s /service_base_path Generate a Ballerina GraphQL service using a GraphQL schema file (`schema.graphql`). $ bal graphql -i schema.graphql -m service -o ./output_path - Generate a Ballerina GraphQL service using a GraphQL schema file (`schema.graphql`) + Generate a Ballerina GraphQL service using a GraphQL schema file (`schema.graphql`) including record types whenever possible. $ bal graphql -i schema.graphql -m service -o ./output_path -r + + Generate Ballerina Graphql clients using a GraphQL config file (`graphql.config.yaml`) + [Experimental]. + $ bal graphql -i graphql.config.yaml + + Generate Ballerina Graphql clients using a GraphQL config file (`graphql.config.yaml`) + and write the output to the given directory [Experimental]. + $ bal graphql -i graphql.config.yaml -o ./output_path diff --git a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help index 07ecf41512c6..ba1503f2fbab 100755 --- a/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help +++ b/cli/ballerina-cli/src/main/resources/cli-help/ballerina-help.help @@ -40,7 +40,10 @@ COMMANDS format Format Ballerina source files grpc Generate the Ballerina sources for a given Protocol Buffer definition - graphql Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and Ballerina service sources for a GraphQL schema + graphql Generate the GraphQL schema for a Ballerina GraphQL service, + generate the Ballerina GraphQL service for a GraphQL schema, + and generate the Ballerina client sources for a GraphQL config + file [Experimental] openapi Generate the Ballerina sources for a given OpenAPI definition and vice versa asyncapi Generate the Ballerina sources for a given AsyncAPI definition From 64157b2929d712e7e662e008fe5635475cdba712 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Tue, 13 Feb 2024 14:54:43 +0530 Subject: [PATCH 198/209] Address reviews --- .../java/io/ballerina/cli/task/CreateExecutableTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index d8fb1db88f99..1a9a2009973b 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -126,9 +126,9 @@ public void execute(Project project) { } } - List emitDiagnostics = new ArrayList<>(emitResult.diagnostics().diagnostics()); - if (!emitDiagnostics.isEmpty()) { - emitDiagnostics.forEach(d -> out.println("\n" + d.toString())); + // Print diagnostics found during emit executable + if (!emitResult.diagnostics().diagnostics().isEmpty()) { + emitResult.diagnostics().diagnostics().forEach(d -> out.println("\n" + d.toString())); } } catch (ProjectException e) { From f5263f5c9c691b96f9b5513d66e8b9c32e234dee Mon Sep 17 00:00:00 2001 From: ShammiL Date: Tue, 13 Feb 2024 15:20:00 +0530 Subject: [PATCH 199/209] Remove unused imports --- .../main/java/io/ballerina/cli/task/CreateExecutableTask.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java index 1a9a2009973b..cd88a3262533 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateExecutableTask.java @@ -29,7 +29,6 @@ import io.ballerina.projects.ProjectException; import io.ballerina.projects.ProjectKind; import io.ballerina.projects.internal.model.Target; -import io.ballerina.tools.diagnostics.Diagnostic; import org.ballerinalang.compiler.plugins.CompilerPlugin; import java.io.File; @@ -38,8 +37,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; import java.util.ServiceLoader; import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException; From 20ad85888acd2c3023c0253ae71cc5dbcccf3b95 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Tue, 13 Feb 2024 15:29:10 +0530 Subject: [PATCH 200/209] Rename predefined types --- .../java/io/ballerina/runtime/api/PredefinedTypes.java | 8 ++++---- .../io/ballerina/runtime/internal/values/XmlSequence.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java index aef3057465fe..72b1d0d946b9 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/PredefinedTypes.java @@ -151,10 +151,10 @@ public class PredefinedTypes { TYPE_TEXT)), EMPTY_MODULE); public static final Type TYPE_READONLY_XML = ReadOnlyUtils.setImmutableTypeAndGetEffectiveType(TYPE_XML); - public static final Type XML_ELEMENT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); - public static final Type XML_COMMENT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_COMMENT, false); - public static final Type XML_PI_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); - public static final Type XML_TEXT_SEQUENCE_TYPE = new BXmlType(PredefinedTypes.TYPE_TEXT, false); + public static final Type TYPE_XML_ELEMENT_SEQUENCE = new BXmlType(PredefinedTypes.TYPE_ELEMENT, false); + public static final Type TYPE_XML_COMMENT_SEQUENCE = new BXmlType(PredefinedTypes.TYPE_COMMENT, false); + public static final Type TYPE_XML_PI_SEQUENCE = new BXmlType(PredefinedTypes.TYPE_PROCESSING_INSTRUCTION, false); + public static final Type TYPE_XML_TEXT_SEQUENCE = new BXmlType(PredefinedTypes.TYPE_TEXT, false); public static final AnyType TYPE_ANY = new BAnyType(TypeConstants.ANY_TNAME, EMPTY_MODULE, false); public static final AnyType TYPE_READONLY_ANY = new BAnyType(TypeConstants.READONLY_ANY_TNAME, EMPTY_MODULE, true); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java index 3bd1e3960812..b41eafe5d225 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java @@ -626,10 +626,10 @@ public Object next() { private Type getSequenceType(Type tempExprType) { return switch (tempExprType.getTag()) { - case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.XML_ELEMENT_SEQUENCE_TYPE; - case TypeTags.XML_COMMENT_TAG -> PredefinedTypes.XML_COMMENT_SEQUENCE_TYPE; - case TypeTags.XML_PI_TAG -> PredefinedTypes.XML_PI_SEQUENCE_TYPE; - default -> PredefinedTypes.XML_TEXT_SEQUENCE_TYPE; + case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.TYPE_XML_ELEMENT_SEQUENCE; + case TypeTags.XML_COMMENT_TAG -> PredefinedTypes.TYPE_XML_COMMENT_SEQUENCE; + case TypeTags.XML_PI_TAG -> PredefinedTypes.TYPE_XML_PI_SEQUENCE; + default -> PredefinedTypes.TYPE_XML_TEXT_SEQUENCE; }; } From ea7f78e8687c7b48437f796d3b6ce985eb791cab Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Wed, 14 Feb 2024 09:32:35 +0530 Subject: [PATCH 201/209] Fix bad sad error --- .../central/client/CentralAPIClient.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java index a2e036d963bf..330dd3dd477b 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java @@ -828,7 +828,7 @@ public PackageNameResolutionResponse resolvePackageNames(PackageNameResolutionRe // Unauthorized access token if (packageResolutionResponse.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType.get(), resolvePackageNamesBody); } // If search request was sent wrongly @@ -905,7 +905,7 @@ public PackageResolutionResponse resolveDependencies(PackageResolutionRequest re // Unauthorized access token if (packageResolutionResponse.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType.get(), packageResolutionResponseBody); } // If search request was sent wrongly @@ -973,7 +973,7 @@ public PackageSearchResult searchPackage(String query, String supportedPlatform, // Unauthorized access token if (searchResponse.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType.get(), searchResponseBody); } // If search request was sent wrongly @@ -1043,7 +1043,7 @@ public ToolSearchResult searchTool(String keyword, String supportedPlatform, Str // Unauthorized access token if (searchResponse.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType.get(), searchResponseBody); } // If search request was sent wrongly @@ -1152,7 +1152,7 @@ public void deprecatePackage(String packageInfo, String deprecationMsg, String s // Unauthorized access token if (deprecationResponse.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType.get(), deprecationResponseBody); } // If deprecation request was sent wrongly @@ -1474,8 +1474,10 @@ protected void handleResponseErrors(Response response, String msg) throws Centra Optional body = Optional.ofNullable(response.body()); if (body.isPresent()) { // If search request was sent wrongly + String responseBody = body.get().string(); + MediaType contentType = body.get().contentType(); if (response.code() == HTTP_BAD_REQUEST || response.code() == HTTP_NOT_FOUND) { - Error error = new Gson().fromJson(body.get().string(), Error.class); + Error error = new Gson().fromJson(responseBody, Error.class); if (error.getMessage() != null && !"".equals(error.getMessage())) { throw new CentralClientException(error.getMessage()); } @@ -1483,14 +1485,14 @@ protected void handleResponseErrors(Response response, String msg) throws Centra // Unauthorized access token if (response.code() == HTTP_UNAUTHORIZED) { - handleUnauthorizedResponse(body); + handleUnauthorizedResponse(contentType, responseBody); } // If error occurred at remote repository or invalid/no response received at the // gateway server if (response.code() == HTTP_INTERNAL_ERROR || response.code() == HTTP_UNAVAILABLE || response.code() == HTTP_BAD_GATEWAY || response.code() == HTTP_GATEWAY_TIMEOUT) { - Error error = new Gson().fromJson(body.get().string(), Error.class); + Error error = new Gson().fromJson(responseBody, Error.class); if (error.getMessage() != null && !"".equals(error.getMessage())) { throw new CentralClientException(msg + " reason:" + error.getMessage()); } @@ -1711,22 +1713,21 @@ private void handleUnauthorizedResponse(Optional body, String resp /** * Handle unauthorized response. * - * @param body response body + * @param mediaType mediaType + * @param responseBody response body * @throws IOException when accessing response body * @throws CentralClientException with unauthorized error message */ - private void handleUnauthorizedResponse(Optional body) + private void handleUnauthorizedResponse(MediaType mediaType, String responseBody) throws IOException, CentralClientException { - if (body.isPresent()) { - Optional contentType = Optional.ofNullable(body.get().contentType()); - if (contentType.isPresent() && isApplicationJsonContentType(contentType.get().toString())) { - Error error = new Gson().fromJson(body.get().string(), Error.class); - throw new CentralClientException("unauthorized access token. " + - "check access token set in 'Settings.toml' file. reason: " + error.getMessage()); - } else { - throw new CentralClientException("unauthorized access token. " + - "check access token set in 'Settings.toml' file."); - } + Optional contentType = Optional.ofNullable(mediaType); + if (contentType.isPresent() && isApplicationJsonContentType(contentType.get().toString())) { + Error error = new Gson().fromJson(responseBody, Error.class); + throw new CentralClientException("unauthorized access token. " + + "check access token set in 'Settings.toml' file. reason: " + error.getMessage()); + } else { + throw new CentralClientException("unauthorized access token. " + + "check access token set in 'Settings.toml' file."); } } From 98bed871eee6cbe9777641f0f5dd390cbacdde00 Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Wed, 14 Feb 2024 11:03:53 +0530 Subject: [PATCH 202/209] Address the review --- .../ballerinalang/central/client/CentralAPIClient.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java index 330dd3dd477b..401be1ce7fd6 100644 --- a/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java +++ b/cli/central-client/src/main/java/org/ballerinalang/central/client/CentralAPIClient.java @@ -1721,14 +1721,13 @@ private void handleUnauthorizedResponse(Optional body, String resp private void handleUnauthorizedResponse(MediaType mediaType, String responseBody) throws IOException, CentralClientException { Optional contentType = Optional.ofNullable(mediaType); + StringBuilder message = new StringBuilder("unauthorized access token. " + + "check access token set in 'Settings.toml' file."); if (contentType.isPresent() && isApplicationJsonContentType(contentType.get().toString())) { Error error = new Gson().fromJson(responseBody, Error.class); - throw new CentralClientException("unauthorized access token. " + - "check access token set in 'Settings.toml' file. reason: " + error.getMessage()); - } else { - throw new CentralClientException("unauthorized access token. " + - "check access token set in 'Settings.toml' file."); + message.append("reason: ").append(error.getMessage()); } + throw new CentralClientException(message.toString()); } private void logResponseVerbose(Response response, String bodyContent) { From b65f39be2b224cc6a469eecefb353ad31978101a Mon Sep 17 00:00:00 2001 From: Thevakumar-Luheerathan Date: Wed, 14 Feb 2024 16:25:48 +0530 Subject: [PATCH 203/209] Fix manifest warning --- .../projects/internal/ManifestBuilder.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index e5f56405621d..2c8388c8052c 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -88,6 +88,8 @@ public class ManifestBuilder { private static final String PACKAGE = "package"; private static final String VERSION = "version"; + public static final String ORG = "org"; + public static final String NAME = "name"; private static final String LICENSE = "license"; private static final String AUTHORS = "authors"; private static final String REPOSITORY = "repository"; @@ -331,24 +333,24 @@ private PackageDescriptor getPackageDescriptor(TomlTableNode tomlTableNode) { TomlTableNode pkgNode = (TomlTableNode) topLevelPkgNode; - org = getStringValueFromTomlTableNode(pkgNode, "org"); - if (org == null) { + org = getStringValueFromTomlTableNode(pkgNode, ORG, ""); + if (pkgNode.entries().get(ORG) == null) { org = defaultOrg().value(); reportDiagnostic(pkgNode, "missing key 'org' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'org = \"" + org + "\"'", ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), DiagnosticSeverity.WARNING); } - name = getStringValueFromTomlTableNode(pkgNode, "name"); - if (name == null) { + name = getStringValueFromTomlTableNode(pkgNode, NAME, ""); + if (pkgNode.entries().get(NAME) == null) { name = defaultName(this.projectPath).value(); reportDiagnostic(pkgNode, "missing key 'name' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'name = \"" + name + "\"'", ProjectDiagnosticErrorCode.MISSING_PKG_INFO_IN_BALLERINA_TOML.diagnosticId(), DiagnosticSeverity.WARNING); } - version = getStringValueFromTomlTableNode(pkgNode, VERSION); - if (version == null) { + version = getStringValueFromTomlTableNode(pkgNode, VERSION, ""); + if (pkgNode.entries().get(VERSION) == null) { version = defaultVersion().value().toString(); reportDiagnostic(pkgNode, "missing key 'version' in table '[package]' in 'Ballerina.toml'. " + "Defaulting to 'version = \"" + version + "\"'", @@ -570,8 +572,8 @@ private List getLocalRepoDependencies() { TomlTableArrayNode dependencyTableArray = (TomlTableArrayNode) dependencyEntries; for (TomlTableNode dependencyNode : dependencyTableArray.children()) { - String name = getStringValueFromDependencyNode(dependencyNode, "name"); - String org = getStringValueFromDependencyNode(dependencyNode, "org"); + String name = getStringValueFromDependencyNode(dependencyNode, NAME); + String org = getStringValueFromDependencyNode(dependencyNode, ORG); String version = getStringValueFromDependencyNode(dependencyNode, VERSION); String repository = getStringValueFromDependencyNode(dependencyNode, REPOSITORY); From b9d24606cf56ac361328f0cfb9e36a0e65925ccb Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 15 Feb 2024 11:12:50 +0530 Subject: [PATCH 204/209] Address comments --- .../main/resources/create_cmd_templates/service/service.bal | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal index 293489862114..597a58d2d1fa 100644 --- a/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal +++ b/cli/ballerina-cli/src/main/resources/create_cmd_templates/service/service.bal @@ -5,7 +5,7 @@ import ballerina/http; service / on new http:Listener(9090) { # A resource for generating greetings - # + name - the input string name + # + name - name as a string or nil # + return - string name with hello message or error resource function get greeting(string? name) returns string|error { // Send a response back to the caller. @@ -13,5 +13,5 @@ service / on new http:Listener(9090) { return error("name should not be empty!"); } return string `Hello, ${name}`; - } + } } From 81a2808a483e005fd6f63bdb78137862c436aa49 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Thu, 15 Feb 2024 09:53:44 +0530 Subject: [PATCH 205/209] Exclude cli and picocli --- .../io/ballerina/cli/launcher/CustomToolClassLoader.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java index 6869c8361663..55085f587b37 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/CustomToolClassLoader.java @@ -46,8 +46,13 @@ protected Class loadClass(String name, boolean resolve) throws ClassNotFoundE Class loadedClass = findLoadedClass(name); if (loadedClass == null) { try { - // First, try to load the class from the URLs - loadedClass = findClass(name); + // Load from parent if cli or picocli classes. This is to avoid SPI and class loading issues + if (name.startsWith("io.ballerina.cli") || name.startsWith("picocli")) { + loadedClass = super.loadClass(name, resolve); + } else { + // Try to load the class from the URLs + loadedClass = findClass(name); + } } catch (ClassNotFoundException e) { try { // If not found, delegate to the parent From fd24a64e7a495eaeccd95c3195e1cf57954da756 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 16 Feb 2024 05:11:03 +0530 Subject: [PATCH 206/209] Expose options toml node locations in ToolContext --- .../buildtools/CodeGeneratorTool.java | 17 +++++++ .../projects/buildtools/ToolContext.java | 47 ++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java index a1985d99ce03..cdac78ac6332 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/CodeGeneratorTool.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package io.ballerina.projects.buildtools; /** diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java index fc954b06719f..e778db0a0274 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/buildtools/ToolContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -20,6 +20,8 @@ import io.ballerina.projects.Package; import io.ballerina.projects.PackageManifest; import io.ballerina.toml.semantic.ast.TomlTableNode; +import io.ballerina.toml.semantic.ast.TopLevelNode; +import io.ballerina.toml.semantic.diagnostics.TomlNodeLocation; import io.ballerina.tools.diagnostics.Diagnostic; import java.nio.file.Path; @@ -43,7 +45,7 @@ public class ToolContext { private final String toolId; private final String filePath; private final String targetModule; - private final Map options; + private final Map options; private final List diagnostics = new ArrayList<>(); ToolContext(Package currentPackage, String toolId, String filePath, @@ -93,7 +95,7 @@ public String targetModule() { * * @return a map of the optional tool configurations. */ - public Map options() { + public Map options() { return this.options; } @@ -148,15 +150,48 @@ public void reportDiagnostic(Diagnostic diagnostic) { diagnostics.add(diagnostic); } - private Map getOptions(TomlTableNode optionsTable) { - Map options = new HashMap<>(); + private Map getOptions(TomlTableNode optionsTable) { + Map options = new HashMap<>(); if (null == optionsTable) { return options; } for (String option: optionsTable.entries().keySet()) { - options.put(option, optionsTable.entries().get(option).toNativeObject()); + options.put(option, new Option(optionsTable.entries().get(option))); } return options; } + + /** + * Represents a single option Toml node in Ballerina.toml file. + * + * @since 2201.9.0 + */ + public static class Option { + private final Object value; + private final TomlNodeLocation location; + + public Option(TopLevelNode optionNode) { + this.value = optionNode.toNativeObject(); + this.location = optionNode.location(); + } + + /** + * Returns the value of the option. + * + * @return the option value. + */ + public Object value() { + return value; + } + + /** + * Returns the location of the option node in Ballerina.toml. + * + * @return the option location. + */ + public TomlNodeLocation location() { + return location; + } + } } From 2392705aa42776a8213735fb670ca32ff5187d56 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Thu, 30 Nov 2023 13:42:00 +0530 Subject: [PATCH 207/209] Fix adding of spaces on each format iteration --- .../core/FormattingTreeModifier.java | 28 +++++++++++-------- .../function_definition_declaration_3.bal | 6 ++++ .../function_definition_declaration_3.bal | 6 ++++ .../statements/do/assert/do_statement_3.bal | 11 ++++++++ .../statements/do/source/do_statement_3.bal | 11 ++++++++ 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/statements/do/assert/do_statement_3.bal create mode 100644 misc/formatter/modules/formatter-core/src/test/resources/statements/do/source/do_statement_3.bal diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index 06f19bbd8fac..f799f5883f53 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -4234,10 +4234,12 @@ private MinutiaeList getLeadingMinutiae(Token token) { // Therefore, increase the 'consecutiveNewlines' count consecutiveNewlines++; - for (int i = 0; i < env.leadingNL; i++) { - prevMinutiae = getNewline(); - leadingMinutiae.add(prevMinutiae); - consecutiveNewlines++; + if (!token.isMissing()) { + for (int i = 0; i < env.leadingNL; i++) { + prevMinutiae = getNewline(); + leadingMinutiae.add(prevMinutiae); + consecutiveNewlines++; + } } } @@ -4257,7 +4259,8 @@ private MinutiaeList getLeadingMinutiae(Token token) { // Shouldn't update the prevMinutiae continue; } - if (env.preserveIndentation) { + if (env.preserveIndentation && + (prevMinutiae == null || prevMinutiae.kind() == SyntaxKind.END_OF_LINE_MINUTIAE)) { addWhitespace(getPreservedIndentation(token), leadingMinutiae); } else { addWhitespace(1, leadingMinutiae); @@ -4493,17 +4496,20 @@ private void preserveIndentation(boolean value) { */ private int getPreservedIndentation(Token token) { int position = token.lineRange().startLine().offset(); + int startLine = token.lineRange().startLine().line(); + for (Token invalidToken : token.leadingInvalidTokens()) { + if (invalidToken.lineRange().startLine().line() == startLine) { + position = invalidToken.lineRange().startLine().offset(); + break; + } + } int tabSize = options.getTabSize(); - int offset = position % tabSize; if (env.currentIndentation % tabSize == 0 && env.currentIndentation > position) { return env.currentIndentation; } + int offset = position % tabSize; if (offset != 0) { - if (offset > 2) { - position = position + tabSize - offset; - } else { - position = position - offset; - } + return offset > 2 ? position + tabSize - offset : position - offset; } return position; } diff --git a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal new file mode 100644 index 000000000000..829ff1919d64 --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal @@ -0,0 +1,6 @@ +function f { + if + worker A { + + } +} diff --git a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal new file mode 100644 index 000000000000..8393cb3352b7 --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal @@ -0,0 +1,6 @@ +function f { + if + worker A{ + + } +} diff --git a/misc/formatter/modules/formatter-core/src/test/resources/statements/do/assert/do_statement_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/statements/do/assert/do_statement_3.bal new file mode 100644 index 000000000000..305ea80f9fbe --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/statements/do/assert/do_statement_3.bal @@ -0,0 +1,11 @@ +function baz() { + int x = 1; + do { + int b = 2; + } on f + + if + while x < 5 { + x += 1; + } + } diff --git a/misc/formatter/modules/formatter-core/src/test/resources/statements/do/source/do_statement_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/statements/do/source/do_statement_3.bal new file mode 100644 index 000000000000..1faa51134160 --- /dev/null +++ b/misc/formatter/modules/formatter-core/src/test/resources/statements/do/source/do_statement_3.bal @@ -0,0 +1,11 @@ +function baz() { + int x = 1; + do { + int b = 2; + } on f + + if + while x < 5 { + x += 1; + } +} From 1fb6dd0136d9aa590ade07e77e8da645531f2e1c Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 20 Feb 2024 11:28:24 +0530 Subject: [PATCH 208/209] Address suggestions --- .../formatter/core/FormattingTreeModifier.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index f799f5883f53..daf03770d9c9 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -245,6 +245,7 @@ import io.ballerina.compiler.syntax.tree.XMLStartTagNode; import io.ballerina.compiler.syntax.tree.XMLStepExpressionNode; import io.ballerina.compiler.syntax.tree.XMLTextNode; +import io.ballerina.tools.text.LinePosition; import io.ballerina.tools.text.LineRange; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -4495,11 +4496,13 @@ private void preserveIndentation(boolean value) { * @param token token of which the indentation is required. */ private int getPreservedIndentation(Token token) { - int position = token.lineRange().startLine().offset(); - int startLine = token.lineRange().startLine().line(); + LinePosition startLinePos = token.lineRange().startLine(); + int position = startLinePos.offset(); + int startLine = startLinePos.line(); for (Token invalidToken : token.leadingInvalidTokens()) { - if (invalidToken.lineRange().startLine().line() == startLine) { - position = invalidToken.lineRange().startLine().offset(); + LinePosition invalidTokenStartLinePos = invalidToken.lineRange().startLine(); + if (invalidTokenStartLinePos.line() == startLine) { + position = invalidTokenStartLinePos.offset(); break; } } From 300adf58ab6d2c4d6379a51adb88e6a0161e0ce9 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 20 Feb 2024 15:52:22 +0530 Subject: [PATCH 209/209] Update test --- .../assert/function_definition_declaration_3.bal | 8 ++++++++ .../source/function_definition_declaration_3.bal | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal index 829ff1919d64..0a1ef5d2fc9e 100644 --- a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal +++ b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/assert/function_definition_declaration_3.bal @@ -4,3 +4,11 @@ function f { } } + +function g { + if + worker + B { + + } +} diff --git a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal index 8393cb3352b7..e7231188cebd 100644 --- a/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal +++ b/misc/formatter/modules/formatter-core/src/test/resources/declarations/function-definition/source/function_definition_declaration_3.bal @@ -4,3 +4,11 @@ function f { } } + +function g { + if + worker + B { + + } +}