Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Build Pipeline committed Sep 20, 2021
2 parents 468fab7 + dc20544 commit 555cc7c
Show file tree
Hide file tree
Showing 26 changed files with 9,335 additions and 468 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
name: Maven Package

on:
push:
branches:
- develop
release:
types:
- published

jobs:
build:
Expand All @@ -21,4 +21,6 @@ jobs:
java-version: 1.8

- name: Build with Maven
run: mvn -B install --file pom.xml -s settings-template.xml
env:
SONATYPE_PASSWORD: ${{ secrets.SonatypePassword }}
run: mvn -B deploy --file pom.xml -s settings-template.xml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ The easier way to start your **Typescript on JVM** project is using the provided
>-DarchetypeArtifactId=java2ts-processor-archetype \
>-DarchetypeVersion=1.1.0
>```
4 changes: 2 additions & 2 deletions archetype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<parent>
<groupId>org.bsc.processor</groupId>
<artifactId>java2ts-processor-parent</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</parent>
<artifactId>java2ts-processor-archetype</artifactId>
<name>java2ts-processor::archetype - ${project.version}</name>
<name>java2ts-processor::archetype</name>
<packaging>maven-archetype</packaging>

<build>
Expand Down
33 changes: 19 additions & 14 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.bsc.processor</groupId>
<artifactId>java2ts-processor-parent</artifactId>
<version>1.2.0</version>
</parent>
<artifactId>java2ts-processor-core</artifactId>
<name>java2ts-processor::core - ${project.version}</name>

<dependencies>

<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.bsc.processor</groupId>
<artifactId>java2ts-processor-parent</artifactId>
<version>1.3.0</version>
</parent>
<artifactId>java2ts-processor-core</artifactId>
<name>java2ts-processor::core</name>
<build>
<plugins>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</dependencies>
</project>
38 changes: 38 additions & 0 deletions core/src/main/java/org/bsc/java2typescript/TSNamespace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.bsc.java2typescript;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

import static java.lang.String.format;

public class TSNamespace {

private final String name;

private final Set<TSType> types;

private TSNamespace(String name, Set<TSType> types) {
this.name = name;
this.types = Collections.unmodifiableSet(types);
}

public String getName() {
return name;
}

public Set<TSType> getTypes() {
return types;
}

public static TSNamespace of( String name, Set<TSType> types ) {
return new TSNamespace( name, types );
}

@Override
public String toString() {
return format( "TSNamespace: { name: '%s', types: [%s] }",
name, getTypes().stream()
.map( TSType::toString ).collect(Collectors.joining(",\n")) );
}
}
14 changes: 13 additions & 1 deletion core/src/main/java/org/bsc/java2typescript/TSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ protected TSType() {
super(3);
}

public static TSType from(Class<?> cl) {

public static TSType of() {
return new TSType() {
{
put(VALUE, Void.class);
}
};
}
public static TSType of(Class<?> cl) {
return new TSType() {
{
put(VALUE, cl);
Expand Down Expand Up @@ -239,4 +247,8 @@ public int hashCode() {
return getValue().hashCode();
}

@Override
public String toString() {
return format("TSType{ value: %s }", getValue().getName());
}
}
32 changes: 16 additions & 16 deletions core/src/main/java/org/bsc/java2typescript/TypescriptConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public TypescriptConverter(Compatibility compatibility) {
public final boolean isRhino() {
return compatibility == Compatibility.RHINO;
}

/**
*
* @param declaredClass
*
* @param type
* @param declaredTypeMap
* @return
*/
public String processStatic(TSType type, java.util.Map<String, TSType> declaredTypeMap) {
Expand Down Expand Up @@ -263,7 +264,7 @@ Context getClassDecl() {

sb.append("class ");

final TSType superclass = TSType.from(type.getValue().getSuperclass());
final TSType superclass = TSType.of(type.getValue().getSuperclass());

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

if (interfaces.length > 0) {

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

Expand Down Expand Up @@ -326,9 +327,8 @@ Context processEnumDecl() {

/**
*
* @param sb
* @param type
* @param declaredTypeMap
* @param level
* @return
*/
Context processMemberClasses(int level) {

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

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

/**
*
* @param bi
* @param level
* @param tstype
* @param declaredTypeMap
* @return
*/
Expand All @@ -417,17 +418,16 @@ public String processClass(int level, TSType tstype, java.util.Map<String, TSTyp
ctx.getClassDecl().append("\n\n");

if (tstype.isFunctional()) {
final Function<Method,String> genAbstractMethod =
m -> isRhino() ?
getMethodDecl(ctx, m, false /* non optional */) :
getMethodParametersAndReturnDecl(ctx, m, false);


methods.stream()
.filter(m -> Modifier.isAbstract(m.getModifiers()))
.findFirst()
.ifPresent(
m -> ctx.append('\t')
.append( genAbstractMethod.apply(m) )
.append(getMethodParametersAndReturnDecl(ctx, m, false))
// Rhino compatibility ???
//.append("\n\t")
//.append(getMethodDecl(ctx, m, false /* non optional */))
.append(ENDL));

methods.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public abstract class TypescriptConverterStatic {
static final String ENDL = ";\n";

public static final List<TSType> PREDEFINED_TYPES = Arrays.asList(
TSType.from(Class.class),
TSType.from(Serializable.class),
TSType.from(Closeable.class),
TSType.from(AutoCloseable.class),
TSType.from(Cloneable.class),
TSType.from(RandomAccess.class)
TSType.of(Class.class),
TSType.of(Serializable.class),
TSType.of(Closeable.class),
TSType.of(AutoCloseable.class),
TSType.of(Cloneable.class),
TSType.of(RandomAccess.class)
);


Expand All @@ -58,20 +58,18 @@ public abstract class TypescriptConverterStatic {
*
*/
static BiPredicate<Class<?>,Type> typeParameterMatch = (declaringClass, type) ->
( type instanceof TypeVariable ) ?
Arrays.stream(declaringClass.getTypeParameters())
.map( (tp) -> tp.getName())
.anyMatch( name -> name.equals(((TypeVariable<?>)type).getName())) :
false
type instanceof TypeVariable && Arrays.stream(declaringClass.getTypeParameters())
.map(tp -> tp.getName())
.anyMatch(name -> name.equals(((TypeVariable<?>) type).getName()))
;

static void log( String fmt, Object ...args ) {
if( Boolean.getBoolean("debug") ) System.out.println( format( fmt, args));
if( Boolean.getBoolean("debug") ) System.out.printf( fmt, args);
}

static void debug( String fmt, Object ...args ) {
System.out.print( "DEBUG: ");
System.out.println( format( fmt, args));
System.out.printf( fmt, args );
}
/**
*
Expand Down Expand Up @@ -265,18 +263,19 @@ static String convertJavaToTS( Class<?> type,
return format("any /*%s*/",type.getName());

}

/**
*
* @param type
* @param declaringMember
* @param declaredTypeMap
* @param packageResolution
* @param typeMatch
* @param onTypeMismatch
* @return
*/
public static <M extends Member> String convertJavaToTS(

/**
*
* @param type
* @param declaringMember
* @param declaringType
* @param declaredTypeMap
* @param packageResolution
* @param onTypeMismatch
* @param <M>
* @return
*/
public static <M extends Member> String convertJavaToTS(
Type type,
M declaringMember,
TSType declaringType,
Expand All @@ -290,6 +289,7 @@ public static <M extends Member> String convertJavaToTS(
Objects.requireNonNull(declaredTypeMap, "declaredTypeMap argument is null!");

log( "PROCESSING MEMEBER: [%s]", declaringMember.getName());

/**
*
*/
Expand Down
53 changes: 53 additions & 0 deletions core/src/main/resources/headerD-rhino.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Project: java2typescript - https://github.com/bsorrentino/java2typescript
*
* Author: bsorrentino
*
* TYPESCRIPT DEFINITIONS
*
*/

type int = number;
type long = number;
type float = number;
type double = number;
type byte = number;
type char = string;

type chararray = [byte];
type bytearray = [char];

declare namespace java.lang {

interface Class<T> {}
interface AutoCloseable {}
interface Cloneable {}

type Object = any;
}

declare namespace java.util {

interface RandomAccess {}
}

declare namespace java.io {

interface Closeable {}
interface Serializable {}
}

//
// Rhino
//

declare const Packages:any;

declare function print( ...args: any[] ):void

declare function load( module:string ):void

//
// Generated declarations
//

13 changes: 6 additions & 7 deletions core/src/main/resources/headerD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ declare namespace java.io {
}

//
// Rhino
//

declare const Packages:any;

//
// Nashorn
// Nashorn compatibility
//

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

}

//
// Generated declarations
//

Loading

0 comments on commit 555cc7c

Please sign in to comment.