use of kalang.antlr.KalangParser.LiteralContext in project kalang by kasonyang.
the class AstBuilder method visitAnnotation.
@Override
@Nullable
public AnnotationNode visitAnnotation(KalangParser.AnnotationContext ctx) {
ClassNode anType = requireAst(ctx.annotationType);
if (anType == null)
return null;
List<Token> vk = ctx.annotationValueKey;
LiteralContext dv = ctx.annotationDefaultValue;
AnnotationNode anNode = new AnnotationNode(anType);
if (vk != null && vk.size() > 0) {
List<LiteralContext> anValues = ctx.annotationValue;
int ksize = vk.size();
for (int i = 0; i < ksize; i++) {
String kname = vk.get(i).getText();
ConstExpr value = visitLiteral(anValues.get(i));
anNode.values.put(kname, value);
}
} else if (dv != null) {
ConstExpr defaultValue = visitLiteral(dv);
anNode.values.put("value", defaultValue);
}
if (!semanticAnalyzer.validateAnnotation(anNode))
return null;
// TODO validate annotation's values
return anNode;
}
Aggregations