Search in sources :

Example 76 with BLangExpression

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

the class BLangPackageBuilder method addRestArgument.

public void addRestArgument(DiagnosticPos pos, Set<Whitespace> ws) {
    BLangRestArgsExpression varArgs = (BLangRestArgsExpression) TreeBuilder.createVarArgsNode();
    varArgs.pos = pos;
    varArgs.addWS(ws);
    varArgs.expr = (BLangExpression) this.exprNodeStack.pop();
    addExpressionNode(varArgs);
}
Also used : BLangRestArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangRestArgsExpression)

Example 77 with BLangExpression

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

the class BLangPackageBuilder method addKeyValueRecord.

public void addKeyValueRecord(Set<Whitespace> ws) {
    BLangRecordKeyValue keyValue = (BLangRecordKeyValue) TreeBuilder.createRecordKeyValue();
    keyValue.addWS(ws);
    keyValue.valueExpr = (BLangExpression) exprNodeStack.pop();
    keyValue.key = new BLangRecordKey((BLangExpression) exprNodeStack.pop());
    recordLiteralNodes.peek().keyValuePairs.add(keyValue);
}
Also used : BLangRecordKey(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKey) BLangRecordKeyValue(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral.BLangRecordKeyValue) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 78 with BLangExpression

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

the class SqlQueryBuilder method visit.

@Override
public void visit(BLangGroupBy groupBy) {
    List<? extends ExpressionNode> varList = groupBy.getVariables();
    Iterator<? extends ExpressionNode> iterator = varList.iterator();
    groupByClause = new StringBuilder("group by ");
    BLangExpression expr = (BLangExpression) iterator.next();
    expr.accept(this);
    groupByClause.append(exprStack.pop());
    while (iterator.hasNext()) {
        expr = (BLangExpression) iterator.next();
        groupByClause.append(", ");
        expr.accept(this);
        groupByClause.append(exprStack.pop());
    }
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 79 with BLangExpression

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

the class SqlQueryBuilder method visit.

@Override
public void visit(BLangOrderBy orderBy) {
    List<? extends ExpressionNode> varRefs = orderBy.getVariables();
    Iterator<? extends ExpressionNode> iterator = varRefs.iterator();
    BLangExpression expr = (BLangExpression) iterator.next();
    orderByClause = new StringBuilder("order by ");
    expr.accept(this);
    orderByClause.append(exprStack.pop());
    while (iterator.hasNext()) {
        orderByClause.append(",").append(" ");
        expr = (BLangExpression) iterator.next();
        expr.accept(this);
        orderByClause.append(exprStack.pop());
    }
}
Also used : BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)

Example 80 with BLangExpression

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

the class Generator method fieldAnnotation.

/**
 * Get description annotation of the field.
 * @param node parent node.
 * @param param field.
 * @return description of the field.
 */
private static String fieldAnnotation(BLangNode node, BLangNode param) {
    String subName = "";
    if (param instanceof BLangVariable) {
        BLangVariable paramVariable = (BLangVariable) param;
        subName = (paramVariable.getName() == null) ? paramVariable.type.tsymbol.name.value : paramVariable.getName().getValue();
    } else if (param instanceof BLangEnum.Enumerator) {
        BLangEnum.Enumerator paramEnumVal = (BLangEnum.Enumerator) param;
        subName = paramEnumVal.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("Field") && attribVal.startsWith(subName + ":")) {
            return attribVal.split(subName + ":")[1].trim();
        }
    }
    // annotation's value
    for (AnnotationAttachmentNode annotation : getAnnotationAttachments(node)) {
        BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
        if (bLangRecordLiteral.getKeyValuePairs().size() != 1) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals("Field")) {
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            return bLangLiteral.toString();
        }
    }
    return "";
}
Also used : BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

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