Search in sources :

Example 26 with BLangIdentifier

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

the class CodeAnalyzer method checkDuplicateNamedArgs.

private void checkDuplicateNamedArgs(List<BLangExpression> args) {
    List<BLangIdentifier> existingArgs = new ArrayList<>();
    args.forEach(arg -> {
        BLangNamedArgsExpression namedArg = (BLangNamedArgsExpression) arg;
        if (existingArgs.contains(namedArg.name)) {
            dlog.error(namedArg.pos, DiagnosticCode.DUPLICATE_NAMED_ARGS, namedArg.name);
        }
        existingArgs.add(namedArg.name);
    });
}
Also used : ArrayList(java.util.ArrayList) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangNamedArgsExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangNamedArgsExpression)

Example 27 with BLangIdentifier

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangDocumentation docNode) {
    Set<BLangIdentifier> visitedAttributes = new HashSet<>();
    for (BLangDocumentationAttribute attribute : docNode.attributes) {
        if (!visitedAttributes.add(attribute.documentationField)) {
            this.dlog.warning(attribute.pos, DiagnosticCode.DUPLICATE_DOCUMENTED_ATTRIBUTE, attribute.documentationField);
            continue;
        }
        Name attributeName = names.fromIdNode(attribute.documentationField);
        BSymbol attributeSymbol = this.env.scope.lookup(attributeName).symbol;
        if (attributeSymbol == null) {
            this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
            continue;
        }
        int ownerSymTag = env.scope.owner.tag;
        if ((ownerSymTag & SymTag.ANNOTATION) == SymTag.ANNOTATION) {
            if (attributeSymbol.tag != SymTag.ANNOTATION_ATTRIBUTE || ((BAnnotationAttributeSymbol) attributeSymbol).docTag != attribute.docTag) {
                this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
                continue;
            }
        } else {
            if (attributeSymbol.tag != SymTag.VARIABLE || ((BVarSymbol) attributeSymbol).docTag != attribute.docTag) {
                this.dlog.warning(attribute.pos, DiagnosticCode.NO_SUCH_DOCUMENTABLE_ATTRIBUTE, attribute.documentationField, attribute.docTag.getValue());
                continue;
            }
        }
        attribute.type = attributeSymbol.type;
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) HashSet(java.util.HashSet) Name(org.wso2.ballerinalang.compiler.util.Name)

Example 28 with BLangIdentifier

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

the class ASTBuilderUtil method createIdentifier.

static BLangIdentifier createIdentifier(DiagnosticPos pos, String value) {
    final BLangIdentifier node = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    node.pos = pos;
    if (value != null) {
        node.setValue(value);
    }
    return node;
}
Also used : BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier)

Example 29 with BLangIdentifier

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

the class Desugar method createAssignmentStmt.

// TODO: Same function is used in symbol enter. Refactor this to reuse the same function.
private StatementNode createAssignmentStmt(BLangVariable variable) {
    BLangSimpleVarRef varRef = (BLangSimpleVarRef) TreeBuilder.createSimpleVariableReferenceNode();
    varRef.pos = variable.pos;
    varRef.variableName = variable.name;
    varRef.symbol = variable.symbol;
    varRef.type = variable.type;
    varRef.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    BLangAssignment assignmentStmt = (BLangAssignment) TreeBuilder.createAssignmentNode();
    assignmentStmt.expr = variable.expr;
    assignmentStmt.pos = variable.pos;
    assignmentStmt.addVariable(varRef);
    return assignmentStmt;
}
Also used : BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)

Example 30 with BLangIdentifier

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

the class Desugar method createInvocationNode.

private BLangInvocation createInvocationNode(String functionName, List<BLangExpression> args, List<BType> retTypes) {
    BLangInvocation invocationNode = (BLangInvocation) TreeBuilder.createInvocationNode();
    BLangIdentifier name = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    name.setLiteral(false);
    name.setValue(functionName);
    invocationNode.name = name;
    invocationNode.pkgAlias = (BLangIdentifier) TreeBuilder.createIdentifierNode();
    // TODO: 2/28/18 need to find a good way to refer to symbols
    invocationNode.symbol = symTable.rootScope.lookup(new Name(functionName)).symbol;
    invocationNode.types = retTypes;
    invocationNode.requiredArgs = args;
    return invocationNode;
}
Also used : BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)20 BLangNameReference (org.wso2.ballerinalang.compiler.tree.BLangNameReference)9 IdentifierNode (org.ballerinalang.model.tree.IdentifierNode)8 BLangInvocation (org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation)7 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)7 BLangUserDefinedType (org.wso2.ballerinalang.compiler.tree.types.BLangUserDefinedType)6 ArrayList (java.util.ArrayList)5 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)5 BLangImportPackage (org.wso2.ballerinalang.compiler.tree.BLangImportPackage)5 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)4 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)4 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)4 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)4 BLangAssignment (org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment)4 Name (org.wso2.ballerinalang.compiler.util.Name)4 SelectExpressionNode (org.ballerinalang.model.tree.clauses.SelectExpressionNode)3 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)3 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)3 List (java.util.List)2 Set (java.util.Set)2