Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rpjayasekara committed May 25, 2021
2 parents 684cdb1 + 03d149c commit 32e89e1
Show file tree
Hide file tree
Showing 84 changed files with 4,960 additions and 1,212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OPTIONS


EXAMPLES
Add a module
Add a module.
$ bal add hello

Add a module with a Ballerina service.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME
ballerina-bindgen - A CLI tool for generating Ballerina bindings for Java APIs.
ballerina-bindgen - A CLI tool for generating Ballerina bindings for Java APIs

SYNOPSIS
bal bindgen [(-cp|--classpath) <classpath>...]
Expand Down Expand Up @@ -48,12 +48,12 @@ OPTIONS


EXAMPLES
Generating the Ballerina bridge code for a standard Java class.
Generate the Ballerina bridge code for a standard Java class.
$ bal bindgen java.utils.ArrayDeque

Generating Ballerina bridge code for library Java classes.
Generate Ballerina bridge code for library Java classes.
$ bal bindgen -cp ./libs/snakeyaml-1.25.jar,./libs/pdfbox-1.8.10.jar -o ./src/sample
org.yaml.snakeyaml.Yaml org.apache.pdfbox.pdmodel.PDDocument java.io.File

Generating Ballerina bridge code using a Maven dependency.
Generate Ballerina bridge code using a Maven dependency.
$ bal bindgen -mvn org.yaml:snakeyaml:1.25 -o ./src/sample org.yaml.snakeyaml.Yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ OPTIONS
Enable experimental language features.

--code-coverage
Enables code coverage. This will analyze the line coverage of
source .bal files in the Ballerina package and add a section
to the testerina report with code coverage details.
Enable code coverage. This will analyze the line coverage of the
source `.bal` files in the Ballerina package and add a section
to the testerina report with the code coverage details.
This feature is not supported with single file executions.

--test-report
Generates an HTML report containing test results. Defaults to 'true'
Generate an HTML report containing the test results. Defaults to 'true'
if code coverage is enabled.

--debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ BALLERINA COMMANDS
search Search Ballerina Central for packages

Other Commands:
grpc Generate Ballerina sources for the given protobuf definition
openapi Generate Ballerina sources for the given OpenAPI definition and vice versa.
version Print Ballerina version
bindgen Generate Ballerina bindings for Java APIs
grpc Generate the Ballerina sources for the given protobuf definition
openapi Generate the Ballerina sources for the given OpenAPI definition and vice versa
version Print the Ballerina version
bindgen Generate the Ballerina bindings for Java APIs
shell Run Ballerina interactive REPL [EXPERIMENTAL]
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ DESCRIPTION


EXAMPLES
Print of Ballerina distribution which is currently configured.
Print the Ballerina distribution which is currently configured.
$ bal home
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME
ballerina-init - Create a new Ballerina package inside the current directory.
ballerina-init - Create a new Ballerina package inside the current directory

SYNOPSIS
bal init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ EXAMPLES
Generate both the Ballerina client and service file.
$ bal openapi --input petstore.yaml -o ./example

Generate services for given tags
Generate services for the given tags.
$ bal openapi -i hello.yaml --mode service --tags pets

Generate services for given operations
Generate services for the given operations.
$ bal openapi -i hello.yaml --mode service --operations listPets
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ SYNOPSIS


DESCRIPTION
Run builds and executes the given .bal file, package, or program.
Run builds and executes the given `.bal` file, package, or program.

If a Ballerina source file (.bal file) or a package directory is given, the run
If a Ballerina source file (`.bal` file) or a package directory is given, the run
command builds and runs it. Compilation is done internally and the
executable will not be created.

Expand Down Expand Up @@ -65,7 +65,7 @@ DEFAULT BEHAVIOR


EXAMPLES
Run the 'main' function and/or services in the hello .bal file.
Run the 'main' function and/or services in the hello.bal file.
$ bal run hello.bal

Run the 'main' function and/or services in the hello executable jar.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DESCRIPTION
Use 'bal test to execute tests in the current package.

Use 'bal test <balfile>' to execute the given Ballerina test file.
Note that testing single BAL files that belongs to a Ballerina package is not allowed.
Note that testing single `.bal` files that belongs to a Ballerina package is not allowed.
File path can be relative or absolute.


Expand Down Expand Up @@ -65,7 +65,7 @@ OPTIONS

--code-coverage
Enables code coverage. This will analyze the line coverage of
source .bal files in the Ballerina package and add a section
source `.bal` files in the Ballerina package and add a section
to the testerina report with code coverage details.
This feature is not supported with single file executions.

Expand All @@ -86,10 +86,10 @@ OPTIONS


EXAMPLES
Run all tests in the current package.
Run all the tests in the current package.
$ bal test

List all test groups in the package.
List all the test groups in the package.
$ bal test --list-groups

Run only the set of tests belonging to the `group_x` in the current package.
Expand All @@ -98,10 +98,10 @@ EXAMPLES
Run only the given set of functions in the current package.
$ bal test --tests testFunction

Run the given set of functions in the default module only
Run only the given set of functions in the default module.
$ bal test --tests PackageName:testA1,testB*

Run the all functions in the given module
Run all the functions in the given module.
$ bal test --tests PackageName.ModuleName:*

Run only the previously-failed test cases in the current package.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OPTIONS


DEFAULT BEHAVIOR
Uninstalls a module from home repository.
Uninstall a module from home repository.


EXAMPLES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testInitCommandArgAndHelp() throws IOException {
initCommand.execute();

Assert.assertTrue(readOutput().contains(
"ballerina-init - Create a new Ballerina package inside the current directory."));
"ballerina-init - Create a new Ballerina package inside the current directory"));
}

@Test(description = "Test init command with help flag")
Expand All @@ -221,7 +221,7 @@ public void testInitCommandWithHelp() throws IOException {
initCommand.execute();

Assert.assertTrue(readOutput().contains(
"ballerina-init - Create a new Ballerina package inside the current directory."));
"ballerina-init - Create a new Ballerina package inside the current directory"));
}

@Test(description = "Test init command inside a directory with invalid package name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol;
import org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols;
import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType;
import org.wso2.ballerinalang.compiler.util.CompilerContext;
import org.wso2.ballerinalang.compiler.util.Name;
import org.wso2.ballerinalang.compiler.util.Names;
Expand Down Expand Up @@ -220,8 +221,11 @@ private static void addLangLibMethods(String basicType, BPackageSymbol langLibMo

BInvokableSymbol invSymbol = (BInvokableSymbol) symbol;

if (Symbols.isFlagOn(invSymbol.flags, Flags.PUBLIC) && !invSymbol.params.isEmpty() &&
basicType.compareToIgnoreCase(invSymbol.params.get(0).type.getKind().name()) == 0) {
if (Symbols.isFlagOn(invSymbol.flags, Flags.PUBLIC) &&
(!invSymbol.params.isEmpty() &&
basicType.compareToIgnoreCase(invSymbol.params.get(0).type.getKind().name()) == 0 ||
invSymbol.restParam != null && basicType.compareToIgnoreCase(((BArrayType) invSymbol.restParam.type)
.eType.tsymbol.getName().getValue()) == 0)) {
methods.put(invSymbol.name.value, invSymbol);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.ballerina.compiler.api.symbols.TypeSymbol;
import io.ballerina.tools.diagnostics.Location;
import org.wso2.ballerinalang.compiler.semantics.analyzer.Types;
import org.wso2.ballerinalang.compiler.semantics.model.types.BArrayType;
import org.wso2.ballerinalang.compiler.semantics.model.types.BType;
import org.wso2.ballerinalang.compiler.util.CompilerContext;

Expand Down Expand Up @@ -134,7 +135,23 @@ protected List<FunctionSymbol> filterLangLibMethods(List<FunctionSymbol> functio
List<FunctionSymbol> filteredFunctions = new ArrayList<>();

for (FunctionSymbol function : functions) {
ParameterSymbol firstParam = function.typeDescriptor().params().get().get(0);

List<ParameterSymbol> functionParams = function.typeDescriptor().params().get();

if (functionParams.isEmpty()) {
// If the function-type-descriptor doesn't have params, then, check for the rest-param
Optional<ParameterSymbol> restParamOptional = function.typeDescriptor().restParam();
if (restParamOptional.isPresent()) {
BArrayType restArrayType =
(BArrayType) ((AbstractTypeSymbol) restParamOptional.get().typeDescriptor()).getBType();
if (types.isAssignable(internalType, restArrayType.eType)) {
filteredFunctions.add(function);
}
}
continue;
}

ParameterSymbol firstParam = functionParams.get(0);
BType firstParamType = ((AbstractTypeSymbol) firstParam.typeDescriptor()).getBType();

if (types.isAssignable(internalType, firstParamType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ public enum DiagnosticErrorCode implements DiagnosticCode {
ERROR_MISSING_DOUBLE_QUOTE("BCE0411", "error.missing.double.quote"),
ERROR_MISSING_ENTITY_REFERENCE_NAME("BCE0412", "error.missing.entity.reference.name"),
ERROR_MISSING_SEMICOLON_IN_XML_REFERENCE("BCE0413", "error.missing.semicolon.in.xml.reference"),
ERROR_MISSING_ATTACH_POINT_NAME("BCE0414", "error.missing.attach.point.name"),

// Missing non-terminal nodes
ERROR_MISSING_FUNCTION_NAME("BCE0500", "error.missing.function.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2858,7 +2858,7 @@ private boolean isEndOfModuleLevelNode(int peekIndex, boolean isObject) {
case SERVICE_KEYWORD:
return isServiceDeclStart(ParserRuleContext.OBJECT_MEMBER, 1);
case PUBLIC_KEYWORD:
return isEndOfModuleLevelNode(peekIndex + 1, isObject);
return !isObject && isEndOfModuleLevelNode(peekIndex + 1, false);
case FUNCTION_KEYWORD:
if (isObject) {
return false;
Expand Down Expand Up @@ -3566,8 +3566,7 @@ private STNode parseRecordTypeDescriptor() {
break;
}
recordRestDescriptor = SyntaxErrors.cloneWithTrailingInvalidNodeMinutiae(recordRestDescriptor,
invalidField,
DiagnosticErrorCode.ERROR_MORE_RECORD_FIELDS_AFTER_REST_FIELD);
invalidField, DiagnosticErrorCode.ERROR_MORE_RECORD_FIELDS_AFTER_REST_FIELD);
token = peek();
}
break;
Expand Down Expand Up @@ -8812,7 +8811,10 @@ private STNode parseAnnotationAttachPoints() {
// Parse attach point. Null represents the end of attach-points.
attachPoint = parseAnnotationAttachPoint();
if (attachPoint == null) {
attachPoint = SyntaxErrors.createMissingTokenWithDiagnostics(SyntaxKind.IDENTIFIER_TOKEN,
STToken missingAttachPointIdent = SyntaxErrors.createMissingToken(SyntaxKind.TYPE_KEYWORD);
STNode identList = STNodeFactory.createNodeList(missingAttachPointIdent);
attachPoint = STNodeFactory.createAnnotationAttachPointNode(STNodeFactory.createEmptyNode(), identList);
attachPoint = SyntaxErrors.addDiagnostic(attachPoint,
DiagnosticErrorCode.ERROR_MISSING_ANNOTATION_ATTACH_POINT);
attachPoints.add(attachPoint);
break;
Expand All @@ -8821,6 +8823,15 @@ private STNode parseAnnotationAttachPoints() {
attachPoints.add(attachPoint);
nextToken = peek();
}

if (attachPoint.lastToken().isMissing() && this.tokenReader.peek().kind == SyntaxKind.IDENTIFIER_TOKEN &&
!this.tokenReader.head().hasTrailingNewline()) {
// Special case, when annotation-decl is in typing state.
// e.g. annotation name on source object f<cursor>
STToken nextNonVirtualToken = this.tokenReader.read();
updateLastNodeInListWithInvalidNode(attachPoints, nextNonVirtualToken,
DiagnosticErrorCode.ERROR_INVALID_TOKEN);
}

endContext();
return STNodeFactory.createNodeList(attachPoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ private static DiagnosticCode getErrorCode(ParserRuleContext currentCtx) {
case IMPORT_SUB_VERSION:
case FUNC_DEF_OR_TYPE_DESC_RHS:
return DiagnosticErrorCode.ERROR_MISSING_SEMICOLON_TOKEN;
case ATTACH_POINT_IDENT:
case SINGLE_KEYWORD_ATTACH_POINT_IDENT:
return DiagnosticErrorCode.ERROR_MISSING_ATTACH_POINT_NAME;
case SIMPLE_TYPE_DESCRIPTOR:
return DiagnosticErrorCode.ERROR_MISSING_BUILTIN_TYPE;
case REQUIRED_PARAM:
Expand Down Expand Up @@ -377,8 +380,6 @@ private static DiagnosticCode getKeywordErrorCode(ParserRuleContext ctx) {
case ANNOTATION_KEYWORD:
return DiagnosticErrorCode.ERROR_MISSING_ANNOTATION_KEYWORD;
case TYPE_KEYWORD:
case ATTACH_POINT_IDENT:
case SINGLE_KEYWORD_ATTACH_POINT_IDENT:
return DiagnosticErrorCode.ERROR_MISSING_TYPE_KEYWORD;
case RECORD_KEYWORD:
case RECORD_FIELD:
Expand Down Expand Up @@ -665,9 +666,13 @@ public static STToken cloneWithTrailingInvalidNodeMinutiae(STToken toClone,
* Converts the invalid node into a list of {@code STMinutiae} nodes.
* <p>
* Here are the steps:
* <br/>
* 1) Iterates through all the tokens in the invalid node. For each token:
* <br/>
* 2) Add the leading minutiae to the list
* <br/>
* 3) Create a new token without leading or trailing minutiae and add it to the list
* <br/>
* 4) Add the trailing minutiae to the list
*
* @param invalidNode the invalid node to be converted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ public STNode invalidNode() {
public void writeTo(StringBuilder builder) {
invalidNode.writeTo(builder);
}

@Override
public String toString() {
// TODO for testing purpose only
return " INVALID[" + this.text() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public <T> T apply(STNodeTransformer<T> transformer) {
@Override
public String toString() {
// TODO for testing purpose only
return " MISSING[" + kind.stringValue() + "]";
return " MISSING[" + leadingMinutiae + kind.stringValue() + trailingMinutiae + "]";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ public STNode trailingMinutiae() {
return trailingMinutiae;
}

public boolean hasTrailingNewline() {
// TODO: Instead of looping here, try to set this as a token property at the lexer
STNodeList minutiaeList = (STNodeList) this.trailingMinutiae;
for (int i = 0; i < minutiaeList.size(); i++) {
if (minutiaeList.get(i).kind == SyntaxKind.END_OF_LINE_MINUTIAE) {
return true;
}
}
return false;
}

public int lookbackTokenCount() {
return lookback;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,26 @@ public STMissingToken transform(STMissingToken missingToken) {
// Misc

public STNode transform(STNodeList nodeList) {
return transformSyntaxNode(nodeList);
if (nodeList.isEmpty()) {
return nodeList;
}

boolean nodeModified = false;
STNode[] newSTNodes = new STNode[nodeList.size()];
for (int index = 0; index < nodeList.size(); index++) {
STNode oldNode = nodeList.get(index);
STNode newNode = modifyNode(oldNode);
if (oldNode != newNode) {
nodeModified = true;
}
newSTNodes[index] = newNode;
}

if (!nodeModified) {
return nodeList;
}

return STNodeFactory.createNodeList(newSTNodes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,4 @@ error.metadata.not.attached.to.a.top.level.construct=metadata not attached to a
error.metadata.not.attached.to.a.object.member=metadata not attached to a object member
error.type.desc.after.rest.descriptor=type descriptor not allowed after rest descriptor
error.configurable.var.implicitly.final=''final'' qualifier not allowed: configurable variables are implicitly final
error.missing.attach.point.name=missing attach point name
Loading

0 comments on commit 32e89e1

Please sign in to comment.