Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeData.java @ 16759:23415229349b
Truffle-DSL: new package structure.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:57:14 +0200 |
parents | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/typesystem/TypeData.java@bd28da642eea |
children | e8d9b3827d4b |
comparison
equal
deleted
inserted
replaced
16758:c5f8eeb3cbc8 | 16759:23415229349b |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2012, 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 com.oracle.truffle.dsl.processor.model; | |
24 | |
25 import java.util.*; | |
26 | |
27 import javax.lang.model.element.*; | |
28 import javax.lang.model.type.*; | |
29 | |
30 import com.oracle.truffle.dsl.processor.java.*; | |
31 | |
32 public class TypeData extends MessageContainer implements Comparable<TypeData> { | |
33 | |
34 private final TypeSystemData typeSystem; | |
35 private final AnnotationValue annotationValue; | |
36 private final TypeMirror primitiveType; | |
37 private final TypeMirror boxedType; | |
38 | |
39 private final int index; | |
40 private final List<TypeCastData> typeCasts = new ArrayList<>(); | |
41 private final List<TypeCheckData> typeChecks = new ArrayList<>(); | |
42 | |
43 public TypeData(TypeSystemData typeSystem, int index, AnnotationValue value, TypeMirror primitiveType, TypeMirror boxedType) { | |
44 this.index = index; | |
45 this.typeSystem = typeSystem; | |
46 this.annotationValue = value; | |
47 this.primitiveType = primitiveType; | |
48 this.boxedType = boxedType; | |
49 } | |
50 | |
51 @Override | |
52 public Element getMessageElement() { | |
53 return typeSystem.getMessageElement(); | |
54 } | |
55 | |
56 @Override | |
57 public AnnotationMirror getMessageAnnotation() { | |
58 return typeSystem.getMessageAnnotation(); | |
59 } | |
60 | |
61 @Override | |
62 public AnnotationValue getMessageAnnotationValue() { | |
63 return annotationValue; | |
64 } | |
65 | |
66 public void addTypeCast(TypeCastData typeCast) { | |
67 this.typeCasts.add(typeCast); | |
68 } | |
69 | |
70 public void addTypeCheck(TypeCheckData typeCheck) { | |
71 this.typeChecks.add(typeCheck); | |
72 } | |
73 | |
74 public List<TypeCastData> getTypeCasts() { | |
75 return typeCasts; | |
76 } | |
77 | |
78 public List<TypeCheckData> getTypeChecks() { | |
79 return typeChecks; | |
80 } | |
81 | |
82 public TypeSystemData getTypeSystem() { | |
83 return typeSystem; | |
84 } | |
85 | |
86 public TypeMirror getPrimitiveType() { | |
87 return primitiveType; | |
88 } | |
89 | |
90 public TypeMirror getBoxedType() { | |
91 return boxedType; | |
92 } | |
93 | |
94 public boolean isGeneric() { | |
95 return ElementUtils.typeEquals(boxedType, getTypeSystem().getGenericType()); | |
96 } | |
97 | |
98 public boolean isVoid() { | |
99 if (getTypeSystem().getVoidType() == null) { | |
100 return false; | |
101 } | |
102 return ElementUtils.typeEquals(boxedType, getTypeSystem().getVoidType().getBoxedType()); | |
103 } | |
104 | |
105 public int compareTo(TypeData o) { | |
106 if (this.equals(o)) { | |
107 return 0; | |
108 } | |
109 return index - o.index; | |
110 } | |
111 | |
112 @Override | |
113 public int hashCode() { | |
114 return Objects.hash(index, primitiveType); | |
115 } | |
116 | |
117 @Override | |
118 public boolean equals(Object obj) { | |
119 if (!(obj instanceof TypeData)) { | |
120 return false; | |
121 } | |
122 TypeData otherType = (TypeData) obj; | |
123 return index == otherType.index && ElementUtils.typeEquals(primitiveType, otherType.primitiveType); | |
124 } | |
125 | |
126 @Override | |
127 public String toString() { | |
128 return getClass().getSimpleName() + "[" + ElementUtils.getSimpleName(primitiveType) + "]"; | |
129 } | |
130 | |
131 public boolean equalsType(TypeData actualTypeData) { | |
132 return ElementUtils.typeEquals(boxedType, actualTypeData.boxedType); | |
133 } | |
134 | |
135 public boolean needsCastTo(TypeData targetType) { | |
136 return ElementUtils.needsCastTo(getPrimitiveType(), targetType.getPrimitiveType()); | |
137 } | |
138 | |
139 public boolean needsCastTo(TypeMirror targetType) { | |
140 return ElementUtils.needsCastTo(getPrimitiveType(), targetType); | |
141 } | |
142 | |
143 public boolean isPrimitive() { | |
144 return ElementUtils.isPrimitive(getPrimitiveType()); | |
145 } | |
146 | |
147 public boolean isImplicitSubtypeOf(TypeData other) { | |
148 List<ImplicitCastData> casts = other.getTypeSystem().lookupByTargetType(other); | |
149 for (ImplicitCastData cast : casts) { | |
150 if (isSubtypeOf(cast.getSourceType())) { | |
151 return true; | |
152 } | |
153 } | |
154 return isSubtypeOf(other); | |
155 } | |
156 | |
157 public boolean isSubtypeOf(TypeData other) { | |
158 return ElementUtils.isSubtype(boxedType, other.boxedType); | |
159 } | |
160 | |
161 } |