|
@@ -1,5 +1,4 @@
|
|
|
-import { ParseException, Span, TokenStream, TokenType } from './index.js'
|
|
|
-import tokenizer from './tokenizer.js'
|
|
|
+import { ParseException, Span, TokenType } from './index.js'
|
|
|
import JavaClass from '../editor/java-class.js'
|
|
|
import {
|
|
|
Assert,
|
|
@@ -931,10 +930,24 @@ function processBody(body, srcObj) {
|
|
|
defaultValue: null,
|
|
|
children: [],
|
|
|
}
|
|
|
- if (body instanceof MapLiteral) {
|
|
|
- body.keys.forEach((key, index) => {
|
|
|
- const name = key.span.getText().replace(/['"]/g, '');
|
|
|
- let value = body.values[index];
|
|
|
+ if (Array.isArray(body)) {
|
|
|
+ if (body[0] !== undefined) {
|
|
|
+ let value = body[0]
|
|
|
+ const simpleObject = isSimpleObject(value)
|
|
|
+ let param = {
|
|
|
+ ...defaultParam,
|
|
|
+ value: simpleObject ? value + '' : '',
|
|
|
+ dataType: srcObj['']?.dataType || getType(value),
|
|
|
+ }
|
|
|
+ if (!simpleObject) {
|
|
|
+ param.children = processBody(value, objToMap(srcObj['']));
|
|
|
+ }
|
|
|
+ arr.push(param)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Object.keys(body).forEach(name => {
|
|
|
+ const value = body[name];
|
|
|
+ const simpleObject = isSimpleObject(value)
|
|
|
let param = {
|
|
|
...defaultParam,
|
|
|
description: srcObj[name]?.description || '',
|
|
@@ -944,58 +957,44 @@ function processBody(body, srcObj) {
|
|
|
error: srcObj[name]?.error || '',
|
|
|
name,
|
|
|
defaultValue: srcObj[name]?.defaultValue,
|
|
|
- value: isSimpleObject(value) ? value.span.getText().trim() : '',
|
|
|
+ value: simpleObject ? value + '' : '',
|
|
|
dataType: getType(value),
|
|
|
}
|
|
|
- if (value instanceof MapLiteral || value instanceof ListLiteral) {
|
|
|
+ if (!simpleObject) {
|
|
|
param.children = processBody(value, objToMap(srcObj[name]));
|
|
|
}
|
|
|
arr.push(param)
|
|
|
});
|
|
|
- } else if (body instanceof ListLiteral) {
|
|
|
- if (body.values[0]) {
|
|
|
- let value = body.values[0]
|
|
|
- let param = {
|
|
|
- ...defaultParam,
|
|
|
- value: isSimpleObject(value) ? value.span.getText().trim() : '',
|
|
|
- dataType: srcObj['']?.dataType || getType(value),
|
|
|
- }
|
|
|
- if (value instanceof MapLiteral || value instanceof ListLiteral) {
|
|
|
- param.children = processBody(value, objToMap(srcObj['']));
|
|
|
- }
|
|
|
- arr.push(param)
|
|
|
- }
|
|
|
}
|
|
|
return arr;
|
|
|
}
|
|
|
|
|
|
function isSimpleObject(object) {
|
|
|
- return !(object instanceof MapLiteral || object instanceof ListLiteral)
|
|
|
+ return !(object != null && typeof object === 'object')
|
|
|
}
|
|
|
|
|
|
function getType(object) {
|
|
|
- if (object instanceof MapLiteral) {
|
|
|
- return "Object";
|
|
|
- }
|
|
|
- if (object instanceof ListLiteral) {
|
|
|
+ if (Array.isArray(object)) {
|
|
|
return "Array";
|
|
|
}
|
|
|
- if (object instanceof UnaryOperation) {
|
|
|
- object = object.operand;
|
|
|
+ const typeStr = typeof object;
|
|
|
+ if (typeStr === 'object') {
|
|
|
+ return "Object";
|
|
|
}
|
|
|
- let type = object.javaType.substring(object.javaType.lastIndexOf(".") + 1);
|
|
|
- if (type === 'Integer' && Number(object.span.getText()) > 0x7fffffff || Number(object.span.getText()) < -0x80000000) {
|
|
|
- return 'Long'
|
|
|
+ if (typeStr === 'number') {
|
|
|
+ if (object > 0x7fffffff || object < -0x80000000) {
|
|
|
+ return 'Long'
|
|
|
+ }
|
|
|
+ return 'Integer'
|
|
|
}
|
|
|
- return type === 'null' ? 'Object' : type;
|
|
|
+
|
|
|
+ return typeStr === 'boolean' ? 'Boolean' : 'String';
|
|
|
}
|
|
|
|
|
|
export function parseJson(bodyStr, srcObj) {
|
|
|
srcObj = srcObj || {}
|
|
|
try {
|
|
|
- JSON.parse(bodyStr)
|
|
|
- let parser = new Parser(new TokenStream(tokenizer(bodyStr)))
|
|
|
- let expr = parser.parseExpression();
|
|
|
+ const expr = JSON.parse(bodyStr)
|
|
|
return {
|
|
|
name: '',
|
|
|
value: '',
|