Skip to content
Permalink
Browse files
Merge branch 'master' of https://github.com/dubbo/dubbo2.js
  • Loading branch information
hufeng committed Apr 24, 2018
2 parents 9f7f529 + e58aa87 commit ca917cac6ba0fc45ffcfda6154244a790c92d02f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 12 deletions.
@@ -22,6 +22,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<source>1.7</source>
<target>1.7</target>
</configuration>
@@ -1,9 +1,9 @@
import {TypeRequest} from './TypeRequest';
import {TDubboCallResult, Dubbo} from 'dubbo2.js';
import {argumentMap} from 'interpret-util';
import {TDubboCallResult, Dubbo} from 'dubbo2.js';

export interface IBasicTypeProvider {
testBasicType(TypeRequest0: TypeRequest): TDubboCallResult<TypeRequest>;
testBasicType(request: TypeRequest): TDubboCallResult<TypeRequest>;
}

export const BasicTypeProviderWrapper = {testBasicType: argumentMap};
@@ -1,13 +1,13 @@
import {UserRequest} from './UserRequest';
import {UserResponse} from './UserResponse';
import {argumentMap, JavaString} from 'interpret-util';
import {TDubboCallResult, Dubbo} from 'dubbo2.js';
import {argumentMap} from 'interpret-util';

export interface IDemoProvider {
sayHello(String0: string): TDubboCallResult<string>;
sayHello(name: JavaString): TDubboCallResult<string>;
test(): TDubboCallResult<void>;
echo(): TDubboCallResult<string>;
getUserInfo(UserRequest0: UserRequest): TDubboCallResult<UserResponse>;
getUserInfo(request: UserRequest): TDubboCallResult<UserResponse>;
}

export const DemoProviderWrapper = {
@@ -1,5 +1,5 @@
import {TDubboCallResult, Dubbo} from 'dubbo2.js';
import {argumentMap} from 'interpret-util';
import {TDubboCallResult, Dubbo} from 'dubbo2.js';

export interface IErrorProvider {
errorTest(): TDubboCallResult<void>;
@@ -51,6 +51,8 @@ export async function toInterface(

log('添加过滤方法:: %j', filtersMethodNames);

//add extra javaType declare;
let extraImport: string[] = ['argumentMap'];
for (let methodName in typeDef.methods) {
if (filtersMethodNames.includes(methodName)) {
continue;
@@ -60,11 +62,42 @@ export async function toInterface(
methodName = methodName.substring(0, methodName.lastIndexOf('@override'));
}

methods.push(
await toMethod(methodName, typeDef.methods[methodName], intepretHandle),
let methodItem = await toMethod(
methodName,
typeDef.methods[methodName],
intepretHandle,
);

//如果是基本类型, 生成typescript的类型与js-to-java类型相对应 javaXXX;
let methodDef = typeDef.methods[methodName];

for (var i = 0, iLen = methodDef.params.length; i < iLen; i++) {
var paramItem = methodDef.params[i];
if (paramItem.isArray) {
if (TypeMap[paramItem.elementType.name]) {
methodItem.parameters[i].type =
TypeMap[paramItem.elementType.name] + '[]';
if (!extraImport.includes(TypeMap[paramItem.elementType.name])) {
extraImport.push(TypeMap[paramItem.elementType.name]);
}
}
} else {
if (TypeMap[paramItem.name]) {
methodItem.parameters[i].type = TypeMap[paramItem.name];
if (!extraImport.includes(TypeMap[paramItem.name])) {
extraImport.push(TypeMap[paramItem.name]);
}
}
}
}
methods.push(methodItem);
}

intepretHandle.sourceFile.addImport({
moduleSpecifier: 'interpret-util',
defaultImport: `{${extraImport.join(',')}}`,
});

log('转换 名称::%s 属性 :%j 方法:%j', typeDef.name, properties, methods);

return {
@@ -89,3 +122,27 @@ export function genePropsGetSet(propsNames: string[]) {
});
return filtersMethodNames;
}

const TypeMap = {
'java.lang.Boolean': 'JavaBoolean',
boolean: 'JavaBoolean',
'java.lang.Integer': 'JavaInteger',
int: 'Javaint',
short: 'Javashort',
'java.lang.Short': 'JavaShort',
byte: 'Javabyte',
'java.lang.Byte': 'JavaByte',
long: 'Javalong',
'java.lang.Long': 'JavaLong',
double: 'Javadouble',
'java.lang.Double': 'JavaDouble',
float: 'Javafloat',
'java.lang.Float': 'JavaFloat',
'java.lang.String': 'JavaString',
char: 'Javachar',
'java.lang.Character': 'bbbbb',
'java.util.List': 'JavaList',
'java.util.Set': 'JavaSet',
'java.util.HashMap': 'JavaHashMap',
'java.util.Map': 'JavaMap',
};
@@ -65,10 +65,6 @@ export async function toTypescript(
moduleSpecifier: 'dubbo2.js',
defaultImport: '{TDubboCallResult,Dubbo}',
});
sourceFile.addImport({
moduleSpecifier: 'interpret-util',
defaultImport: '{argumentMap}',
});
sourceFile.addFunction(
toProxyFunc({
typeName: intepretHandle.classPath.substring(
@@ -54,3 +54,25 @@ function minusRedundancy(itemParam: any) {
}
}
}

export type JavaString=Object;
export type JavaBoolean=Object;
export type Javaboolean=Object;
export type JavaInteger=Object;
export type Javaint=Object;
export type JavaShort=Object;
export type Javashort=Object;
export type Javabyte=Object;
export type JavaByte=Object;
export type JavaLong=Object;
export type Javalong=Object;
export type Javadouble=Object;
export type JavaDouble=Object;
export type Javafloat=Object;
export type JavaFloat=Object;
export type Javachar=Object;
export type Javachars=Object;
export type JavaList=Object;
export type JavaSet=Object;
export type JavaHashMap=Object;
export type JavaMap=Object;

0 comments on commit ca917ca

Please sign in to comment.