Search in sources :

Example 1 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangAnnotationAttachment annAttachmentNode) {
    BSymbol symbol = this.symResolver.resolveAnnotation(annAttachmentNode.pos, env, names.fromString(annAttachmentNode.pkgAlias.getValue()), names.fromString(annAttachmentNode.getAnnotationName().getValue()));
    if (symbol == this.symTable.notFoundSymbol) {
        this.dlog.error(annAttachmentNode.pos, DiagnosticCode.UNDEFINED_ANNOTATION, annAttachmentNode.getAnnotationName().getValue());
        return;
    }
    // Validate Attachment Point against the Annotation Definition.
    BAnnotationSymbol annotationSymbol = (BAnnotationSymbol) symbol;
    annAttachmentNode.annotationSymbol = annotationSymbol;
    if (annotationSymbol.getAttachmentPoints() != null && annotationSymbol.getAttachmentPoints().size() > 0) {
        BLangAnnotationAttachmentPoint[] attachmentPointsArrray = new BLangAnnotationAttachmentPoint[annotationSymbol.getAttachmentPoints().size()];
        Optional<BLangAnnotationAttachmentPoint> matchingAttachmentPoint = Arrays.stream(annotationSymbol.getAttachmentPoints().toArray(attachmentPointsArrray)).filter(attachmentPoint -> attachmentPoint.equals(annAttachmentNode.attachmentPoint)).findAny();
        if (!matchingAttachmentPoint.isPresent()) {
            String msg = annAttachmentNode.attachmentPoint.getAttachmentPoint().getValue();
            this.dlog.error(annAttachmentNode.pos, DiagnosticCode.ANNOTATION_NOT_ALLOWED, annotationSymbol, msg);
        }
    }
    // Validate Annotation Attachment data struct against Annotation Definition struct.
    validateAnnotationAttachmentExpr(annAttachmentNode, annotationSymbol);
}
Also used : Arrays(java.util.Arrays) BTupleType(org.wso2.ballerinalang.compiler.semantics.model.types.BTupleType) BLangWhere(org.wso2.ballerinalang.compiler.tree.clauses.BLangWhere) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) BLangStreamingQueryStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStreamingQueryStatement) WindowClauseNode(org.ballerinalang.model.tree.clauses.WindowClauseNode) BBuiltInRefType(org.wso2.ballerinalang.compiler.semantics.model.types.BBuiltInRefType) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) SelectClauseNode(org.ballerinalang.model.tree.clauses.SelectClauseNode) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) Flag(org.ballerinalang.model.elements.Flag) BLangTupleDestructure(org.wso2.ballerinalang.compiler.tree.statements.BLangTupleDestructure) BuiltInReferenceTypeNode(org.ballerinalang.model.tree.types.BuiltInReferenceTypeNode) BLangVariableReference(org.wso2.ballerinalang.compiler.tree.expressions.BLangVariableReference) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) BServiceSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BServiceSymbol) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) EnumSet(java.util.EnumSet) BLangBinaryExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangBinaryExpr) CompilerPhase(org.ballerinalang.compiler.CompilerPhase) BLangCompoundAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangCompoundAssignment) JoinStreamingInput(org.ballerinalang.model.tree.clauses.JoinStreamingInput) Set(java.util.Set) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) BLangMatchStmtPatternClause(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch.BLangMatchStmtPatternClause) SelectExpressionNode(org.ballerinalang.model.tree.clauses.SelectExpressionNode) BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol) BLangLambdaFunction(org.wso2.ballerinalang.compiler.tree.expressions.BLangLambdaFunction) BLangXMLNSStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangXMLNSStatement) BLangSelectExpression(org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectExpression) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) BLangInvokableNode(org.wso2.ballerinalang.compiler.tree.BLangInvokableNode) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) StreamingQueryStatementNode(org.ballerinalang.model.tree.statements.StreamingQueryStatementNode) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) OrderByNode(org.ballerinalang.model.tree.clauses.OrderByNode) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BLangPostIncrement(org.wso2.ballerinalang.compiler.tree.statements.BLangPostIncrement) ArrayList(java.util.ArrayList) Flags(org.wso2.ballerinalang.util.Flags) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) TreeBuilder(org.ballerinalang.model.TreeBuilder) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) StreamActionNode(org.ballerinalang.model.tree.clauses.StreamActionNode) PatternStreamingEdgeInputNode(org.ballerinalang.model.tree.clauses.PatternStreamingEdgeInputNode) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangForever(org.wso2.ballerinalang.compiler.tree.statements.BLangForever) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) BLangOrderBy(org.wso2.ballerinalang.compiler.tree.clauses.BLangOrderBy) BLangSelectClause(org.wso2.ballerinalang.compiler.tree.clauses.BLangSelectClause) SymTag(org.wso2.ballerinalang.compiler.semantics.model.symbols.SymTag) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) BLangDocumentationAttribute(org.wso2.ballerinalang.compiler.tree.expressions.BLangDocumentationAttribute) BEndpointVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BEndpointVarSymbol) BLangPatternStreamingEdgeInput(org.wso2.ballerinalang.compiler.tree.clauses.BLangPatternStreamingEdgeInput) BLangType(org.wso2.ballerinalang.compiler.tree.types.BLangType) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BInvokableType(org.wso2.ballerinalang.compiler.semantics.model.types.BInvokableType) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) Lists(org.wso2.ballerinalang.util.Lists) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangPatternStreamingInput(org.wso2.ballerinalang.compiler.tree.clauses.BLangPatternStreamingInput) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) OperatorKind(org.ballerinalang.model.tree.OperatorKind) BLangHaving(org.wso2.ballerinalang.compiler.tree.clauses.BLangHaving) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol) BOperatorSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BOperatorSymbol) Names(org.wso2.ballerinalang.compiler.util.Names) BLangFail(org.wso2.ballerinalang.compiler.tree.statements.BLangFail) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangDiagnosticLog(org.wso2.ballerinalang.compiler.util.diagnotic.BLangDiagnosticLog) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) WhereNode(org.ballerinalang.model.tree.clauses.WhereNode) BStructType(org.wso2.ballerinalang.compiler.semantics.model.types.BStructType) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) TypeKind(org.ballerinalang.model.types.TypeKind) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) BLangWindow(org.wso2.ballerinalang.compiler.tree.clauses.BLangWindow) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) Collectors(java.util.stream.Collectors) BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) HavingNode(org.ballerinalang.model.tree.clauses.HavingNode) BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangNode(org.wso2.ballerinalang.compiler.tree.BLangNode) BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangCatch(org.wso2.ballerinalang.compiler.tree.statements.BLangCatch) BLangFieldBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangFieldBasedAccess) List(java.util.List) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) NodeKind(org.ballerinalang.model.tree.NodeKind) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangBind(org.wso2.ballerinalang.compiler.tree.statements.BLangBind) Optional(java.util.Optional) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) BLangStreamAction(org.wso2.ballerinalang.compiler.tree.clauses.BLangStreamAction) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangStreamingInput(org.wso2.ballerinalang.compiler.tree.clauses.BLangStreamingInput) BLangStatement(org.wso2.ballerinalang.compiler.tree.statements.BLangStatement) BLangNodeVisitor(org.wso2.ballerinalang.compiler.tree.BLangNodeVisitor) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) TypeTags(org.wso2.ballerinalang.compiler.util.TypeTags) HashSet(java.util.HashSet) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) BInvokableSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol) GroupByNode(org.ballerinalang.model.tree.clauses.GroupByNode) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangPatternClause(org.wso2.ballerinalang.compiler.tree.clauses.BLangPatternClause) BUnionType(org.wso2.ballerinalang.compiler.semantics.model.types.BUnionType) VariableReferenceNode(org.ballerinalang.model.tree.expressions.VariableReferenceNode) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangGroupBy(org.wso2.ballerinalang.compiler.tree.clauses.BLangGroupBy) Name(org.wso2.ballerinalang.compiler.util.Name) BLangJoinStreamingInput(org.wso2.ballerinalang.compiler.tree.clauses.BLangJoinStreamingInput) StreamingInput(org.ballerinalang.model.tree.clauses.StreamingInput) DiagnosticCode(org.ballerinalang.util.diagnostic.DiagnosticCode) BLangSetAssignment(org.wso2.ballerinalang.compiler.tree.clauses.BLangSetAssignment) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) BLangInvocation(org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) BLangBlockStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt) Collections(java.util.Collections) SymbolTable(org.wso2.ballerinalang.compiler.semantics.model.SymbolTable) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

Example 2 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangStruct structNode) {
    BSymbol structSymbol = structNode.symbol;
    SymbolEnv structEnv = SymbolEnv.createPkgLevelSymbolEnv(structNode, structSymbol.scope, env);
    structNode.fields.forEach(field -> analyzeDef(field, structEnv));
    structNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.STRUCT);
        annotationAttachment.accept(this);
    });
    analyzeDef(structNode.initFunction, structEnv);
    structNode.docAttachments.forEach(doc -> analyzeDef(doc, structEnv));
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Example 3 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangEndpoint endpointNode) {
    endpointNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.ENDPOINT);
        this.analyzeDef(annotationAttachment, env);
    });
    if (endpointNode.configurationExpr == null) {
        return;
    }
    BType configType = symTable.errType;
    if (endpointNode.symbol != null && endpointNode.symbol.type.tag == TypeTags.STRUCT) {
        if (endpointNode.configurationExpr.getKind() == NodeKind.RECORD_LITERAL_EXPR) {
            // Init expression.
            configType = endpointSPIAnalyzer.getEndpointConfigType((BStructSymbol) endpointNode.symbol.type.tsymbol);
        } else {
            // assign Expression.
            configType = endpointNode.symbol.type;
        }
    }
    this.typeChecker.checkExpr(endpointNode.configurationExpr, env, Lists.of(configType));
}
Also used : BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BStructSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)

Example 4 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

@Override
public void visit(BLangTransformer transformerNode) {
    SymbolEnv transformerEnv = SymbolEnv.createTransformerEnv(transformerNode, transformerNode.symbol.scope, env);
    transformerNode.annAttachments.forEach(annotationAttachment -> {
        annotationAttachment.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.TRANSFORMER);
        this.analyzeDef(annotationAttachment, transformerEnv);
    });
    transformerNode.docAttachments.forEach(doc -> analyzeDef(doc, transformerEnv));
    validateTransformerMappingType(transformerNode.source);
    validateTransformerMappingType(transformerNode.retParams.get(0));
    analyzeStmt(transformerNode.body, transformerEnv);
    // TODO: update this accordingly once the unsafe conversion are supported
    int returnCount = transformerNode.retParams.size();
    if (returnCount == 0) {
        dlog.error(transformerNode.pos, DiagnosticCode.TRANSFORMER_MUST_HAVE_OUTPUT);
    } else if (returnCount > 1) {
        dlog.error(transformerNode.pos, DiagnosticCode.TOO_MANY_OUTPUTS_FOR_TRANSFORMER, 1, returnCount);
    }
    this.processWorkers(transformerNode, transformerEnv);
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 5 with BLangAnnotationAttachmentPoint

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

the class SemanticAnalyzer method visit.

public void visit(BLangConnector connectorNode) {
    BSymbol connectorSymbol = connectorNode.symbol;
    SymbolEnv connectorEnv = SymbolEnv.createConnectorEnv(connectorNode, connectorSymbol.scope, env);
    connectorNode.annAttachments.forEach(a -> {
        a.attachmentPoint = new BLangAnnotationAttachmentPoint(BLangAnnotationAttachmentPoint.AttachmentPoint.CONNECTOR);
        this.analyzeDef(a, connectorEnv);
    });
    connectorNode.docAttachments.forEach(doc -> analyzeDef(doc, connectorEnv));
    connectorNode.params.forEach(param -> this.analyzeDef(param, connectorEnv));
    connectorNode.varDefs.forEach(varDef -> this.analyzeDef(varDef, connectorEnv));
    connectorNode.endpoints.forEach(e -> analyzeDef(e, connectorEnv));
    this.analyzeDef(connectorNode.initFunction, connectorEnv);
    connectorNode.actions.forEach(action -> this.analyzeDef(action, connectorEnv));
    this.analyzeDef(connectorNode.initAction, connectorEnv);
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangAnnotationAttachmentPoint(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)

Aggregations

BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)16 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)12 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)7 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)4 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)2 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)2 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)2 CaseFormat (com.google.common.base.CaseFormat)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonNull (com.google.gson.JsonNull)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1