Search in sources :

Example 11 with ClassReference

use of kalang.ast.ClassReference 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

ClassReference (kalang.ast.ClassReference)11 ExprNode (kalang.ast.ExprNode)9 ThisExpr (kalang.ast.ThisExpr)6 AssignExpr (kalang.ast.AssignExpr)5 StaticFieldExpr (kalang.ast.StaticFieldExpr)5 ExprStmt (kalang.ast.ExprStmt)4 ObjectFieldExpr (kalang.ast.ObjectFieldExpr)4 BlockStmt (kalang.ast.BlockStmt)3 VarObject (kalang.ast.VarObject)3 ObjectType (kalang.core.ObjectType)3 Nullable (javax.annotation.Nullable)2 AmbiguousMethodException (kalang.AmbiguousMethodException)2 MethodNotFoundException (kalang.MethodNotFoundException)2 ConstExpr (kalang.ast.ConstExpr)2 FieldExpr (kalang.ast.FieldExpr)2 FieldNode (kalang.ast.FieldNode)2 InvocationExpr (kalang.ast.InvocationExpr)2 LocalVarNode (kalang.ast.LocalVarNode)2 MethodNode (kalang.ast.MethodNode)2 ParameterExpr (kalang.ast.ParameterExpr)2