Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
#9 Display generic class names properly, including those with type va…
Browse files Browse the repository at this point in the history
…riables.
  • Loading branch information
Gerald Boersma committed Apr 11, 2020
1 parent a21642b commit 3fa399d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
</docletArtifact>
<useStandardDocletOptions>true</useStandardDocletOptions>
<additionalOptions>
<additionalOption>-output-model true</additionalOption>
<!-- Specify each diagram option here as an additionOption tag. -->
</additionalOptions>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.sun.javadoc.ParameterizedType;
import com.sun.javadoc.ProgramElementDoc;
import com.sun.javadoc.Type;
import com.sun.javadoc.TypeVariable;

import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -546,9 +548,30 @@ private static String buildParameterString(Type type) {
String sep = "";
for (Type param : paramType.typeArguments()) {
sb.append(sep);
sb.append(shortName(param));
TypeVariable paramTypeVariable = param.asTypeVariable();
if (paramTypeVariable != null) {
sb.append(paramTypeVariable.simpleTypeName());
} else {
sb.append(shortName(param));
}
sep = ", ";
}
} else {
// If a generic type has only type variables, it is not a parameterized type.
// It is only considered a parameterized type if it has at least one specific type
// (which itself can also be a parameterized type).
// Need to handle the case where we have a class that has type parameters.
ClassDoc classDocType = type.asClassDoc();
if (classDocType != null) {
TypeVariable[] typeParams = classDocType.typeParameters();
String sep = "";
for (int i=0; i<typeParams.length; i++) {
sb.append(sep);
TypeVariable typeParam = typeParams[i];
sb.append(typeParam.simpleTypeName());
sep = ", ";
}
}
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ public void className(ModelClass modelClass) {
// The name will remain unique across the model, and this
// does not affect the way the class is displayed.
print(modelClass.fullNameWithoutParameters());
for (String param: modelClass.parameters()) {
// It is also possible for a parameter to be a generic, and have <> embedded in the name.
// For example: List<Optional<String>>.
// We'll do the same thing here- just remove the <>.
// That should still guarantee a unique name in all cases.
param = param.replace("<", "").replace(">", "");
print(param);
}
}

public void classType(ModelClass modelClass) {
Expand Down

0 comments on commit 3fa399d

Please sign in to comment.