Skip to content

Commit 555cc7c

Browse files
author
Build Pipeline
committed
Merge branch 'release/1.3.0'
2 parents 468fab7 + dc20544 commit 555cc7c

26 files changed

Lines changed: 9335 additions & 468 deletions

.github/workflows/maven-publish.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
name: Maven Package
55

66
on:
7-
push:
8-
branches:
9-
- develop
7+
release:
8+
types:
9+
- published
1010

1111
jobs:
1212
build:
@@ -21,4 +21,6 @@ jobs:
2121
java-version: 1.8
2222

2323
- name: Build with Maven
24-
run: mvn -B install --file pom.xml -s settings-template.xml
24+
env:
25+
SONATYPE_PASSWORD: ${{ secrets.SonatypePassword }}
26+
run: mvn -B deploy --file pom.xml -s settings-template.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ The easier way to start your **Typescript on JVM** project is using the provided
183183
>-DarchetypeArtifactId=java2ts-processor-archetype \
184184
>-DarchetypeVersion=1.1.0
185185
>```
186+

archetype/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<parent>
66
<groupId>org.bsc.processor</groupId>
77
<artifactId>java2ts-processor-parent</artifactId>
8-
<version>1.2.0</version>
8+
<version>1.3.0</version>
99
</parent>
1010
<artifactId>java2ts-processor-archetype</artifactId>
11-
<name>java2ts-processor::archetype - ${project.version}</name>
11+
<name>java2ts-processor::archetype</name>
1212
<packaging>maven-archetype</packaging>
1313

1414
<build>

core/pom.xml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<parent>
4-
<groupId>org.bsc.processor</groupId>
5-
<artifactId>java2ts-processor-parent</artifactId>
6-
<version>1.2.0</version>
7-
</parent>
8-
<artifactId>java2ts-processor-core</artifactId>
9-
<name>java2ts-processor::core - ${project.version}</name>
10-
11-
<dependencies>
12-
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>org.bsc.processor</groupId>
6+
<artifactId>java2ts-processor-parent</artifactId>
7+
<version>1.3.0</version>
8+
</parent>
9+
<artifactId>java2ts-processor-core</artifactId>
10+
<name>java2ts-processor::core</name>
11+
<build>
12+
<plugins>
13+
</plugins>
14+
</build>
15+
16+
<dependencies>
17+
1318
<dependency>
1419
<groupId>junit</groupId>
1520
<artifactId>junit</artifactId>
1621
<scope>test</scope>
1722
</dependency>
18-
19-
</dependencies>
23+
24+
</dependencies>
2025
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.bsc.java2typescript;
2+
3+
import java.util.Collections;
4+
import java.util.Set;
5+
import java.util.stream.Collectors;
6+
7+
import static java.lang.String.format;
8+
9+
public class TSNamespace {
10+
11+
private final String name;
12+
13+
private final Set<TSType> types;
14+
15+
private TSNamespace(String name, Set<TSType> types) {
16+
this.name = name;
17+
this.types = Collections.unmodifiableSet(types);
18+
}
19+
20+
public String getName() {
21+
return name;
22+
}
23+
24+
public Set<TSType> getTypes() {
25+
return types;
26+
}
27+
28+
public static TSNamespace of( String name, Set<TSType> types ) {
29+
return new TSNamespace( name, types );
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return format( "TSNamespace: { name: '%s', types: [%s] }",
35+
name, getTypes().stream()
36+
.map( TSType::toString ).collect(Collectors.joining(",\n")) );
37+
}
38+
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ protected TSType() {
2929
super(3);
3030
}
3131

32-
public static TSType from(Class<?> cl) {
32+
33+
public static TSType of() {
34+
return new TSType() {
35+
{
36+
put(VALUE, Void.class);
37+
}
38+
};
39+
}
40+
public static TSType of(Class<?> cl) {
3341
return new TSType() {
3442
{
3543
put(VALUE, cl);
@@ -239,4 +247,8 @@ public int hashCode() {
239247
return getValue().hashCode();
240248
}
241249

250+
@Override
251+
public String toString() {
252+
return format("TSType{ value: %s }", getValue().getName());
253+
}
242254
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public TypescriptConverter(Compatibility compatibility) {
5151
public final boolean isRhino() {
5252
return compatibility == Compatibility.RHINO;
5353
}
54-
54+
5555
/**
56-
*
57-
* @param declaredClass
56+
*
57+
* @param type
58+
* @param declaredTypeMap
5859
* @return
5960
*/
6061
public String processStatic(TSType type, java.util.Map<String, TSType> declaredTypeMap) {
@@ -263,7 +264,7 @@ Context getClassDecl() {
263264

264265
sb.append("class ");
265266

266-
final TSType superclass = TSType.from(type.getValue().getSuperclass());
267+
final TSType superclass = TSType.of(type.getValue().getSuperclass());
267268

268269
if (superclass != null) {
269270
inherited.append(" extends ").append(getTypeName(superclass, type, true));
@@ -274,7 +275,7 @@ Context getClassDecl() {
274275

275276
if (interfaces.length > 0) {
276277

277-
final String ifc = Arrays.stream(interfaces).map(c -> TSType.from(c))
278+
final String ifc = Arrays.stream(interfaces).map(c -> TSType.of(c))
278279
.map(t -> getTypeName(t, type, true)).collect(Collectors.joining(", "));
279280
inherited.append((type.getValue().isInterface()) ? " extends " : " implements ").append(ifc);
280281

@@ -326,9 +327,8 @@ Context processEnumDecl() {
326327

327328
/**
328329
*
329-
* @param sb
330-
* @param type
331-
* @param declaredTypeMap
330+
* @param level
331+
* @return
332332
*/
333333
Context processMemberClasses(int level) {
334334

@@ -344,7 +344,7 @@ Context processMemberClasses(int level) {
344344

345345
Stream.of(memberClasses).peek(c -> debug("nested class name[%s]", c.getName()))
346346
// .filter(distinctByKey( c -> c.getSimpleName() ))
347-
.filter(distinctByKey(c -> c.getName())).map(cl -> TSType.from(cl))
347+
.filter(distinctByKey(c -> c.getName())).map(cl -> TSType.of(cl))
348348
.peek(t -> debug("nested type name[%s]", t.getTypeName()))
349349
.map(t -> processClass(level + 1, t, declaredTypeMap))
350350
.forEach(decl -> sb.append(decl));
@@ -401,7 +401,8 @@ public Context contextOf(TSType tstype, java.util.Map<String, TSType> declaredTy
401401

402402
/**
403403
*
404-
* @param bi
404+
* @param level
405+
* @param tstype
405406
* @param declaredTypeMap
406407
* @return
407408
*/
@@ -417,17 +418,16 @@ public String processClass(int level, TSType tstype, java.util.Map<String, TSTyp
417418
ctx.getClassDecl().append("\n\n");
418419

419420
if (tstype.isFunctional()) {
420-
final Function<Method,String> genAbstractMethod =
421-
m -> isRhino() ?
422-
getMethodDecl(ctx, m, false /* non optional */) :
423-
getMethodParametersAndReturnDecl(ctx, m, false);
424-
421+
425422
methods.stream()
426423
.filter(m -> Modifier.isAbstract(m.getModifiers()))
427424
.findFirst()
428425
.ifPresent(
429426
m -> ctx.append('\t')
430-
.append( genAbstractMethod.apply(m) )
427+
.append(getMethodParametersAndReturnDecl(ctx, m, false))
428+
// Rhino compatibility ???
429+
//.append("\n\t")
430+
//.append(getMethodDecl(ctx, m, false /* non optional */))
431431
.append(ENDL));
432432

433433
methods.stream()

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public abstract class TypescriptConverterStatic {
3939
static final String ENDL = ";\n";
4040

4141
public static final List<TSType> PREDEFINED_TYPES = Arrays.asList(
42-
TSType.from(Class.class),
43-
TSType.from(Serializable.class),
44-
TSType.from(Closeable.class),
45-
TSType.from(AutoCloseable.class),
46-
TSType.from(Cloneable.class),
47-
TSType.from(RandomAccess.class)
42+
TSType.of(Class.class),
43+
TSType.of(Serializable.class),
44+
TSType.of(Closeable.class),
45+
TSType.of(AutoCloseable.class),
46+
TSType.of(Cloneable.class),
47+
TSType.of(RandomAccess.class)
4848
);
4949

5050

@@ -58,20 +58,18 @@ public abstract class TypescriptConverterStatic {
5858
*
5959
*/
6060
static BiPredicate<Class<?>,Type> typeParameterMatch = (declaringClass, type) ->
61-
( type instanceof TypeVariable ) ?
62-
Arrays.stream(declaringClass.getTypeParameters())
63-
.map( (tp) -> tp.getName())
64-
.anyMatch( name -> name.equals(((TypeVariable<?>)type).getName())) :
65-
false
61+
type instanceof TypeVariable && Arrays.stream(declaringClass.getTypeParameters())
62+
.map(tp -> tp.getName())
63+
.anyMatch(name -> name.equals(((TypeVariable<?>) type).getName()))
6664
;
6765

6866
static void log( String fmt, Object ...args ) {
69-
if( Boolean.getBoolean("debug") ) System.out.println( format( fmt, args));
67+
if( Boolean.getBoolean("debug") ) System.out.printf( fmt, args);
7068
}
7169

7270
static void debug( String fmt, Object ...args ) {
7371
System.out.print( "DEBUG: ");
74-
System.out.println( format( fmt, args));
72+
System.out.printf( fmt, args );
7573
}
7674
/**
7775
*
@@ -265,18 +263,19 @@ static String convertJavaToTS( Class<?> type,
265263
return format("any /*%s*/",type.getName());
266264

267265
}
268-
269-
/**
270-
*
271-
* @param type
272-
* @param declaringMember
273-
* @param declaredTypeMap
274-
* @param packageResolution
275-
* @param typeMatch
276-
* @param onTypeMismatch
277-
* @return
278-
*/
279-
public static <M extends Member> String convertJavaToTS(
266+
267+
/**
268+
*
269+
* @param type
270+
* @param declaringMember
271+
* @param declaringType
272+
* @param declaredTypeMap
273+
* @param packageResolution
274+
* @param onTypeMismatch
275+
* @param <M>
276+
* @return
277+
*/
278+
public static <M extends Member> String convertJavaToTS(
280279
Type type,
281280
M declaringMember,
282281
TSType declaringType,
@@ -290,6 +289,7 @@ public static <M extends Member> String convertJavaToTS(
290289
Objects.requireNonNull(declaredTypeMap, "declaredTypeMap argument is null!");
291290

292291
log( "PROCESSING MEMEBER: [%s]", declaringMember.getName());
292+
293293
/**
294294
*
295295
*/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Project: java2typescript - https://github.com/bsorrentino/java2typescript
3+
*
4+
* Author: bsorrentino
5+
*
6+
* TYPESCRIPT DEFINITIONS
7+
*
8+
*/
9+
10+
type int = number;
11+
type long = number;
12+
type float = number;
13+
type double = number;
14+
type byte = number;
15+
type char = string;
16+
17+
type chararray = [byte];
18+
type bytearray = [char];
19+
20+
declare namespace java.lang {
21+
22+
interface Class<T> {}
23+
interface AutoCloseable {}
24+
interface Cloneable {}
25+
26+
type Object = any;
27+
}
28+
29+
declare namespace java.util {
30+
31+
interface RandomAccess {}
32+
}
33+
34+
declare namespace java.io {
35+
36+
interface Closeable {}
37+
interface Serializable {}
38+
}
39+
40+
//
41+
// Rhino
42+
//
43+
44+
declare const Packages:any;
45+
46+
declare function print( ...args: any[] ):void
47+
48+
declare function load( module:string ):void
49+
50+
//
51+
// Generated declarations
52+
//
53+

core/src/main/resources/headerD.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ declare namespace java.io {
3838
}
3939

4040
//
41-
// Rhino
42-
//
43-
44-
declare const Packages:any;
45-
46-
//
47-
// Nashorn
41+
// Nashorn compatibility
4842
//
4943

5044
declare function print( ...args: any[] ):void
@@ -58,3 +52,8 @@ declare namespace Java {
5852
export function from<T>( list:java.util.List<T> ):Array<T> ;
5953

6054
}
55+
56+
//
57+
// Generated declarations
58+
//
59+

0 commit comments

Comments
 (0)