提交 d4639193 编写于 作者: D darcy

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

Reviewed-by: mchung
上级 2ff3b4e4
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,7 @@ package sun.reflect.generics.reflectiveObjects; ...@@ -27,7 +27,7 @@ package sun.reflect.generics.reflectiveObjects;
import java.lang.reflect.GenericArrayType; import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Objects;
/** /**
* Implementation of GenericArrayType interface for core reflection. * Implementation of GenericArrayType interface for core reflection.
...@@ -81,18 +81,13 @@ public class GenericArrayTypeImpl ...@@ -81,18 +81,13 @@ public class GenericArrayTypeImpl
if (o instanceof GenericArrayType) { if (o instanceof GenericArrayType) {
GenericArrayType that = (GenericArrayType) o; GenericArrayType that = (GenericArrayType) o;
Type thatComponentType = that.getGenericComponentType(); return Objects.equals(genericComponentType, that.getGenericComponentType());
return genericComponentType == null ?
thatComponentType == null :
genericComponentType.equals(thatComponentType);
} else } else
return false; return false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return (genericComponentType == null) ? return Objects.hashCode(genericComponentType);
0:
genericComponentType.hashCode();
} }
} }
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,7 @@ import java.lang.reflect.ParameterizedType; ...@@ -33,7 +33,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable; import java.lang.reflect.TypeVariable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
/** Implementing class for ParameterizedType interface. */ /** Implementing class for ParameterizedType interface. */
...@@ -47,9 +47,7 @@ public class ParameterizedTypeImpl implements ParameterizedType { ...@@ -47,9 +47,7 @@ public class ParameterizedTypeImpl implements ParameterizedType {
Type ownerType) { Type ownerType) {
this.actualTypeArguments = actualTypeArguments; this.actualTypeArguments = actualTypeArguments;
this.rawType = rawType; this.rawType = rawType;
if (ownerType != null) { this.ownerType = (ownerType != null) ? ownerType : rawType.getDeclaringClass();
this.ownerType = ownerType;
} else { this.ownerType = rawType.getDeclaringClass();}
validateConstructorArguments(); validateConstructorArguments();
} }
...@@ -62,7 +60,6 @@ public class ParameterizedTypeImpl implements ParameterizedType { ...@@ -62,7 +60,6 @@ public class ParameterizedTypeImpl implements ParameterizedType {
for (int i = 0; i < actualTypeArguments.length; i++) { for (int i = 0; i < actualTypeArguments.length; i++) {
// check actuals against formals' bounds // check actuals against formals' bounds
} }
} }
/** /**
...@@ -189,14 +186,9 @@ public class ParameterizedTypeImpl implements ParameterizedType { ...@@ -189,14 +186,9 @@ public class ParameterizedTypeImpl implements ParameterizedType {
return ownerEquality && rawEquality && typeArgEquality; return ownerEquality && rawEquality && typeArgEquality;
} }
return return
(ownerType == null ? Objects.equals(ownerType, thatOwner) &&
thatOwner == null : Objects.equals(rawType, thatRawType) &&
ownerType.equals(thatOwner)) &&
(rawType == null ?
thatRawType == null :
rawType.equals(thatRawType)) &&
Arrays.equals(actualTypeArguments, // avoid clone Arrays.equals(actualTypeArguments, // avoid clone
that.getActualTypeArguments()); that.getActualTypeArguments());
} else } else
...@@ -207,8 +199,8 @@ public class ParameterizedTypeImpl implements ParameterizedType { ...@@ -207,8 +199,8 @@ public class ParameterizedTypeImpl implements ParameterizedType {
public int hashCode() { public int hashCode() {
return return
Arrays.hashCode(actualTypeArguments) ^ Arrays.hashCode(actualTypeArguments) ^
(ownerType == null ? 0 : ownerType.hashCode() ) ^ Objects.hashCode(ownerType) ^
(rawType == null ? 0 : rawType.hashCode() ); Objects.hashCode(rawType);
} }
public String toString() { public String toString() {
...@@ -239,10 +231,7 @@ public class ParameterizedTypeImpl implements ParameterizedType { ...@@ -239,10 +231,7 @@ public class ParameterizedTypeImpl implements ParameterizedType {
for(Type t: actualTypeArguments) { for(Type t: actualTypeArguments) {
if (!first) if (!first)
sb.append(", "); sb.append(", ");
if (t instanceof Class) sb.append(t.getTypeName());
sb.append(((Class)t).getName());
else
sb.append(t.toString());
first = false; first = false;
} }
sb.append(">"); sb.append(">");
......
...@@ -170,13 +170,8 @@ public class TypeVariableImpl<D extends GenericDeclaration> ...@@ -170,13 +170,8 @@ public class TypeVariableImpl<D extends GenericDeclaration>
GenericDeclaration thatDecl = that.getGenericDeclaration(); GenericDeclaration thatDecl = that.getGenericDeclaration();
String thatName = that.getName(); String thatName = that.getName();
return return Objects.equals(genericDeclaration, thatDecl) &&
(genericDeclaration == null ? Objects.equals(name, thatName);
thatDecl == null :
genericDeclaration.equals(thatDecl)) &&
(name == null ?
thatName == null :
name.equals(thatName));
} else } else
return false; return false;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -203,10 +203,7 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator ...@@ -203,10 +203,7 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
sb.append(" & "); sb.append(" & ");
first = false; first = false;
if (bound instanceof Class) sb.append(bound.getTypeName());
sb.append(((Class)bound).getName() );
else
sb.append(bound.toString());
} }
return sb.toString(); return sb.toString();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册