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 b470a4f commit e07e0e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ listener websub:Listener ln = check new(port, {
}
});

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

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

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

@websub:SubscriberServiceConfig {
}
service /sample on new websub:Listener(port, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.ballerina.stdlib.websub.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, WebSubDiagnosticCodes.WEBSUB_109, 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 e07e0e7

Please sign in to comment.