Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adds toString on generated ParameterizedType
It eases the debugging when parameterized types are created using
the Types.newParameterizedType factory method.
  • Loading branch information
a-peyrard committed Jun 9, 2015
1 parent 51982bb commit dee37c8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions restx-common/src/main/java/restx/common/Types.java
Expand Up @@ -57,6 +57,46 @@ public boolean equals(Object obj) {
}
return false;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Type ownerType = getOwnerType();
if (ownerType != null) {
if (ownerType instanceof Class) {
sb.append(((Class) ownerType).getName());
} else {
sb.append(ownerType.toString());
}

sb.append(".");
if (ownerType instanceof ParameterizedType) {

sb.append(rawType.getName().replace(((Class) ((ParameterizedType) ownerType).getRawType()).getName() + "$", ""));
} else {
sb.append(rawType.getName());
}
} else {
sb.append(rawType.getName());
}

if (arguments != null && arguments.length > 0) {
sb.append("<");
boolean first = true;

for (Type current : arguments) {
if (!first) {
sb.append(", ");
}
sb.append(current.toString()); // getTypeName() in jse8
first = false;
}

sb.append(">");
}

return sb.toString();
}
};
}

Expand Down

0 comments on commit dee37c8

Please sign in to comment.