use of kalang.ast.ParameterNode in project kalang by kasonyang.
the class ObjectType method getParameterDescriptors.
private ParameterDescriptor[] getParameterDescriptors(MethodNode method) {
ParameterNode[] pms = method.getParameters();
Type[] ptypes = parseTypes(MethodUtil.getParameterTypes(method));
ParameterDescriptor[] pds = new ParameterDescriptor[ptypes.length];
for (int j = 0; j < pds.length; j++) {
ParameterNode p = pms[j];
pds[j] = new ParameterDescriptor(p.getName(), ptypes[j], p.modifier);
}
return pds;
}
use of kalang.ast.ParameterNode in project kalang by kasonyang.
the class AstBuilder method declareLocalVar.
@Nullable
private LocalVarNode declareLocalVar(String name, Type type, int modifier, ParserRuleContext ctx) {
LocalVarNode localVarNode = new LocalVarNode(type, name, modifier);
ParameterNode param = this.getNamedParameter(name);
LocalVarNode var = this.getNamedLocalVar(name);
if (param != null || var != null) {
handleSyntaxError("variable is defined", ctx);
return null;
}
if (name != null) {
this.varTables.put(name, localVarNode);
}
return localVarNode;
}
use of kalang.ast.ParameterNode in project kalang by kasonyang.
the class AstUtil method createScriptMainMethodIfNotExists.
public static void createScriptMainMethodIfNotExists(ClassNode clazz) {
ClassType clazzType = Types.getClassType(clazz);
MethodDescriptor[] methods = clazzType.getMethodDescriptors(null, false, false);
Type[] argTypes = new Type[] { Types.getArrayType(Types.getStringClassType()) };
MethodDescriptor mainMethod = MethodUtil.getMethodDescriptor(methods, "main", argTypes);
if (mainMethod == null) {
MethodNode m = clazz.createMethodNode(Types.VOID_TYPE, "main", Modifier.PUBLIC + Modifier.STATIC);
ParameterNode p = m.createParameter(argTypes[0], "arg");
BlockStmt body = m.getBody();
try {
NewObjectExpr newScriptExpr = new NewObjectExpr(clazzType);
ObjectInvokeExpr invokeExpr = ObjectInvokeExpr.create(newScriptExpr, "run", new ExprNode[] { new ParameterExpr(p) });
body.statements.add(new ExprStmt(invokeExpr));
} catch (MethodNotFoundException | AmbiguousMethodException ex) {
throw Exceptions.unexceptedException(ex);
}
}
}
Aggregations