Search in sources :

Example 1 with BLangAnnotAttribute

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

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

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

Aggregations

ArrayList (java.util.ArrayList)1 AnnotationDoc (org.ballerinalang.docgen.model.AnnotationDoc)1 Variable (org.ballerinalang.docgen.model.Variable)1 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)1 BAnnotationAttributeSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BAnnotationAttributeSymbol)1 BLangAnnotAttribute (org.wso2.ballerinalang.compiler.tree.BLangAnnotAttribute)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1