Skip to content

Commit

Permalink
Merge branch 'feature/core' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Mar 18, 2018
2 parents 68c2adf + 2b791bf commit 115838a
Show file tree
Hide file tree
Showing 8 changed files with 978 additions and 892 deletions.
10 changes: 10 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<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.0.0-SNAPSHOT</version>
</parent>
<artifactId>java2ts-processor-core</artifactId>
<name>java2ts-processor::core - ${project.version}</name>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package org.bsc.processor;
package org.bsc.java2typescript;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;


/**
Expand Down Expand Up @@ -45,7 +52,7 @@ public static TSType functional( Class<?> cl, String alias ) {
}};
}

protected static TSType from( Class<?> cl ) {
public static TSType from( Class<?> cl ) {
return new TSType() {{ put( "value", cl); }};
}

Expand Down Expand Up @@ -115,6 +122,45 @@ public final String getTypeName() {
public final String getSimpleTypeName() {
return (hasAlias()) ? getAlias() : getValue().getSimpleName();
}

/**
*
* @param type
* @return
*/
public Set<Field> getFields() {

final Predicate<Field> 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<Method> getMethods() {
final Predicate<Method> 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( ) );

}


/**
*
Expand Down
Loading

0 comments on commit 115838a

Please sign in to comment.