Search in sources :

Example 1 with LiteralContext

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;
}
Also used : LiteralContext(kalang.antlr.KalangParser.LiteralContext) ClassNode(kalang.ast.ClassNode) ConstExpr(kalang.ast.ConstExpr) AnnotationNode(kalang.ast.AnnotationNode) Token(org.antlr.v4.runtime.Token) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 LiteralContext (kalang.antlr.KalangParser.LiteralContext)1 AnnotationNode (kalang.ast.AnnotationNode)1 ClassNode (kalang.ast.ClassNode)1 ConstExpr (kalang.ast.ConstExpr)1 Token (org.antlr.v4.runtime.Token)1