-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmethod.js
57 lines (49 loc) · 1.25 KB
/
method.js
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
/*jslint node: true, indent: 2 */
'use strict';
var doBody = require('./helper/body');
var args = require('./helper/arguments');
var identifier = require('./helper/identifier');
// name, params, isRef, returnType, body, flags
module.exports = function (node, indent) {
var codegen, str = '';
if (node.isAbstract) {
str += 'abstract ';
}
if (node.isFinal) {
str += 'final ';
}
if (node.isStatic) {
str += 'static ';
}
// Fall back to public if nothing is specified
if (!node.visibility) {
node.visibility = 'public';
}
str += node.visibility + ' function ';
if (node.byref) {
str += '&';
}
str += node.name;
str += args(node.arguments, indent, this);
// php7 / return type
if (node.type) {
str += this.ws + ':' + this.ws;
if (node.nullable) {
str += '?';
}
str += identifier(node.type);
}
// It lacks body. Must be an abstract method declaration.
if (node.isAbstract || !node.body) {
return str + ';';
}
codegen = this.process.bind(this);
if (this.options.bracketsNewLine) {
str += this.nl + indent + '{' + this.nl;
} else {
str += this.ws + '{' + this.nl;
}
str += doBody.call(this, codegen, indent, node.body.children);
str += indent + '}';
return str;
};