Skip to content

Commit

Permalink
Add support for named-args and rest-args
Browse files Browse the repository at this point in the history
  • Loading branch information
ayeshLK committed May 2, 2024
1 parent fbb2e23 commit 0a179b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ final readonly & string[] TOPICS = ["test", "test1"];

configurable int port = 9090;

listener websubhub:Listener ln = new(port, {
listener websubhub:Listener ln1 = new(port, {
secureSocket: {
key: {
path: "tests/resources/ballerinaKeystore.pkcs12",
password: "ballerina"
}
}
});

listener websubhub:Listener ln2 = check new(listenTo = port, config = {
secureSocket: {
key: {
path: "tests/resources/ballerinaKeystore.pkcs12",
password: "ballerina"
}
}
});

listener websubhub:Listener ln3 = check new(listenTo = port);

listener websubhub:Listener ln4 = check new(listenTo = 9090, config = {
secureSocket: {
key: {
path: "tests/resources/ballerinaKeystore.pkcs12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.ballerina.stdlib.websubhub.task;

import io.ballerina.compiler.api.SemanticModel;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
import io.ballerina.compiler.api.symbols.TypeDescKind;
Expand All @@ -28,7 +29,9 @@
import io.ballerina.compiler.syntax.tree.FunctionArgumentNode;
import io.ballerina.compiler.syntax.tree.ImplicitNewExpressionNode;
import io.ballerina.compiler.syntax.tree.ListenerDeclarationNode;
import io.ballerina.compiler.syntax.tree.NamedArgumentNode;
import io.ballerina.compiler.syntax.tree.PositionalArgumentNode;
import io.ballerina.compiler.syntax.tree.RestArgumentNode;
import io.ballerina.compiler.syntax.tree.SeparatedNodeList;
import io.ballerina.compiler.syntax.tree.SyntaxKind;
import io.ballerina.compiler.syntax.tree.TypeDescriptorNode;
Expand Down Expand Up @@ -112,8 +115,7 @@ private void verifyListenerArgType(SyntaxNodeAnalysisContext context,
SeparatedNodeList<FunctionArgumentNode> functionArgs) {
// two args are valid only if the first arg is numeric (i.e, port and config)
if (functionArgs.size() > 1) {
PositionalArgumentNode firstArg = (PositionalArgumentNode) functionArgs.get(0);
Optional<Symbol> firstArgSymbolOpt = context.semanticModel().symbol(firstArg.expression());
Optional<Symbol> firstArgSymbolOpt = getFirstListenerArg(context.semanticModel(), functionArgs.get(0));
if (firstArgSymbolOpt.isEmpty()) {
return;
}
Expand All @@ -128,4 +130,14 @@ private void verifyListenerArgType(SyntaxNodeAnalysisContext context,
updateContext(context, WebSubHubDiagnosticCodes.WEBSUBHUB_101, secondArg.location());
}
}

private Optional<Symbol> getFirstListenerArg(SemanticModel semanticModel, FunctionArgumentNode firstArg) {
if (SyntaxKind.POSITIONAL_ARG.equals(firstArg.kind())) {
return semanticModel.symbol(((PositionalArgumentNode) firstArg).expression());
} else if (SyntaxKind.NAMED_ARG.equals(firstArg.kind())) {
return semanticModel.symbol(((NamedArgumentNode) firstArg).expression());
} else {
return semanticModel.symbol(((RestArgumentNode) firstArg).expression());
}
}
}

0 comments on commit 0a179b9

Please sign in to comment.