OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, the Dart project authors. | 2 * Copyright (c) 2013, the Dart project authors. |
3 * | 3 * |
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
12 * the License. | 12 * the License. |
13 */ | 13 */ |
14 package com.google.dart.engine.internal.resolver; | 14 package com.google.dart.engine.internal.resolver; |
15 | 15 |
16 import com.google.dart.engine.AnalysisEngine; | 16 import com.google.dart.engine.AnalysisEngine; |
17 import com.google.dart.engine.element.ClassElement; | 17 import com.google.dart.engine.element.ClassElement; |
18 import com.google.dart.engine.element.Element; | 18 import com.google.dart.engine.element.Element; |
19 import com.google.dart.engine.element.LibraryElement; | 19 import com.google.dart.engine.element.LibraryElement; |
20 import com.google.dart.engine.internal.scope.Namespace; | 20 import com.google.dart.engine.internal.scope.Namespace; |
21 import com.google.dart.engine.internal.scope.NamespaceBuilder; | 21 import com.google.dart.engine.internal.scope.NamespaceBuilder; |
22 import com.google.dart.engine.internal.type.BottomTypeImpl; | 22 import com.google.dart.engine.internal.type.BottomTypeImpl; |
23 import com.google.dart.engine.internal.type.DynamicTypeImpl; | 23 import com.google.dart.engine.internal.type.DynamicTypeImpl; |
24 import com.google.dart.engine.type.InterfaceType; | 24 import com.google.dart.engine.type.InterfaceType; |
25 import com.google.dart.engine.type.Type; | 25 import com.google.dart.engine.type.Type; |
26 | 26 |
27 /** | 27 /** |
28 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language | 28 * Instances of the class {@code TypeProviderImpl} provide access to types defin
ed by the language |
29 * by looking for those types in the element model for the core library. | 29 * by looking for those types in the element model for the core library. |
30 * | 30 * |
31 * @coverage dart.engine.resolver | 31 * @coverage dart.engine.resolver |
32 */ | 32 */ |
33 public class TypeProviderImpl implements TypeProvider { | 33 public class TypeProviderImpl implements TypeProvider { |
34 /** | 34 /** |
35 * The type representing the built-in type 'bool'. | 35 * The type representing the built-in type 'bool'. |
36 */ | 36 */ |
37 private InterfaceType boolType; | 37 private InterfaceType boolType; |
38 | 38 |
39 /** | 39 /** |
40 * The type representing the type 'bottom'. | 40 * The type representing the type 'bottom'. |
41 */ | 41 */ |
42 private Type bottomType; | 42 private Type bottomType; |
43 | 43 |
44 /** | 44 /** |
45 * The type representing the built-in type 'double'. | 45 * The type representing the built-in type 'double'. |
46 */ | 46 */ |
47 private InterfaceType doubleType; | 47 private InterfaceType doubleType; |
48 | 48 |
49 /** | 49 /** |
| 50 * The type representing the built-in type 'Deprecated'. |
| 51 */ |
| 52 private InterfaceType deprecatedType; |
| 53 |
| 54 /** |
50 * The type representing the built-in type 'dynamic'. | 55 * The type representing the built-in type 'dynamic'. |
51 */ | 56 */ |
52 private Type dynamicType; | 57 private Type dynamicType; |
53 | 58 |
54 /** | 59 /** |
55 * The type representing the built-in type 'Function'. | 60 * The type representing the built-in type 'Function'. |
56 */ | 61 */ |
57 private InterfaceType functionType; | 62 private InterfaceType functionType; |
58 | 63 |
59 /** | 64 /** |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 */ | 106 */ |
102 private InterfaceType symbolType; | 107 private InterfaceType symbolType; |
103 | 108 |
104 /** | 109 /** |
105 * The type representing the built-in type 'Type'. | 110 * The type representing the built-in type 'Type'. |
106 */ | 111 */ |
107 private InterfaceType typeType; | 112 private InterfaceType typeType; |
108 | 113 |
109 /** | 114 /** |
110 * Initialize a newly created type provider to provide the types defined in th
e given library. | 115 * Initialize a newly created type provider to provide the types defined in th
e given library. |
111 * | 116 * |
112 * @param coreLibrary the element representing the core library (dart:core). | 117 * @param coreLibrary the element representing the core library (dart:core). |
113 */ | 118 */ |
114 public TypeProviderImpl(LibraryElement coreLibrary) { | 119 public TypeProviderImpl(LibraryElement coreLibrary) { |
115 initializeFrom(coreLibrary); | 120 initializeFrom(coreLibrary); |
116 } | 121 } |
117 | 122 |
118 @Override | 123 @Override |
119 public InterfaceType getBoolType() { | 124 public InterfaceType getBoolType() { |
120 return boolType; | 125 return boolType; |
121 } | 126 } |
122 | 127 |
123 @Override | 128 @Override |
124 public Type getBottomType() { | 129 public Type getBottomType() { |
125 return bottomType; | 130 return bottomType; |
126 } | 131 } |
127 | 132 |
128 @Override | 133 @Override |
| 134 public InterfaceType getDeprecatedType() { |
| 135 return deprecatedType; |
| 136 } |
| 137 |
| 138 @Override |
129 public InterfaceType getDoubleType() { | 139 public InterfaceType getDoubleType() { |
130 return doubleType; | 140 return doubleType; |
131 } | 141 } |
132 | 142 |
133 @Override | 143 @Override |
134 public Type getDynamicType() { | 144 public Type getDynamicType() { |
135 return dynamicType; | 145 return dynamicType; |
136 } | 146 } |
137 | 147 |
138 @Override | 148 @Override |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 196 } |
187 | 197 |
188 @Override | 198 @Override |
189 public InterfaceType getTypeType() { | 199 public InterfaceType getTypeType() { |
190 return typeType; | 200 return typeType; |
191 } | 201 } |
192 | 202 |
193 /** | 203 /** |
194 * Return the type with the given name from the given namespace, or {@code nul
l} if there is no | 204 * Return the type with the given name from the given namespace, or {@code nul
l} if there is no |
195 * class with the given name. | 205 * class with the given name. |
196 * | 206 * |
197 * @param namespace the namespace in which to search for the given name | 207 * @param namespace the namespace in which to search for the given name |
198 * @param typeName the name of the type being searched for | 208 * @param typeName the name of the type being searched for |
199 * @return the type that was found | 209 * @return the type that was found |
200 */ | 210 */ |
201 private InterfaceType getType(Namespace namespace, String typeName) { | 211 private InterfaceType getType(Namespace namespace, String typeName) { |
202 Element element = namespace.get(typeName); | 212 Element element = namespace.get(typeName); |
203 if (element == null) { | 213 if (element == null) { |
204 AnalysisEngine.getInstance().getLogger().logInformation("No definition of
type " + typeName); | 214 AnalysisEngine.getInstance().getLogger().logInformation("No definition of
type " + typeName); |
205 return null; | 215 return null; |
206 } | 216 } |
207 return ((ClassElement) element).getType(); | 217 return ((ClassElement) element).getType(); |
208 } | 218 } |
209 | 219 |
210 /** | 220 /** |
211 * Initialize the types provided by this type provider from the given library. | 221 * Initialize the types provided by this type provider from the given library. |
212 * | 222 * |
213 * @param library the library containing the definitions of the core types | 223 * @param library the library containing the definitions of the core types |
214 */ | 224 */ |
215 private void initializeFrom(LibraryElement library) { | 225 private void initializeFrom(LibraryElement library) { |
216 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); | 226 Namespace namespace = new NamespaceBuilder().createPublicNamespace(library); |
217 boolType = getType(namespace, "bool"); | 227 boolType = getType(namespace, "bool"); |
218 bottomType = BottomTypeImpl.getInstance(); | 228 bottomType = BottomTypeImpl.getInstance(); |
| 229 deprecatedType = getType(namespace, "Deprecated"); |
219 doubleType = getType(namespace, "double"); | 230 doubleType = getType(namespace, "double"); |
220 dynamicType = DynamicTypeImpl.getInstance(); | 231 dynamicType = DynamicTypeImpl.getInstance(); |
221 functionType = getType(namespace, "Function"); | 232 functionType = getType(namespace, "Function"); |
222 intType = getType(namespace, "int"); | 233 intType = getType(namespace, "int"); |
223 listType = getType(namespace, "List"); | 234 listType = getType(namespace, "List"); |
224 mapType = getType(namespace, "Map"); | 235 mapType = getType(namespace, "Map"); |
225 nullType = getType(namespace, "Null"); | 236 nullType = getType(namespace, "Null"); |
226 numType = getType(namespace, "num"); | 237 numType = getType(namespace, "num"); |
227 objectType = getType(namespace, "Object"); | 238 objectType = getType(namespace, "Object"); |
228 stackTraceType = getType(namespace, "StackTrace"); | 239 stackTraceType = getType(namespace, "StackTrace"); |
229 stringType = getType(namespace, "String"); | 240 stringType = getType(namespace, "String"); |
230 symbolType = getType(namespace, "Symbol"); | 241 symbolType = getType(namespace, "Symbol"); |
231 typeType = getType(namespace, "Type"); | 242 typeType = getType(namespace, "Type"); |
232 } | 243 } |
233 } | 244 } |
OLD | NEW |