8014357: Minor refactorings to sun.reflect.generics.reflectiveObjects.*

Reviewed-by: mchung
This commit is contained in:
Joe Darcy 2013-05-10 12:25:16 -07:00
parent d8751e2c7f
commit b1127b3050
4 changed files with 16 additions and 40 deletions

View File

@ -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 @@ package sun.reflect.generics.reflectiveObjects;
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 @@ public class GenericArrayTypeImpl
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);
}
}

View File

@ -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.ParameterizedType;
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 @@ public class ParameterizedTypeImpl implements ParameterizedType {
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 @@ public class ParameterizedTypeImpl implements ParameterizedType {
for (int i = 0; i < actualTypeArguments.length; i++) {
// check actuals against formals' bounds
}
}
/**
@ -189,14 +186,9 @@ public class ParameterizedTypeImpl implements ParameterizedType {
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 class ParameterizedTypeImpl implements ParameterizedType {
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 @@ public class ParameterizedTypeImpl implements ParameterizedType {
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(">");

View File

@ -170,13 +170,8 @@ public class TypeVariableImpl<D extends GenericDeclaration>
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;

View File

@ -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 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
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();
}