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; + } + } }