Skip to content

Commit

Permalink
add check for functional interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed May 21, 2018
1 parent 9c89d89 commit 8de3fd2
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions core/src/main/java/org/bsc/java2typescript/TSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.String.format;
import java.util.Arrays;

/**
*
* @author softphone
Expand All @@ -27,25 +29,6 @@ protected TSType() {
super(3);
}

public static TSType from(Class<?> cl, boolean exports) {
return new TSType() {
{
put(VALUE, cl);
put(EXPORT, exports);
}
};
}

public static TSType from(Class<?> cl, String alias, boolean exports) {
return new TSType() {
{
put(VALUE, cl);
put(EXPORT, exports);
put(ALIAS, alias);
}
};
}

public static TSType from(Class<?> cl) {
return new TSType() {
{
Expand All @@ -54,7 +37,6 @@ public static TSType from(Class<?> cl) {
};
}


/**
*
* @return
Expand Down Expand Up @@ -97,6 +79,15 @@ public String getAlias() {
return (String) super.get(ALIAS);
}

/**
*
* @return
*/
public TSType setAlias( String value ) {
super.put(ALIAS,value);
return this;
}

/**
*
* @return
Expand All @@ -107,11 +98,10 @@ public boolean isFunctionalInterface() {
if( !getValue().isInterface()) return false;
if( getValue().isAnnotationPresent(FunctionalInterface.class)) return true;

//return Arrays.stream(c.getDeclaredMethods())
// .filter( m -> Modifier.isAbstract(m.getModifiers()) )
// .count() == 1;

return (Boolean)super.getOrDefault( FUNCTIONAL, false);
return (Boolean)super.getOrDefault( FUNCTIONAL, false) &&
Arrays.stream(getValue().getDeclaredMethods())
.filter( m -> Modifier.isAbstract(m.getModifiers()) )
.count() == 1;
}

/**
Expand Down

0 comments on commit 8de3fd2

Please sign in to comment.