1 /*
2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 package jdk.vm.ci.meta;
24 
25 /**
26  * Implementation of {@link JavaType} for unresolved HotSpot classes.
27  */
28 public final class UnresolvedJavaType implements JavaType {
29     private final String name;
30 
31     @Override
getName()32     public String getName() {
33         return name;
34     }
35 
UnresolvedJavaType(String name)36     private UnresolvedJavaType(String name) {
37         this.name = name;
38         assert name.length() == 1 && JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0)) != null || name.charAt(0) == '[' || name.charAt(name.length() - 1) == ';' : name;
39     }
40 
41     /**
42      * Creates an unresolved type for a valid {@link JavaType#getName() type name}.
43      */
create(String name)44     public static UnresolvedJavaType create(String name) {
45         return new UnresolvedJavaType(name);
46     }
47 
48     @Override
getComponentType()49     public JavaType getComponentType() {
50         if (getName().charAt(0) == '[') {
51             return new UnresolvedJavaType(getName().substring(1));
52         }
53         return null;
54     }
55 
56     @Override
getArrayClass()57     public JavaType getArrayClass() {
58         return new UnresolvedJavaType('[' + getName());
59     }
60 
61     @Override
getJavaKind()62     public JavaKind getJavaKind() {
63         return JavaKind.Object;
64     }
65 
66     @Override
hashCode()67     public int hashCode() {
68         return getName().hashCode();
69     }
70 
71     @Override
equals(Object obj)72     public boolean equals(Object obj) {
73         if (this == obj) {
74             return true;
75         }
76         if (obj == null || !(obj instanceof UnresolvedJavaType)) {
77             return false;
78         }
79         UnresolvedJavaType that = (UnresolvedJavaType) obj;
80         return this.getName().equals(that.getName());
81     }
82 
83     @Override
toString()84     public String toString() {
85         return "UnresolvedJavaType<" + getName() + ">";
86     }
87 
88     @Override
resolve(ResolvedJavaType accessingClass)89     public ResolvedJavaType resolve(ResolvedJavaType accessingClass) {
90         return accessingClass.lookupType(this, true);
91     }
92 }
93