Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into update-gitignore-…
Browse files Browse the repository at this point in the history
…with-comments
  • Loading branch information
Thevakumar-Luheerathan committed Nov 7, 2023
2 parents 44d89bd + 3e17306 commit 370ccde
Show file tree
Hide file tree
Showing 32 changed files with 343 additions and 119 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can use the following resources to learn Ballerina.
>**Tip:** If you are unsure whether you have found a bug, search the existing issues in the GitHub repo and raise it in the [Ballerina Discord](https://discord.com/invite/wAJYFbMrG2) or [Stack Overflow](https://stackoverflow.com/questions/tagged/ballerina).
- Language, Tooling, Website: <a href="https://github.com/ballerina-platform/ballerina-lang/issues">ballerina-lang</a> repo
- Ballerina library: <a href="https://github.com/ballerina-platform/ballerina-standard-library/issues">ballerina-lang</a> repo
- Ballerina library: <a href="https://github.com/ballerina-platform/ballerina-standard-library/issues">ballerina-library</a> repo
- Security flaw: send an email to security@ballerina.io. For details, see the <a href="https://ballerina.io/security-policy/">security policy</a>.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private String getXmlNsUriPrefix(Map<String, String> nsPrefixMap, String uri) {
}

private void writeAttributes(HashSet<String> curNSSet, Map<String, String> attributeMap) throws XMLStreamException {
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI(XMLNS);
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI("");
for (Map.Entry<String, String> attributeEntry : attributeMap.entrySet()) {
String key = attributeEntry.getKey();
int closingCurlyPos = key.lastIndexOf('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public class TableValueImpl<K, V> implements TableValue<K, V> {
private long maxIntKey = 0;

//These are required to achieve the iterator behavior
private LinkedHashMap<Long, K> indexToKeyMap;
private LinkedHashMap<Long, Long> indexToKeyMap;
private LinkedHashMap<Long, Long> keyToIndexMap;
private LinkedHashMap<K, V> keyValues;
private LinkedHashMap<Long, KeyValuePair<K, V>> keyValues;
private long noOfAddedEntries = 0;

private boolean nextKeySupported;
Expand Down Expand Up @@ -478,9 +478,11 @@ private class TableIterator<K, V> implements IteratorValue {

@Override
public Object next() {
K key = (K) indexToKeyMap.get(cursor);
if (key != null) {
V value = (V) keyValues.get(key);
Long hash = indexToKeyMap.get(cursor);
if (hash != null) {
KeyValuePair<K, V> keyValuePair = (KeyValuePair<K, V>) keyValues.get(hash);
K key = keyValuePair.getKey();
V value = keyValuePair.getValue();

List<Type> types = new ArrayList<>();
types.add(TypeChecker.getType(key));
Expand Down Expand Up @@ -534,7 +536,7 @@ public V putData(V data) {
entries.put(hash, entryList);
updateIndexKeyMappings((K) data, hash);
values.put(hash, newData);
keyValues.put((K) data, data);
keyValues.put(hash, KeyValuePair.of((K) data, data));
return data;
}

Expand Down Expand Up @@ -588,7 +590,7 @@ public void addData(V data) {
extEntries.add(entry);
List<V> extValues = values.get(hash);
extValues.add(data);
keyValues.put(key, data);
keyValues.put(hash, KeyValuePair.of(key, data));
updateIndexKeyMappings(key, hash);
return;
}
Expand Down Expand Up @@ -630,14 +632,13 @@ public V putData(K key, V data) {
}

private V putData(K key, V value, List<V> data, Map.Entry<K, V> entry, Long hash) {

List<Map.Entry<K, V>> entryList = new ArrayList<>();
entryList.add(entry);
entries.put(hash, entryList);
keys.put(hash, key);
updateIndexKeyMappings(key, hash);
values.put(hash, data);
keyValues.put(key, value);
keyValues.put(hash, KeyValuePair.of(key, value));
return data.get(0);
}

Expand All @@ -655,8 +656,8 @@ public V putData(V data) {
}

public V remove(K key) {
keyValues.remove(key);
Long hash = TableUtils.hash(key, null);
keyValues.remove(hash);
List<Map.Entry<K, V>> entryList = entries.get(hash);
if (entryList != null && entryList.size() > 1) {
for (Map.Entry<K, V> entry: entryList) {
Expand Down Expand Up @@ -747,11 +748,33 @@ public K wrapKey(MapValue data) {
}
}

private static final class KeyValuePair<K, V> {
private K key;
private V value;

public KeyValuePair(K key, V value) {
this.key = key;
this.value = value;
}

public static <K, V> KeyValuePair<K, V> of(K key, V value) {
return new KeyValuePair<>(key, value);
}

public K getKey() {
return key;
}

public V getValue() {
return value;
}
}

// This method updates the indexes and the order required by the iterators
private void updateIndexKeyMappings(K key, Long hash) {
if (!keyToIndexMap.containsKey(hash)) {
keyToIndexMap.put(hash, noOfAddedEntries);
indexToKeyMap.put(noOfAddedEntries, key);
indexToKeyMap.put(noOfAddedEntries, hash);
noOfAddedEntries++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ private BError createXMLCycleError() {
}

private void mergeAdjoiningTextNodesIntoList(List leftList, List<BXml> appendingList) {
XmlPi lastChild = (XmlPi) leftList.get(leftList.size() - 1);
String firstChildContent = ((XmlPi) appendingList.get(0)).getData();
String mergedTextContent = lastChild.getData() + firstChildContent;
XmlText lastChild = (XmlText) leftList.get(leftList.size() - 1);
String firstChildContent = appendingList.get(0).getTextValue();
String mergedTextContent = lastChild.getTextValue() + firstChildContent;
XmlText text = new XmlText(mergedTextContent);
leftList.set(leftList.size() - 1, text);
for (int i = 1; i < appendingList.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.ballerinalang.util.RepoUtils;
import picocli.CommandLine;

import java.io.File;
Expand Down Expand Up @@ -277,8 +278,9 @@ public void testBalTestWithStickyFlag() throws IOException {
String buildLog = readOutput(true);
Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("bal-test-project.txt"));
Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString(
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml")).trim());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(),
readFileAsString(projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml"))
.trim().replace("INSERT_VERSION_HERE", RepoUtils.getBallerinaShortVersion()));

// remove build file
Files.deleteIfExists(projectPath.resolve(TARGET_DIR_NAME).resolve(BUILD_FILE));
Expand All @@ -294,8 +296,9 @@ public void testBalTestWithStickyFlag() throws IOException {
String secondBuildLog = readOutput(true);
Assert.assertEquals(secondBuildLog.replaceAll("\r", ""), getOutput("bal-test-project.txt"));
Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString(
projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml")).trim());
Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(),
readFileAsString(projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDeps.toml"))
.trim().replace("INSERT_VERSION_HERE", RepoUtils.getBallerinaShortVersion()));
}

@Test(description = "Test a ballerina project with the flag dump-graph")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0-SNAPSHOT"
distribution-version = "INSERT_VERSION_HERE"

[[package]]
org = "ballerina"
Expand Down
16 changes: 8 additions & 8 deletions misc/formatter/modules/formatter-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ according to the default [Ballerina style guide](https://github.com/ballerina-pl
The Ballerina format command can be used to format Ballerina source files.

```sh
$ ballerina format --help
$ bal format --help
Prints the help guide for the Ballerina format tool.

Usage:
ballerina format [<ballerinaFile> | <moduleName>] [-d | --dry-run]
bal format [<ballerinaFile> | <moduleName>] [-d | --dry-run]
ballerinaFile:
Path of a single Ballerina source file, which needs to be formatted.
moduleName:
Expand All @@ -29,26 +29,26 @@ Flags:

**Example 1:** Formats all the Ballerina source files in a Ballerina project.
```sh
$ ballerina format
$ bal format
```

This command should be executed from the root of the Ballerina project.

**Example 2:** Formats all the Ballerina source files in a Ballerina module.
```sh
$ ballerina format module1
$ bal format module1
```
This command should be executed from the root of the Ballerina project.

**Example 3:** Formats a single Ballerina source file.
```sh
$ ballerina format hello.bal
$ bal format hello.bal
```

**Example 4:** Performs a dry run of the formatter to see which files will be formatted
if executed.
```sh
$ ballerina format -d
$ ballerina format module1 -d
$ ballerina format hello.bal -d
$ bal format -d
$ bal format module1 -d
$ bal format hello.bal -d
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class Messages {
private static final String ARGUMENT_ERROR = "too many arguments." + System.lineSeparator()
+ "usage: only one argument, either a ballerina file name or a module "
+ "name, can be applied at a time with or without the option." + System.lineSeparator()
+ "i.e: ballerina format [ballerinaFile | ModuleName] [-d | --dry-run]" + System.lineSeparator()
+ System.lineSeparator() + "run `ballerina format -h` for more details.";
+ "i.e: bal format [ballerinaFile | ModuleName] [-d | --dry-run]" + System.lineSeparator()
+ System.lineSeparator() + "run `bal format -h` for more details.";

private static final String SUCCESS_MESSAGE = "format successful.";

private static final String NOT_BALLERINA_PROJECT = "not a valid Ballerina project." + System.lineSeparator()
+ "usage: ballerina format should be run inside a ballerina project or pass in a ballerina file."
+ System.lineSeparator() + "i.e. `ballerina format <ballerina-file>`"
+ System.lineSeparator() + System.lineSeparator() + "run `ballerina format -h` for more details";
+ "usage: bal format should be run inside a ballerina project or pass in a ballerina file."
+ System.lineSeparator() + "i.e. `bal format <ballerina-file>`"
+ System.lineSeparator() + System.lineSeparator() + "run `bal format -h` for more details";

private static final String NO_MODULE_FOUND = "couldn't find an existing module by the name: ";

Expand All @@ -42,7 +42,7 @@ public class Messages {

private static final String NOT_BALLERINA_FILE = "not a valid ballerina source file." + System.lineSeparator()
+ "usage: ballerina source files should have the file extension as `.bal`." + System.lineSeparator()
+ "i.e. `ballerina format hello.bal`";
+ "i.e. `bal format hello.bal`";

private static final String NO_BALLERINA_FILE_OR_MODULE = "couldn't find an existing ballerina file or " +
"module by the name: ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setup() {
compileResult = BCompileUtil.compile("test-src/record/closed_record_type_inclusion.bal");
}

@Test(description = "Negative tests" , groups = {"disableOnOldParser"})
@Test(description = "Negative tests")
public void negativeTests() {
CompileResult negative = BCompileUtil.compile("test-src/record/closed_record_type_inclusion_negative.bal");
int index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setup() {
compileResult = BCompileUtil.compile("test-src/record/open_record_type_inclusion.bal");
}

@Test(description = "Negative tests" , groups = {"disableOnOldParser"})
@Test(description = "Negative tests")
public void negativeTests() {
CompileResult negative = BCompileUtil.compile("test-src/record/open_record_type_inclusion_negative.bal");
int index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testFPInStructIncorrectArg() {
BAssertUtil.validateError(result, 0, "incompatible types: expected 'string', found 'Person'", 32, 30);
}

@Test(groups = { "disableOnOldParser" })
@Test()
public void testFPWithNoImport() {
CompileResult result =
BCompileUtil.compile("test-src/expressions/lambda/negative/fp-with-import-negative.bal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setup() {
result = BCompileUtil.compile("test-src/expressions/lambda/function-pointers-with-optional-args.bal");
}

@Test(groups = { "disableOnOldParser" })
@Test()
public void testFunctionPointersWithNamedArgs() {
CompileResult result =
BCompileUtil.compile("test-src/expressions/lambda/function-pointers-with-named-args-negative.bal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public Object[][] readOnlyFieldTests() {
};
}

@Test(groups = "disableOnOldParser")
@Test()
public void testReadOnlyFieldsSemanticNegative() {
CompileResult compileResult =
BCompileUtil.compile("test-src/expressions/mappingconstructor/readonly_field_negative.bal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testDocAnnotation() {
Assert.assertNotNull(docNode);
}

@Test(description = "Test doc struct.", groups = { "disableOnOldParser" })
@Test(description = "Test doc struct.")
public void testDocStruct() {
CompileResult compileResult = BCompileUtil.compile("test-src/object/object_doc_annotation.bal");
Assert.assertEquals(compileResult.getWarnCount(), 0);
Expand All @@ -88,7 +88,7 @@ public void testDocStruct() {
EMPTY_STRING), "struct `field c` documentation");
}

@Test(description = "Test doc negative cases.", groups = { "disableOnOldParser" })
@Test(description = "Test doc negative cases.")
public void testDocumentationNegative() {
CompileResult compileResult = BCompileUtil.compile("test-src/object/object_documentation_negative.bal");
Assert.assertEquals(compileResult.getErrorCount(), 0, getErrorString(compileResult.getDiagnostics()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testLetExpressionWithLimitClause() {
Assert.assertTrue((Boolean) values);
}

@Test(description = "Test limit clause with incompatible types", groups = {"disableOnOldParser"})
@Test(description = "Test limit clause with incompatible types")
public void testNegativeScenarios() {
negativeResult = BCompileUtil.compile("test-src/query/limit-clause-negative.bal");
Assert.assertEquals(negativeResult.getErrorCount(), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @since Swan Lake
*/
@Test(groups = {"disableOnOldParser"})
@Test()
public class OrderByClauseTest {

private CompileResult result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testNegativeQueryExprForXML() {
validateError(negativeResult, index++, "incompatible types: expected " +
"'xml<((xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text) & readonly)> & readonly'," +
" found 'xml'", 21, 16);
validateError(negativeResult, index++, "incompatible types: expected 'xml:Element & readonly', " + "" +
validateError(negativeResult, index++, "incompatible types: expected 'xml:Element & readonly', " +
"found 'xml:Element'", 25, 16);
validateError(negativeResult, index++,
"incompatible types: expected 'xml<(xml:Element & readonly)> & readonly', found 'xml:Element'",
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testSimpleQueryExprForXML() {
"<name>Sherlock Holmes</name><name>The Da Vinci Code</name>");
}

@Test(groups = {"disableOnOldParser"}, description = "Test simple query expression for XMLs - #2")
@Test(description = "Test simple query expression for XMLs - #2")
public void testSimpleQueryExprForXML2() {
Object returnValues = BRunUtil.invoke(result, "testSimpleQueryExprForXML2");
Assert.assertNotNull(returnValues);
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testSimpleQueryExprForXMLOrNilResult() {
"<name>Sherlock Holmes</name><name>The Da Vinci Code</name>");
}

@Test(groups = {"disableOnOldParser"}, description = "Test simple query expression for xml? - #2")
@Test(description = "Test simple query expression for xml? - #2")
public void testSimpleQueryExprForXMLOrNilResult2() {
Object returnValues = BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResult2");
Assert.assertNotNull(returnValues);
Expand Down Expand Up @@ -355,8 +355,7 @@ public void testSimpleQueryExprForXMLWithReadonly1() {
BRunUtil.invoke(result, "testSimpleQueryExprForXMLWithReadonly1");
}

@Test(groups = {"disableOnOldParser"},
description = "Test simple query expression for XMLs with readonly intersection - #2")
@Test(description = "Test simple query expression for XMLs with readonly intersection - #2")
public void testSimpleQueryExprForXMLWithReadonly2() {
BRunUtil.invoke(result, "testSimpleQueryExprForXMLWithReadonly2");
}
Expand Down Expand Up @@ -386,8 +385,7 @@ public void testSimpleQueryExprForXMLOrNilResultWithReadonly1() {
BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResultWithReadonly1");
}

@Test(groups = {"disableOnOldParser"},
description = "Test simple query expression for xml? with readonly intersection - #2")
@Test(description = "Test simple query expression for xml? with readonly intersection - #2")
public void testSimpleQueryExprForXMLOrNilResultWithReadonly2() {
BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResultWithReadonly2");
}
Expand Down Expand Up @@ -522,6 +520,11 @@ public void testQueryExpressionIteratingOverStreamReturningXMLWithReadonly() {
BRunUtil.invoke(result, "testQueryExpressionIteratingOverStreamReturningXMLWithReadonly");
}

@Test(description = "Test XML template with query expression iterating over xml starting with whitespace")
public void testQueryExpressionXmlStartWithWhiteSpace() {
BRunUtil.invoke(result, "testQueryExpressionXmlStartWithWhiteSpace");
}

@AfterClass
public void tearDown() {
result = null;
Expand Down
Loading

0 comments on commit 370ccde

Please sign in to comment.