in lib/generator.js [1042:1138]
visitObject(ast, level) {
assert.equal(ast.type, 'object');
if (ast.fields.length === 0) {
this.emit('new java.util.HashMap<>()');
return;
}
var hasExpandField = false;
var hasNotExpandField = false;
for (let i = 0; i < ast.fields.length; i++) {
const field = ast.fields[i];
if (field.type === 'expandField') {
hasExpandField = true;
break;
} else {
hasNotExpandField = true;
}
}
if (!hasExpandField) {
this.emit('TeaConverter.buildMap(\n');
for (let i = 0; i < ast.fields.length; i++) {
this.visitObjectField(ast.fields[i], level + 1);
if (i < ast.fields.length - 1) {
this.emit(',');
}
this.emit('\n');
}
this.emit(')', level);
return;
}
var all = [];
// 分段
var current = [];
for (let i = 0; i < ast.fields.length; i++) {
const field = ast.fields[i];
if (field.type === 'objectField') {
current.push(field);
} else {
if (current.length > 0) {
all.push(current);
}
all.push(field);
current = [];
}
}
if (current.length > 0) {
all.push(current);
}
this.emit('TeaConverter.merge(');
if (ast.inferred && ast.inferred.valueType.name === 'string') {
this.emit('String.class');
} else {
this.emit('Object.class');
}
var hasExpandFieldBuildMap = false;
if (hasExpandField && hasNotExpandField) {
hasExpandFieldBuildMap = true;
this.emit(',\n');
this.emit('TeaConverter.buildMap(\n', level + 1);
} else {
this.emit(',\n');
}
for (let i = 0; i < all.length; i++) {
const item = all[i];
if (Array.isArray(item)) {
for (var j = 0; j < item.length; j++) {
this.visitObjectField(item[j], level + 2);
if (item[j + 1]) {
this.emit(',\n');
} else {
this.emit('\n');
}
}
} else {
this.emit('', level + 1);
this.visitExpr(item.expr, level);
if (all[i + 1]) {
this.emit(',');
}
this.emit('\n');
}
if (hasExpandFieldBuildMap) {
this.emit(')', level + 1);
if (all[i + 1]) {
this.emit(',\n');
} else {
this.emit('\n');
}
hasExpandFieldBuildMap = false;
}
}
this.emit(')', level);
}