Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Aug 28, 2017
1 parent 96e4b11 commit f90898d
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 17 deletions.
23 changes: 16 additions & 7 deletions processor/src/main/java/org/bsc/processor/TypescriptProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
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;
import javax.annotation.processing.SupportedSourceVersion;
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;

/**
*
Expand All @@ -47,7 +48,8 @@ public class TypescriptProcessor extends AbstractProcessorEx {
Closeable.class,
AutoCloseable.class,
Comparable.class,
Cloneable.class
Cloneable.class,
RandomAccess.class
);

/**
Expand Down Expand Up @@ -288,7 +290,15 @@ private String processClass( BeanInfo bi, java.util.Map<String, Class<?>> decla
}



@SuppressWarnings("unchecked")
private Observable<? extends AnnotationValue> getAnnotationValueValue(
java.util.Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry )
{

final AnnotationValue av = entry.getValue();
return Observable.fromIterable((List<? extends AnnotationValue>)av.getValue());

}

private Observable<Class<?>> rxEnumerateDeclaredPackageAndClass( final Context processingContext ) {

Expand All @@ -299,10 +309,9 @@ private Observable<Class<?>> 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<? extends AnnotationValue>)av.getValue());
})
.flatMap( (entry) -> {
return this.getAnnotationValueValue(entry);
})
.map( (av) -> av.getValue() )
//.doOnNext((av) -> info( "AnnotationValue [%s]",av) )
.ofType(DeclaredType.class)
Expand Down
24 changes: 22 additions & 2 deletions processor/src/main/resources/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,35 @@ declare namespace java.lang {

interface Class<T> {}
interface AutoCloseable {}

interface Cloneable {}
interface Comparable<T> {

compareTo?( arg0:T ):number;

}
}

declare namespace java.util {

interface RandomAccess {}
}

declare namespace java.io {

interface Serializable {}
}
}

declare namespace java.util.stream {

interface StreamInitializer<T>{
//builder?( ):any /* java.util.stream.Stream$Builder */;
concat?( arg0:Stream<T>,arg1:Stream<T> ):Stream<T>;
empty?( ):Stream<T>;
generate?( arg0:any /* java.util.function.Supplier */ ):Stream<T>;
iterate?( arg0:java.lang.Object,arg1:any /* java.util.function.UnaryOperator */ ):Stream<T>;
of?( arg0:[any] /* [Ljava.lang.Object; */ ):Stream<T>;
of?( arg0:java.lang.Object ):Stream<T>;

}

}
28 changes: 28 additions & 0 deletions processor/src/test/java/JShellTest.java
Original file line number Diff line number Diff line change
@@ -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<Method> test1( final Class<?> clazz ) {

Predicate<Method> include = m ->
!m.isBridge() &&
!m.isSynthetic() &&
Character.isJavaIdentifierStart(m.getName().charAt(0)) &&
m.getName().chars().skip(1).allMatch(Character::isJavaIdentifierPart);

Set<Method> methods = new LinkedHashSet<>();
Collections.addAll(methods, clazz.getMethods());
methods.removeIf(include.negate());

Stream.of(clazz.getDeclaredMethods())
.filter(include)
.forEach(methods::add);
return methods;
}
}
23 changes: 15 additions & 8 deletions test/src/main/java/org/test/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions test/src/main/ts/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path="../../../target/ts/jdk8.d.ts" />


let list = new java.util.ArrayList<string>();


list.add( "a1" );
list.add( "a1" );
list.add( "a1" );

55 changes: 55 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
}
}

0 comments on commit f90898d

Please sign in to comment.