From f90898da8e1a61abe8b1d3c379be7a00efc28e37 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Mon, 28 Aug 2017 12:22:06 +0200 Subject: [PATCH] update --- .../bsc/processor/TypescriptProcessor.java | 23 +++++--- processor/src/main/resources/header.ts | 24 +++++++- processor/src/test/java/JShellTest.java | 28 ++++++++++ test/src/main/java/org/test/package-info.java | 23 +++++--- test/src/main/ts/test.ts | 10 ++++ test/tsconfig.json | 55 +++++++++++++++++++ 6 files changed, 146 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/JShellTest.java create mode 100644 test/src/main/ts/test.ts create mode 100644 test/tsconfig.json diff --git a/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java b/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java index 0971608..7d08c3d 100644 --- a/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java +++ b/processor/src/main/java/org/bsc/processor/TypescriptProcessor.java @@ -16,6 +16,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.RandomAccess; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedOptions; @@ -23,11 +24,11 @@ import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; import javax.tools.FileObject; import io.reactivex.Observable; -import static java.lang.String.format; /** * @@ -47,7 +48,8 @@ public class TypescriptProcessor extends AbstractProcessorEx { Closeable.class, AutoCloseable.class, Comparable.class, - Cloneable.class + Cloneable.class, + RandomAccess.class ); /** @@ -288,7 +290,15 @@ private String processClass( BeanInfo bi, java.util.Map> decla } - + @SuppressWarnings("unchecked") + private Observable getAnnotationValueValue( + java.util.Map.Entry entry ) + { + + final AnnotationValue av = entry.getValue(); + return Observable.fromIterable((List)av.getValue()); + + } private Observable> rxEnumerateDeclaredPackageAndClass( final Context processingContext ) { @@ -299,10 +309,9 @@ private Observable> rxEnumerateDeclaredPackageAndClass( final Context p .doOnNext((m) -> info( "Mirror [%s]", m.toString() )) .concatMap( (am) -> Observable.fromIterable(am.getElementValues().entrySet() )) .filter( (entry) -> "declare".equals(String.valueOf(entry.getKey().getSimpleName())) ) - .flatMap( (entry) -> { - final AnnotationValue av = entry.getValue(); - return Observable.fromIterable((List)av.getValue()); - }) + .flatMap( (entry) -> { + return this.getAnnotationValueValue(entry); + }) .map( (av) -> av.getValue() ) //.doOnNext((av) -> info( "AnnotationValue [%s]",av) ) .ofType(DeclaredType.class) diff --git a/processor/src/main/resources/header.ts b/processor/src/main/resources/header.ts index 0d73115..6550d09 100644 --- a/processor/src/main/resources/header.ts +++ b/processor/src/main/resources/header.ts @@ -17,7 +17,7 @@ declare namespace java.lang { interface Class {} interface AutoCloseable {} - + interface Cloneable {} interface Comparable { compareTo?( arg0:T ):number; @@ -25,7 +25,27 @@ declare namespace java.lang { } } +declare namespace java.util { + + interface RandomAccess {} +} + declare namespace java.io { interface Serializable {} -} \ No newline at end of file +} + +declare namespace java.util.stream { + + interface StreamInitializer{ + //builder?( ):any /* java.util.stream.Stream$Builder */; + concat?( arg0:Stream,arg1:Stream ):Stream; + empty?( ):Stream; + generate?( arg0:any /* java.util.function.Supplier */ ):Stream; + iterate?( arg0:java.lang.Object,arg1:any /* java.util.function.UnaryOperator */ ):Stream; + of?( arg0:[any] /* [Ljava.lang.Object; */ ):Stream; + of?( arg0:java.lang.Object ):Stream; + + } + +} diff --git a/processor/src/test/java/JShellTest.java b/processor/src/test/java/JShellTest.java new file mode 100644 index 0000000..e5c2f3d --- /dev/null +++ b/processor/src/test/java/JShellTest.java @@ -0,0 +1,28 @@ +import java.lang.reflect.Method; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; + +public class JShellTest { + + + static Set test1( final Class clazz ) { + + Predicate include = m -> + !m.isBridge() && + !m.isSynthetic() && + Character.isJavaIdentifierStart(m.getName().charAt(0)) && + m.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart); + + Set methods = new LinkedHashSet<>(); + Collections.addAll(methods, clazz.getMethods()); + methods.removeIf(include.negate()); + + Stream.of(clazz.getDeclaredMethods()) + .filter(include) + .forEach(methods::add); + return methods; + } +} diff --git a/test/src/main/java/org/test/package-info.java b/test/src/main/java/org/test/package-info.java index f38136e..70e0105 100644 --- a/test/src/main/java/org/test/package-info.java +++ b/test/src/main/java/org/test/package-info.java @@ -14,19 +14,26 @@ java.util.stream.BaseStream.class, java.util.stream.Stream .class, - java.util.Map.class, - java.util.Collection.class, - java.util.List.class, - java.util.Set.class, java.util.Iterator.class, java.util.Comparator.class, + java.util.Collection.class, + java.util.AbstractCollection.class, + java.util.Map.class, + java.util.AbstractMap.class, + java.util.HashMap.class, + java.util.Set.class, + java.util.AbstractSet.class, + java.util.HashSet.class, + java.util.List.class, + java.util.AbstractList.class, + java.util.ArrayList.class, - java.beans.Beans.class, + //java.beans.Beans.class, - java.sql.Wrapper.class, - java.sql.Connection.class, + //java.sql.Wrapper.class, + //java.sql.Connection.class, - javax.xml.ws.WebServiceFeature.class, + //javax.xml.ws.WebServiceFeature.class, }) package org.test; diff --git a/test/src/main/ts/test.ts b/test/src/main/ts/test.ts new file mode 100644 index 0000000..9fbbed1 --- /dev/null +++ b/test/src/main/ts/test.ts @@ -0,0 +1,10 @@ +/// + + +let list = new java.util.ArrayList(); + + +list.add( "a1" ); +list.add( "a1" ); +list.add( "a1" ); + diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000..b0e7ec2 --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,55 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation: */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + "outDir": "./target", /* Redirect output structure to the directory. */ + //"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "baseUrl": "./src/main/ts", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": [ + "./target/ts" + ] /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + + /* Source Map Options */ + // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + } +} \ No newline at end of file