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