Search in sources :

Example 81 with BLangExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.

the class Generator method paramAnnotation.

/**
 * Get description annotation of the parameter.
 * @param node parent node.
 * @param param parameter.
 * @return description of the parameter.
 */
private static String paramAnnotation(BLangNode node, BLangVariable param) {
    String subName = param.getName() == null ? param.type.tsymbol.name.value : param.getName().getValue();
    for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
        BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
        if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
            continue;
        }
        BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
        String attribVal = bLangLiteral.toString();
        if ((annotation.getAnnotationName().getValue().equals("Param")) && attribVal.startsWith(subName + ":")) {
            return attribVal.split(subName + ":")[1].trim();
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 82 with BLangExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.

the class Generator method annotFieldAnnotation.

/**
 * Get description annotation of the annotation attribute.
 * @param annotationNode parent node.
 * @param annotAttribute annotation attribute.
 * @return description of the annotation attribute.
 */
private static String annotFieldAnnotation(BLangAnnotation annotationNode, BLangAnnotAttribute annotAttribute) {
    List<? extends AnnotationAttachmentNode> annotationAttachments = getAnnotationAttachments(annotationNode);
    for (AnnotationAttachmentNode annotation : annotationAttachments) {
        if ("Field".equals(annotation.getAnnotationName().getValue())) {
            BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            String value = bLangLiteral.toString();
            if (value.startsWith(annotAttribute.getName().getValue())) {
                String[] valueParts = value.split(":");
                return valueParts.length == 2 ? valueParts[1] : valueParts[0];
            }
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 83 with BLangExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project ballerina by ballerina-lang.

the class ServiceProtoUtils method getInvocationExpression.

private static BLangInvocation getInvocationExpression(BlockNode body) {
    if (body == null) {
        return null;
    }
    for (StatementNode statementNode : body.getStatements()) {
        BLangExpression expression = null;
        // example : conn.send inside while block.
        if (statementNode instanceof BLangWhile) {
            BLangWhile langWhile = (BLangWhile) statementNode;
            BLangInvocation invocExp = getInvocationExpression(langWhile.getBody());
            if (invocExp != null) {
                return invocExp;
            }
        }
        // example : conn.send inside for block.
        if (statementNode instanceof BLangForeach) {
            BLangForeach langForeach = (BLangForeach) statementNode;
            BLangInvocation invocExp = getInvocationExpression(langForeach.getBody());
            if (invocExp != null) {
                return invocExp;
            }
        }
        // example : conn.send inside if block.
        if (statementNode instanceof BLangIf) {
            BLangIf langIf = (BLangIf) statementNode;
            BLangInvocation invocExp = getInvocationExpression(langIf.getBody());
            if (invocExp != null) {
                return invocExp;
            }
            invocExp = getInvocationExpression((BLangBlockStmt) langIf.getElseStatement());
            if (invocExp != null) {
                return invocExp;
            }
        }
        // example : _ = conn.send(msg);
        if (statementNode instanceof BLangAssignment) {
            BLangAssignment assignment = (BLangAssignment) statementNode;
            expression = assignment.getExpression();
        }
        // example : grpc:HttpConnectorError err = conn.send(msg);
        if (statementNode instanceof BLangVariableDef) {
            BLangVariableDef variableDef = (BLangVariableDef) statementNode;
            BLangVariable variable = variableDef.getVariable();
            expression = variable.getInitialExpression();
        }
        if (expression != null && expression instanceof BLangInvocation) {
            BLangInvocation invocation = (BLangInvocation) expression;
            if ("send".equals(invocation.getName().getValue())) {
                return invocation;
            }
        }
    }
    return null;
}
Also used : BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 84 with BLangExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method getDataForSecret.

private Map<String, String> getDataForSecret(List<BLangExpression> data) throws KubernetesPluginException {
    Map<String, String> dataMap = new HashMap<>();
    for (BLangExpression bLangExpression : data) {
        Path dataFilePath = Paths.get(((BLangLiteral) bLangExpression).getValue().toString());
        String key = String.valueOf(dataFilePath.getFileName());
        String content = Base64.encodeBase64String(KubernetesUtils.readFileContent(dataFilePath));
        dataMap.put(key, content);
    }
    return dataMap;
}
Also used : Path(java.nio.file.Path) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 85 with BLangExpression

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method getDataForConfigMap.

private Map<String, String> getDataForConfigMap(List<BLangExpression> data) throws KubernetesPluginException {
    Map<String, String> dataMap = new HashMap<>();
    for (BLangExpression bLangExpression : data) {
        Path dataFilePath = Paths.get(((BLangLiteral) bLangExpression).getValue().toString());
        String key = String.valueOf(dataFilePath.getFileName());
        String content = new String(KubernetesUtils.readFileContent(dataFilePath), StandardCharsets.UTF_8);
        dataMap.put(key, content);
    }
    return dataMap;
}
Also used : Path(java.nio.file.Path) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) HashMap(java.util.HashMap) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Aggregations

BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)101 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)27 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 ArrayList (java.util.ArrayList)22 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)19 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)15 BLangLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral)15 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)14 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)14 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)14 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)13 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)11 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)11 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)11 BLangTypeConversionExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeConversionExpr)11 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)10 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)10 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)10 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)10 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)10