All Downloads are FREE. Search and download functionalities are using the official Maven repository.

vertx-typescript.template.ts.templ Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
@includeNamed{'/vertx-java/template/common-lib.templ'}

@code{
  def renderLinkToHtml(link) {
    return null;
  }
}

@comment{"Generate the module name of a type"}
@comment{"=================================="}

@code{
  def genModuleName(moduleType) {
    String sn = helper.convertCamelCaseToUnderscores(moduleType.raw.simpleName);
    if (!type.raw.moduleName.equals(moduleType.raw.moduleName)) {
      sn = "../" + moduleType.raw.moduleName + "-js/" + sn;
    }
    return sn + '.d.ts';
  }
}

@comment{"Generate the TypeScript type of a type"}
@comment{"======================================"}

@code{
  def genTSType(type) {
    if (type.kind == CLASS_STRING) {
      return 'string';
    } else if (type.kind == CLASS_PRIMITIVE || type.kind == CLASS_BOXED_PRIMITIVE) {
      if (type.simpleName == 'boolean' || type.simpleName == 'Boolean') {
        return 'boolean';
      } else if (type.simpleName == 'char' || type.simpleName == 'Character') {
        return 'string';
      } else {
        return 'number';
      }
    } else if (type.kind == CLASS_JSON_OBJECT) {
      return 'any';
    } else if (type.kind == CLASS_DATA_OBJECT) {
      return 'any';
    } else if (type.kind == CLASS_JSON_ARRAY) {
      return 'any[]';
    } else if (type.kind == CLASS_ENUM) {
      return 'any';
    } else if (type.kind == CLASS_API) {
      return type.raw.simpleName;
    } else if (type.kind.collection) {
      return 'Array<' + genTSType(type.args[0]) + '>';
    } else if (type.kind == CLASS_MAP) {
      return 'any';
    } else if (type.kind == CLASS_OBJECT) {
      return 'any';
    } else if (type.kind == CLASS_HANDLER) {
      if (type.args[0].kind == CLASS_ASYNC_RESULT) {
        return '(res: ' + genTSType(type.args[0].args[0]) + ', err?: Throwable) => void';
      } else {
        return '(e: ' + genTSType(type.args[0]) + ') => void';
      }
    } else if (type.name.equals('void') || type.kind == CLASS_VOID) {
      return 'void';
    } else {
      return type.raw.simpleName;
    }
  }
}

@comment{"Generate a method"}
@comment{"================="}

@declare{'genMethod'} 
  @if{method.staticMethod == static}
  @if{method.doc != null}
  /**
  @{renderDocToHtml(" *", method.doc, renderLinkToHtml)}
   */@end{}
  @{method.name}(@foreach{param: method.params}@{param.name}: @{genTSType(param.type)}@end{", "}): @{genTSType(method.returnType)};
  @end{}
@end{}

@comment{"Generate interface"}
@comment{"=================="}

@if{type.raw.moduleName.equals("vertx")}
/// 
@else{}
/// 
/// 
@end{}
@if{ifaceSimpleName == 'Vertx'}
/// 
@end{}
@foreach{referencedType : referencedTypes}
/// 
@end{}

declare module "@{type.raw.moduleName}-js/@{helper.convertCamelCaseToUnderscores(type.raw.simpleName)}" {
  export = @{ifaceSimpleName};
}

@if{doc != null}
/**
@{renderDocToHtml(" *", doc, renderLinkToHtml)}
 */@end{}
interface @{ifaceSimpleName}

@if{concreteSuperTypes.size() > 0}
  extends
  @foreach{concreteSuperType: concreteSuperTypes}
    @{genTSType(concreteSuperType)}
  @end{}
@end{}

@if{abstractSuperTypes.size() > 0}
  extends
  @foreach{abstractSuperType: abstractSuperTypes}
    @{genTSType(abstractSuperType)}
  @end{', '}
@end{}

@comment{"TODO handle this!!"}
@comment{
@if{handlerSuperType != null}
  @if{abstractSuperTypes.empty}
    extends
  @else{}
    ,
  @end{}
  Handler
@end{}
}

{
  @foreach{method:methods}
    @includeNamed{'genMethod';static=false}
  @end{}
}

@comment{"Check if there are static methods"}
@code{hasStaticMethods = false}
@foreach{method:methods}
  @if{method.staticMethod}@code{hasStaticMethods = true}@end{}
@end{}

declare var @{ifaceSimpleName}: {
  new(): @{ifaceSimpleName};
@if{hasStaticMethods}
@foreach{method:methods}
  @includeNamed{'genMethod';static=true}
@end{}
@end{}
}

@if{ifaceSimpleName == 'Vertx'}
declare var vertx: Vertx;
declare var console: Console;
@end{}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy