use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class Desugar method visit.
@Override
public void visit(BLangAction actionNode) {
addReturnIfNotPresent(actionNode);
SymbolEnv actionEnv = SymbolEnv.createResourceActionSymbolEnv(actionNode, actionNode.symbol.scope, env);
// To preserve endpoint code gen order at action.
Collections.reverse(actionNode.endpoints);
actionNode.endpoints = rewrite(actionNode.endpoints, actionEnv);
actionNode.body = rewrite(actionNode.body, actionEnv);
actionNode.workers = rewrite(actionNode.workers, actionEnv);
// we rewrite it's parameter list to have the receiver variable as the first parameter
BInvokableSymbol actionSymbol = actionNode.symbol;
List<BVarSymbol> params = actionSymbol.params;
BVarSymbol receiverSymbol = actionNode.symbol.receiverSymbol;
params.add(0, receiverSymbol);
BInvokableType actionType = (BInvokableType) actionSymbol.type;
if (receiverSymbol != null) {
actionType.paramTypes.add(0, receiverSymbol.type);
}
result = actionNode;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class Desugar method visit.
public void visit(BLangTransformer transformerNode) {
addTransformerReturn(transformerNode);
SymbolEnv tranEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
transformerNode.body = rewrite(transformerNode.body, tranEnv);
addArgInitExpr(transformerNode, transformerNode.retParams.get(0));
BInvokableSymbol transformerSymbol = transformerNode.symbol;
List<BVarSymbol> params = transformerSymbol.params;
params.add(0, transformerNode.source.symbol);
BInvokableType transformerType = (BInvokableType) transformerSymbol.type;
transformerType.paramTypes.add(0, transformerNode.source.type);
result = transformerNode;
}
use of org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType in project ballerina by ballerina-lang.
the class PackageActionFunctionAndTypesFilter method invocationsAndFieldsOnIdentifier.
/**
* Get the invocations and fields against an identifier (functions, struct fields and types including the enums).
* @param context Text Document Service context (Completion Context)
* @param delimiterIndex delimiter index (index of either . or :)
* @return {@link ArrayList} List of filtered symbol info
*/
private ArrayList<SymbolInfo> invocationsAndFieldsOnIdentifier(TextDocumentServiceContext context, int delimiterIndex) {
ArrayList<SymbolInfo> actionFunctionList = new ArrayList<>();
TokenStream tokenStream = context.get(DocumentServiceKeys.TOKEN_STREAM_KEY);
List<SymbolInfo> symbols = context.get(CompletionKeys.VISIBLE_SYMBOLS_KEY);
SymbolTable symbolTable = context.get(DocumentServiceKeys.SYMBOL_TABLE_KEY);
String variableName = CommonUtil.getPreviousDefaultToken(tokenStream, delimiterIndex).getText();
SymbolInfo variable = this.getVariableByName(variableName, symbols);
String builtinPkgName = symbolTable.builtInPackageSymbol.name.getValue();
Map<Name, Scope.ScopeEntry> entries = new HashMap<>();
String currentPkgName = context.get(DocumentServiceKeys.CURRENT_PACKAGE_NAME_KEY);
if (variable == null) {
return actionFunctionList;
}
String packageID;
BType bType = variable.getScopeEntry().symbol.getType();
String bTypeValue;
if (variable.getScopeEntry().symbol instanceof BEndpointVarSymbol) {
BType getClientFuncType = ((BEndpointVarSymbol) variable.getScopeEntry().symbol).getClientFunction.type;
if (!UtilSymbolKeys.ACTION_INVOCATION_SYMBOL_KEY.equals(tokenStream.get(delimiterIndex).getText()) || !(getClientFuncType instanceof BInvokableType)) {
return actionFunctionList;
}
BType boundType = ((BInvokableType) getClientFuncType).retTypes.get(0);
packageID = boundType.tsymbol.pkgID.toString();
bTypeValue = boundType.toString();
} else if (bType instanceof BArrayType) {
packageID = ((BArrayType) bType).eType.tsymbol.pkgID.toString();
bTypeValue = bType.toString();
} else {
packageID = bType.tsymbol.pkgID.toString();
bTypeValue = bType.toString();
}
// Extract the package symbol. This is used to extract the entries of the particular package
SymbolInfo packageSymbolInfo = symbols.stream().filter(item -> {
Scope.ScopeEntry scopeEntry = item.getScopeEntry();
return (scopeEntry.symbol instanceof BPackageSymbol) && scopeEntry.symbol.pkgID.toString().equals(packageID);
}).findFirst().orElse(null);
if (packageSymbolInfo == null && packageID.equals(builtinPkgName)) {
// If the packageID is ballerina.builtin, we extract entries of builtin package
entries = symbolTable.builtInPackageSymbol.scope.entries;
} else if (packageSymbolInfo == null && packageID.equals(currentPkgName)) {
entries = this.getScopeEntries(bType, context);
} else if (packageSymbolInfo != null) {
// If the package exist, we extract particular entries from package
entries = packageSymbolInfo.getScopeEntry().symbol.scope.entries;
}
entries.forEach((name, scopeEntry) -> {
if (scopeEntry.symbol instanceof BInvokableSymbol && ((BInvokableSymbol) scopeEntry.symbol).receiverSymbol != null) {
String symbolBoundedName = ((BInvokableSymbol) scopeEntry.symbol).receiverSymbol.getType().toString();
if (symbolBoundedName.equals(bTypeValue)) {
// TODO: Need to handle the name in a proper manner
String[] nameComponents = name.toString().split("\\.");
SymbolInfo actionFunctionSymbol = new SymbolInfo(nameComponents[nameComponents.length - 1], scopeEntry);
actionFunctionList.add(actionFunctionSymbol);
}
} else if ((scopeEntry.symbol instanceof BTypeSymbol) && bTypeValue.equals(scopeEntry.symbol.type.toString())) {
// Get the struct fields
Map<Name, Scope.ScopeEntry> fields = scopeEntry.symbol.scope.entries;
fields.forEach((fieldName, fieldScopeEntry) -> {
actionFunctionList.add(new SymbolInfo(fieldName.getValue(), fieldScopeEntry));
});
}
});
// Populate possible iterable operators over the variable
populateIterableOperations(variable, actionFunctionList);
return actionFunctionList;
}
Aggregations