### Line numbering example Source: https://jtsgen.readthedocs.io/en/latest/Build.html A simple list of line numbers used for reference. ```text 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ``` -------------------------------- ### Configure jtsgen in Maven pom.xml Source: https://jtsgen.readthedocs.io/en/latest/Maven.html A complete example showing the dependency setup with 'provided' scope and maven-compiler-plugin configuration for output directory and compiler arguments. ```xml 4.0.0 jtsgen-example api 1.0.0-SNAPSHOT com.github.dzuvic jtsgen-processor 0.4.0 provided org.apache.maven.plugins maven-compiler-plugin 3.3 1.8 1.8 1.8 ../client/src -AjtsgenLogLevel=info ``` -------------------------------- ### Build the project on Linux Source: https://jtsgen.readthedocs.io/en/latest/Build.html Execute the Gradle build command in a Linux environment. ```bash $ ./gradlew build Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0. See https://docs.gradle.org/4.8/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 14s 18 actionable tasks: 10 executed, 8 up-to-date ``` -------------------------------- ### Configure Getter and Setter Prefixes Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html Default regular expressions used by TSModule to identify getter and setter methods. ```text getterPrefixes default: { "get([_a-zA-Z0-9].*)", "is([_a-zA-Z0-9]].*)" } ``` ```text setterPrefixes default: { "set([_a-zA-Z0-9]].*)"} ``` -------------------------------- ### Configuring jtsgen via javac parameters Source: https://jtsgen.readthedocs.io/en/latest/Usage.html Pass configuration parameters to the annotation processor using the -A prefix with the javac command. ```bash javac -AjtsgenLogLevel=FINEST MyClass.java ``` -------------------------------- ### Customize output directory Source: https://jtsgen.readthedocs.io/en/latest/Gradle.html Set the compiler arguments to define the target directory for generated TypeScript files. ```groovy def tsOutDir="${buildDir}/ts" compileJava { options.compilerArgs = [ "-s", tsOutDir ] dependsOn(createTsDir) } ``` -------------------------------- ### Configure jtsgen with Kotlin kapt Source: https://jtsgen.readthedocs.io/en/latest/Gradle.html Enable the kotlin-kapt plugin and configure the processor for Kotlin class conversion. ```groovy apply plugin: 'kotlin-kapt' dependencies { compileOnly "com.github.dzuvic:jtsgen-annotations:${jtsgen_Version}" compileOnly "com.github.dzuvic:jtsgen-processor:${jtsgen_Version}" kapt "com.github.dzuvic:jtsgen-processor:${jtsgen_Version}" } kapt { correctErrorTypes = true arguments { arg("jtsgenModuleVersion", version) } } ``` -------------------------------- ### Configure jtsgen dependencies Source: https://jtsgen.readthedocs.io/en/latest/Gradle.html Add jtsgen annotations and processor as compile-time dependencies. ```groovy dependencies { compileOnly "com.github.dzuvic:jtsgen-annotations:${jtsgen_Version}" compileOnly "com.github.dzuvic:jtsgen-processor:${jtsgen_Version}" } ``` -------------------------------- ### Applying the TSModule Annotation Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html The TSModule annotation must be applied to a package element within the compilation unit. ```java @TSModule( moduleName = "namespace_test", nameSpaceMapping = "jts.modules.nsmap -> easy" ) package jts.modules.nsmap; import dz.jtsgen.annotations.TSModule; ``` -------------------------------- ### Define a basic Java to TypeScript type mapping Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html Maps a specific Java canonical type to a target TypeScript type. ```text java.util.Date -> IDateJSStatic ``` -------------------------------- ### Configure jtsgen for Gradle 4.6+ Source: https://jtsgen.readthedocs.io/en/latest/Gradle.html Use the annotationProcessor configuration to ensure the processor is correctly detected by the compiler. ```groovy dependencies { compileOnly "com.github.dzuvic:jtsgen-annotations:${jtsgen_Version}" compileOnly "com.github.dzuvic:jtsgen-processor:${jtsgen_Version}" annotationProcessor "com.github.dzuvic:jtsgen-processor:${jtsgen_Version}" } ``` -------------------------------- ### Mapping DSL grammar definition Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html The ANTLR BNF variant defining the syntax for the mapping DSL. ```text mapping : origin whsp* arrow whsp* target; arrow : '->' | '|->' origin : jident ( '.' , jident )* tsAngleType? target : ( jident '.' )* tstypes+ tsLit : tsChar* tsAngleType : '<' jident ( ',' jident )* '>' tsLitType : '`' jident '`' tsTypes : tstype | ( tstype whtsp )* tsType : tsLit | tsangletype | tslittype | whtsp jident : ('a'-'z' | 'A' - 'Z' | '_' ) ('a'-'z' | 'A' - 'Z' | '_' | '0' - '9')* tsChar : * all chars expecpt '<' | '>' | '`' * ``` -------------------------------- ### Define a Java data class Source: https://jtsgen.readthedocs.io/en/latest/Introduction.html A sample Java class representing a data model that will be processed by jtsgen. ```java public class Person { private String name; private LocalDate birthdate; private Sex sex; public Person(String name, LocalDate birthdate, Sex sex) { this.name = name; this.birthdate = birthdate; this.sex = sex; } public String getName() { return name; } public void setName(String name) { this.name = name; } public LocalDate getBirthdate() { return birthdate; } //... } ``` -------------------------------- ### Define a Java to TypeScript mapping with literal embedding Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html Uses backticks to embed TypeScript types literally, such as array syntax. ```text java.util.List -> `T`[] ``` -------------------------------- ### Define a Java to TypeScript mapping with type variables Source: https://jtsgen.readthedocs.io/en/latest/Customizing.html Uses type variables to convert generic Java types to corresponding TypeScript generic types. ```text java.util.List -> Array ``` -------------------------------- ### Configure Optional Type Mapping Source: https://jtsgen.readthedocs.io/en/latest/Appendix.html Use this annotation to map Java Optional types to TypeScript optional types with undefined support. ```java @TSModule( moduleName = "myModule", customTypeMappings = { "java.util.Optional[T] -> `T` | undefined" } ) ``` -------------------------------- ### Define jtsgen version in Gradle Source: https://jtsgen.readthedocs.io/en/latest/Gradle.html Store the jtsgen version in an extension variable for consistent dependency management. ```groovy buildscript { ext { jtsgen_Version="0.4.0" } } ``` -------------------------------- ### Generated TypeScript output Source: https://jtsgen.readthedocs.io/en/latest/Introduction.html The resulting TypeScript interface and enum generated from the corresponding Java class. ```typescript export enum Sex { M, F } export interface Person { birthdate: string; sex: Sex; name: string; } ``` -------------------------------- ### Annotating a Java interface for TypeScript conversion Source: https://jtsgen.readthedocs.io/en/latest/Usage.html Apply the @TypeScript annotation to any Java class, interface, or enum to trigger the conversion process during compilation. ```java @TypeScript public interface InterFaceSample { int getSomeInt(); String getSomeString(); } ``` -------------------------------- ### TSType model definition Source: https://jtsgen.readthedocs.io/en/latest/Build.html The abstract class representing the converted type information within the jtsgen processor. ```java /* * Copyright (c) 2017 Dragan Zuvic * * This file is part of jtsgen. * * jtsgen is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * jtsgen is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with jtsgen. If not, see http://www.gnu.org/licenses/ * */ package dz.jtsgen.processor.model; import dz.jtsgen.processor.model.rendering.TSTypeElement; import org.immutables.value.Value; import javax.lang.model.element.Element; import java.util.List; import java.util.Optional; import static dz.jtsgen.processor.util.StringUtils.lastOf; import static dz.jtsgen.processor.util.StringUtils.untill; /** * This type contains all information about a converted type */ public abstract class TSType implements TSTypeElement { @Value.Default public String getNamespace() { return untill(this.getElement().toString()); } @Value.Default public String getName() { return lastOf(this.getElement().toString()); } public abstract List getMembers(); public abstract List getConstants(); public abstract Optional getDocumentString(); public abstract List getSuperTypes(); public abstract List getTypeParams(); @Value.Parameter public abstract Element getElement(); public abstract String getKeyword(); public abstract TSType changedNamespace(String namespace, List members, List methods, List mappedConstants); public abstract List getMethods(); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.