Search in sources :

Example 1 with BAnnotationSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.

the class CompilerPluginRunner method getAnnotationSymbols.

private List<BAnnotationSymbol> getAnnotationSymbols(String annPackage) {
    List<BAnnotationSymbol> annotationSymbols = new ArrayList<>();
    BLangPackage pkgNode = this.packageCache.get(annPackage);
    if (pkgNode == null) {
        return annotationSymbols;
    }
    SymbolEnv pkgEnv = symTable.pkgEnvMap.get(pkgNode.symbol);
    if (pkgEnv != null) {
        for (BLangAnnotation annotationNode : pkgEnv.enclPkg.annotations) {
            annotationSymbols.add((BAnnotationSymbol) annotationNode.symbol);
        }
    }
    return annotationSymbols;
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) ArrayList(java.util.ArrayList) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

Example 2 with BAnnotationSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol 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 3 with BAnnotationSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

public void visit(BLangAnnotAttribute annotationAttribute) {
    BAnnotationAttributeSymbol annotationAttributeSymbol = Symbols.createAnnotationAttributeSymbol(names.fromIdNode(annotationAttribute.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    annotationAttributeSymbol.docTag = DocTag.FIELD;
    annotationAttributeSymbol.expr = annotationAttribute.expr;
    annotationAttribute.symbol = annotationAttributeSymbol;
    ((BAnnotationSymbol) env.scope.owner).attributes.add(annotationAttributeSymbol);
    defineSymbol(annotationAttribute.pos, annotationAttributeSymbol);
}
Also used : BAnnotationAttributeSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol)

Example 4 with BAnnotationSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

public void visit(BLangAnnotation annotationNode) {
    BSymbol annotationSymbol = Symbols.createAnnotationSymbol(Flags.asMask(annotationNode.flagSet), names.fromIdNode(annotationNode.name), env.enclPkg.symbol.pkgID, null, env.scope.owner);
    annotationSymbol.type = new BAnnotationType((BAnnotationSymbol) annotationSymbol);
    annotationNode.attachmentPoints.forEach(point -> ((BAnnotationSymbol) annotationSymbol).attachmentPoints.add(point));
    annotationNode.symbol = annotationSymbol;
    defineSymbol(annotationNode.pos, annotationSymbol);
    SymbolEnv annotationEnv = SymbolEnv.createAnnotationEnv(annotationNode, annotationSymbol.scope, env);
    annotationNode.attributes.forEach(att -> this.defineNode(att, annotationEnv));
    if (annotationNode.typeNode != null) {
        BType structType = this.symResolver.resolveTypeNode(annotationNode.typeNode, annotationEnv);
        ((BAnnotationSymbol) annotationSymbol).attachedType = structType.tsymbol;
    }
}
Also used : BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BAnnotationType(org.wso2.ballerinalang.compiler.semantics.model.types.BAnnotationType) BType(org.wso2.ballerinalang.compiler.semantics.model.types.BType) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

Example 5 with BAnnotationSymbol

use of org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol in project ballerina by ballerina-lang.

the class CompilerPluginRunner method handleAnnotationProcesses.

private void handleAnnotationProcesses(CompilerPlugin plugin) {
    // Get the list of packages of annotations that this particular compiler plugin is interested in.
    SupportedAnnotationPackages supportedAnnotationPackages = plugin.getClass().getAnnotation(SupportedAnnotationPackages.class);
    if (supportedAnnotationPackages == null) {
        return;
    }
    String[] annotationPkgs = supportedAnnotationPackages.value();
    if (annotationPkgs.length == 0) {
        return;
    }
    for (String annPackage : annotationPkgs) {
        // Check whether each annotation type definition is available in the AST.
        List<BAnnotationSymbol> annotationSymbols = getAnnotationSymbols(annPackage);
        annotationSymbols.forEach(annSymbol -> {
            DefinitionID definitionID = new DefinitionID(annSymbol.pkgID.name.value, annSymbol.name.value);
            List<CompilerPlugin> processorList = processorMap.computeIfAbsent(definitionID, k -> new ArrayList<>());
            processorList.add(plugin);
        });
    }
}
Also used : CompilerPlugin(org.ballerinalang.compiler.plugins.CompilerPlugin) SupportedAnnotationPackages(org.ballerinalang.compiler.plugins.SupportedAnnotationPackages) BAnnotationSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)

Aggregations

BAnnotationSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationSymbol)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)3 ArrayList (java.util.ArrayList)2 BAnnotationAttributeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol)2 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)2 BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)2 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 CompilerPhase (org.ballerinalang.compiler.CompilerPhase)1 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 SupportedAnnotationPackages (org.ballerinalang.compiler.plugins.SupportedAnnotationPackages)1 TreeBuilder (org.ballerinalang.model.TreeBuilder)1