feat: use @javatypes defiend java type
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
9b5a303c21
commit
53ee92e20d
@ -1,9 +1,12 @@
|
||||
import { ConnectionFactoryAdapter } from "./connection"
|
||||
import { RabbitTemplateAdapter } from "./template"
|
||||
import { JSClass } from "@ccms/container"
|
||||
|
||||
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
|
||||
export class RabbitAdminAdapter {
|
||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
private RabbitAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
|
||||
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
|
||||
|
@ -2,7 +2,7 @@ import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
||||
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
||||
|
||||
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
||||
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
||||
export const AcknowledgeMode: org.springframework.amqp.core.AcknowledgeMode = Java.type('org.springframework.amqp.core.AcknowledgeMode')
|
||||
interface ContainerConfig {
|
||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
||||
queueNames: string[]
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { JSClass } from "@ccms/container"
|
||||
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
|
||||
|
||||
const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
|
||||
export class AmqpAdmin {
|
||||
@JSClass('org.springframework.amqp.core.TopicExchange')
|
||||
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
|
||||
@ -10,14 +8,15 @@ export class AmqpAdmin {
|
||||
private Queue: typeof org.springframework.amqp.core.Queue
|
||||
@JSClass('org.springframework.amqp.core.Binding')
|
||||
private Binding: typeof org.springframework.amqp.core.Binding
|
||||
|
||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
||||
private RabbitAdmin: typeof org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
|
||||
private DestinationType: typeof org.springframework.amqp.core.Binding.DestinationType
|
||||
private DestinationType: org.springframework.amqp.core.Binding.DestinationType
|
||||
|
||||
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
||||
|
||||
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
|
||||
if (amqpAdmin instanceof RabbitAdmin) {
|
||||
if (amqpAdmin instanceof this.RabbitAdmin) {
|
||||
this.amqpAdmin = amqpAdmin
|
||||
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
|
||||
this.amqpAdmin = amqpAdmin.getHandler()
|
||||
|
@ -1,8 +1,8 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@ccms/types/dist/typings/jdk" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/amqp" />
|
||||
/// <reference types="@ccms/types/dist/typings/rabbitmq" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-amqp" />
|
||||
/// <reference types="@javatypes/spring-rabbit" />
|
||||
/// <reference types="@javatypes/amqp-client" />
|
||||
|
||||
import { amqp } from '@ccms/api'
|
||||
import { getContainer, reduceMetadata } from '@ccms/container'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/bukkit" />
|
||||
/// <reference types="@javatypes/spigot-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/bungee" />
|
||||
/// <reference types="@javatypes/bungee-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -24,7 +24,8 @@
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/nashorn": "^0.7.0"
|
||||
"@ccms/nashorn": "^0.7.0",
|
||||
"@javatypes/jdk": "^1.14.0"
|
||||
},
|
||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/jdk" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
|
||||
/**
|
||||
* 反射工具类
|
||||
@ -11,7 +11,7 @@ const methodCache = []
|
||||
|
||||
class Reflect {
|
||||
private obj: java.lang.Object
|
||||
private class: java.lang.Class
|
||||
private class: java.lang.Class<any>
|
||||
|
||||
constructor(obj: any) {
|
||||
// if (obj === undefined || obj === null) { throw Error(`reflect object can't be ${obj}!`) }
|
||||
@ -26,8 +26,8 @@ class Reflect {
|
||||
}
|
||||
}
|
||||
|
||||
method(name: string, ...args: any[]) {
|
||||
return declaredMethod(this.class, name, args)
|
||||
method(name: string, ...args: java.lang.Class<any>[]) {
|
||||
return declaredMethod(this.class, name, ...args)
|
||||
}
|
||||
|
||||
methods() {
|
||||
@ -90,7 +90,7 @@ function types(values: any[], def?: any) {
|
||||
if (values === null) {
|
||||
return []
|
||||
}
|
||||
let result: java.lang.Class[] = []
|
||||
let result: java.lang.Class<any>[] = []
|
||||
values.forEach(t => result.push((t || def) ? JavaObject.class : t instanceof JavaClass ? t : t.class))
|
||||
return result
|
||||
}
|
||||
@ -119,7 +119,7 @@ function declaredConstructor(clazz, param) {
|
||||
return accessible(constructor)
|
||||
}
|
||||
|
||||
function declaredField(clazz: java.lang.Class, name: string | java.lang.String) {
|
||||
function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.String) {
|
||||
if (!clazz) { throw Error(`target class can't be ${clazz}!`) }
|
||||
let target = clazz
|
||||
let field = null
|
||||
@ -139,17 +139,17 @@ function declaredField(clazz: java.lang.Class, name: string | java.lang.String)
|
||||
return field
|
||||
}
|
||||
|
||||
function declaredMethod(clazz: java.lang.Class, name: string, ...clazzs: any[]): java.lang.reflect.Method {
|
||||
function declaredMethod(clazz: java.lang.Class<any>, name: string, ...clazzs: java.lang.Class<any>[]): java.lang.reflect.Method {
|
||||
let key = clazz.getName() + '.' + name + ':' + (clazzs || []).join(':')
|
||||
if (!methodCache[key]) {
|
||||
try {
|
||||
methodCache[key] = clazz.getMethod(name, clazzs as any)
|
||||
methodCache[key] = clazz.getMethod(name, ...clazzs)
|
||||
} catch (ex) {
|
||||
try {
|
||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs as any)
|
||||
} catch (ex) {
|
||||
for (const m of Java.from(declaredMethods(clazz))) {
|
||||
if (m.name == name) {
|
||||
if (m.getName() == name) {
|
||||
methodCache[key] = m
|
||||
break
|
||||
}
|
||||
@ -160,8 +160,8 @@ function declaredMethod(clazz: java.lang.Class, name: string, ...clazzs: any[]):
|
||||
return methodCache[key]
|
||||
}
|
||||
|
||||
function declaredMethods(clazz) {
|
||||
return clazz.declaredMethods
|
||||
function declaredMethods(clazz: java.lang.Class<any>) {
|
||||
return clazz.getDeclaredMethods()
|
||||
}
|
||||
|
||||
let classMethodsCache: any[] = []
|
||||
|
@ -1,5 +1,3 @@
|
||||
/// <reference types="@ccms/types/dist/typings/spring" />
|
||||
|
||||
import { Model } from './model'
|
||||
|
||||
const HikariDataSource = Java.type('com.zaxxer.hikari.HikariDataSource')
|
||||
@ -69,7 +67,7 @@ export class DataBase {
|
||||
*/
|
||||
query<T>(sql: string, ...args: any[]): Array<T> {
|
||||
let startTime = Date.now()
|
||||
let result = Java.from(this.jdbcTemplate.queryForList(sql, args))
|
||||
let result = Java.from<any>(this.jdbcTemplate.queryForList(sql, args))
|
||||
console.debug(java.lang.String.format(`\n[DB] query \nSQL : ${sql.replace(/\?/ig, '%s')} \nCOST : ${Date.now() - startTime}ms`, args))
|
||||
return result
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@ccms/types/dist/typings/jdk/index" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/spring-jdbc" />
|
||||
|
||||
export * from './database'
|
||||
export * from './manager'
|
@ -13,8 +13,8 @@ declare global {
|
||||
|
||||
namespace Java {
|
||||
function type<T = any>(clazz: string): T
|
||||
function from<T>(javaObj: T[]): T[]
|
||||
function to<T>(array: T[], type?: T): T[]
|
||||
function from<T = any>(javaObj: T[]): T[]
|
||||
function to<T = any>(array: T[], type?: T): T[]
|
||||
function extend(...parentTypes: any[]): any
|
||||
function synchronized(func: () => void, lock: any): Function
|
||||
function asJSONCompatible<T = any>(obj: T): T
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/nukkit" />
|
||||
/// <reference types="@javatypes/nukkit-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,4 +1,4 @@
|
||||
/// <reference types="@ccms/types/dist/typings/sponge" />
|
||||
/// <reference types="@javatypes/sponge-api" />
|
||||
|
||||
import { server } from '@ccms/api'
|
||||
import { Container } from '@ccms/container'
|
||||
|
@ -1,18 +1,18 @@
|
||||
import { server, constants } from '@ccms/api'
|
||||
import { provideSingleton } from '@ccms/container';
|
||||
import { provideSingleton } from '@ccms/container'
|
||||
|
||||
import * as reflect from '@ccms/common/dist/reflect'
|
||||
|
||||
const Sponge = org.spongepowered.api.Sponge;
|
||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers;
|
||||
const File = Java.type("java.io.File");
|
||||
const Sponge = org.spongepowered.api.Sponge
|
||||
const TextSerializers = org.spongepowered.api.text.serializer.TextSerializers
|
||||
const File = Java.type("java.io.File")
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class SpongeServer extends server.ReflectServer {
|
||||
private pluginsFolder: string;
|
||||
private pluginsFolder: string
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
super()
|
||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||
}
|
||||
|
||||
@ -35,25 +35,25 @@ export class SpongeServer extends server.ReflectServer {
|
||||
if (typeof sender === 'string') {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
return Sponge.getCommandManager().process(sender, command).getQueryResult().get()
|
||||
return Sponge.getCommandManager().process(sender, command).getQueryResult().get() != 0
|
||||
}
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult().get()
|
||||
return Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command).getQueryResult().get() != 0
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
return this.pluginsFolder
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Sponge.getPluginManager() as any;
|
||||
return Sponge.getPluginManager() as any
|
||||
}
|
||||
getDedicatedServer() {
|
||||
return reflect.on(Sponge.getServer()).get()
|
||||
}
|
||||
getNettyPipeline() {
|
||||
return this.pipeline;
|
||||
return this.pipeline
|
||||
}
|
||||
getRootLogger() {
|
||||
return this.rootLogger;
|
||||
return this.rootLogger
|
||||
}
|
||||
sendJson(sender: string | any, json: string): void {
|
||||
if (typeof sender === "string") {
|
||||
|
@ -24,6 +24,7 @@
|
||||
"typescript": "^3.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ccms/api": "^0.7.0",
|
||||
"@ccms/container": "^0.7.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
/// <reference types="@ccms/types/dist/typings/jdk/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/tomcat/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/index" />
|
||||
/// <reference types="@ccms/types/dist/typings/spring/beans/index" />
|
||||
/// <reference types="@ccms/nashorn" />
|
||||
/// <reference types="@javatypes/jdk" />
|
||||
/// <reference types="@javatypes/tomcat" />
|
||||
/// <reference types="@javatypes/spring-web" />
|
||||
/// <reference types="@javatypes/spring-core" />
|
||||
/// <reference types="@javatypes/spring-beans" />
|
||||
|
||||
export * from './server'
|
||||
export * from './decorators'
|
||||
|
Loading…
Reference in New Issue
Block a user