8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*
Reviewed-by: mchung
--- a/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/GenericArrayTypeImpl.java Fri May 10 10:12:58 2013 -0700
+++ b/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/GenericArrayTypeImpl.java Fri May 10 12:25:16 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type;
-
+import java.util.Objects;
/**
* Implementation of GenericArrayType interface for core reflection.
@@ -81,18 +81,13 @@
if (o instanceof GenericArrayType) {
GenericArrayType that = (GenericArrayType) o;
- Type thatComponentType = that.getGenericComponentType();
- return genericComponentType == null ?
- thatComponentType == null :
- genericComponentType.equals(thatComponentType);
+ return Objects.equals(genericComponentType, that.getGenericComponentType());
} else
return false;
}
@Override
public int hashCode() {
- return (genericComponentType == null) ?
- 0:
- genericComponentType.hashCode();
+ return Objects.hashCode(genericComponentType);
}
}
--- a/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java Fri May 10 10:12:58 2013 -0700
+++ b/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java Fri May 10 12:25:16 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
-
+import java.util.Objects;
/** Implementing class for ParameterizedType interface. */
@@ -47,9 +47,7 @@
Type ownerType) {
this.actualTypeArguments = actualTypeArguments;
this.rawType = rawType;
- if (ownerType != null) {
- this.ownerType = ownerType;
- } else { this.ownerType = rawType.getDeclaringClass();}
+ this.ownerType = (ownerType != null) ? ownerType : rawType.getDeclaringClass();
validateConstructorArguments();
}
@@ -62,7 +60,6 @@
for (int i = 0; i < actualTypeArguments.length; i++) {
// check actuals against formals' bounds
}
-
}
/**
@@ -189,14 +186,9 @@
return ownerEquality && rawEquality && typeArgEquality;
}
-
return
- (ownerType == null ?
- thatOwner == null :
- ownerType.equals(thatOwner)) &&
- (rawType == null ?
- thatRawType == null :
- rawType.equals(thatRawType)) &&
+ Objects.equals(ownerType, thatOwner) &&
+ Objects.equals(rawType, thatRawType) &&
Arrays.equals(actualTypeArguments, // avoid clone
that.getActualTypeArguments());
} else
@@ -207,8 +199,8 @@
public int hashCode() {
return
Arrays.hashCode(actualTypeArguments) ^
- (ownerType == null ? 0 : ownerType.hashCode() ) ^
- (rawType == null ? 0 : rawType.hashCode() );
+ Objects.hashCode(ownerType) ^
+ Objects.hashCode(rawType);
}
public String toString() {
@@ -239,10 +231,7 @@
for(Type t: actualTypeArguments) {
if (!first)
sb.append(", ");
- if (t instanceof Class)
- sb.append(((Class)t).getName());
- else
- sb.append(t.toString());
+ sb.append(t.getTypeName());
first = false;
}
sb.append(">");
--- a/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Fri May 10 10:12:58 2013 -0700
+++ b/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java Fri May 10 12:25:16 2013 -0700
@@ -170,13 +170,8 @@
GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName();
- return
- (genericDeclaration == null ?
- thatDecl == null :
- genericDeclaration.equals(thatDecl)) &&
- (name == null ?
- thatName == null :
- name.equals(thatName));
+ return Objects.equals(genericDeclaration, thatDecl) &&
+ Objects.equals(name, thatName);
} else
return false;
--- a/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/WildcardTypeImpl.java Fri May 10 10:12:58 2013 -0700
+++ b/jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/WildcardTypeImpl.java Fri May 10 12:25:16 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -203,10 +203,7 @@
sb.append(" & ");
first = false;
- if (bound instanceof Class)
- sb.append(((Class)bound).getName() );
- else
- sb.append(bound.toString());
+ sb.append(bound.getTypeName());
}
return sb.toString();
}