UNPKG

interpret-dubbo2js

Version:

apache dubbo & dubbo-js interpret java-jar file to typescript files

62 lines (61 loc) 2.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const debug_1 = __importDefault(require("debug")); const type_parse_1 = require("../util/type-parse"); const log = debug_1.default('j2t:core:toMethod'); /** * java方法转换为typescript method-ast ; * @param methodDef * @returns {MethodSignatureStructure} */ async function toMethod(methodName, methodDef, intepretHandle) { log('调用转换方法 toMethod::', methodName, methodDef); let parameters = []; for (var i = 0, iLen = methodDef.params.length; i < iLen; i++) { var paramItem = methodDef.params[i]; if (paramItem.isArray) { let type = await type_parse_1.jType2Ts(paramItem.elementType, intepretHandle); let name = (methodDef.formalParams && methodDef.formalParams[i]) || paramItem.elementType.name.substring(paramItem.elementType.name.lastIndexOf('.') + 1) + i; parameters.push({ name, type: type + '[]', }); } else { let type = await type_parse_1.jType2Ts(paramItem, intepretHandle); let name = (methodDef.formalParams && methodDef.formalParams[i]) || paramItem.name.substring(paramItem.name.lastIndexOf('.') + 1) + i; parameters.push({ name, type, }); } } let returnType = await type_parse_1.jType2Ts(methodDef.ret, intepretHandle); return { name: methodName, parameters, returnType: `TDubboCallResult<${returnType}>`, }; } exports.toMethod = toMethod;