Search in sources :

Example 76 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class CodeGenerator method createPackageVarInfo.

// Create info entries
private void createPackageVarInfo(BLangVariable varNode) {
    BVarSymbol varSymbol = varNode.symbol;
    varSymbol.varIndex = getPVIndex(varSymbol.type.tag);
    int varNameCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.name.value);
    int typeSigCPIndex = addUTF8CPEntry(currentPkgInfo, varSymbol.type.getDesc());
    PackageVarInfo pkgVarInfo = new PackageVarInfo(varNameCPIndex, typeSigCPIndex, varSymbol.flags, varSymbol.varIndex.value);
    currentPkgInfo.pkgVarInfoMap.put(varSymbol.name.value, pkgVarInfo);
    LocalVariableInfo localVarInfo = getLocalVarAttributeInfo(varSymbol);
    LocalVariableAttributeInfo pkgVarAttrInfo = (LocalVariableAttributeInfo) currentPkgInfo.getAttributeInfo(AttributeInfo.Kind.LOCAL_VARIABLES_ATTRIBUTE);
    pkgVarAttrInfo.localVars.add(localVarInfo);
// TODO Populate annotation attribute
}
Also used : LocalVariableInfo(org.wso2.ballerinalang.programfile.LocalVariableInfo) LocalVariableAttributeInfo(org.wso2.ballerinalang.programfile.attributes.LocalVariableAttributeInfo) PackageVarInfo(org.wso2.ballerinalang.programfile.PackageVarInfo) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 77 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class AnnotationDesugar method initAnnotation.

private void initAnnotation(BLangAnnotationAttachment attachment, BLangVariable annotationMapEntryVar, BLangBlockStmt target, BSymbol parentSymbol, int index) {
    BLangVariable annotationVar = null;
    if (attachment.annotationSymbol.attachedType != null) {
        // create: AttachedType annotationVar = { annotation-expression }
        annotationVar = ASTBuilderUtil.createVariable(attachment.pos, attachment.annotationName.value, attachment.annotationSymbol.attachedType.type);
        annotationVar.expr = attachment.expr;
        ASTBuilderUtil.defineVariable(annotationVar, parentSymbol, names);
        ASTBuilderUtil.createVariableDefStmt(attachment.pos, target).var = annotationVar;
    }
    // create: annotationMapEntryVar["name$index"] = annotationVar;
    BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
    if (annotationVar != null) {
        assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationVar.symbol);
    } else {
        assignmentStmt.expr = ASTBuilderUtil.createLiteral(target.pos, symTable.nullType, null);
    }
    BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
    indexAccessNode.pos = target.pos;
    indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, attachment.annotationSymbol.bvmAlias() + "$" + index);
    indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapEntryVar.symbol);
    indexAccessNode.type = annotationMapEntryVar.symbol.type;
    assignmentStmt.varRefs.add(indexAccessNode);
}
Also used : BLangIndexBasedAccess(org.wso2.ballerinalang.compiler.tree.expressions.BLangIndexBasedAccess) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 78 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class TreeVisitor method visit.

public void visit(BLangResource resourceNode) {
    String resourceName = resourceNode.getName().getValue();
    BSymbol resourceSymbol = resourceNode.symbol;
    SymbolEnv resourceEnv = SymbolEnv.createResourceActionSymbolEnv(resourceNode, resourceSymbol.scope, symbolEnv);
    if (isWithinParameterContext(resourceName, NODE_TYPE_RESOURCE)) {
        this.populateSymbols(this.resolveAllVisibleSymbols(resourceEnv), resourceEnv);
        setTerminateVisitor(true);
    } else if (!ScopeResolverConstants.getResolverByClass(cursorPositionResolver).isCursorBeforeNode(resourceNode.getPosition(), resourceNode, this, this.documentServiceContext)) {
        // TODO:Handle Annotation attachments
        // Visit the endpoints
        resourceNode.endpoints.forEach(bLangEndpoint -> this.acceptNode(bLangEndpoint, resourceEnv));
        // Cursor position is calculated against the resource parameter scope resolver
        cursorPositionResolver = ResourceParamScopeResolver.class;
        resourceNode.workers.forEach(w -> this.acceptNode(w, resourceEnv));
        this.blockOwnerStack.push(resourceNode);
        // Cursor position is calculated against the Block statement scope resolver
        cursorPositionResolver = BlockStatementScopeResolver.class;
        acceptNode(resourceNode.body, resourceEnv);
        this.blockOwnerStack.pop();
    }
}
Also used : CommonUtil(org.ballerinalang.langserver.common.utils.CommonUtil) Arrays(java.util.Arrays) BLangReturn(org.wso2.ballerinalang.compiler.tree.statements.BLangReturn) TokenStream(org.antlr.v4.runtime.TokenStream) Token(org.antlr.v4.runtime.Token) BLangWorkerReceive(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerReceive) BLangBreak(org.wso2.ballerinalang.compiler.tree.statements.BLangBreak) BLangImportPackage(org.wso2.ballerinalang.compiler.tree.BLangImportPackage) LSNodeVisitor(org.ballerinalang.langserver.common.LSNodeVisitor) BLangTryCatchFinally(org.wso2.ballerinalang.compiler.tree.statements.BLangTryCatchFinally) Map(java.util.Map) ServiceScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ServiceScopeResolver) TopLevelNode(org.ballerinalang.model.tree.TopLevelNode) SymbolResolver(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolResolver) BLangWhile(org.wso2.ballerinalang.compiler.tree.statements.BLangWhile) Names(org.wso2.ballerinalang.compiler.util.Names) DocumentServiceKeys(org.ballerinalang.langserver.DocumentServiceKeys) BLangAssignment(org.wso2.ballerinalang.compiler.tree.statements.BLangAssignment) BLangSimpleVarRef(org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef) ConnectorScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ConnectorScopeResolver) BLangLock(org.wso2.ballerinalang.compiler.tree.statements.BLangLock) ScopeResolverConstants(org.ballerinalang.langserver.completions.util.ScopeResolverConstants) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) BPackageSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol) ObjectTypeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ObjectTypeScopeResolver) BLangXMLNS(org.wso2.ballerinalang.compiler.tree.BLangXMLNS) Collectors(java.util.stream.Collectors) 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) List(java.util.List) Scope(org.wso2.ballerinalang.compiler.semantics.model.Scope) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) ResourceParamScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ResourceParamScopeResolver) BlockStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.BlockStatementScopeResolver) StatementNode(org.ballerinalang.model.tree.statements.StatementNode) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) BLangBind(org.wso2.ballerinalang.compiler.tree.statements.BLangBind) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) BLangIf(org.wso2.ballerinalang.compiler.tree.statements.BLangIf) SymbolEnter(org.wso2.ballerinalang.compiler.semantics.analyzer.SymbolEnter) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction) PackageNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.PackageNodeScopeResolver) BLangForeach(org.wso2.ballerinalang.compiler.tree.statements.BLangForeach) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangExpressionStmt(org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt) BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation) BLangAbort(org.wso2.ballerinalang.compiler.tree.statements.BLangAbort) HashMap(java.util.HashMap) BLangTransaction(org.wso2.ballerinalang.compiler.tree.statements.BLangTransaction) Stack(java.util.Stack) ArrayList(java.util.ArrayList) BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) BLangVariableDef(org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef) BLangMatch(org.wso2.ballerinalang.compiler.tree.statements.BLangMatch) Position(org.eclipse.lsp4j.Position) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) BLangForkJoin(org.wso2.ballerinalang.compiler.tree.statements.BLangForkJoin) BLangEndpointTypeNode(org.wso2.ballerinalang.compiler.tree.types.BLangEndpointTypeNode) MatchStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.MatchStatementScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) TextDocumentServiceContext(org.ballerinalang.langserver.TextDocumentServiceContext) BLangObject(org.wso2.ballerinalang.compiler.tree.BLangObject) BLangNext(org.wso2.ballerinalang.compiler.tree.statements.BLangNext) Symbols(org.wso2.ballerinalang.compiler.semantics.model.symbols.Symbols) BLangThrow(org.wso2.ballerinalang.compiler.tree.statements.BLangThrow) BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) Name(org.wso2.ballerinalang.compiler.util.Name) BLangLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangLiteral) TopLevelNodeScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.TopLevelNodeScopeResolver) BLangWorkerSend(org.wso2.ballerinalang.compiler.tree.statements.BLangWorkerSend) Node(org.ballerinalang.model.tree.Node) 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) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) BSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol) ResourceParamScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.ResourceParamScopeResolver) BlockStatementScopeResolver(org.ballerinalang.langserver.completions.util.positioning.resolvers.BlockStatementScopeResolver) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 79 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for annotations.
 * @param annotationNode ballerina annotation node.
 * @return documentation for annotation.
 */
public static AnnotationDoc createDocForNode(BLangAnnotation annotationNode) {
    String annotationName = annotationNode.getName().getValue();
    List<Variable> attributes = new ArrayList<>();
    // Iterate through the attributes of the annotation
    if (annotationNode.getAttributes().size() > 0) {
        for (BLangAnnotAttribute annotAttribute : annotationNode.getAttributes()) {
            String dataType = getTypeName(annotAttribute.getTypeNode());
            String desc = annotFieldAnnotation(annotationNode, annotAttribute);
            Variable variable = new Variable(annotAttribute.getName().value, dataType, desc);
            attributes.add(variable);
        }
    }
    return new AnnotationDoc(annotationName, description(annotationNode), new ArrayList<>(), attributes);
}
Also used : AnnotationDoc(org.ballerinalang.docgen.model.AnnotationDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) ArrayList(java.util.ArrayList) BLangAnnotAttribute(org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute)

Example 80 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class HtmlDocTest method testPrivateConstructsInPackage.

@Test(description = "Private constructs should not appear at all.")
public void testPrivateConstructsInPackage() {
    BLangPackage bLangPackage = createPackage("package x.y; " + "function hello(){}" + "enum Direction { IN,OUT}" + "enum Money { USD,LKR}" + "annotation ParameterInfo;" + "annotation ReturnInfo;" + "int total = 98;" + "string content = \"Name\";" + "struct Message {}" + "struct Response {}");
    Page page = generatePage(bLangPackage);
    Assert.assertEquals(page.constructs.size(), 0);
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Page(org.ballerinalang.docgen.model.Page) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7