Search in sources :

Example 6 with StaticFieldExpr

use of kalang.ast.StaticFieldExpr in project kalang by kasonyang.

the class AstUtil method createGetter.

public static void createGetter(ClassNode clazz, FieldDescriptor field, int accessModifier) {
    String fn = field.getName();
    String getterName = "get" + NameUtil.firstCharToUpperCase(fn);
    boolean isStatic = isStatic(field.getModifier());
    if (isStatic) {
        accessModifier |= Modifier.STATIC;
    }
    MethodNode getter = clazz.createMethodNode(field.getType(), getterName, accessModifier);
    // getter.offset = field.offset;
    BlockStmt body = getter.getBody();
    FieldExpr fe;
    ClassReference cr = new ClassReference(clazz);
    if (isStatic) {
        fe = new StaticFieldExpr(cr, field);
    } else {
        fe = new ObjectFieldExpr(new ThisExpr(Types.getClassType(clazz)), field);
    }
    body.statements.add(new ReturnStmt(fe));
}
Also used : StaticFieldExpr(kalang.ast.StaticFieldExpr) ObjectFieldExpr(kalang.ast.ObjectFieldExpr) MethodNode(kalang.ast.MethodNode) BlockStmt(kalang.ast.BlockStmt) ClassReference(kalang.ast.ClassReference) StaticFieldExpr(kalang.ast.StaticFieldExpr) FieldExpr(kalang.ast.FieldExpr) ObjectFieldExpr(kalang.ast.ObjectFieldExpr) ReturnStmt(kalang.ast.ReturnStmt) ThisExpr(kalang.ast.ThisExpr)

Aggregations

StaticFieldExpr (kalang.ast.StaticFieldExpr)6 ClassReference (kalang.ast.ClassReference)5 ExprNode (kalang.ast.ExprNode)5 ObjectFieldExpr (kalang.ast.ObjectFieldExpr)5 ThisExpr (kalang.ast.ThisExpr)5 AssignExpr (kalang.ast.AssignExpr)3 ExprStmt (kalang.ast.ExprStmt)3 BlockStmt (kalang.ast.BlockStmt)2 FieldExpr (kalang.ast.FieldExpr)2 FieldNode (kalang.ast.FieldNode)2 MethodNode (kalang.ast.MethodNode)2 Nullable (javax.annotation.Nullable)1 AmbiguousMethodException (kalang.AmbiguousMethodException)1 FieldNotFoundException (kalang.FieldNotFoundException)1 MethodNotFoundException (kalang.MethodNotFoundException)1 KalangParser (kalang.antlr.KalangParser)1 LocalVarDeclContext (kalang.antlr.KalangParser.LocalVarDeclContext)1 VarDeclContext (kalang.antlr.KalangParser.VarDeclContext)1 InvocationExpr (kalang.ast.InvocationExpr)1 ObjectInvokeExpr (kalang.ast.ObjectInvokeExpr)1