use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.
the class Desugar method reorderNamedArgs.
private void reorderNamedArgs(BLangInvocation iExpr, BInvokableSymbol invocableSymbol) {
Map<String, BLangExpression> namedArgs = new HashMap<>();
iExpr.namedArgs.forEach(expr -> namedArgs.put(((NamedArgNode) expr).getName().value, expr));
// Re-order the named arguments
List<BLangExpression> args = new ArrayList<>();
for (BVarSymbol param : invocableSymbol.defaultableParams) {
args.add(namedArgs.get(param.name.value));
}
iExpr.namedArgs = args;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method generateEndpointStartOrStop.
private BLangBlockStmt generateEndpointStartOrStop(BLangEndpoint endpoint, BInvokableSymbol funSymbol, SymbolEnv env, BSymbol encSymbol) {
BLangBlockStmt temp = new BLangBlockStmt();
if (funSymbol == null || endpoint.configurationExpr == null || endpoint.configurationExpr.getKind() != NodeKind.RECORD_LITERAL_EXPR) {
// 2: If endpoint in initialized
return temp;
}
final DiagnosticPos pos = endpoint.pos;
final String epName = endpoint.name.value;
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.symbol.type);
final Name name = names.fromIdNode(endpoint.name);
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
List<BLangVariable> args = new ArrayList<>();
if (funSymbol.params.size() == 1) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, funSymbol, args, symResolver);
if (funSymbol.params.size() != 1) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.
the class IterableCodeDesugar method generateTableAggregator.
private void generateTableAggregator(BLangBlockStmt blockStmt, IterableContext ctx) {
final DiagnosticPos pos = blockStmt.pos;
List<BLangVariable> variables = new ArrayList<>(1);
variables.add(ctx.resultVar);
variables.add(ctx.iteratorResultVariables.get(0));
BInvokableSymbol addSymbol = (BInvokableSymbol) symTable.rootScope.lookup(names.fromString(TABLE_ADD_FUNCTION)).symbol;
BLangInvocation addFunctionInvocation = ASTBuilderUtil.createInvocationExpr(pos, addSymbol, variables, symResolver);
BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, blockStmt);
expressionStmt.expr = addFunctionInvocation;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.
the class StatementContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
ArrayList<CompletionItem> completionItems = new ArrayList<>();
// action invocation or worker invocation
if (isInvocationOrFieldAccess(completionContext)) {
ArrayList<SymbolInfo> actionAndFunctions = new ArrayList<>();
PackageActionFunctionAndTypesFilter actionFunctionTypeFilter = new PackageActionFunctionAndTypesFilter();
actionAndFunctions.addAll(actionFunctionTypeFilter.filterItems(completionContext));
this.populateCompletionItemList(actionAndFunctions, completionItems);
} else {
CompletionItem xmlns = new CompletionItem();
xmlns.setLabel(ItemResolverConstants.XMLNS);
xmlns.setInsertText(Snippet.NAMESPACE_DECLARATION.toString());
xmlns.setInsertTextFormat(InsertTextFormat.Snippet);
xmlns.setDetail(ItemResolverConstants.SNIPPET_TYPE);
completionItems.add(xmlns);
// Add the var keyword
CompletionItem varKeyword = new CompletionItem();
varKeyword.setInsertText("var ");
varKeyword.setLabel("var");
varKeyword.setDetail(ItemResolverConstants.KEYWORD_TYPE);
completionItems.add(varKeyword);
StatementTemplateFilter statementTemplateFilter = new StatementTemplateFilter();
// Add the statement templates
completionItems.addAll(statementTemplateFilter.filterItems(completionContext));
// We need to remove the functions having a receiver symbol and the bTypes of the following
// ballerina.coordinator, ballerina.runtime, and anonStructs
ArrayList<String> invalidPkgs = new ArrayList<>(Arrays.asList("ballerina.runtime", "ballerina.transactions.coordinator"));
completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY).removeIf(symbolInfo -> {
BSymbol bSymbol = symbolInfo.getScopeEntry().symbol;
String symbolName = bSymbol.getName().getValue();
return (bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).receiverSymbol != null) || (bSymbol instanceof BPackageSymbol && invalidPkgs.contains(symbolName)) || (symbolName.startsWith("$anonStruct"));
});
populateCompletionItemList(completionContext.get(CompletionKeys.VISIBLE_SYMBOLS_KEY), completionItems);
// Now we need to sort the completion items and populate the completion items specific to the scope owner
// as an example, resource, action, function scopes are different from the if-else, while, and etc
Class itemSorter = completionContext.get(CompletionKeys.BLOCK_OWNER_KEY).getClass();
ItemSorters.getSorterByClass(itemSorter).sortItems(completionContext, completionItems);
}
return completionItems;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol in project ballerina by ballerina-lang.
the class SymbolEnter method defineVarSymbol.
public BVarSymbol defineVarSymbol(DiagnosticPos pos, Set<Flag> flagSet, BType varType, Name varName, SymbolEnv env) {
// Create variable symbol
Scope enclScope = env.scope;
BVarSymbol varSymbol;
if (varType.tag == TypeTags.INVOKABLE) {
varSymbol = new BInvokableSymbol(SymTag.VARIABLE, Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
} else {
varSymbol = new BVarSymbol(Flags.asMask(flagSet), varName, env.enclPkg.symbol.pkgID, varType, enclScope.owner);
}
// Find duplicates
if (!symResolver.checkForUniqueSymbol(pos, env, varSymbol, SymTag.VARIABLE_NAME)) {
varSymbol.type = symTable.errType;
}
enclScope.define(varSymbol.name, varSymbol);
return varSymbol;
}
Aggregations