All Projects → bsorrentino → java2typescript

bsorrentino / java2typescript

Licence: MIT license
Java Processor to generate Typescript Definition from Java classes - This is to help developing on JVM javascript engine (ie Nashorn) using Typescript

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to java2typescript

Quickperf
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties
Stars: ✭ 231 (+862.5%)
Mutual labels:  jvm
Javaguide
「Java学习+面试指南」一份涵盖大部分 Java 程序员所需要掌握的核心知识。准备 Java 面试,首选 JavaGuide!
Stars: ✭ 114,707 (+477845.83%)
Mutual labels:  jvm
LLVM-JVM
[W.I.P] A Just-In-Time Java Virtual Machine written in Haskell
Stars: ✭ 22 (-8.33%)
Mutual labels:  jvm
Smallrye Mutiny
An Intuitive Event-Driven Reactive Programming Library for Java
Stars: ✭ 231 (+862.5%)
Mutual labels:  jvm
Argon2 Jvm
Argon2 Binding for the JVM
Stars: ✭ 245 (+920.83%)
Mutual labels:  jvm
pitifulvm
A shabby implementation of Java virtual machine in C
Stars: ✭ 124 (+416.67%)
Mutual labels:  jvm
Future
High-performance Future implementation for the JVM
Stars: ✭ 223 (+829.17%)
Mutual labels:  jvm
gchisto
GC日志分析工具,网上不容易找到源码,这里备份一个。不确定工具是否正确,不确定是否有时间研究。
Stars: ✭ 32 (+33.33%)
Mutual labels:  jvm
Konfig
Simple config properties API for Kotlin
Stars: ✭ 249 (+937.5%)
Mutual labels:  jvm
mleap
R Interface to MLeap
Stars: ✭ 24 (+0%)
Mutual labels:  jvm
My Review
主要存放平时理论学习,比如java jdk源码分析、并发理论;面试、数据库、Linux、中间件、分布式、网络协议等方向
Stars: ✭ 237 (+887.5%)
Mutual labels:  jvm
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+11575%)
Mutual labels:  jvm
java-server-sdk
LaunchDarkly Server-Side SDK for Java
Stars: ✭ 71 (+195.83%)
Mutual labels:  jvm
Python Jvm Interpreter
Java Virtual Machine implementation in Python
Stars: ✭ 232 (+866.67%)
Mutual labels:  jvm
Computer-Science-Learn-Notes
CS(Computer Science)生涯:读书笔记,集成Java知识体系!(Java基础、JVM、JUC、Spring系列、面试八股文、力扣刷题笔记,数据结构和算法、SpringBoot整合其他框架等)
Stars: ✭ 141 (+487.5%)
Mutual labels:  jvm
Paguro
Generic, Null-safe, Immutable Collections and Functional Transformations for the JVM
Stars: ✭ 231 (+862.5%)
Mutual labels:  jvm
doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-8.33%)
Mutual labels:  jvm
sconfig
Scala configuration library supporting HOCON for Scala, Java, Scala.js, and Scala Native
Stars: ✭ 99 (+312.5%)
Mutual labels:  jvm
oh-my-jvm
☕️ using golang write jvm
Stars: ✭ 16 (-33.33%)
Mutual labels:  jvm
play-scala-fileupload-example
An example Play application showing custom multiform fileupload in Scala
Stars: ✭ 29 (+20.83%)
Mutual labels:  jvm

java2typescript

Join the chat at https://gitter.im/bsorrentino/java2typescript

Java Processor to generate Typescript Definition file (.d.ts) from whatever Java classes.

Diagram of solution

java2ts diagram

What is it for ?

This is to help developing on JVM javascript engine, either GraalJs or Rhino using Typescript

Nashorn has been DEPRECATED (refer to JEP335 )

The main goal is having the definitions available in the modern IDE like Visual Studio Code and Atom and then use the intellisense feature available for java classes within typescript

What is it not for ?

It is not a transpiler from Java to Javascript like datathings/java2typescript

Similar projects

typescript-generator is a tool for generating TypeScript definition files (.d.ts) from Java JSON classes. If you have REST service written in Java using object to JSON mapping you can use typescript-generator to generate TypeScript interfaces from Java classes.

1c is aimed to compile TypeScript to runnable code on both JVM and web browser. You can implement the full stack with TypeScript while using libraries from Maven and NPM together.

Related Project

NPM compliant CommonJS module loader for the JVM

DEMO

To give an idea about how to work there is a demo available online here.

The backend of such demo has been developed using typescript on jvm provided by this project itself (dogfooding). java2typescript-demo project

Description

Basic idea is to develop a Project by mixing Java & Javascript code (or completely in Javascript) relying on the Nashorn Javascript engine or Rhino javascript engine. This powerful engines enable Javascript language in JVM and they allow to access to every java class present in classpath in a pretty straightforward way. That's cool, the Javascript is very easy to learn, but the question are :

  1. Is it possible develop a complete and well structured Javascript application ?
  2. Developing in Javascript on JVM is as productive as programming in Java ?

Just to answer the questions above that this project has been developed.

  1. Is it possible develop a complete and well structured Javascript application ?

Yes it is, but with help of a powerful Typescript that fills language's gaps and produce Javascript as output

  1. Developing in Javascript on JVM is as productive as programming in Java ?

Yes it could be, but we need :

  • An IDE with intellisense capability that is able to inspect java/javascript classes during development.

This is the main goal of project, that is to generate Typescript Declarations enabling every Typescript-Aware IDE (eg. Atom, VSCode) to give you the intellisense feature make more comfortable use access to Java features/classes from Javascript

  • A module module system that allow to arrange application in separate well-defined modules

This is achieved by project jvm-npm that enable use of commonJS enabling Typescript Modules.

Getting Started

Let assume that you have successfully setup a java project

Declares the classes you want to generate the Typescript declaration for

Create a file package-info.java and annotate the given package with @Java2TS that will contain all the @Type of which you want the Typescript declaration.

** Type Attributes **

Name Mandatory Type Description
value Yes Class Full Qualified Name of Java class
alias No String Assign a new name to exported class in typescript
export No boolean If true, other than typescript declaration adds definition in file *-types.ts. It is need for instantiable classes, in order to use new operator or factory method(s)
functional No boolean If true other than typescript declaration adds a particular definition. Valid only for interfaces that have one abstract method and haven't @FunctionalInterface annotation

Example

@Java2TS(declare = {

  @Type(java.nio.file.Files.class, export="true"),
  @Type(java.nio.file.Path.class),
  @Type(java.nio.file.Paths.class, export="true"),

  @Type(value=java.util.stream.Stream.class,export=true),

  @Type(java.util.Collection.class),
  @Type(java.util.Map.class),
  @Type(value=java.util.List.class, alias="List" ),
  @Type(java.util.Set.class),
  @Type(value=java.util.Arrays.class, export=true),

  @Type(java.util.Optional.class),

  @Type(value=java.net.URI.class, export=true),
  @Type(java.net.URL.class),

  @Type(java.lang.Runnable.class, functional=true)

})
package org.mypackage;

Add the dependency containing the Java2TS Processor

<dependency>
  <groupId>org.bsc.processor</groupId>
  <artifactId>java2ts-processor</artifactId>
  <version>version</version>
</dependency>

Add the Annotation Processor Plugin

Graajs compatibility see samples

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>3.3.3</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
          <outputDirectory>${project.build.directory}</outputDirectory>
       <options>
            <ts.outfile>name</ts.outfile><!-- name of generated file -->
       </options>
      </configuration>
    </execution>
  </executions>
</plugin>

Enforce Rhino compatibility see samples

<plugin>
  <groupId>org.bsc.maven</groupId>
  <artifactId>maven-processor-plugin</artifactId>
  <version>3.3.3</version>
  <executions>
    <execution>
      <id>process</id>
      <goals>
        <goal>process</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
          <outputDirectory>${project.build.directory}</outputDirectory>
       <options>
            <ts.outfile>name</ts.outfile><!-- name of generated file -->
            <compatibility>rhino</compatibility>
       </options>
      </configuration>
    </execution>
  </executions>
</plugin>

Use Maven Archetype

The easier way to start your Typescript on JVM project is using the provided maven archetype

Interactive Mode

mvn archetype:generate \
-DarchetypeGroupId=org.bsc.processor \
-DarchetypeArtifactId=java2ts-processor-archetype \
-DarchetypeVersion=1.1.0
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].