forked from rethinkdb/rethinkdb-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstSubclass.java
More file actions
69 lines (68 loc) · 2.27 KB
/
AstSubclass.java
File metadata and controls
69 lines (68 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<%page args="term_name, classname, superclass, all_terms" />
package com.rethinkdb.gen.ast;
import com.rethinkdb.gen.proto.TermType;
import com.rethinkdb.gen.exc.ReqlDriverError;
import com.rethinkdb.model.Arguments;
import com.rethinkdb.model.OptArgs;
import com.rethinkdb.ast.ReqlAst;
<%block name="add_imports" />
public class ${classname} extends ${superclass} {
<%block name="member_vars" />\
<%block name="constructors">
%if term_name is not None:
public ${classname}(Object arg) {
this(new Arguments(arg), null);
}
public ${classname}(Arguments args) {
this(args, null);
}
public ${classname}(Arguments args, OptArgs optargs) {
super(TermType.${term_name}, args, optargs);
}
%else:
protected ${classname}(TermType termType, Arguments args, OptArgs optargs) {
super(termType, args, optargs);
}
%endif
</%block>\
<%block name="static_factories"></%block>\
<%block name="optArgs">\
% if optargs:
% for type in ["Object", "ReqlFunction0", "ReqlFunction1", "ReqlFunction2", "ReqlFunction3", "ReqlFunction4"]:
public ${classname} optArg(String optname, ${type} value) {
OptArgs newOptargs = OptArgs.fromMap(optargs).with(optname, value);
return new ${classname}(args, newOptargs);
}
% endfor
% endif
</%block>
<%block name="special_methods" />\
% for term, info in all_terms.items():
% if classname in info.get('include_in'):
% for methodname in info['methodnames']:
% for signature in info['signatures']:
% if signature['first_arg'] == classname:
% if signature['args'][0]['type'].endswith('...'):
<% remainingArgs = signature['args'] %>\
% else:
<% remainingArgs = signature['args'][1:] %>\
% endif
public ${info['classname']} ${methodname}(${
', '.join("%s %s" % (arg['type'], arg['var'])
for arg in remainingArgs)}) {
Arguments arguments = new Arguments(this);
%for arg in remainingArgs:
%if arg['type'].endswith('...'):
arguments.coerceAndAddAll(${arg['var']});
%else:
arguments.coerceAndAdd(${arg['var']});
%endif
%endfor
return new ${info['classname']}(arguments);
}
% endif
% endfor
% endfor
% endif
% endfor
}