Skip to content

Commit

Permalink
support of declarative member classes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed May 16, 2018
1 parent 2bed0f3 commit 34124ec
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 245 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.classpath
.settings/
.project
.vscode/
38 changes: 33 additions & 5 deletions core/src/main/java/org/bsc/java2typescript/TSType.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,35 @@ public String getAlias() {
return (String) super.get(ALIAS);
}

private String getMemberSimpleTypeName() {

return format( "%s$%s", getValue().getDeclaringClass().getSimpleName(), getValue().getSimpleName());
}

/**
*
* @return
*/
public final String getTypeName() {
return (hasAlias()) ? getAlias() : format( "%s.%s", getNamespace(), getValue().getSimpleName());
return (hasAlias()) ? getAlias() : format( "%s.%s", getNamespace(),
(getValue().isMemberClass() ? getMemberSimpleTypeName() : getValue().getSimpleName()));
}

/**
*
* @return
*/
public final String getSimpleTypeName() {
return (hasAlias()) ? getAlias() : getValue().getSimpleName();
return (hasAlias()) ? getAlias() :
((getValue().isMemberClass()) ? getMemberSimpleTypeName() : getValue().getSimpleName());
}

/**
*
* @return
*/
public final boolean supportNamespace() {
return !getValue().isMemberClass() && !hasAlias();
return !hasAlias();
}

/**
Expand Down Expand Up @@ -165,6 +172,19 @@ public Set<Method> getMethods() {

}

/**
*
* @param name
* @return
*/
private Class<?> getMemberClassForName( String fqn ) throws ClassNotFoundException {
char[] ch = fqn.toCharArray();
int i = fqn.lastIndexOf('.');
ch[i] = '$';

return Class.forName(String.valueOf(ch));
}

/**
*
* @param dt
Expand All @@ -174,10 +194,18 @@ private Class<?> getClassFrom(Object dt) {
if (dt instanceof Class)
return (Class<?>) dt;

final String fqn = dt.toString();
try {
return Class.forName(dt.toString());
return Class.forName(fqn);

} catch (ClassNotFoundException e1) {
throw new RuntimeException(String.format("class not found [%s]", dt), e1);

try {
return getMemberClassForName(fqn);

} catch (ClassNotFoundException e2) {
throw new RuntimeException(String.format("class not found [%s]", dt), e1);
}
}
}

Expand Down
Loading

0 comments on commit 34124ec

Please sign in to comment.