Skip to content

Commit 3b9f840

Browse files
committed
Merge branch 'release/2.0-20241009'
2 parents 08be7a0 + a46e728 commit 3b9f840

36 files changed

Lines changed: 1268 additions & 675 deletions

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ bin/
2121

2222
.idea/
2323
*.iml
24-
package-lock.json
24+
25+
/.java-version
26+
/.mvn/

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,35 @@
55

66
[![Join the chat at https://gitter.im/bsorrentino/java2typescript](https://badges.gitter.im/bsorrentino/java2typescript.svg)](https://gitter.im/bsorrentino/java2typescript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
77

8-
Java Processor to **generate [Typescript](https://www.typescriptlang.org/) Definition file (.d.ts)** from whatever Java classes.
8+
Java Processor to **generate [Typescript](https://www.typescriptlang.org/) Definition file (`.d.ts`)** from whatever Java classes.
99

1010
## Diagram of solution
1111

12-
![java2ts diagram](images/java2ts2.png)
12+
```mermaid
13+
---
14+
title: Java to TypeScript Conversion Process
15+
---
16+
flowchart LR
17+
18+
subgraph "Java Compiler"
19+
B(Java2TypeScript Processor)
20+
end
21+
22+
subgraph "Java Project"
23+
direction LR
24+
A[Package_Info.java]:::javaSrc ---|Lookup annotations| B
25+
C[Dependencies Classpath]:::javaSrc ---|Lookup classes| B
26+
end
27+
28+
subgraph "Typescript"
29+
D[<Output>.d.ts]:::tsFile
30+
E[<Output>_types.ts]:::tsFile
31+
end
32+
33+
B o-->|Generate| D
34+
B o-->|Generate| E
35+
36+
```
1337

1438
## What is it for ?
1539

@@ -29,10 +53,10 @@ It is not a transpiler from Java to Javascript like [datathings/java2typescript
2953
* [1c](https://1c.wizawu.com/#/whatis)
3054
> 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.
3155
32-
## Related Project
56+
## Modules Support
3357

34-
* [jvm-npm](https://github.com/bsorrentino/jvm-npm)
35-
> NPM compliant CommonJS module loader for the JVM
58+
* Rhino is compliant with CommonJS module loader for the JVM
59+
> Graaljs is compliant with ES6 module loader for the JVM
3660
3761
## DEMO
3862

@@ -124,7 +148,7 @@ package org.mypackage;
124148
<plugin>
125149
<groupId>org.bsc.maven</groupId>
126150
<artifactId>maven-processor-plugin</artifactId>
127-
<version>3.3.3</version>
151+
<version>5.1</version>
128152
<executions>
129153
<execution>
130154
<id>process</id>
@@ -150,7 +174,7 @@ package org.mypackage;
150174
<plugin>
151175
<groupId>org.bsc.maven</groupId>
152176
<artifactId>maven-processor-plugin</artifactId>
153-
<version>3.3.3</version>
177+
<version>5.1</version>
154178
<executions>
155179
<execution>
156180
<id>process</id>

archetype/pom.xml

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,52 @@
11
<?xml version="1.0"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4-
<modelVersion>4.0.0</modelVersion>
5-
<parent>
6-
<groupId>org.bsc.processor</groupId>
7-
<artifactId>java2ts-processor-parent</artifactId>
8-
<version>1.4.0</version>
9-
</parent>
10-
<artifactId>java2ts-processor-archetype</artifactId>
11-
<name>java2ts-processor::archetype</name>
12-
<packaging>maven-archetype</packaging>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.bsc.processor</groupId>
8+
<artifactId>java2ts-processor-parent</artifactId>
9+
<version>2.0-20241009</version>
10+
</parent>
11+
<artifactId>java2ts-processor-archetype</artifactId>
12+
<name>java2ts-processor::archetype</name>
13+
<packaging>maven-archetype</packaging>
1314

14-
<build>
15-
<extensions>
16-
<extension>
17-
<groupId>org.apache.maven.archetype</groupId>
18-
<artifactId>archetype-packaging</artifactId>
19-
<version>3.0.1</version>
20-
</extension>
21-
</extensions>
22-
<!--
23-
<resources>
24-
<resource>
25-
<directory>src/main/resources</directory>
26-
<filtering>true</filtering>
27-
<includes>
28-
<include>archetype-resources/pom.xml</include>
29-
</includes>
30-
</resource>
31-
</resources>
32-
-->
33-
<plugins>
15+
<build>
16+
<extensions>
17+
<extension>
18+
<groupId>org.apache.maven.archetype</groupId>
19+
<artifactId>archetype-packaging</artifactId>
20+
<version>3.3.0</version>
21+
</extension>
22+
</extensions>
3423

35-
<plugin>
36-
<artifactId>maven-resources-plugin</artifactId>
37-
<version>3.0.2</version>
38-
<executions>
39-
<execution>
40-
<id>copy-resources</id>
41-
<!-- here the phase you need -->
42-
<phase>validate</phase>
43-
<goals>
44-
<goal>copy-resources</goal>
45-
</goals>
46-
<configuration>
47-
<escapeString>\</escapeString>
48-
<outputDirectory>${project.build.outputDirectory}/archetype-resources</outputDirectory>
49-
<resources>
50-
<resource>
51-
<directory>${basedir}/tofilter</directory>
52-
<filtering>true</filtering>
53-
</resource>
54-
</resources>
55-
</configuration>
56-
</execution>
57-
</executions>
58-
</plugin>
24+
<plugins>
5925

60-
</plugins>
26+
<plugin>
27+
<artifactId>maven-resources-plugin</artifactId>
28+
<executions>
29+
<execution>
30+
<id>copy-resources</id>
31+
<!-- here the phase you need -->
32+
<phase>validate</phase>
33+
<goals>
34+
<goal>copy-resources</goal>
35+
</goals>
36+
<configuration>
37+
<escapeString>\</escapeString>
38+
<outputDirectory>${project.build.outputDirectory}/archetype-resources</outputDirectory>
39+
<resources>
40+
<resource>
41+
<directory>${basedir}/tofilter</directory>
42+
<filtering>true</filtering>
43+
</resource>
44+
</resources>
45+
</configuration>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
50+
</plugins>
6151
</build>
6252
</project>

core/pom.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
<parent>
55
<groupId>org.bsc.processor</groupId>
66
<artifactId>java2ts-processor-parent</artifactId>
7-
<version>1.4.0</version>
7+
<version>2.0-20241009</version>
88
</parent>
9+
910
<artifactId>java2ts-processor-core</artifactId>
1011
<name>java2ts-processor::core</name>
11-
<build>
12-
<plugins>
13-
</plugins>
14-
</build>
1512

1613
<dependencies>
1714

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module org.bsc.java2typescript {
2+
3+
4+
exports org.bsc.java2typescript;
5+
6+
}

core/src/main/java/org/bsc/java2typescript/Java2TSConverter.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bsc.java2typescript.transformer.TSJavaClass2StaticDefinitionTransformer;
55

66
import java.lang.reflect.Executable;
7+
import java.util.Map;
78
import java.util.Optional;
89

910
import static java.lang.String.format;
@@ -77,12 +78,9 @@ public enum Compatibility {
7778
NASHORN, RHINO, GRAALJS;
7879

7980
public String javaType(String fqn) {
80-
switch (this.ordinal()) {
81-
case 1:
82-
return format("Packages.%s", fqn);
83-
default:
84-
return format("Java.type(\"%s\")", fqn);
85-
}
81+
return (this == RHINO ) ?
82+
format("Packages.%s", fqn) :
83+
format("Java.type(\"%s\")", fqn);
8684
}
8785
}
8886

@@ -121,46 +119,31 @@ private Java2TSConverter(Options options) {
121119
JavaClass2StaticDefinitionTransformer = new TSJavaClass2StaticDefinitionTransformer();
122120
}
123121

124-
/**
125-
* @return
126-
*/
127122
public final boolean isRhino() {
128123
return options.compatibility == Compatibility.RHINO;
129124
}
130125

131-
/**
132-
* @param m
133-
* @param type
134-
* @param declaredTypeMap
135-
* @param packageResolution
136-
* @return
137-
*/
138-
public <E extends Executable> String getMethodParametersAndReturnDecl(E m, TSType type,
139-
java.util.Map<String, TSType> declaredTypeMap, boolean packageResolution) {
126+
public <E extends Executable> String getMethodParametersAndReturnDecl(E m,
127+
TSType type,
128+
Map<String, TSType> declaredTypeMap,
129+
boolean packageResolution)
130+
{
140131

141132
return TSConverterContext.of(type, declaredTypeMap, options)
142133
.getMethodParametersAndReturnDecl(m, packageResolution);
143134
}
144135

145-
/**
146-
* @param tstype
147-
* @param declaredTypeMap
148-
* @return
149-
*/
150-
public String javaClass2StaticDefinitionTransformer(TSType tstype, java.util.Map<String, TSType> declaredTypeMap) {
136+
public String javaClass2StaticDefinitionTransformer(TSType tstype,
137+
Map<String, TSType> declaredTypeMap) {
151138

152139
return TSConverterContext.of(tstype, declaredTypeMap, options)
153140
.apply( JavaClass2StaticDefinitionTransformer )
154141
.toString();
155142
}
156143

157-
/**
158-
* @param level
159-
* @param tstype
160-
* @param declaredTypeMap
161-
* @return
162-
*/
163-
public String javaClass2DeclarationTransformer(int level, TSType tstype, java.util.Map<String, TSType> declaredTypeMap) {
144+
public String javaClass2DeclarationTransformer(int level,
145+
TSType tstype,
146+
Map<String, TSType> declaredTypeMap) {
164147

165148
return TSConverterContext.of(tstype, declaredTypeMap, options)
166149
.apply(javaClass2DeclarationTransformer)

core/src/main/java/org/bsc/java2typescript/TSNamespace.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,21 @@
66

77
import static java.lang.String.format;
88

9-
public class TSNamespace {
9+
public record TSNamespace (String name, Set<TSType> types ) {
1010

11-
private final String name;
12-
13-
private final Set<TSType> types;
14-
15-
private TSNamespace(String name, Set<TSType> types) {
11+
public TSNamespace(String name, Set<TSType> types) {
1612
this.name = name;
1713
this.types = Collections.unmodifiableSet(types);
1814
}
1915

20-
public String getName() {
21-
return name;
22-
}
23-
24-
public Set<TSType> getTypes() {
25-
return types;
26-
}
27-
2816
public static TSNamespace of( String name, Set<TSType> types ) {
2917
return new TSNamespace( name, types );
3018
}
3119

3220
@Override
3321
public String toString() {
3422
return format( "TSNamespace: { name: '%s', types: [%s] }",
35-
name, getTypes().stream()
23+
name, types().stream()
3624
.map( TSType::toString ).collect(Collectors.joining(",\n")) );
3725
}
3826
}

0 commit comments

Comments
 (0)