diff --git a/README.md b/README.md index 553b928..becb990 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,14 @@ It is not a transpiler from Java to Javascript like [datathings/java2typescript ## Similar projects * [typescript-generator](https://github.com/vojtechhabarta/typescript-generator) +> 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](https://1c.wizawu.com/#/whatis) +> 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 * [jvm-npm](https://github.com/bsorrentino/jvm-npm) +> NPM compliant CommonJS module loader for the JVM ## Description @@ -123,5 +127,5 @@ The easier way to start your **Typescript on JVM** project is using the provided >mvn archetype:generate \ >-DarchetypeGroupId=org.bsc.processor \ >-DarchetypeArtifactId=java2ts-processor-archetype \ ->-DarchetypeVersion=0.2.0 +>-DarchetypeVersion=1.0-beta1 >``` diff --git a/archetype/pom.xml b/archetype/pom.xml index bccc29b..480db52 100644 --- a/archetype/pom.xml +++ b/archetype/pom.xml @@ -5,7 +5,7 @@ org.bsc.processor java2ts-processor-parent - 0.2.0 + 1.0-beta1 java2ts-processor-archetype java2ts-processor::archetype - ${project.version} diff --git a/core/pom.xml b/core/pom.xml index c1cc555..4fdd988 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -3,7 +3,7 @@ org.bsc.processor java2ts-processor-parent - 0.2.0 + 1.0-beta1 java2ts-processor-core java2ts-processor::core - ${project.version} diff --git a/core/src/main/java/org/bsc/java2typescript/TSType.java b/core/src/main/java/org/bsc/java2typescript/TSType.java index d420936..2c3a682 100644 --- a/core/src/main/java/org/bsc/java2typescript/TSType.java +++ b/core/src/main/java/org/bsc/java2typescript/TSType.java @@ -8,183 +8,187 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; - - +import static java.lang.String.format; /** * * @author softphone * */ @SuppressWarnings("serial") -public class TSType extends HashMap { - - protected TSType() { - super(3); - } - - public static TSType from( Class cl, boolean export ) { - return new TSType() {{ - put( "value", cl); - put( "export", export); - }}; - } - - public static TSType from( Class cl, String alias, boolean export ) { - return new TSType() {{ - put( "value", cl); - put( "export", export); - put( "alias", alias); - }}; - } - - /** - * Assume that class is managed as Functional Interface - * - * @param cl - * @param alias - * @return - */ - public static TSType functional( Class cl, String alias ) { - return new TSType() {{ - put( "value", cl); - put( "alias", alias); - put("functional", true); - }}; - } - - public static TSType from( Class cl ) { - return new TSType() {{ put( "value", cl); }}; - } - - /** - * - * @return - */ - public Class getValue() { - return getClassFrom(super.get("value")); - } - - /** - * - * @return - */ - public boolean isExport() { - return (boolean) super.getOrDefault("export", false); - } - - /** - * - * @return - */ - public TSType setExport( boolean export ) { - super.put("export", export); - return this; - } - - /** - * - * @return - */ - public boolean isFunctionalInterface() { - return ((boolean) super.getOrDefault("functional", false)) || - (getValue().isInterface() && getValue().isAnnotationPresent(FunctionalInterface.class)); - } - - /** - * - * @return - */ - public boolean hasAlias() { - final String alias = (String) super.get("alias"); - return alias!=null && !alias.isEmpty(); - } - - /** - * - * @return - */ - public String getAlias() { - return (String) super.get("alias"); - } - - /** - * - * @return - */ - public final String getTypeName() { - return (hasAlias()) ? getAlias() : getValue().getName(); - } - - /** - * - * @return - */ - public final String getSimpleTypeName() { - return (hasAlias()) ? getAlias() : getValue().getSimpleName(); - } +public class TSType extends HashMap { + + private static final String ALIAS = "alias"; + private static final String VALUE = "value"; + private static final String EXPORT = "export"; + private static final String NAMESPACE = "namespace"; + + protected TSType() { + super(3); + } + + public static TSType from(Class cl, boolean export) { + return new TSType() { + { + put(VALUE, cl); + put(EXPORT, export); + } + }; + } + + public static TSType from(Class cl, String alias, boolean export) { + return new TSType() { + { + put(VALUE, cl); + put(EXPORT, export); + put(ALIAS, alias); + } + }; + } + + public static TSType from(Class cl) { + return new TSType() { + { + put(VALUE, cl); + } + }; + } /** - * - * @param type - * @return - */ - public Set getFields() { - - final Predicate std = f -> - !f.isSynthetic() && - Modifier.isPublic( f.getModifiers() ) && - Character.isJavaIdentifierStart(f.getName().charAt(0)) && - f.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart); - - return Stream.concat( Stream.of(getValue().getFields()), Stream.of(getValue().getDeclaredFields()) ) - .filter(std) - .collect( Collectors.toSet( ) ); - - } - + * + * @return + */ + public Class getValue() { + return getClassFrom(super.get(VALUE)); + } + /** - * - * @param type - * @return - */ - public Set getMethods() { - final Predicate include = m -> - !m.isBridge() && - !m.isSynthetic() && - Modifier.isPublic( m.getModifiers() ) && - Character.isJavaIdentifierStart(m.getName().charAt(0)) && - m.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart); - - return Stream.concat( Stream.of(getValue().getMethods()), Stream.of(getValue().getDeclaredMethods()) ) - .filter(include) - .collect( Collectors.toSet( ) ); - - } - - + * + * @return + */ + public boolean isExport() { + return (boolean) super.getOrDefault(EXPORT, false); + } + + /** + * + * @return + */ + public TSType setExport(boolean exports) { + super.put(EXPORT, exports); + return this; + } + + /** + * + * @return + */ + public boolean hasAlias() { + final String alias = (String) super.get(ALIAS); + return alias != null && !alias.isEmpty(); + } + + /** + * + * @return + */ + public String getAlias() { + return (String) super.get(ALIAS); + } + + /** + * + * @return + */ + public final String getTypeName() { + return (hasAlias()) ? getAlias() : format( "%s.%s", getNamespace(), getValue().getSimpleName()); + } + + /** + * + * @return + */ + public final String getSimpleTypeName() { + return (hasAlias()) ? getAlias() : getValue().getSimpleName(); + } + + /** + * + * @return + */ + public final boolean supportNamespace() { + return !getValue().isMemberClass() && !hasAlias(); + } + + /** + * + * @return + */ + public final String getNamespace() { + return (String) super.getOrDefault(NAMESPACE, getValue().getPackage().getName()); + } + + /** + * + * @return + */ + public boolean isFunctionalInterface() { + return TypescriptConverter.isFunctionalInterface( getValue() ); + } + /** + * + * @param type + * @return + */ + public Set getFields() { + + final Predicate std = f -> !f.isSynthetic() && Modifier.isPublic(f.getModifiers()) + && Character.isJavaIdentifierStart(f.getName().charAt(0)) + && f.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart); + + return Stream.concat(Stream.of(getValue().getFields()), Stream.of(getValue().getDeclaredFields())).filter(std) + .collect(Collectors.toSet()); + + } + + /** + * + * @param type + * @return + */ + public Set getMethods() { + final Predicate include = m -> !m.isBridge() && !m.isSynthetic() && Modifier.isPublic(m.getModifiers()) + && Character.isJavaIdentifierStart(m.getName().charAt(0)) + && m.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart); + + return Stream.concat(Stream.of(getValue().getMethods()), Stream.of(getValue().getDeclaredMethods())) + .filter(include).collect(Collectors.toSet()); + + } + /** * * @param dt * @return */ - private Class getClassFrom( Object dt ) { - if( dt instanceof Class ) return (Class)dt; - - try { + private Class getClassFrom(Object dt) { + if (dt instanceof Class) + return (Class) dt; + + try { return Class.forName(dt.toString()); } catch (ClassNotFoundException e1) { - throw new RuntimeException(String.format("class not found [%s]",dt), e1); + throw new RuntimeException(String.format("class not found [%s]", dt), e1); } } - - @Override - public boolean equals(Object o) { - return getValue().equals(((TSType)o).getValue()); - } - - @Override - public int hashCode() { - return getValue().hashCode(); - } + + @Override + public boolean equals(Object o) { + return getValue().equals(((TSType) o).getValue()); + } + + @Override + public int hashCode() { + return getValue().hashCode(); + } } diff --git a/core/src/main/java/org/bsc/java2typescript/TypescriptConverter.java b/core/src/main/java/org/bsc/java2typescript/TypescriptConverter.java index 0f6fd5a..67ef43c 100644 --- a/core/src/main/java/org/bsc/java2typescript/TypescriptConverter.java +++ b/core/src/main/java/org/bsc/java2typescript/TypescriptConverter.java @@ -22,15 +22,11 @@ import java.util.Optional; import java.util.RandomAccess; import java.util.concurrent.ConcurrentHashMap; -import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.BiPredicate; -import java.util.function.BinaryOperator; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.function.UnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -43,27 +39,17 @@ public class TypescriptConverter { TSType.from(Serializable.class), TSType.from(Closeable.class), TSType.from(AutoCloseable.class), - TSType.from(Comparable.class), TSType.from(Cloneable.class), - TSType.from(RandomAccess.class), - TSType.from(Function.class, "Func", false), - TSType.from(BiFunction.class, "BiFunc", false), - TSType.from(Consumer.class), - TSType.from(BiConsumer.class), - TSType.from(UnaryOperator.class), - TSType.from(BinaryOperator.class), - TSType.from(Supplier.class), - TSType.from(Predicate.class), - TSType.from(BiPredicate.class), - TSType.from(Runnable.class) - ); + TSType.from(RandomAccess.class) + ); /** * */ - public static BiPredicate, Class> isPackageMatch = (a, b) -> - a.getPackage().equals(b.getPackage()) ; + public static BiPredicate isNamespaceMatch = (a, b) -> + b.supportNamespace() && a.getNamespace().equals(b.getNamespace()) ; + /** * @@ -96,28 +82,6 @@ public static final String processFunctionalInterface( TSType type ) { return null; } - /** - * - * @param type - * @param alias - * @return - */ - public static final String getAliasDeclaration( Class type, String alias ) { - Objects.requireNonNull(type, "argument 'type' is not defined!"); - Objects.requireNonNull(alias, "argument 'alias' is not defined!"); - - final TypeVariable[] typeParameters = type.getTypeParameters(); - - if( typeParameters!=null && typeParameters.length > 0 ) { - - final String pp = Arrays.stream(typeParameters).map( tp -> tp.getName() ).collect( Collectors.joining(",","<", ">")); - return format( "type %s%s = %s%s;\n\n", alias, pp, type.getName(), pp ); - - } - - return format( "type %s = %s;\n\n", alias, type.getName() ); - } - /** * * @param p @@ -158,7 +122,17 @@ static boolean isFactoryMethod( Method m ) { m.getReturnType().equals(m.getDeclaringClass())); } - + /** + * + * @return + */ + public static boolean isFunctionalInterface( final Class c ) { + if( !c.isInterface()) return false; + if( c.isAnnotationPresent(FunctionalInterface.class)) return true; + + return Arrays.stream(c.getDeclaredMethods()).filter( m -> Modifier.isAbstract(m.getModifiers()) ).count() == 1; + } + /** * * @param type_parameters_list @@ -198,7 +172,7 @@ static String getTypeName( TSType type, TSType declaringType, boolean packageRes return new StringBuilder() .append( - type.getValue().getPackage().equals(currentNS) || type.isFunctionalInterface() ? + type.getValue().getPackage().equals(currentNS) ? type.getSimpleTypeName() : type.getTypeName() ) @@ -252,7 +226,7 @@ public static String convertJavaToTS( Type type, .replace( rawType.getName(), tstype.getTypeName()) // use Alias ; - if( tstype.isFunctionalInterface() || (packageResolution && isPackageMatch.test(tstype.getValue(), declaringType.getValue())) ) { + if( packageResolution && isNamespaceMatch.test(tstype, declaringType) ) { result = result.replace( tstype.getTypeName(), tstype.getSimpleTypeName()); } @@ -540,7 +514,7 @@ private String getMethodParametersAndReturnDecl( Context { final java.util.Set TypeVarSet = new java.util.HashSet<>(5); - final Consumer> addTypeVar = tv -> TypeVarSet.add(tv.getName()) ; + final Consumer> addTypeVar = tv -> TypeVarSet.add(tv.getName()) ; final Parameter[] params = m.getParameters(); @@ -549,8 +523,7 @@ private String getMethodParametersAndReturnDecl( Context .map( (tp) -> { final String name = getParameterName(tp); - - + if( tp.isVarArgs() ) { String type = null; @@ -621,7 +594,7 @@ private String getMethodParametersAndReturnDecl( Context * @param m * @return */ - private String getMethodDecl( Context ctx, final Method m ) { + private String getMethodDecl( Context ctx, final Method m, boolean optional ) { final StringBuilder sb = new StringBuilder(); @@ -635,6 +608,7 @@ private String getMethodDecl( Context ctx, final Method m ) { } else { sb.append(m.getName()); + if( optional ) sb.append('?'); } sb.append( getMethodParametersAndReturnDecl(ctx, m, true) ); @@ -734,14 +708,17 @@ Context getClassDecl() } - + sb.append( getTypeName(type, type, true) ); - if( inherited.length()>0 ) { + if( inherited.length()>0 || type.hasAlias()) { - sb.append("/*") - .append( inherited ) - .append("*/"); + sb.append("/*"); + + if( type.hasAlias() ) sb.append( type.getValue().getName() ); + if( inherited.length()>0 ) sb.append( inherited ); + + sb.append("*/"); } sb.append( " {"); @@ -849,40 +826,61 @@ public String processClass( int level, TSType tstype, java.util.Map methodSet = - tstype.getMethods() - .stream() - .filter( md -> (tstype.isExport() && isStatic(md))==false ) - .filter( (md) -> { - final String name = md.getName(); - return !( name.contains("$") || // remove unnamed - name.equals("getClass") || - name.equals("hashCode") || - name.equals("wait") || - name.equals("notify") || - name.equals("notifyAll") ); - }) - .collect( Collectors.toCollection(() -> new java.util.LinkedHashSet() )); - - methodSet.stream() - .map( md -> getMethodDecl(ctx, md) ) - .sorted().forEach( (decl) -> + if( tstype.isFunctionalInterface() ) { + + tstype.getMethods().stream() + .filter( m -> Modifier.isAbstract(m.getModifiers()) ) + .findFirst() + .ifPresent( m -> ctx.append( '\t' ) + .append( getMethodParametersAndReturnDecl( ctx, m, false) ) + .append( ENDL )) ; + + tstype.getMethods().stream() + .filter( m -> !Modifier.isAbstract(m.getModifiers()) ) + .map( m -> getMethodDecl(ctx, m, true /*optional*/) ) + .sorted() + .forEach( decl -> ctx.append( '\t' ) .append(decl) .append( ENDL )) ; + + + } else { + + ctx.processEnumDecl(); + + final java.util.Set methodSet = + tstype.getMethods() + .stream() + .filter( md -> (tstype.isExport() && isStatic(md))==false ) + .filter( (md) -> { + final String name = md.getName(); + return !( name.contains("$") || // remove unnamed + name.equals("getClass") || + name.equals("hashCode") || + name.equals("wait") || + name.equals("notify") || + name.equals("notifyAll") ); + }) + .collect( Collectors.toCollection(() -> new java.util.LinkedHashSet() )); + + methodSet.stream() + .map( md -> getMethodDecl(ctx, md, false /*optional*/) ) + .sorted().forEach( (decl) -> + ctx.append( '\t' ) + .append(decl) + .append( ENDL )) + ; + } ctx.append("\n} // end ") .append(tstype.getSimpleTypeName()) @@ -891,9 +889,9 @@ public String processClass( int level, TSType tstype, java.util.Map void ; - -type Func = ( t:T ) => R ; -type BiFunc = ( t:T, u:U ) => R ; - -type Supplier = () => T ; - -type Consumer = ( v:T ) => void ; -type BiConsumer = ( t:T, u:U ) => void ; - -type UnaryOperator = ( v:T ) => T ; -type BinaryOperator = ( t:T, u:T ) => T ; - -type Predicate = ( v:T ) => boolean ; -type BiPredicate = ( t:T, u:U ) => boolean ; - -type Comparator = ( o1:T, o2:T ) => int ; - declare namespace java.lang { interface Class {} interface AutoCloseable {} interface Cloneable {} - interface Comparable { - - compareTo?( arg0:T ):number; - - } - type Object = any; } diff --git a/core/src/test/java/org/bsc/java2typescript/ConverterTest.java b/core/src/test/java/org/bsc/java2typescript/ConverterTest.java new file mode 100644 index 0000000..29eaf02 --- /dev/null +++ b/core/src/test/java/org/bsc/java2typescript/ConverterTest.java @@ -0,0 +1,35 @@ +package org.bsc.java2typescript; + + +import java.util.function.Consumer; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import org.junit.Assert; +import org.junit.Test; + +public class ConverterTest { + + interface Action { + + default void m1() {}; + + void apply(); + } + interface Action2 { + + void m1(); + + void apply(); + } + @Test + public void functionalInterfaceTest() { + + + Assert.assertThat(TypescriptConverter.isFunctionalInterface(java.lang.Runnable.class) , is(true)); + Assert.assertThat(TypescriptConverter.isFunctionalInterface(Consumer.class) , is(true)); + Assert.assertThat(TypescriptConverter.isFunctionalInterface(Action.class) , is(true)); + Assert.assertThat(TypescriptConverter.isFunctionalInterface(Action.class), is(true)); + Assert.assertThat(TypescriptConverter.isFunctionalInterface(Action2.class) , is(false)); + } +} diff --git a/core/src/test/java/org/bsc/java2typescript/ProcessorTest.java b/core/src/test/java/org/bsc/java2typescript/ProcessorTest.java index 4b08261..111b2c6 100644 --- a/core/src/test/java/org/bsc/java2typescript/ProcessorTest.java +++ b/core/src/test/java/org/bsc/java2typescript/ProcessorTest.java @@ -52,7 +52,7 @@ public void testWildcardType() throws Exception { final Method m = type.getValue().getMethod("merge", BiConsumer.class ); final String result = converter.getMethodParametersAndReturnDecl( m, type, - declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.from(BiConsumer.class)), + declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.from(BiConsumer.class, "BiConsumer", false)), true) ; Assert.assertThat( result, IsNull.notNullValue()); @@ -62,7 +62,7 @@ public void testWildcardType() throws Exception { final Method m = type.getValue().getMethod("concatMap", Function.class ); final String result = converter.getMethodParametersAndReturnDecl( m, type, - declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.functional(Function.class, "Func")), + declaredTypeMap( TSType.from(String.class), TSType.from(Sample2.class), TSType.from(Function.class, "Func", false)), true) ; Assert.assertThat( result, IsNull.notNullValue()); @@ -102,7 +102,7 @@ public void testFunctionalInterface() throws Exception { final Method m = type.getValue().getMethod("creator", java.util.concurrent.Callable.class ); final String result = converter.getMethodParametersAndReturnDecl( m, type, - declaredTypeMap( TSType.from(String.class), TSType.functional(java.util.concurrent.Callable.class, "Supplier")), + declaredTypeMap( TSType.from(String.class), TSType.from(java.util.concurrent.Callable.class, "Supplier", false)), true) ; Assert.assertThat( result, IsNull.notNullValue()); @@ -214,8 +214,8 @@ public void testSample1() throws Exception { final Method m = type.getMethod("method1_3"); final Type rType = m.getGenericReturnType(); final String result = TypescriptConverter.convertJavaToTS(rType, m, - TSType.from(type), - declaredClassMap(java.util.function.BiPredicate.class), + TSType.from(type), + declaredTypeMap( TSType.from(java.util.function.BiPredicate.class, "BiPredicate",false) ), true, Optional.of(addTypeVar)); Assert.assertThat( result, IsNull.notNullValue()); @@ -302,7 +302,7 @@ public void testSample1() throws Exception { final Type pType = m.getParameters()[0].getParameterizedType(); final String rresult = TypescriptConverter.convertJavaToTS(pType, m, TSType.from(type), - declaredClassMap(Sample2.class, Consumer.class), + declaredTypeMap( TSType.from(Sample2.class), TSType.from(Consumer.class, "Consumer", false)), true, Optional.empty()); Assert.assertThat( rresult, IsNull.notNullValue()); diff --git a/pom.xml b/pom.xml index 346f17d..afa8123 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.bsc.processor java2ts-processor-parent - 0.2.0 + 1.0-beta1 pom java2ts-processor::parent - ${project.version} diff --git a/processor/pom.xml b/processor/pom.xml index 6beca2f..9a7ed9e 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -7,7 +7,7 @@ org.bsc.processor java2ts-processor-parent - 0.2.0 + 1.0-beta1 diff --git a/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java b/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java index 1ce6082..d6843ce 100644 --- a/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java +++ b/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java @@ -48,7 +48,22 @@ public class TypescriptProcessor extends AbstractProcessorEx { TSType.from(java.util.Map.class), TSType.from(java.util.stream.Stream.class, true), TSType.from(java.util.stream.Collectors.class,true), - TSType.from(java.util.Optional.class, true) + TSType.from(java.util.Optional.class, true), + + TSType.from(java.lang.Comparable.class), + TSType.from(java.util.function.Function.class, "Func", false), + TSType.from(java.util.function.BiFunction.class, "BiFunction", false), + TSType.from(java.util.function.Consumer.class, "Consumer", false), + TSType.from(java.util.function.BiConsumer.class, "BiConsumer", false), + TSType.from(java.util.function.UnaryOperator.class, "UnaryOperator", false), + TSType.from(java.util.function.BinaryOperator.class, "BinaryOperator", false), + TSType.from(java.util.function.Supplier.class, "Supplier", false), + TSType.from(java.util.function.Predicate.class, "Predicate", false), + TSType.from(java.util.function.BiPredicate.class, "BiPredicate", false), + TSType.from(java.lang.Runnable.class, "Runnable", false) + + + ); /** @@ -109,18 +124,8 @@ public boolean process( Context processingContext ) throws Exception { final Set types = enumerateDeclaredPackageAndClass( processingContext ); types.addAll(REQUIRED_TYPES); - - // Generate Alias - wD.append("//\n") - .append("// TYPE ALIASES\n") - .append("//\n\n"); - types.stream() - .filter( t -> !t.isFunctionalInterface() ) - .filter( t -> t.hasAlias() ) - .map( t -> TypescriptConverter.getAliasDeclaration(t.getValue(), t.getAlias()) ) - .forEach( wD_append ); - - types.addAll(PREDEFINED_TYPES); + + types.addAll(PREDEFINED_TYPES); final java.util.Map declaredTypes = types.stream() diff --git a/processor/src/main/java/org/bsc/processor/annotation/Type.java b/processor/src/main/java/org/bsc/processor/annotation/Type.java index 817117c..7cc357c 100644 --- a/processor/src/main/java/org/bsc/processor/annotation/Type.java +++ b/processor/src/main/java/org/bsc/processor/annotation/Type.java @@ -11,5 +11,4 @@ Class value(); boolean export() default false ; String alias() default ""; - boolean functional() default false ; } diff --git a/sample/pom.xml b/sample/pom.xml index da23767..68bfb6f 100644 --- a/sample/pom.xml +++ b/sample/pom.xml @@ -8,7 +8,7 @@ org.bsc.processor java2ts-processor-parent - 0.2.0 + 1.0-beta1 diff --git a/sample/src/main/java/org/bsc/java2ts/jdk8/package-info.java b/sample/src/main/java/org/bsc/java2ts/jdk8/package-info.java index 652d1f2..291606e 100644 --- a/sample/src/main/java/org/bsc/java2ts/jdk8/package-info.java +++ b/sample/src/main/java/org/bsc/java2ts/jdk8/package-info.java @@ -6,7 +6,7 @@ @Java2TS(declare = { @Type(java.lang.System.class), - @Type(value=java.util.List.class, alias="List" ), + @Type(value=java.util.List.class), @Type(value=java.util.Arrays.class, export=true), @Type(java.nio.file.Files.class), @@ -18,7 +18,7 @@ @Type(value=java.net.URI.class, export=true), @Type(java.net.URL.class), - @Type(value=java.util.concurrent.Callable.class, functional=true, alias="Supplier"), + @Type(value=java.util.concurrent.Callable.class, alias="Callable"), diff --git a/sample/src/main/ts/main.ts b/sample/src/main/ts/main.ts index 9154a3f..80fd302 100644 --- a/sample/src/main/ts/main.ts +++ b/sample/src/main/ts/main.ts @@ -2,16 +2,16 @@ import * as colors from "colors/safe"; import mustache = require("mustache"); -import {Stream, URI, Arrays} from "ts/jdk8-types"; +import {Stream, URI, Arrays, Optional} from "ts/jdk8-types"; let b = "hello jjs"; -let a = Arrays.asList( [ "item1", "item2", "item3", "item4.1"] ); +let a = Arrays.asList( "item1", "item2", "item3", "item4.1" ); print( colors.red(b) ); -a.stream().forEach( (e:any) => { +a.stream().forEach( e => { print( colors.green(e) ); }); @@ -45,3 +45,6 @@ let uri = URI.create( u1 ); print( uri.resolve( u2 ).toString() ); print( URI.create( u1 + u2 ).normalize().toString() ); print( uri.resolve( u3 ).toString() ); + +print( Optional.empty().map( e => "element: " + e).orElse("nil") ); +print( Optional.of("HELLO").map( e => "element: " + e).orElse("nil") );