| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class RuntimeTypeInformation { | 7 class RuntimeTypeInformation { |
| 8 final Compiler compiler; | 8 final Compiler compiler; |
| 9 | 9 |
| 10 RuntimeTypeInformation(this.compiler); | 10 RuntimeTypeInformation(this.compiler); |
| 11 | 11 |
| 12 // TODO(karlklose): remove when using type representations. | 12 // TODO(karlklose): remove when using type representations. |
| 13 String getStringRepresentation(DartType type, {bool expandRawType: false}) { | 13 String getStringRepresentation(DartType type, {bool expandRawType: false}) { |
| 14 StringBuffer builder = new StringBuffer(); | 14 StringBuffer builder = new StringBuffer(); |
| 15 void build(DartType t) { | 15 void build(DartType t) { |
| 16 if (t is TypeVariableType) { | 16 if (t is TypeVariableType) { |
| 17 builder.add(t.name.slowToString()); | 17 builder.add(t.name.slowToString()); |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 JavaScriptBackend backend = compiler.backend; | 20 JavaScriptBackend backend = compiler.backend; |
| 21 builder.add(backend.namer.getName(t.element)); | 21 builder.add(backend.namer.getName(t.element)); |
| 22 if (t is InterfaceType) { | 22 if (t is InterfaceType) { |
| 23 InterfaceType interface = t; | 23 InterfaceType interface = t; |
| 24 ClassElement element = t.element; | 24 ClassElement element = t.element; |
| 25 if (element.typeVariables.isEmpty) return; | 25 if (element.typeVariables.isEmpty) return; |
| 26 bool isRaw = interface.typeArguments.isEmpty; | 26 bool isRaw = interface.isRaw; |
| 27 if (isRaw && !expandRawType) return; | 27 if (isRaw && !expandRawType) return; |
| 28 builder.add('<'); | 28 builder.add('<'); |
| 29 Iterable items = | 29 Iterable items = interface.typeArguments; |
| 30 isRaw ? element.typeVariables : interface.typeArguments; | |
| 31 var stringify = isRaw ? (_) => 'dynamic' : (type) => type.toString(); | 30 var stringify = isRaw ? (_) => 'dynamic' : (type) => type.toString(); |
| 32 bool first = true; | 31 bool first = true; |
| 33 for (var item in items) { | 32 for (var item in items) { |
| 34 if (first) { | 33 if (first) { |
| 35 first = false; | 34 first = false; |
| 36 } else { | 35 } else { |
| 37 builder.add(', '); | 36 builder.add(', '); |
| 38 } | 37 } |
| 39 builder.add(stringify(item)); | 38 builder.add(stringify(item)); |
| 40 } | 39 } |
| 41 builder.add('>'); | 40 builder.add('>'); |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 | 43 |
| 45 build(type); | 44 build(type); |
| 46 return builder.toString(); | 45 return builder.toString(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 static bool hasTypeArguments(DartType type) { | 48 static bool hasTypeArguments(DartType type) { |
| 50 if (type is InterfaceType) { | 49 if (type is InterfaceType) { |
| 51 InterfaceType interfaceType = type; | 50 InterfaceType interfaceType = type; |
| 52 return !interfaceType.typeArguments.isEmpty; | 51 return !interfaceType.isRaw; |
| 53 } | 52 } |
| 54 return false; | 53 return false; |
| 55 } | 54 } |
| 56 | 55 |
| 57 static int getTypeVariableIndex(TypeVariableType variable) { | 56 static int getTypeVariableIndex(TypeVariableType variable) { |
| 58 ClassElement classElement = variable.element.getEnclosingClass(); | 57 ClassElement classElement = variable.element.getEnclosingClass(); |
| 59 Link<DartType> variables = classElement.typeVariables; | 58 Link<DartType> variables = classElement.typeVariables; |
| 60 for (int index = 0; !variables.isEmpty; | 59 for (int index = 0; !variables.isEmpty; |
| 61 index++, variables = variables.tail) { | 60 index++, variables = variables.tail) { |
| 62 if (variables.head == variable) return index; | 61 if (variables.head == variable) return index; |
| 63 } | 62 } |
| 64 } | 63 } |
| 65 } | 64 } |
| OLD | NEW |