use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project kubernetes by ballerinax.
the class KubernetesPlugin method extractEndpointName.
private Set<String> extractEndpointName(ServiceNode serviceNode) {
Set<String> endpoints = new HashSet<>();
List<BLangSimpleVarRef> endpointList = ((BLangService) serviceNode).boundEndpoints;
for (BLangSimpleVarRef var : endpointList) {
endpoints.add(var.variableName.getValue());
}
return endpoints;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getSignatureInfoModel.
/**
* Get the required signature information filled model.
*
* @param bInvokableSymbol Invokable symbol
* @param signatureContext Signature operation context
* @return {@link SignatureInfoModel} SignatureInfoModel containing signature information
*/
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
Map<String, String> paramDescMap = new HashMap<>();
SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
List<ParameterInfoModel> paramModels = new ArrayList<>();
String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
if (!blangFunction.getDocumentationAttachments().isEmpty()) {
// Get the first documentation attachment
BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
bLangDocumentation.attributes.forEach(attribute -> {
if (attribute.docTag.equals(DocTag.PARAM)) {
paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
}
});
} else {
// TODO: Should be deprecated in due course
// Iterate over the attachments list and extract the attachment Description Map
blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
BLangExpression expr = annotationAttachment.expr;
if (expr instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
BLangExpression key = recordKeyValue.key.expr;
BLangExpression value = recordKeyValue.getValue();
if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
String annotationValue = ((BLangLiteral) value).getValue().toString();
if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
paramDescMap.put(paramName, annotationDesc);
} else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
signatureInfoModel.setSignatureDescription(annotationValue);
}
}
}
}
});
}
bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
parameterInfoModel.setParamType(bVarSymbol.getType().toString());
parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
paramModels.add(parameterInfoModel);
});
signatureInfoModel.setParameterInfoModels(paramModels);
return signatureInfoModel;
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleAssignNodeWithVar.
private void handleAssignNodeWithVar(BLangAssignment assignNode) {
int ignoredCount = 0;
int createdSymbolCount = 0;
List<Name> newVariables = new ArrayList<Name>();
List<BType> expTypes = new ArrayList<>();
// Check each LHS expression.
for (int i = 0; i < assignNode.varRefs.size(); i++) {
BLangExpression varRef = assignNode.varRefs.get(i);
// If the assignment is declared with "var", then lhs supports only simpleVarRef expressions only.
if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
dlog.error(varRef.pos, DiagnosticCode.INVALID_VARIABLE_ASSIGNMENT, varRef);
expTypes.add(symTable.errType);
continue;
}
// Check variable symbol if exists.
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
((BLangVariableReference) varRef).lhsVar = true;
Name varName = names.fromIdNode(simpleVarRef.variableName);
if (varName == Names.IGNORE) {
ignoredCount++;
simpleVarRef.type = this.symTable.noType;
expTypes.add(symTable.noType);
typeChecker.checkExpr(simpleVarRef, env);
continue;
}
BSymbol symbol = symResolver.lookupSymbol(env, varName, SymTag.VARIABLE);
if (symbol == symTable.notFoundSymbol) {
createdSymbolCount++;
newVariables.add(varName);
expTypes.add(symTable.noType);
} else {
expTypes.add(symbol.type);
}
}
if (ignoredCount == assignNode.varRefs.size() || createdSymbolCount == 0) {
dlog.error(assignNode.pos, DiagnosticCode.NO_NEW_VARIABLES_VAR_ASSIGNMENT);
}
// Check RHS expressions with expected type list.
if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
expTypes = Lists.of(symTable.noType);
}
List<BType> rhsTypes = typeChecker.checkExpr(assignNode.expr, this.env, expTypes);
if (assignNode.safeAssignment) {
rhsTypes = Lists.of(handleSafeAssignmentWithVarDeclaration(assignNode.pos, rhsTypes.get(0)));
}
if (assignNode.getKind() == NodeKind.TUPLE_DESTRUCTURE) {
if (rhsTypes.get(0) != symTable.errType && rhsTypes.get(0).tag == TypeTags.TUPLE) {
BTupleType tupleType = (BTupleType) rhsTypes.get(0);
rhsTypes = tupleType.tupleTypes;
} else if (rhsTypes.get(0) != symTable.errType && rhsTypes.get(0).tag != TypeTags.TUPLE) {
dlog.error(assignNode.pos, DiagnosticCode.INCOMPATIBLE_TYPES_EXP_TUPLE, rhsTypes.get(0));
rhsTypes = typeChecker.getListWithErrorTypes(assignNode.varRefs.size());
}
}
// visit all lhs expressions
for (int i = 0; i < assignNode.varRefs.size(); i++) {
BLangExpression varRef = assignNode.varRefs.get(i);
if (varRef.getKind() != NodeKind.SIMPLE_VARIABLE_REF) {
continue;
}
BType actualType = rhsTypes.get(i);
BLangSimpleVarRef simpleVarRef = (BLangSimpleVarRef) varRef;
Name varName = names.fromIdNode(simpleVarRef.variableName);
if (newVariables.contains(varName)) {
// define new variables
this.symbolEnter.defineVarSymbol(simpleVarRef.pos, Collections.emptySet(), actualType, varName, env);
}
typeChecker.checkExpr(simpleVarRef, env);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SemanticAnalyzer method handleServiceEndpointBinds.
private void handleServiceEndpointBinds(BLangService serviceNode, BServiceSymbol serviceSymbol) {
for (BLangSimpleVarRef ep : serviceNode.boundEndpoints) {
typeChecker.checkExpr(ep, env);
if (ep.symbol == null || (ep.symbol.tag & SymTag.ENDPOINT) != SymTag.ENDPOINT) {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, ep.variableName);
continue;
}
final BEndpointVarSymbol epSym = (BEndpointVarSymbol) ep.symbol;
if ((epSym.tag & SymTag.ENDPOINT) == SymTag.ENDPOINT) {
if (epSym.registrable) {
serviceSymbol.boundEndpoints.add(epSym);
if (serviceNode.endpointType == null) {
serviceNode.endpointType = (BStructType) epSym.type;
serviceNode.endpointClientType = endpointSPIAnalyzer.getClientType((BStructSymbol) serviceNode.endpointType.tsymbol);
}
// TODO : Validate serviceType endpoint type with bind endpoint types.
} else {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_NOT_SUPPORT_REGISTRATION, epSym);
}
} else {
dlog.error(ep.pos, DiagnosticCode.ENDPOINT_INVALID_TYPE, epSym);
}
}
if (serviceNode.endpointType == null) {
dlog.error(serviceNode.pos, DiagnosticCode.SERVICE_INVALID_ENDPOINT_TYPE, serviceNode.name);
}
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef in project ballerina by ballerina-lang.
the class SemanticAnalyzer method checkRetryStmtValidity.
private void checkRetryStmtValidity(BLangExpression retryCountExpr) {
boolean error = true;
NodeKind retryKind = retryCountExpr.getKind();
if (retryKind == NodeKind.LITERAL) {
if (retryCountExpr.type.tag == TypeTags.INT) {
int retryCount = Integer.parseInt(((BLangLiteral) retryCountExpr).getValue().toString());
if (retryCount >= 0) {
error = false;
}
}
} else if (retryKind == NodeKind.SIMPLE_VARIABLE_REF) {
if (((BLangSimpleVarRef) retryCountExpr).symbol.flags == Flags.CONST) {
if (((BLangSimpleVarRef) retryCountExpr).symbol.type.tag == TypeTags.INT) {
error = false;
}
}
}
if (error) {
this.dlog.error(retryCountExpr.pos, DiagnosticCode.INVALID_RETRY_COUNT);
}
}
Aggregations