< prev index next >
src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java
Print this page
@@ -205,12 +205,14 @@
}
@Override // java.lang.Object
public String toString() {
// Reusable toString implementation, but needs to be
- // specialized for quirks of arrays.
- return annotationsToString(getAnnotations(), false) + type.toString();
+ // specialized for quirks of arrays and interior types of
+ // wildcards, etc.
+ return annotationsToString(getAnnotations(), false) +
+ ((type instanceof Class) ? type.getTypeName(): type.toString());
}
protected String annotationsToString(Annotation[] annotations, boolean leadingSpace) {
if (annotations != null && annotations.length > 0) {
StringJoiner sj = new StringJoiner(" ");
@@ -375,10 +377,17 @@
private TypeVariable<?> getTypeVariable() {
return (TypeVariable)getType();
}
+ // For toString, the declaration of a type variable should
+ // including information about its bounds, etc. However, the
+ // use of a type variable should not. For that reason, it is
+ // acceptable for the toString implementation of
+ // AnnotatedTypeVariableImpl to use the inherited
+ // implementation from AnnotatedTypeBaseImpl.
+
@Override
public boolean equals(Object o) {
if (o instanceof AnnotatedTypeVariable) {
AnnotatedTypeVariable that = (AnnotatedTypeVariable) o;
return equalsTypeAndAnnotations(that) &&
@@ -443,10 +452,28 @@
private ParameterizedType getParameterizedType() {
return (ParameterizedType)getType();
}
@Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(annotationsToString(getAnnotations(), false));
+
+ Type t = getParameterizedType().getRawType();
+ sb.append(t.getTypeName());
+
+ StringJoiner sj = new StringJoiner(", ", "<", ">");
+ sj.setEmptyValue("");
+ for(AnnotatedType typeArg: getAnnotatedActualTypeArguments()) {
+ sj.add(typeArg.toString());
+ }
+ sb.append(sj.toString());
+
+ return sb.toString();
+ }
+
+ @Override
public boolean equals(Object o) {
if (o instanceof AnnotatedParameterizedType) {
AnnotatedParameterizedType that = (AnnotatedParameterizedType) o;
return equalsTypeAndAnnotations(that) &&
Arrays.equals(getAnnotatedActualTypeArguments(), that.getAnnotatedActualTypeArguments());
@@ -522,10 +549,37 @@
private boolean hasUpperBounds() {
return hasUpperBounds;
}
@Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(annotationsToString(getAnnotations(), false));
+ sb.append("?");
+
+ AnnotatedType[] bounds = getAnnotatedLowerBounds();
+ if (bounds.length > 0) {
+ sb.append(" super ");
+ } else {
+ bounds = getAnnotatedUpperBounds();
+ if (bounds.length > 0) {
+ sb.append(" extends ");
+ }
+ // With extra work, could check for and elide " extends
+ // Object" if Object was not annotated.
+ }
+
+ StringJoiner sj = new StringJoiner(" & ");
+ for(AnnotatedType bound : bounds) {
+ sj.add(bound.toString());
+ }
+ sb.append(sj.toString());
+ return sb.toString();
+ }
+
+
+ @Override
public boolean equals(Object o) {
if (o instanceof AnnotatedWildcardType) {
AnnotatedWildcardType that = (AnnotatedWildcardType) o;
return equalsTypeAndAnnotations(that) &&
// Treats ordering as significant
< prev index next >