mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8310849: Pattern matching for instanceof and arrayType cleanup in j.l.invoke and j.l.reflect
Reviewed-by: mchung, darcy
This commit is contained in:
parent
7ce967a10c
commit
2bd4136bdb
34 changed files with 211 additions and 292 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, 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
|
||||
|
@ -53,7 +53,7 @@ public class BytecodeDescriptor {
|
|||
int start, int end, ClassLoader loader) {
|
||||
String str = bytecodeSignature;
|
||||
int[] i = {start};
|
||||
ArrayList<Class<?>> ptypes = new ArrayList<Class<?>>();
|
||||
var ptypes = new ArrayList<Class<?>>();
|
||||
if (i[0] < end && str.charAt(i[0]) == '(') {
|
||||
++i[0]; // skip '('
|
||||
while (i[0] < end && str.charAt(i[0]) != ')') {
|
||||
|
@ -97,7 +97,7 @@ public class BytecodeDescriptor {
|
|||
} else if (c == '[') {
|
||||
Class<?> t = parseSig(str, i, end, loader);
|
||||
if (t != null)
|
||||
t = java.lang.reflect.Array.newInstance(t, 0).getClass();
|
||||
t = t.arrayType();
|
||||
return t;
|
||||
} else {
|
||||
return Wrapper.forBasicType(c).primitiveType();
|
||||
|
@ -114,10 +114,10 @@ public class BytecodeDescriptor {
|
|||
}
|
||||
|
||||
public static String unparse(Object type) {
|
||||
if (type instanceof Class<?>)
|
||||
return unparse((Class<?>) type);
|
||||
if (type instanceof MethodType)
|
||||
return ((MethodType) type).toMethodDescriptorString();
|
||||
if (type instanceof Class<?> cl)
|
||||
return unparse(cl);
|
||||
if (type instanceof MethodType mt)
|
||||
return mt.toMethodDescriptorString();
|
||||
return (String) type;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2023, 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
|
||||
|
@ -354,8 +354,8 @@ public class BytecodeName {
|
|||
Object[] components0 = components;
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
Object c = components[i];
|
||||
if (c instanceof String) {
|
||||
String mc = toBytecodeName((String) c);
|
||||
if (c instanceof String s) {
|
||||
String mc = toBytecodeName(s);
|
||||
if (i == 0 && components.length == 1)
|
||||
return mc; // usual case
|
||||
if ((Object)mc != c) {
|
||||
|
@ -376,8 +376,8 @@ public class BytecodeName {
|
|||
}
|
||||
int slen = 0;
|
||||
for (Object c : components) {
|
||||
if (c instanceof String)
|
||||
slen += String.valueOf(c).length();
|
||||
if (c instanceof String s)
|
||||
slen += s.length();
|
||||
else
|
||||
slen += 1;
|
||||
}
|
||||
|
@ -408,9 +408,8 @@ public class BytecodeName {
|
|||
public static String toDisplayName(String s) {
|
||||
Object[] components = parseBytecodeName(s);
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
if (!(components[i] instanceof String))
|
||||
if (!(components[i] instanceof String sn))
|
||||
continue;
|
||||
String sn = (String) components[i];
|
||||
// note that the name is already demangled!
|
||||
//sn = toSourceName(sn);
|
||||
if (!isJavaIdent(sn) || sn.indexOf('$') >=0 ) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, 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
|
||||
|
@ -76,8 +76,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static int unboxInteger(Object x, boolean cast) {
|
||||
if (x instanceof Integer)
|
||||
return (Integer) x;
|
||||
if (x instanceof Integer i)
|
||||
return i;
|
||||
return primitiveConversion(Wrapper.INT, x, cast).intValue();
|
||||
}
|
||||
|
||||
|
@ -85,8 +85,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static byte unboxByte(Object x, boolean cast) {
|
||||
if (x instanceof Byte)
|
||||
return (Byte) x;
|
||||
if (x instanceof Byte b)
|
||||
return b;
|
||||
return primitiveConversion(Wrapper.BYTE, x, cast).byteValue();
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static short unboxShort(Object x, boolean cast) {
|
||||
if (x instanceof Short)
|
||||
return (Short) x;
|
||||
if (x instanceof Short s)
|
||||
return s;
|
||||
return primitiveConversion(Wrapper.SHORT, x, cast).shortValue();
|
||||
}
|
||||
|
||||
|
@ -103,8 +103,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static boolean unboxBoolean(Object x, boolean cast) {
|
||||
if (x instanceof Boolean)
|
||||
return (Boolean) x;
|
||||
if (x instanceof Boolean b)
|
||||
return b;
|
||||
return (primitiveConversion(Wrapper.BOOLEAN, x, cast).intValue() & 1) != 0;
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static char unboxCharacter(Object x, boolean cast) {
|
||||
if (x instanceof Character)
|
||||
return (Character) x;
|
||||
if (x instanceof Character c)
|
||||
return c;
|
||||
return (char) primitiveConversion(Wrapper.CHAR, x, cast).intValue();
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static long unboxLong(Object x, boolean cast) {
|
||||
if (x instanceof Long)
|
||||
return (Long) x;
|
||||
if (x instanceof Long l)
|
||||
return l;
|
||||
return primitiveConversion(Wrapper.LONG, x, cast).longValue();
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static float unboxFloat(Object x, boolean cast) {
|
||||
if (x instanceof Float)
|
||||
return (Float) x;
|
||||
if (x instanceof Float f)
|
||||
return f;
|
||||
return primitiveConversion(Wrapper.FLOAT, x, cast).floatValue();
|
||||
}
|
||||
|
||||
|
@ -139,8 +139,8 @@ public class ValueConversions {
|
|||
return x;
|
||||
}
|
||||
static double unboxDouble(Object x, boolean cast) {
|
||||
if (x instanceof Double)
|
||||
return (Double) x;
|
||||
if (x instanceof Double d)
|
||||
return d;
|
||||
return primitiveConversion(Wrapper.DOUBLE, x, cast).doubleValue();
|
||||
}
|
||||
|
||||
|
@ -236,12 +236,12 @@ public class ValueConversions {
|
|||
if (!cast) return null;
|
||||
return ZERO_INT;
|
||||
}
|
||||
if (x instanceof Number) {
|
||||
res = (Number) x;
|
||||
} else if (x instanceof Boolean) {
|
||||
res = ((boolean)x ? ONE_INT : ZERO_INT);
|
||||
} else if (x instanceof Character) {
|
||||
res = (int)(char)x;
|
||||
if (x instanceof Number n) {
|
||||
res = n;
|
||||
} else if (x instanceof Boolean b) {
|
||||
res = b ? ONE_INT : ZERO_INT;
|
||||
} else if (x instanceof Character c) {
|
||||
res = (int) c;
|
||||
} else {
|
||||
// this will fail with the required ClassCastException:
|
||||
res = (Number) x;
|
||||
|
@ -259,16 +259,16 @@ public class ValueConversions {
|
|||
* Byte, Short, Character, or Integer.
|
||||
*/
|
||||
public static int widenSubword(Object x) {
|
||||
if (x instanceof Integer)
|
||||
return (int) x;
|
||||
else if (x instanceof Boolean)
|
||||
return fromBoolean((boolean) x);
|
||||
else if (x instanceof Character)
|
||||
return (char) x;
|
||||
else if (x instanceof Short)
|
||||
return (short) x;
|
||||
else if (x instanceof Byte)
|
||||
return (byte) x;
|
||||
if (x instanceof Integer i)
|
||||
return i;
|
||||
else if (x instanceof Boolean b)
|
||||
return fromBoolean(b);
|
||||
else if (x instanceof Character c)
|
||||
return c;
|
||||
else if (x instanceof Short s)
|
||||
return s;
|
||||
else if (x instanceof Byte b)
|
||||
return b;
|
||||
else
|
||||
// Fail with a ClassCastException.
|
||||
return (int) x;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2023, 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
|
||||
|
@ -580,9 +580,9 @@ public enum Wrapper {
|
|||
}
|
||||
|
||||
private static Number numberValue(Object x) {
|
||||
if (x instanceof Number) return (Number)x;
|
||||
if (x instanceof Character) return (int)(Character)x;
|
||||
if (x instanceof Boolean) return (Boolean)x ? 1 : 0;
|
||||
if (x instanceof Number n) return n;
|
||||
if (x instanceof Character c) return (int) c;
|
||||
if (x instanceof Boolean b) return b ? 1 : 0;
|
||||
// Remaining allowed case of void: Must be a null reference.
|
||||
return (Number)x;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2023, 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
|
||||
|
@ -95,8 +95,8 @@ public final class AnnotatedTypeFactory {
|
|||
} else if (type instanceof ParameterizedType t) {
|
||||
if (t.getOwnerType() == null)
|
||||
return addTo;
|
||||
if (t.getRawType() instanceof Class
|
||||
&& Modifier.isStatic(((Class) t.getRawType()).getModifiers()))
|
||||
if (t.getRawType() instanceof Class<?> c
|
||||
&& Modifier.isStatic(c.getModifiers()))
|
||||
return addTo;
|
||||
return nestingForType(t.getOwnerType(), addTo.pushInner());
|
||||
}
|
||||
|
@ -178,10 +178,9 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public AnnotatedType getAnnotatedOwnerType() {
|
||||
if (!(type instanceof Class<?>))
|
||||
if (!(type instanceof Class<?> nested))
|
||||
throw new IllegalStateException("Can't compute owner");
|
||||
|
||||
Class<?> nested = (Class<?>)type;
|
||||
Class<?> owner = nested.getDeclaringClass();
|
||||
if (owner == null) // top-level, local or anonymous
|
||||
return null;
|
||||
|
@ -250,16 +249,12 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AnnotatedType &&
|
||||
return o instanceof AnnotatedType that &&
|
||||
!(o instanceof AnnotatedArrayType) &&
|
||||
!(o instanceof AnnotatedTypeVariable) &&
|
||||
!(o instanceof AnnotatedParameterizedType) &&
|
||||
!(o instanceof AnnotatedWildcardType)) {
|
||||
AnnotatedType that = (AnnotatedType) o;
|
||||
return equalsTypeAndAnnotations(that);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
!(o instanceof AnnotatedWildcardType) &&
|
||||
equalsTypeAndAnnotations(that);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -334,13 +329,10 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AnnotatedArrayType that) {
|
||||
return equalsTypeAndAnnotations(that) &&
|
||||
return o instanceof AnnotatedArrayType that &&
|
||||
equalsTypeAndAnnotations(that) &&
|
||||
Objects.equals(getAnnotatedGenericComponentType(),
|
||||
that.getAnnotatedGenericComponentType());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -378,11 +370,8 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AnnotatedTypeVariable that) {
|
||||
return equalsTypeAndAnnotations(that);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return o instanceof AnnotatedTypeVariable that
|
||||
&& equalsTypeAndAnnotations(that);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,12 +446,9 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AnnotatedParameterizedType that) {
|
||||
return equalsTypeAndAnnotations(that) &&
|
||||
return o instanceof AnnotatedParameterizedType that &&
|
||||
equalsTypeAndAnnotations(that) &&
|
||||
Arrays.equals(getAnnotatedActualTypeArguments(), that.getAnnotatedActualTypeArguments());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -568,15 +554,12 @@ public final class AnnotatedTypeFactory {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof AnnotatedWildcardType that) {
|
||||
return equalsTypeAndAnnotations(that) &&
|
||||
return o instanceof AnnotatedWildcardType that &&
|
||||
equalsTypeAndAnnotations(that) &&
|
||||
// Treats ordering as significant
|
||||
Arrays.equals(getAnnotatedLowerBounds(), that.getAnnotatedLowerBounds()) &&
|
||||
// Treats ordering as significant
|
||||
Arrays.equals(getAnnotatedUpperBounds(), that.getAnnotatedUpperBounds());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -434,8 +434,8 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable {
|
|||
|
||||
// Check for array of string, class, enum const, annotation,
|
||||
// or ExceptionProxy
|
||||
if (v1 instanceof Object[] && v2 instanceof Object[])
|
||||
return Arrays.equals((Object[]) v1, (Object[]) v2);
|
||||
if (v1 instanceof Object[] a1 && v2 instanceof Object[] a2)
|
||||
return Arrays.equals(a1, a2);
|
||||
|
||||
// Check for ill formed annotation(s)
|
||||
if (v2.getClass() != type)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
|
@ -445,9 +445,8 @@ public class AnnotationParser {
|
|||
}
|
||||
static Class<?> toClass(Type o) {
|
||||
if (o instanceof GenericArrayType gat)
|
||||
return Array.newInstance(toClass(gat.getGenericComponentType()), 0)
|
||||
.getClass();
|
||||
return (Class)o;
|
||||
return toClass(gat.getGenericComponentType()).arrayType();
|
||||
return (Class<?>) o;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
|
@ -25,7 +25,6 @@
|
|||
|
||||
package sun.reflect.generics.factory;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -59,12 +58,12 @@ public class CoreReflectionFactory implements GenericsFactory {
|
|||
|
||||
|
||||
private ClassLoader getDeclsLoader() {
|
||||
if (decl instanceof Class) {return ((Class) decl).getClassLoader();}
|
||||
if (decl instanceof Method) {
|
||||
return ((Method) decl).getDeclaringClass().getClassLoader();
|
||||
if (decl instanceof Class<?> c) {return c.getClassLoader();}
|
||||
if (decl instanceof Method m) {
|
||||
return m.getDeclaringClass().getClassLoader();
|
||||
}
|
||||
assert decl instanceof Constructor : "Constructor expected";
|
||||
return ((Constructor) decl).getDeclaringClass().getClassLoader();
|
||||
return ((Constructor<?>) decl).getDeclaringClass().getClassLoader();
|
||||
|
||||
}
|
||||
|
||||
|
@ -119,8 +118,8 @@ public class CoreReflectionFactory implements GenericsFactory {
|
|||
}
|
||||
|
||||
public Type makeArrayType(Type componentType){
|
||||
if (componentType instanceof Class<?>)
|
||||
return Array.newInstance((Class<?>) componentType, 0).getClass();
|
||||
if (componentType instanceof Class<?> ct)
|
||||
return ct.arrayType();
|
||||
else
|
||||
return GenericArrayTypeImpl.make(componentType);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
|
@ -70,12 +70,8 @@ public class GenericArrayTypeImpl
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof GenericArrayType) {
|
||||
GenericArrayType that = (GenericArrayType) o;
|
||||
|
||||
return Objects.equals(genericComponentType, that.getGenericComponentType());
|
||||
} else
|
||||
return false;
|
||||
return o instanceof GenericArrayType that
|
||||
&& Objects.equals(genericComponentType, that.getGenericComponentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
|
@ -25,10 +25,7 @@
|
|||
|
||||
package sun.reflect.generics.reflectiveObjects;
|
||||
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
|
||||
import java.lang.reflect.MalformedParameterizedTypeException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
|
@ -165,42 +162,13 @@ public class ParameterizedTypeImpl implements ParameterizedType {
|
|||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof ParameterizedType) {
|
||||
// Check that information is equivalent
|
||||
ParameterizedType that = (ParameterizedType) o;
|
||||
|
||||
if (this == that)
|
||||
return true;
|
||||
|
||||
Type thatOwner = that.getOwnerType();
|
||||
Type thatRawType = that.getRawType();
|
||||
|
||||
if (false) { // Debugging
|
||||
boolean ownerEquality = (ownerType == null ?
|
||||
thatOwner == null :
|
||||
ownerType.equals(thatOwner));
|
||||
boolean rawEquality = (rawType == null ?
|
||||
thatRawType == null :
|
||||
rawType.equals(thatRawType));
|
||||
|
||||
boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone
|
||||
that.getActualTypeArguments());
|
||||
for (Type t : actualTypeArguments) {
|
||||
System.out.printf("\t\t%s%s%n", t, t.getClass());
|
||||
}
|
||||
|
||||
System.out.printf("\towner %s\traw %s\ttypeArg %s%n",
|
||||
ownerEquality, rawEquality, typeArgEquality);
|
||||
return ownerEquality && rawEquality && typeArgEquality;
|
||||
}
|
||||
|
||||
return
|
||||
Objects.equals(ownerType, thatOwner) &&
|
||||
Objects.equals(rawType, thatRawType) &&
|
||||
if (this == o)
|
||||
return true;
|
||||
return o instanceof ParameterizedType that &&
|
||||
Objects.equals(ownerType, that.getOwnerType()) &&
|
||||
Objects.equals(rawType, that.getRawType()) &&
|
||||
Arrays.equals(actualTypeArguments, // avoid clone
|
||||
that.getActualTypeArguments());
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -219,10 +187,10 @@ public class ParameterizedTypeImpl implements ParameterizedType {
|
|||
|
||||
sb.append("$");
|
||||
|
||||
if (ownerType instanceof ParameterizedTypeImpl) {
|
||||
if (ownerType instanceof ParameterizedTypeImpl pt) {
|
||||
// Find simple name of nested type by removing the
|
||||
// shared prefix with owner.
|
||||
sb.append(rawType.getName().replace( ((ParameterizedTypeImpl)ownerType).rawType.getName() + "$",
|
||||
sb.append(rawType.getName().replace(pt.rawType.getName() + "$",
|
||||
""));
|
||||
} else
|
||||
sb.append(rawType.getSimpleName());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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,6 @@ package sun.reflect.generics.reflectiveObjects;
|
|||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.Member;
|
||||
|
@ -42,7 +41,6 @@ import sun.reflect.annotation.TypeAnnotationParser;
|
|||
import sun.reflect.annotation.AnnotationType;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
||||
/**
|
||||
|
@ -94,7 +92,7 @@ public class TypeVariableImpl<D extends GenericDeclaration>
|
|||
throw new AssertionError("Unexpected kind of GenericDeclaration" +
|
||||
decl.getClass().toString());
|
||||
}
|
||||
return new TypeVariableImpl<T>(decl, name, bs, f);
|
||||
return new TypeVariableImpl<>(decl, name, bs, f);
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,8 +119,8 @@ public class TypeVariableImpl<D extends GenericDeclaration>
|
|||
*/
|
||||
public Type[] getBounds() {
|
||||
Object[] value = bounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
if (value instanceof FieldTypeSignature[] sigs) {
|
||||
value = reifyBounds(sigs);
|
||||
bounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
|
@ -137,8 +135,8 @@ public class TypeVariableImpl<D extends GenericDeclaration>
|
|||
* @since 1.5
|
||||
*/
|
||||
public D getGenericDeclaration() {
|
||||
if (genericDeclaration instanceof Class)
|
||||
ReflectUtil.checkPackageAccess((Class)genericDeclaration);
|
||||
if (genericDeclaration instanceof Class<?> c)
|
||||
ReflectUtil.checkPackageAccess(c);
|
||||
else if ((genericDeclaration instanceof Method) ||
|
||||
(genericDeclaration instanceof Constructor))
|
||||
ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration);
|
||||
|
@ -159,18 +157,10 @@ public class TypeVariableImpl<D extends GenericDeclaration>
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof TypeVariable &&
|
||||
o.getClass() == TypeVariableImpl.class) {
|
||||
TypeVariable<?> that = (TypeVariable<?>) o;
|
||||
|
||||
GenericDeclaration thatDecl = that.getGenericDeclaration();
|
||||
String thatName = that.getName();
|
||||
|
||||
return Objects.equals(genericDeclaration, thatDecl) &&
|
||||
Objects.equals(name, thatName);
|
||||
|
||||
} else
|
||||
return false;
|
||||
return o instanceof TypeVariable<?> that &&
|
||||
o.getClass() == TypeVariableImpl.class &&
|
||||
Objects.equals(genericDeclaration, that.getGenericDeclaration()) &&
|
||||
Objects.equals(name, that.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, 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
|
||||
|
@ -30,7 +30,6 @@ import java.lang.reflect.Type;
|
|||
import java.lang.reflect.WildcardType;
|
||||
import sun.reflect.generics.factory.GenericsFactory;
|
||||
import sun.reflect.generics.tree.FieldTypeSignature;
|
||||
import sun.reflect.generics.visitor.Reifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
|
@ -101,8 +100,8 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
|
|||
*/
|
||||
public Type[] getUpperBounds() {
|
||||
Object[] value = upperBounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
if (value instanceof FieldTypeSignature[] sigs) {
|
||||
value = reifyBounds(sigs);
|
||||
upperBounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
|
@ -132,8 +131,8 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
|
|||
*/
|
||||
public Type[] getLowerBounds() {
|
||||
Object[] value = lowerBounds;
|
||||
if (value instanceof FieldTypeSignature[]) {
|
||||
value = reifyBounds((FieldTypeSignature[])value);
|
||||
if (value instanceof FieldTypeSignature[] sigs) {
|
||||
value = reifyBounds(sigs);
|
||||
lowerBounds = value;
|
||||
}
|
||||
return (Type[])value.clone();
|
||||
|
@ -168,15 +167,9 @@ public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof WildcardType) {
|
||||
WildcardType that = (WildcardType) o;
|
||||
return
|
||||
Arrays.equals(this.getLowerBounds(),
|
||||
that.getLowerBounds()) &&
|
||||
Arrays.equals(this.getUpperBounds(),
|
||||
that.getUpperBounds());
|
||||
} else
|
||||
return false;
|
||||
return o instanceof WildcardType that
|
||||
&& Arrays.equals(this.getLowerBounds(), that.getLowerBounds())
|
||||
&& Arrays.equals(this.getUpperBounds(), that.getUpperBounds());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2005, 2023, 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
|
||||
|
@ -98,14 +98,14 @@ public final class MethodUtil extends SecureClassLoader {
|
|||
} catch (InvocationTargetException ie) {
|
||||
Throwable t = ie.getCause();
|
||||
|
||||
if (t instanceof InvocationTargetException) {
|
||||
throw (InvocationTargetException)t;
|
||||
} else if (t instanceof IllegalAccessException) {
|
||||
throw (IllegalAccessException)t;
|
||||
} else if (t instanceof RuntimeException) {
|
||||
throw (RuntimeException)t;
|
||||
} else if (t instanceof Error) {
|
||||
throw (Error)t;
|
||||
if (t instanceof InvocationTargetException ite) {
|
||||
throw ite;
|
||||
} else if (t instanceof IllegalAccessException iae) {
|
||||
throw iae;
|
||||
} else if (t instanceof RuntimeException re) {
|
||||
throw re;
|
||||
} else if (t instanceof Error error) {
|
||||
throw error;
|
||||
} else {
|
||||
throw new Error("Unexpected invocation error", t);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue