use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol 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.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class EndpointDesugar method generateServiceRegistered.
private BLangBlockStmt generateServiceRegistered(BEndpointVarSymbol endpoint, BLangService service, SymbolEnv env, BSymbol encSymbol, BSymbol varEncSymbol) {
final DiagnosticPos pos = service.pos;
final String epName = endpoint.name.value;
BLangBlockStmt temp = new BLangBlockStmt();
final BLangVariable epVariable = ASTBuilderUtil.createVariable(pos, epName, endpoint.type);
final Name name = endpoint.name;
epVariable.symbol = (BVarSymbol) symResolver.lookupMemberSymbol(pos, encSymbol.scope, env, name, SymTag.VARIABLE);
final BLangVariableDef serviceTypeDef = ASTBuilderUtil.createVariableDefStmt(pos, temp);
serviceTypeDef.var = ASTBuilderUtil.createVariable(pos, service.name + "type", symTable.typeDesc);
ASTBuilderUtil.defineVariable(serviceTypeDef.var, varEncSymbol, names);
final BLangUnaryExpr typeOfExpr = ASTBuilderUtil.createUnaryExpr(pos);
serviceTypeDef.var.expr = typeOfExpr;
typeOfExpr.operator = OperatorKind.TYPEOF;
typeOfExpr.expr = getTypeAccessExpression(pos, service.symbol.type);
typeOfExpr.type = symTable.typeDesc;
List<BLangVariable> args = Lists.of(serviceTypeDef.var);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() == 2) {
// Endpoint is already desugared. Fix this correctly.
args.add(0, epVariable);
}
final BLangExpressionStmt expressionStmt = ASTBuilderUtil.createExpressionStmt(pos, temp);
final BLangInvocation iExpr = ASTBuilderUtil.createInvocationExpr(pos, endpoint.registerFunction, args, symResolver);
if (endpoint.registerFunction != null && endpoint.registerFunction.params.size() != 2) {
iExpr.expr = ASTBuilderUtil.createVariableRef(epVariable.pos, epVariable.symbol);
}
expressionStmt.expr = iExpr;
return temp;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class BLangEndpointContextResolver method resolveItems.
@Override
@SuppressWarnings("unchecked")
public ArrayList<CompletionItem> resolveItems(TextDocumentServiceContext completionContext) {
BLangNode bLangEndpoint = completionContext.get(CompletionKeys.SYMBOL_ENV_NODE_KEY);
ArrayList<CompletionItem> completionItems = new ArrayList<>();
ArrayList<SymbolInfo> configurationFields = new ArrayList<>();
List<BStructSymbol.BAttachedFunction> attachedFunctions = new ArrayList<>();
if (((BLangEndpoint) bLangEndpoint).type.tsymbol instanceof BStructSymbol) {
attachedFunctions.addAll(((BStructSymbol) ((BLangEndpoint) bLangEndpoint).type.tsymbol).attachedFuncs);
}
BStructSymbol.BAttachedFunction initFunction = attachedFunctions.stream().filter(bAttachedFunction -> bAttachedFunction.funcName.getValue().equals(INIT)).findFirst().orElseGet(null);
BVarSymbol configSymbol = initFunction.symbol.getParameters().get(0);
BType configSymbolType = configSymbol.getType();
if (configSymbolType instanceof BStructType) {
((BStructType) configSymbolType).getFields().forEach(bStructField -> configurationFields.add(new SymbolInfo(bStructField.getName().getValue(), new Scope.ScopeEntry(bStructField.symbol, null))));
}
this.populateCompletionItemList(configurationFields, completionItems);
return completionItems;
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class AbstractItemResolver method populateCompletionItemList.
/**
* Populate the completion item list by considering the.
* @param symbolInfoList - list of symbol information
* @param completionItems - completion item list to populate
*/
protected void populateCompletionItemList(List<SymbolInfo> symbolInfoList, List<CompletionItem> completionItems) {
symbolInfoList.forEach(symbolInfo -> {
CompletionItem completionItem = null;
BSymbol bSymbol = symbolInfo.getScopeEntry() != null ? symbolInfo.getScopeEntry().symbol : null;
if ((bSymbol instanceof BInvokableSymbol && ((BInvokableSymbol) bSymbol).kind != null && !((BInvokableSymbol) bSymbol).kind.equals(SymbolKind.WORKER)) || symbolInfo.isIterableOperation()) {
completionItem = this.populateBallerinaFunctionCompletionItem(symbolInfo);
} else if (!(bSymbol instanceof BInvokableSymbol) && bSymbol instanceof BVarSymbol) {
completionItem = this.populateVariableDefCompletionItem(symbolInfo);
} else if (bSymbol instanceof BTypeSymbol && !bSymbol.getName().getValue().equals(UtilSymbolKeys.NOT_FOUND_TYPE) && !(bSymbol instanceof BAnnotationSymbol)) {
completionItem = this.populateBTypeCompletionItem(symbolInfo);
}
if (completionItem != null) {
completionItems.add(completionItem);
}
});
}
use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol in project ballerina by ballerina-lang.
the class SignatureTreeVisitor method populateSymbols.
/**
* Populate the symbols.
* @param symbolEntries symbol entries
*/
private void populateSymbols(Map<Name, Scope.ScopeEntry> symbolEntries) {
// TODO: Populate only the visible functions
this.terminateVisitor = true;
String identifierAgainst = documentServiceContext.get(SignatureKeys.IDENTIFIER_AGAINST);
List<SymbolInfo> visibleSymbols = new ArrayList<>();
/*
During the first iteration we filter out the functions and if there is, the variable reference against which
the function is called.
*/
symbolEntries.forEach((k, v) -> {
if (v.symbol instanceof BInvokableSymbol && !(v.symbol instanceof BOperatorSymbol) && !v.symbol.getName().getValue().contains("<init>")) {
SymbolInfo symbolInfo = new SymbolInfo(k.getValue(), v);
visibleSymbols.add(symbolInfo);
} else if (v.symbol instanceof BVarSymbol && k.getValue().equals(identifierAgainst)) {
documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
} else if (v.symbol instanceof BPackageSymbol && k.getValue().equals(identifierAgainst)) {
documentServiceContext.put(SignatureKeys.IDENTIFIER_PKGID, v.symbol.pkgID.toString());
documentServiceContext.put(SignatureKeys.IDENTIFIER_TYPE, v.symbol.type.toString());
visibleSymbols.addAll(this.getInvokableSymbolsInPackage((BPackageSymbol) v.symbol));
}
});
/*
In this iteration we filter out the functions either having a receiver or otherwise.
If the identifier against value is a valid value, then check whether the receiver type equals to identifier
type. If there is no identifier, filter out functions without the receiver
*/
List<SymbolInfo> filteredSymbols = new ArrayList<>();
visibleSymbols.forEach(symbolInfo -> {
BVarSymbol receiver = ((BInvokableSymbol) symbolInfo.getScopeEntry().symbol).receiverSymbol;
String[] nameTokens = symbolInfo.getSymbolName().split("\\.");
String funcNameFromSymbol = nameTokens[nameTokens.length - 1];
String functionName = documentServiceContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
String identifierPkgName = documentServiceContext.get(SignatureKeys.IDENTIFIER_PKGID);
boolean onIdentifierTypePkg = "package".equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE)) && symbolInfo.getScopeEntry().symbol.pkgID.toString().equals(identifierPkgName);
boolean onReceiverTypeMatchIdentifier = receiver != null && receiver.type.toString().equals(documentServiceContext.get(SignatureKeys.IDENTIFIER_TYPE));
boolean onIdentifierAgainstNull = (receiver == null && (identifierAgainst == null || identifierAgainst.equals("")));
if ((onIdentifierTypePkg || onReceiverTypeMatchIdentifier || onIdentifierAgainstNull) && funcNameFromSymbol.equals(functionName)) {
filteredSymbols.add(symbolInfo);
}
});
documentServiceContext.put(SignatureKeys.FILTERED_FUNCTIONS, filteredSymbols);
}
Aggregations