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 "";
}
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);
}
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);
}
Aggregations