Skip to content

Commit a8aac88

Browse files
committed
Merge branch 'release/1.4.0'
2 parents c8f79b6 + 04469b6 commit a8aac88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1625
-24278
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ bin/
2121

2222
.idea/
2323
*.iml
24+
package-lock.json

archetype/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.bsc.processor</groupId>
77
<artifactId>java2ts-processor-parent</artifactId>
8-
<version>1.3.1</version>
8+
<version>1.4.0</version>
99
</parent>
1010
<artifactId>java2ts-processor-archetype</artifactId>
1111
<name>java2ts-processor::archetype</name>

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.bsc.processor</groupId>
66
<artifactId>java2ts-processor-parent</artifactId>
7-
<version>1.3.1</version>
7+
<version>1.4.0</version>
88
</parent>
99
<artifactId>java2ts-processor-core</artifactId>
1010
<name>java2ts-processor::core</name>
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package org.bsc.java2typescript;
2+
3+
import org.bsc.java2typescript.transformer.TSJavaClass2DeclarationTransformer;
4+
import org.bsc.java2typescript.transformer.TSJavaClass2StaticDefinitionTransformer;
5+
6+
import java.lang.reflect.Executable;
7+
import java.util.Optional;
8+
9+
import static java.lang.String.format;
10+
11+
/**
12+
* @author bsorrentino
13+
*/
14+
public class Java2TSConverter extends TSConverterStatic {
15+
public static class Builder {
16+
17+
private Compatibility compatibility = Compatibility.NASHORN;
18+
private boolean foreignObjectPrototype = false;
19+
20+
private Builder() {}
21+
22+
public Builder compatibility(Compatibility compatibility) {
23+
this.compatibility = compatibility;
24+
return this;
25+
}
26+
27+
public Builder compatibility(String compatibility) {
28+
29+
this.compatibility
30+
= Optional.ofNullable(compatibility)
31+
.map( v -> {
32+
try {
33+
return Java2TSConverter.Compatibility.valueOf(v.toUpperCase());
34+
} catch( Exception e ) {
35+
return Compatibility.NASHORN;
36+
}
37+
})
38+
.orElse( Compatibility.NASHORN );
39+
return this;
40+
}
41+
42+
public Builder foreignObjectPrototype(boolean foreignObjectPrototype) {
43+
this.foreignObjectPrototype = foreignObjectPrototype;
44+
return this;
45+
}
46+
47+
public Builder foreignObjectPrototype(String foreignObjectPrototype) {
48+
this.foreignObjectPrototype =
49+
Optional.ofNullable(foreignObjectPrototype)
50+
.map( v -> {
51+
try {
52+
return Boolean.valueOf(v);
53+
} catch( Exception e ) {
54+
return false;
55+
}
56+
})
57+
.orElse( false );
58+
59+
return this;
60+
}
61+
62+
public Java2TSConverter build() {
63+
return new Java2TSConverter(
64+
new Options( compatibility, foreignObjectPrototype) );
65+
}
66+
}
67+
68+
/**
69+
*
70+
* @return
71+
*/
72+
public static Builder builder() {
73+
return new Builder();
74+
}
75+
76+
public enum Compatibility {
77+
NASHORN, RHINO, GRAALJS;
78+
79+
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+
}
86+
}
87+
}
88+
89+
public static class Options {
90+
public final Compatibility compatibility;
91+
public final boolean foreignObjectPrototype;
92+
93+
private Options(Compatibility compatibility, boolean foreignObjectPrototype) {
94+
this.compatibility = compatibility;
95+
this.foreignObjectPrototype = foreignObjectPrototype;
96+
}
97+
98+
public static Options of(Compatibility compatibility, boolean foreignObjectPrototype) {
99+
return new Options(compatibility, foreignObjectPrototype);
100+
}
101+
102+
public static Options of(Compatibility compatibility) {
103+
return new Options(compatibility, false);
104+
}
105+
106+
public static Options ofDefault() {
107+
return new Options(Compatibility.NASHORN, false);
108+
}
109+
}
110+
111+
final Options options;
112+
113+
final TSJavaClass2DeclarationTransformer javaClass2DeclarationTransformer;
114+
final TSJavaClass2StaticDefinitionTransformer JavaClass2StaticDefinitionTransformer;
115+
116+
private Java2TSConverter(Options options) {
117+
super();
118+
this.options = options;
119+
120+
javaClass2DeclarationTransformer = new TSJavaClass2DeclarationTransformer();
121+
JavaClass2StaticDefinitionTransformer = new TSJavaClass2StaticDefinitionTransformer();
122+
}
123+
124+
/**
125+
* @return
126+
*/
127+
public final boolean isRhino() {
128+
return options.compatibility == Compatibility.RHINO;
129+
}
130+
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) {
140+
141+
return TSConverterContext.of(type, declaredTypeMap, options)
142+
.getMethodParametersAndReturnDecl(m, packageResolution);
143+
}
144+
145+
/**
146+
* @param tstype
147+
* @param declaredTypeMap
148+
* @return
149+
*/
150+
public String javaClass2StaticDefinitionTransformer(TSType tstype, java.util.Map<String, TSType> declaredTypeMap) {
151+
152+
return TSConverterContext.of(tstype, declaredTypeMap, options)
153+
.apply( JavaClass2StaticDefinitionTransformer )
154+
.toString();
155+
}
156+
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) {
164+
165+
return TSConverterContext.of(tstype, declaredTypeMap, options)
166+
.apply(javaClass2DeclarationTransformer)
167+
.toString();
168+
169+
}
170+
171+
}

0 commit comments

Comments
 (0)