| /* |
| * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0, which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * This Source Code may also be made available under the following Secondary |
| * Licenses when the conditions for such availability set forth in the |
| * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| * version 2 with the GNU Classpath Exception, which is available at |
| * https://www.gnu.org/software/classpath/license.html. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| */ |
| |
| package org.jvnet.tiger_types; |
| |
| import java.lang.reflect.GenericArrayType; |
| import java.lang.reflect.Type; |
| |
| /** |
| * Implementation of GenericArrayType interface for core reflection. |
| */ |
| final class GenericArrayTypeImpl implements GenericArrayType { |
| private Type genericComponentType; |
| |
| GenericArrayTypeImpl(Type ct) { |
| assert ct!=null; |
| genericComponentType = ct; |
| } |
| |
| /** |
| * Returns a <tt>Type</tt> object representing the component type |
| * of this array. |
| * |
| * @return a <tt>Type</tt> object representing the component type |
| * of this array |
| * @since 1.5 |
| */ |
| public Type getGenericComponentType() { |
| return genericComponentType; // return cached component type |
| } |
| |
| public String toString() { |
| Type componentType = getGenericComponentType(); |
| StringBuilder sb = new StringBuilder(); |
| |
| if (componentType instanceof Class) |
| sb.append(((Class) componentType).getName()); |
| else |
| sb.append(componentType.toString()); |
| sb.append("[]"); |
| return sb.toString(); |
| } |
| |
| @Override |
| public boolean equals(Object o) { |
| if (o instanceof GenericArrayType) { |
| GenericArrayType that = (GenericArrayType) o; |
| |
| Type thatComponentType = that.getGenericComponentType(); |
| return genericComponentType.equals(thatComponentType); |
| } else |
| return false; |
| } |
| |
| @Override |
| public int hashCode() { |
| return genericComponentType.hashCode(); |
| } |
| } |