Skip to content

Commit

Permalink
disable export generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Dec 29, 2017
1 parent 06fcc9d commit 24c3247
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 64 deletions.
18 changes: 10 additions & 8 deletions jdk8/src/main/java/org/bsc/java2ts/jdk8/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
@Type(java.lang.Class.class),
@Type(java.lang.Iterable.class),
@Type(java.lang.CharSequence.class),
@Type(value=java.lang.String.class, export=true),
@Type(java.lang.String.class),
@Type(java.lang.Comparable.class),
@Type(java.lang.Runnable.class),

@Type(java.util.stream.BaseStream.class),
@Type(value=java.util.stream.Stream.class, export=true),
@Type(java.util.stream.Stream.class),

@Type(java.util.Iterator.class),
@Type(java.util.Comparator.class),
@Type(java.util.Collection.class),
@Type(java.util.Map.class),
@Type(java.util.List.class ),
@Type(java.util.Set.class),
@Type(value=java.util.HashMap.class, export=true),
@Type(value=java.util.HashSet.class, export=true),
@Type(value=java.util.ArrayList.class, export=true),
@Type(value=java.util.Optional.class, export=true),
@Type(java.util.Arrays.class),
@Type(java.util.HashMap.class),
@Type(java.util.HashSet.class),
@Type(java.util.ArrayList.class),
@Type(java.util.Optional.class),

@Type(value=java.nio.file.Files.class, export=true),
@Type(java.nio.file.Files.class),
@Type(java.nio.file.Path.class),
@Type(value=java.nio.file.Paths.class, export=true),
@Type(java.nio.file.Paths.class),
@Type(java.nio.file.AccessMode.class),

@Type(java.util.function.UnaryOperator.class),
Expand All @@ -37,5 +38,6 @@
})
package org.bsc.java2ts.jdk8;


import org.bsc.processor.annotation.Java2TS;
import org.bsc.processor.annotation.Type;
117 changes: 64 additions & 53 deletions processor/src/main/java/org/bsc/processor/TypescriptProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -97,17 +98,38 @@ private void addDeclaration( java.io.Writer w, TSType t, boolean isRhinoCompatib

try {
if( isRhinoCompatible ) {
w.append( String.format( "exports.%s:%s\t\t=\t%s;\n", type.getSimpleName(), type.getName(), type.getName()));
w.append( String.format( "export const %s:%s\t\t=\t%s;\n", type.getSimpleName(), type.getName(), type.getName()));
}
else {
w.append( String.format( "exports.%s:%s\t\t=\tJava.type( \"%s\" );\n", type.getSimpleName(), type.getName(), type.getName()));
w.append( String.format( "export const %s:%s\t\t=\tJava.type( \"%s\" );\n", type.getSimpleName(), type.getName(), type.getName()));
}
} catch (IOException e) {
error( "error adding [%s]", t.getValue());
}

}

/**
*
* @param file
* @param header
* @return
* @throws IOException
*/
private java.io.Writer openFile( Path file, String header ) throws IOException {

final FileObject out = super.getSourceOutputFile( Paths.get("ts"), file );

info( "output file [%s]", out.getName() );

final java.io.Writer w = out.openWriter();

try(final java.io.InputStream is = getClass().getClassLoader().getResourceAsStream("headerD.ts") ) {
int c; while( (c = is.read()) != -1 ) w.write(c);
}

return w;
}
/**
*
* @param processingContext
Expand All @@ -116,58 +138,47 @@ private void addDeclaration( java.io.Writer w, TSType t, boolean isRhinoCompatib
@Override
public boolean process( Context processingContext ) throws Exception {

final String targetDefinitionFile = processingContext.getOptionMap().getOrDefault("ts.outfile", "out");
final String compatibility = processingContext.getOptionMap().getOrDefault("compatibility", "nashorn");
final String targetDefinitionFile = processingContext.getOptionMap().getOrDefault("ts.outfile", "out");
//final String compatibility = processingContext.getOptionMap().getOrDefault("compatibility", "nashorn");

try(
final java.io.Writer wD = openFile( Paths.get(targetDefinitionFile.concat(".d.ts")), "headerD.ts" );
/* final java.io.Writer wT = openFile( Paths.get(targetDefinitionFile.concat(".ts")), "headerT.ts" ); */
) {



final FileObject outD = super.getSourceOutputFile( Paths.get("ts"), Paths.get(targetDefinitionFile.concat(".d.ts")));
final FileObject outT = super.getSourceOutputFile( Paths.get("ts"), Paths.get(targetDefinitionFile.concat(".ts")));

info( "output definition file [%s]", outD.getName() );
info( "output declaration file [%s]", outT.getName() );

final java.io.Writer wD = outD.openWriter();
final java.io.Writer wT = outT.openWriter();

try(final java.io.InputStream is = getClass().getClassLoader().getResourceAsStream("header.ts") ) {
int c;
while( (c = is.read()) != -1 ) wD.write(c);
}

final List<TSType> types = enumerateDeclaredPackageAndClass( processingContext );


final List<Class<?>> classes = types.stream()
.peek( t -> addDeclaration(wT, t, compatibility.equalsIgnoreCase("rhino")) )
.map( t -> t.valueAsClass() )
.collect( Collectors.toList());


//
// Check for Required classes
//
REQUIRED_CLASSES.stream()
.filter( c -> !classes.contains(c))
.forEach( c -> classes.add(c) );


final java.util.Map<String, Class<?>> declaredClasses = classes.stream().collect( Collectors.toMap( clazz -> clazz.getName() , clazz -> clazz ));

PREDEFINED_CLASSES.forEach( clazz -> declaredClasses.put( clazz.getName(), clazz) );

classes.stream()
.filter( clazz -> !PREDEFINED_CLASSES.contains(clazz) )
.map( clazz -> processClass( getBeanInfo(clazz), declaredClasses))
.forEach( s -> {
try {
wD.append( s );
} catch (IOException e) {
error( "error adding [%s]", s);
}
} );

wD.close();
wT.close();
final List<TSType> types = enumerateDeclaredPackageAndClass( processingContext );

final List<Class<?>> classes = types.stream()
//.peek( t -> addDeclaration(wT, t, compatibility.equalsIgnoreCase("rhino")) )
.map( t -> t.valueAsClass() )
.collect( Collectors.toList());


//
// Check for Required classes
//
REQUIRED_CLASSES.stream()
.filter( c -> !classes.contains(c))
.forEach( c -> classes.add(c) );


final java.util.Map<String, Class<?>> declaredClasses = classes.stream().collect( Collectors.toMap( clazz -> clazz.getName() , clazz -> clazz ));

PREDEFINED_CLASSES.forEach( clazz -> declaredClasses.put( clazz.getName(), clazz) );

classes.stream()
.filter( clazz -> !PREDEFINED_CLASSES.contains(clazz) )
.map( clazz -> processClass( getBeanInfo(clazz), declaredClasses))
.forEach( s -> {
try {
wD.append( s );
} catch (IOException e) {
error( "error adding [%s]", s);
}
} );

} // end try-with-resources

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ type char = string;
type chararray = [byte];
type bytearray = [char];

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

type Runnable = () => void;

interface Supplier<T> {
Expand Down
3 changes: 3 additions & 0 deletions processor/src/main/resources/headerT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference path="jdk8.d.ts" />


0 comments on commit 24c3247

Please sign in to comment.