import {DecoratorImpl} from "./DecoratorImpl"; import {DecoratorAttributes} from "./DecoratorAttributes"; import {IOException, NoSuchElementException} from "../Exception"; export type accessorGetFunc = ()=>T export type accessorSetFunc = ( value: T )=>void export type getStringFunc = accessorGetFunc export type getNumberFunc = accessorGetFunc export type getObjectFunc = accessorGetFunc export type getBooleanFunc= accessorGetFunc export type getStringFuncA = accessorGetFunc export type getNumberFuncA = accessorGetFunc export type getObjectFuncA = accessorGetFunc export type getBooleanFuncA= accessorGetFunc export type setStringFunc = accessorSetFunc export type setNumberFunc = accessorSetFunc export type setObjectFunc = accessorSetFunc export type setBooleanFunc= accessorSetFunc export type setStringFuncA = accessorSetFunc export type setNumberFuncA = accessorSetFunc export type setObjectFuncA = accessorSetFunc export type setBooleanFuncA= accessorSetFunc export abstract class Lombok{ public static GETTER( orThrow: boolean = false ):Function{ return DecoratorImpl.attributeDecorator(DecoratorAttributes .empty() .final() .setDecorator("GETTER") .propertyName((target:string)=>"get"+target.substr(0,1).toUpperCase()+target.substr(1,target.length)) .setMethod(function(target:string){ try {return this[target];}catch (e) { if(orThrow) new NoSuchElementException(`Lombok : Getter element [ ${target} ] not found !`); return null; } }).getSink()); } public static SETTER():Function{ return DecoratorImpl.attributeDecorator(DecoratorAttributes .empty() .final() .setDecorator("SETTER") .propertyName((target:string)=> "set"+target.substr(0,1).toUpperCase()+target.substr(1,target.length)) .setMethod(function(value:T,target:string){ try{this[target] = value;}catch (e) { throw new IOException(`Lombok : Setter method [ ${target} ] not found !`) } return void 0; }).getSink()); } }