Search in sources :

Example 1 with BLangAnnotation

use of org.wso2.ballerinalang.compiler.tree.BLangAnnotation 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 BLangAnnotation

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

the class BLangPackageBuilder method endAnnotationDef.

public void endAnnotationDef(Set<Whitespace> ws, String identifier, boolean publicAnnotation, boolean isTypeAttached) {
    BLangAnnotation annotationNode = (BLangAnnotation) this.annotationStack.pop();
    annotationNode.addWS(ws);
    annotationNode.setName(this.createIdentifier(identifier));
    if (publicAnnotation) {
        annotationNode.flagSet.add(Flag.PUBLIC);
    }
    while (!attachmentPointStack.empty()) {
        annotationNode.attachmentPoints.add(attachmentPointStack.pop());
    }
    if (isTypeAttached) {
        annotationNode.typeNode = (BLangType) this.typeNodeStack.pop();
    }
    this.compUnit.addTopLevelNode(annotationNode);
}
Also used : BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation)

Example 3 with BLangAnnotation

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

the class BLangPackageBuilder method startAnnotationDef.

public void startAnnotationDef(DiagnosticPos pos) {
    BLangAnnotation annotNode = (BLangAnnotation) TreeBuilder.createAnnotationNode();
    annotNode.pos = pos;
    attachAnnotations(annotNode);
    attachDocumentations(annotNode);
    attachDeprecatedNode(annotNode);
    this.annotationStack.add(annotNode);
}
Also used : BLangAnnotation(org.wso2.ballerinalang.compiler.tree.BLangAnnotation)

Example 4 with BLangAnnotation

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

the class Generator method annotFieldAnnotation.

/**
 * Get description annotation of the annotation attribute.
 * @param annotationNode parent node.
 * @param annotAttribute annotation attribute.
 * @return description of the annotation attribute.
 */
private static String annotFieldAnnotation(BLangAnnotation annotationNode, BLangAnnotAttribute annotAttribute) {
    List<? extends AnnotationAttachmentNode> annotationAttachments = getAnnotationAttachments(annotationNode);
    for (AnnotationAttachmentNode annotation : annotationAttachments) {
        if ("Field".equals(annotation.getAnnotationName().getValue())) {
            BLangRecordLiteral bLangRecordLiteral = (BLangRecordLiteral) annotation.getExpression();
            BLangExpression bLangLiteral = bLangRecordLiteral.getKeyValuePairs().get(0).getValue();
            String value = bLangLiteral.toString();
            if (value.startsWith(annotAttribute.getName().getValue())) {
                String[] valueParts = value.split(":");
                return valueParts.length == 2 ? valueParts[1] : valueParts[0];
            }
        }
    }
    return "";
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 5 with BLangAnnotation

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

the class DocumentationTest method testDocAnnotation.

@Test(description = "Test doc annotation.")
public void testDocAnnotation() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/annotation.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for Test annotation\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
    docNodes = ((BLangAnnotation) packageNode.getAnnotations().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Aggregations

BLangAnnotation (org.wso2.ballerinalang.compiler.tree.BLangAnnotation)5 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)4 ArrayList (java.util.ArrayList)3 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BLangAnnotationAttachmentPoint (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachmentPoint)2 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)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 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1