Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #import("../../../lib/dartdoc/mirrors/mirrors.dart"); | |
| 6 #import("../../../lib/dartdoc/mirrors/mirrors_util.dart"); | |
| 7 | |
| 8 #import('dart:io'); | |
| 9 | |
| 10 int count(Iterable iterable) { | |
| 11 var count = 0; | |
| 12 for (var element in iterable) { | |
| 13 count++; | |
| 14 } | |
| 15 return count; | |
| 16 } | |
| 17 | |
| 18 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) { | |
| 19 for (var element in iterable) { | |
| 20 if (element.declaration == expected.declaration) { | |
| 21 return true; | |
| 22 } | |
| 23 } | |
| 24 return false; | |
| 25 } | |
| 26 | |
| 27 main() { | |
| 28 var scriptPath = new Path.fromNative(new Options().script); | |
| 29 var dirPath = scriptPath.directoryPath; | |
| 30 var libPath = dirPath.join(new Path.fromNative('../../../')); | |
| 31 var inputPath = dirPath.join(new Path.fromNative('mirrors_helper.dart')); | |
| 32 var compilation = new Compilation(inputPath.toNativePath(), | |
| 33 libPath.toNativePath()); | |
| 34 Expect.isNotNull(compilation, "No compilation created"); | |
| 35 | |
| 36 var mirrors = compilation.mirrors(); | |
| 37 Expect.isNotNull(mirrors, "No mirror system returned from compilation"); | |
| 38 | |
| 39 var libraries = mirrors.libraries(); | |
| 40 Expect.isNotNull(libraries, "No libraries map returned"); | |
| 41 Expect.isFalse(libraries.isEmpty(), "Empty libraries map returned"); | |
| 42 | |
| 43 var helperLibrary = findMirror(libraries, "mirrors_helper"); | |
| 44 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); | |
| 45 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName(), | |
| 46 "Unexpected library simple name"); | |
| 47 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName(), | |
| 48 "Unexpected library qualified name"); | |
| 49 | |
| 50 var types = helperLibrary.types(); | |
| 51 Expect.isNotNull(types, "No types map returned"); | |
| 52 Expect.isFalse(types.isEmpty(), "Empty types map returned"); | |
| 53 | |
| 54 testFoo(mirrors, helperLibrary, types); | |
| 55 testBar(mirrors, helperLibrary, types); | |
| 56 testBaz(mirrors, helperLibrary, types); | |
| 57 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func]. | |
| 58 // TODO(johnniwinther): Add tests of type argument substitution, which | |
| 59 // is not currently implemented in dart2js. | |
| 60 // TODO(johnniwinther): Add tests of Location and Source. | |
| 61 } | |
| 62 | |
| 63 // Testing class Foo: | |
| 64 // | |
| 65 // class Foo { | |
| 66 // | |
| 67 // } | |
| 68 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, | |
| 69 Map<Object,TypeMirror> types) { | |
| 70 var fooClass = findMirror(types, "Foo"); | |
| 71 Expect.isNotNull(fooClass, "Type 'Foo' not found"); | |
| 72 Expect.isTrue(fooClass is InterfaceMirror, | |
| 73 "Unexpected mirror type returned"); | |
|
Lasse Reichstein Nielsen
2012/07/04 10:58:59
Indentation, preferably to paren. Also below.
Johnni Winther
2012/07/04 13:19:17
Done.
| |
| 74 Expect.stringEquals("Foo", fooClass.simpleName(), | |
| 75 "Unexpected type simple name"); | |
| 76 Expect.stringEquals("mirrors_helper.Foo", fooClass.qualifiedName(), | |
| 77 "Unexpected type qualified name"); | |
| 78 | |
| 79 Expect.equals(helperLibrary, fooClass.library(), | |
| 80 "Unexpected library returned from type"); | |
| 81 | |
| 82 Expect.isFalse(fooClass.isObject, "Class is Object"); | |
| 83 Expect.isFalse(fooClass.isDynamic, "Class is Dynamic"); | |
| 84 Expect.isFalse(fooClass.isVoid, "Class is void"); | |
| 85 Expect.isFalse(fooClass.isTypeVariable, "Class is a type variable"); | |
| 86 Expect.isFalse(fooClass.isTypedef, "Class is a typedef"); | |
| 87 Expect.isFalse(fooClass.isFunction, "Class is a function"); | |
| 88 | |
| 89 Expect.isTrue(fooClass.isDeclaration, "Class is not declaration"); | |
| 90 Expect.equals(fooClass, fooClass.declaration, | |
| 91 "Class is not its declaration"); | |
| 92 | |
| 93 Expect.isTrue(fooClass.isClass, "Class is not class"); | |
| 94 Expect.isFalse(fooClass.isInterface, "Class is interface"); | |
| 95 Expect.isFalse(fooClass.isPrivate, "Class is private"); | |
| 96 | |
| 97 var objectType = fooClass.superclass(); | |
| 98 Expect.isNotNull(objectType, "Superclass is null"); | |
| 99 Expect.isTrue(objectType.isObject, "Object is not Object"); | |
| 100 Expect.isFalse(objectType.isDeclaration, "Object type is declaration"); | |
| 101 Expect.isTrue(containsType(fooClass, computeSubdeclarations(system, objectType )), | |
|
Lasse Reichstein Nielsen
2012/07/04 10:58:59
Line length.
Johnni Winther
2012/07/04 13:19:17
Done.
| |
| 102 "Class is not subclass of superclass"); | |
| 103 | |
| 104 var fooInterfaces = fooClass.interfaces(); | |
| 105 Expect.isNotNull(fooInterfaces, "Interfaces map is null"); | |
| 106 Expect.isTrue(fooInterfaces.isEmpty(), "Interfaces map is not empty"); | |
| 107 | |
| 108 var fooSubdeclarations = computeSubdeclarations(system, fooClass); | |
| 109 Expect.equals(1, count(fooSubdeclarations), "Unexpected subtype count"); | |
| 110 for (var fooSubdeclaration in fooSubdeclarations) { | |
| 111 Expect.equals(fooClass, fooSubdeclaration.superclass().declaration, | |
| 112 "Class is not superclass of subclass"); | |
| 113 } | |
| 114 | |
| 115 Expect.throws(() => fooClass.typeArguments(), | |
| 116 (exception) => true, | |
| 117 "Class has type arguments"); | |
|
Lasse Reichstein Nielsen
2012/07/04 10:58:59
Indentation still off.
Johnni Winther
2012/07/04 13:19:17
Done.
| |
| 118 var fooClassTypeVariables = fooClass.typeVariables(); | |
| 119 Expect.isNotNull(fooClassTypeVariables, "Type variable list is null"); | |
| 120 Expect.isTrue(fooClassTypeVariables.isEmpty(), | |
| 121 "Type variable list is not empty"); | |
| 122 | |
| 123 Expect.isNull(fooClass.defaultType(), "Class has default type"); | |
| 124 | |
| 125 var fooClassMembers = fooClass.declaredMembers(); | |
| 126 Expect.isNotNull(fooClassMembers, "Declared members map is null"); | |
| 127 Expect.isTrue(fooClassMembers.isEmpty(), "Declared members map is unempty"); | |
| 128 | |
| 129 var fooClassConstructors = fooClass.constructors(); | |
| 130 Expect.isNotNull(fooClassConstructors, "Constructors map is null"); | |
| 131 Expect.isTrue(fooClassConstructors.isEmpty(), | |
| 132 "Constructors map is unempty"); | |
| 133 } | |
| 134 | |
| 135 // Testing interface Bar: | |
| 136 // | |
| 137 // interface Bar<E> { | |
| 138 // | |
| 139 // } | |
| 140 void testBar(MirrorSystem system, LibraryMirror helperLibrary, | |
| 141 Map<Object,TypeMirror> types) { | |
| 142 var barInterface = findMirror(types, "Bar"); | |
| 143 Expect.isNotNull(barInterface, "Type 'Bar' not found"); | |
| 144 Expect.isTrue(barInterface is InterfaceMirror, | |
| 145 "Unexpected mirror type returned"); | |
| 146 Expect.stringEquals("Bar", barInterface.simpleName(), | |
| 147 "Unexpected type simple name"); | |
| 148 Expect.stringEquals("mirrors_helper.Bar", barInterface.qualifiedName(), | |
| 149 "Unexpected type qualified name"); | |
| 150 | |
| 151 Expect.equals(helperLibrary, barInterface.library(), | |
| 152 "Unexpected library returned from type"); | |
| 153 | |
| 154 Expect.isFalse(barInterface.isObject, "Interface is Object"); | |
| 155 Expect.isFalse(barInterface.isDynamic, "Interface is Dynamic"); | |
| 156 Expect.isFalse(barInterface.isVoid, "Interface is void"); | |
| 157 Expect.isFalse(barInterface.isTypeVariable, "Interface is a type variable"); | |
| 158 Expect.isFalse(barInterface.isTypedef, "Interface is a typedef"); | |
| 159 Expect.isFalse(barInterface.isFunction, "Interface is a function"); | |
| 160 | |
| 161 Expect.isTrue(barInterface.isDeclaration, "Interface is not declaration"); | |
| 162 Expect.equals(barInterface, barInterface.declaration, | |
| 163 "Interface is not its declaration"); | |
| 164 | |
| 165 Expect.isFalse(barInterface.isClass, "Interface is class"); | |
| 166 Expect.isTrue(barInterface.isInterface, "Interface is not interface"); | |
| 167 Expect.isFalse(barInterface.isPrivate, "Interface is private"); | |
| 168 | |
| 169 var objectType = barInterface.superclass(); | |
| 170 Expect.isNotNull(objectType, "Superclass is null"); | |
| 171 Expect.isTrue(objectType.isObject, "Object is not Object"); | |
| 172 Expect.isFalse(objectType.isDeclaration, "Object type is declaration"); | |
| 173 Expect.isTrue(containsType(barInterface, | |
| 174 computeSubdeclarations(system, objectType)), | |
| 175 "Class is not subclass of superclass"); | |
| 176 | |
| 177 var barInterfaces = barInterface.interfaces(); | |
| 178 Expect.isNotNull(barInterfaces, "Interfaces map is null"); | |
| 179 Expect.isTrue(barInterfaces.isEmpty(), "Interfaces map is not empty"); | |
| 180 | |
| 181 var barSubdeclarations = computeSubdeclarations(system, barInterface); | |
| 182 Expect.equals(1, count(barSubdeclarations), "Unexpected subtype count"); | |
| 183 for (var barSubdeclaration in barSubdeclarations) { | |
| 184 Expect.isTrue(containsType(barInterface, | |
| 185 barSubdeclaration.interfaces().getValues()), | |
| 186 "Interface is not superinterface of subclass"); | |
| 187 } | |
| 188 | |
| 189 Expect.throws(() => barInterface.typeArguments(), | |
| 190 (exception) => true, | |
| 191 "Interface has type arguments"); | |
| 192 var barInterfaceTypeVariables = barInterface.typeVariables(); | |
| 193 Expect.isNotNull(barInterfaceTypeVariables, "Type variable list is null"); | |
| 194 Expect.isFalse(barInterfaceTypeVariables.isEmpty(), | |
| 195 "Type variable list is empty"); | |
| 196 Expect.equals(barInterfaceTypeVariables.length, 1, | |
| 197 "Unexpected number of type variables"); | |
| 198 | |
| 199 var barE = barInterfaceTypeVariables[0]; | |
| 200 Expect.isNotNull(barE, "Type variable is null"); | |
| 201 Expect.isTrue(barE.isTypeVariable, "Type variable is not type variable"); | |
| 202 | |
| 203 Expect.isNull(barInterface.defaultType(), "Interface has default type"); | |
| 204 | |
| 205 var barInterfaceMembers = barInterface.declaredMembers(); | |
| 206 Expect.isNotNull(barInterfaceMembers, "Declared members map is null"); | |
| 207 Expect.isTrue(barInterfaceMembers.isEmpty(), | |
| 208 "Declared members map is unempty"); | |
| 209 | |
| 210 var barInterfaceConstructors = barInterface.constructors(); | |
| 211 Expect.isNotNull(barInterfaceConstructors, "Constructors map is null"); | |
| 212 Expect.isTrue(barInterfaceConstructors.isEmpty(), | |
| 213 "Constructors map is unempty"); | |
| 214 } | |
| 215 | |
| 216 // Testing class Baz: | |
| 217 // | |
| 218 // class Baz<E,F extends Foo> implements Bar<E> { | |
| 219 // Baz(); | |
| 220 // const Baz.named(); | |
| 221 // factory Baz.factory(); | |
| 222 // | |
| 223 // method1(e) {} | |
| 224 // static void method2(E e, [F f = null]) {} | |
| 225 // void method3(E func1(F f), Func<E,F> func2) {} | |
| 226 // | |
| 227 // bool operator==(Object other) => return false; | |
| 228 // Baz<E,F> operator negate() => this; | |
| 229 // } | |
| 230 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, | |
| 231 Map<Object,TypeMirror> types) { | |
| 232 var bazClass = findMirror(types, "Baz"); | |
| 233 Expect.isNotNull(bazClass, "Type 'Baz' not found"); | |
| 234 Expect.isTrue(bazClass is InterfaceMirror, | |
| 235 "Unexpected mirror type returned"); | |
| 236 Expect.stringEquals("Baz", bazClass.simpleName(), | |
| 237 "Unexpected type simple name"); | |
| 238 Expect.stringEquals("mirrors_helper.Baz", bazClass.qualifiedName(), | |
| 239 "Unexpected type qualified name"); | |
| 240 | |
| 241 Expect.equals(helperLibrary, bazClass.library(), | |
| 242 "Unexpected library returned from type"); | |
| 243 | |
| 244 Expect.isFalse(bazClass.isObject, "Class is Object"); | |
| 245 Expect.isFalse(bazClass.isDynamic, "Class is Dynamic"); | |
| 246 Expect.isFalse(bazClass.isVoid, "Class is void"); | |
| 247 Expect.isFalse(bazClass.isTypeVariable, "Class is a type variable"); | |
| 248 Expect.isFalse(bazClass.isTypedef, "Class is a typedef"); | |
| 249 Expect.isFalse(bazClass.isFunction, "Class is a function"); | |
| 250 | |
| 251 Expect.isTrue(bazClass.isDeclaration, "Class is not declaration"); | |
| 252 Expect.equals(bazClass, bazClass.declaration, | |
| 253 "Class is not its declaration"); | |
| 254 | |
| 255 Expect.isTrue(bazClass.isClass, "Class is not class"); | |
| 256 Expect.isFalse(bazClass.isInterface, "Class is interface"); | |
| 257 Expect.isFalse(bazClass.isPrivate, "Class is private"); | |
| 258 | |
| 259 var objectType = bazClass.superclass(); | |
| 260 Expect.isNotNull(objectType, "Superclass is null"); | |
| 261 Expect.isTrue(objectType.isObject, "Object is not Object"); | |
| 262 Expect.isFalse(objectType.isDeclaration, "Object type is declaration"); | |
| 263 Expect.isTrue(containsType(bazClass, | |
| 264 computeSubdeclarations(system, objectType)), | |
| 265 "Class is not subclass of superclass"); | |
| 266 | |
| 267 var bazInterfaces = bazClass.interfaces(); | |
| 268 Expect.isNotNull(bazInterfaces, "Interfaces map is null"); | |
| 269 Expect.isTrue(!bazInterfaces.isEmpty(), "Interfaces map is empty"); | |
| 270 for (var bazInterface in bazInterfaces.getValues()) { | |
| 271 Expect.isTrue(containsType(bazClass, | |
| 272 computeSubdeclarations(system, objectType)), | |
| 273 "Class is not subclass of superinterface"); | |
| 274 } | |
| 275 | |
| 276 var bazSubdeclarations = computeSubdeclarations(system, bazClass); | |
| 277 Expect.equals(0, count(bazSubdeclarations), "Unexpected subtype count"); | |
| 278 | |
| 279 var barInterface = findMirror(bazInterfaces, "Bar"); | |
| 280 Expect.isNotNull(barInterface, "Interface bar is missing"); | |
| 281 Expect.isFalse(barInterface.isDeclaration, "Interface type is declaration"); | |
| 282 var barInterfaceTypeArguments = barInterface.typeArguments(); | |
| 283 Expect.isNotNull(barInterfaceTypeArguments, "Type arguments are missing"); | |
| 284 // TODO(johnniwinther): Ensure type arguments on supertypes. Expected result | |
| 285 // should have been 1: | |
| 286 Expect.equals(0, barInterfaceTypeArguments.length, | |
| 287 "Type arguments is empty"); | |
| 288 | |
| 289 Expect.throws(() => bazClass.typeArguments(), | |
| 290 (exception) => true, | |
| 291 "Class has type arguments"); | |
| 292 var bazClassTypeVariables = bazClass.typeVariables(); | |
| 293 Expect.isNotNull(bazClassTypeVariables, "Type variable list is null"); | |
| 294 Expect.equals(2, bazClassTypeVariables.length, | |
| 295 "Type variable list is not empty"); | |
| 296 | |
| 297 var bazE = bazClassTypeVariables[0]; | |
| 298 Expect.isNotNull(bazE, "Type variable is null"); | |
| 299 Expect.stringEquals('E', bazE.simpleName(), "Unexpected simpleName"); | |
| 300 Expect.stringEquals('mirrors_helper.Baz.E', bazE.qualifiedName(), | |
| 301 "Unexpected qualifiedName"); | |
| 302 Expect.equals(bazClass, bazE.declarer(), | |
| 303 "Unexpected type variable declarer"); | |
| 304 var bazEbound = bazE.bound(); | |
| 305 Expect.isNotNull(bazEbound, "Missing type variable bound"); | |
| 306 Expect.isFalse(bazEbound.isDeclaration, "Bound is declaration"); | |
| 307 Expect.isTrue(bazEbound.isObject, "Bound is not object"); | |
| 308 | |
| 309 var bazF = bazClassTypeVariables[1]; | |
| 310 Expect.isNotNull(bazF, "Type variable is null"); | |
| 311 Expect.stringEquals('F', bazF.simpleName(), "Unexpected simpleName"); | |
| 312 Expect.stringEquals('mirrors_helper.Baz.F', bazF.qualifiedName(), | |
| 313 "Unexpected qualifiedName"); | |
| 314 Expect.equals(bazClass, bazF.declarer()); | |
| 315 var bazFbound = bazF.bound(); | |
| 316 Expect.isNotNull(bazFbound, "Missing type variable bound"); | |
| 317 Expect.isFalse(bazFbound.isDeclaration, "Bound is declaration"); | |
| 318 Expect.stringEquals("mirrors_helper.Foo", bazFbound.qualifiedName(), | |
| 319 "Bound is not Foo"); | |
| 320 | |
| 321 Expect.isNull(bazClass.defaultType(), "Class has default type"); | |
| 322 | |
| 323 var bazClassMembers = bazClass.declaredMembers(); | |
| 324 Expect.isNotNull(bazClassMembers, "Declared members map is null"); | |
| 325 Expect.equals(8, bazClassMembers.length, | |
| 326 "Unexpected number of declared members"); | |
| 327 | |
| 328 //////////////////////////////////////////////////////////////////////////// | |
| 329 // method1(e) {} | |
| 330 //////////////////////////////////////////////////////////////////////////// | |
| 331 var method1 = findMirror(bazClassMembers, "method1"); | |
| 332 Expect.isNotNull(method1, "method1 not found"); | |
| 333 Expect.stringEquals('method1', method1.simpleName(), | |
| 334 "Unexpected method simpleName"); | |
| 335 Expect.stringEquals('mirrors_helper.Baz.method1', method1.qualifiedName(), | |
| 336 "Unexpected method qualifiedName"); | |
| 337 Expect.equals(method1.surroundingDeclaration(), bazClass, | |
| 338 "Unexpected surrounding declaration"); | |
| 339 Expect.isFalse(method1.isTopLevel, "Method is top level"); | |
| 340 Expect.isFalse(method1.isConstructor, "Method is constructor"); | |
| 341 Expect.isFalse(method1.isField, "Method is field"); | |
| 342 Expect.isTrue(method1.isMethod, "Method is not method"); | |
| 343 Expect.isFalse(method1.isPrivate, "Method is private"); | |
| 344 Expect.isFalse(method1.isStatic, "Method is static"); | |
| 345 Expect.isTrue(method1 is MethodMirror, "Method is not MethodMirror"); | |
| 346 Expect.isFalse(method1.isConst, "Method is const"); | |
| 347 Expect.isFalse(method1.isFactory, "Method is factory"); | |
| 348 Expect.isNull(method1.constructorName, | |
| 349 "Method constructorName is non-null"); | |
| 350 Expect.isFalse(method1.isGetter, "Method is getter"); | |
| 351 Expect.isFalse(method1.isSetter, "Method is setter"); | |
| 352 Expect.isFalse(method1.isOperator, "Method is operator"); | |
| 353 Expect.isNull(method1.operatorName, | |
| 354 "Method operatorName is non-null"); | |
| 355 | |
| 356 var dynamicType = method1.returnType(); | |
| 357 Expect.isNotNull(dynamicType, "Return type was null"); | |
| 358 Expect.isFalse(dynamicType.isObject, "Dynamic is Object"); | |
| 359 Expect.isTrue(dynamicType.isDynamic, "Dynamic is not Dynamic"); | |
| 360 Expect.isFalse(dynamicType.isVoid, "Dynamic is void"); | |
| 361 Expect.isFalse(dynamicType.isTypeVariable, "Dynamic is a type variable"); | |
| 362 Expect.isFalse(dynamicType.isTypedef, "Dynamic is a typedef"); | |
| 363 Expect.isFalse(dynamicType.isFunction, "Dynamic is a function"); | |
| 364 | |
| 365 var method1Parameters = method1.parameters(); | |
| 366 Expect.isNotNull(method1Parameters, "Method parameters is null"); | |
| 367 Expect.equals(1, method1Parameters.length, "Unexpected parameter count"); | |
| 368 var method1Parameter1 = method1Parameters[0]; | |
| 369 Expect.isNotNull(method1Parameter1, "Parameter is null"); | |
| 370 Expect.equals(dynamicType, method1Parameter1.type()); | |
| 371 Expect.stringEquals("e", method1Parameter1.simpleName(), | |
| 372 "Unexpected parameter simpleName"); | |
| 373 Expect.stringEquals("mirrors_helper.Baz.method1#e", | |
| 374 method1Parameter1.qualifiedName(), | |
| 375 "Unexpected parameter qualifiedName"); | |
| 376 Expect.isFalse(method1Parameter1.hasDefaultValue(), | |
| 377 "Parameter has default value"); | |
| 378 Expect.isNull(method1Parameter1.defaultValue(), | |
| 379 "Parameter default value is non-null"); | |
| 380 Expect.isFalse(method1Parameter1.isOptional(), "Parameter is optional"); | |
| 381 | |
| 382 //////////////////////////////////////////////////////////////////////////// | |
| 383 // static void method2(E e, [F f = null]) {} | |
| 384 //////////////////////////////////////////////////////////////////////////// | |
| 385 var method2 = findMirror(bazClassMembers, "method2"); | |
| 386 Expect.isNotNull(method2, "method2 not found"); | |
| 387 Expect.stringEquals('method2', method2.simpleName(), | |
| 388 "Unexpected method simpleName"); | |
| 389 Expect.stringEquals('mirrors_helper.Baz.method2', method2.qualifiedName(), | |
| 390 "Unexpected method qualifiedName"); | |
| 391 Expect.equals(method2.surroundingDeclaration(), bazClass, | |
| 392 "Unexpected surrounding declaration"); | |
| 393 Expect.isFalse(method2.isTopLevel, "Method is top level"); | |
| 394 Expect.isFalse(method2.isConstructor, "Method is constructor"); | |
| 395 Expect.isFalse(method2.isField, "Method is field"); | |
| 396 Expect.isTrue(method2.isMethod, "Method is not method"); | |
| 397 Expect.isFalse(method2.isPrivate, "Method is private"); | |
| 398 Expect.isTrue(method2.isStatic, "Method is not static"); | |
| 399 Expect.isTrue(method2 is MethodMirror, "Method is not MethodMirror"); | |
| 400 Expect.isFalse(method2.isConst, "Method is const"); | |
| 401 Expect.isFalse(method2.isFactory, "Method is factory"); | |
| 402 Expect.isNull(method2.constructorName, | |
| 403 "Method constructorName is non-null"); | |
| 404 Expect.isFalse(method2.isGetter, "Method is getter"); | |
| 405 Expect.isFalse(method2.isSetter, "Method is setter"); | |
| 406 Expect.isFalse(method2.isOperator, "Method is operator"); | |
| 407 Expect.isNull(method2.operatorName, | |
| 408 "Method operatorName is non-null"); | |
| 409 | |
| 410 var voidType = method2.returnType(); | |
| 411 Expect.isNotNull(voidType, "Return type was null"); | |
| 412 Expect.isFalse(voidType.isObject, "void is Object"); | |
| 413 Expect.isFalse(voidType.isDynamic, "void is Dynamic"); | |
| 414 Expect.isTrue(voidType.isVoid, "void is not void"); | |
| 415 Expect.isFalse(voidType.isTypeVariable, "void is a type variable"); | |
| 416 Expect.isFalse(voidType.isTypedef, "void is a typedef"); | |
| 417 Expect.isFalse(voidType.isFunction, "void is a function"); | |
| 418 | |
| 419 var method2Parameters = method2.parameters(); | |
| 420 Expect.isNotNull(method2Parameters, "Method parameters is null"); | |
| 421 Expect.equals(2, method2Parameters.length, "Unexpected parameter count"); | |
| 422 var method2Parameter1 = method2Parameters[0]; | |
| 423 Expect.isNotNull(method2Parameter1, "Parameter is null"); | |
| 424 Expect.equals(bazE, method2Parameter1.type()); | |
| 425 Expect.stringEquals("e", method2Parameter1.simpleName(), | |
| 426 "Unexpected parameter simpleName"); | |
| 427 Expect.stringEquals("mirrors_helper.Baz.method2#e", | |
| 428 method2Parameter1.qualifiedName(), | |
| 429 "Unexpected parameter qualifiedName"); | |
| 430 Expect.isFalse(method2Parameter1.hasDefaultValue(), | |
| 431 "Parameter has default value"); | |
| 432 Expect.isNull(method2Parameter1.defaultValue(), | |
| 433 "Parameter default value is non-null"); | |
| 434 Expect.isFalse(method2Parameter1.isOptional(), "Parameter is optional"); | |
| 435 var method2Parameter2 = method2Parameters[1]; | |
| 436 Expect.isNotNull(method2Parameter2, "Parameter is null"); | |
| 437 Expect.equals(bazF, method2Parameter2.type()); | |
| 438 Expect.stringEquals("f", method2Parameter2.simpleName(), | |
| 439 "Unexpected parameter simpleName"); | |
| 440 Expect.stringEquals("mirrors_helper.Baz.method2#f", | |
| 441 method2Parameter2.qualifiedName(), | |
| 442 "Unexpected parameter qualifiedName"); | |
| 443 // TODO(johnniwinther): Should return true: | |
| 444 Expect.isFalse(method2Parameter2.hasDefaultValue(), | |
| 445 "Parameter has default value"); | |
| 446 // TODO(johnniwinther): Should return a non-null value: | |
| 447 Expect.isNull(method2Parameter2.defaultValue(), | |
| 448 "Parameter default value is non-null"); | |
| 449 Expect.isTrue(method2Parameter2.isOptional(), "Parameter is not optional"); | |
| 450 | |
| 451 //////////////////////////////////////////////////////////////////////////// | |
| 452 // void method3(E func1(F f), Func<E,F> func2) {} | |
| 453 //////////////////////////////////////////////////////////////////////////// | |
| 454 var method3 = findMirror(bazClassMembers, "method3"); | |
| 455 Expect.isNotNull(method3, "method3 not found"); | |
| 456 Expect.stringEquals('method3', method3.simpleName(), | |
| 457 "Unexpected method simpleName"); | |
| 458 Expect.stringEquals('mirrors_helper.Baz.method3', method3.qualifiedName(), | |
| 459 "Unexpected method qualifiedName"); | |
| 460 Expect.equals(method3.surroundingDeclaration(), bazClass, | |
| 461 "Unexpected surrounding declaration"); | |
| 462 Expect.isFalse(method3.isTopLevel, "Method is top level"); | |
| 463 Expect.isFalse(method3.isConstructor, "Method is constructor"); | |
| 464 Expect.isFalse(method3.isField, "Method is field"); | |
| 465 Expect.isTrue(method3.isMethod, "Method is not method"); | |
| 466 Expect.isFalse(method3.isPrivate, "Method is private"); | |
| 467 Expect.isFalse(method3.isStatic, "Method is static"); | |
| 468 Expect.isTrue(method3 is MethodMirror, "Method is not MethodMirror"); | |
| 469 Expect.isFalse(method3.isConst, "Method is const"); | |
| 470 Expect.isFalse(method3.isFactory, "Method is factory"); | |
| 471 Expect.isNull(method3.constructorName, | |
| 472 "Method constructorName is non-null"); | |
| 473 Expect.isFalse(method3.isGetter, "Method is getter"); | |
| 474 Expect.isFalse(method3.isSetter, "Method is setter"); | |
| 475 Expect.isFalse(method3.isOperator, "Method is operator"); | |
| 476 Expect.isNull(method3.operatorName, | |
| 477 "Method operatorName is non-null"); | |
| 478 | |
| 479 Expect.equals(voidType, method3.returnType(), "Return type is not void"); | |
| 480 | |
| 481 var method3Parameters = method3.parameters(); | |
| 482 Expect.isNotNull(method3Parameters, "Method parameters is null"); | |
| 483 Expect.equals(2, method3Parameters.length, "Unexpected parameter count"); | |
| 484 var method3Parameter1 = method3Parameters[0]; | |
| 485 Expect.isNotNull(method3Parameter1, "Parameter is null"); | |
| 486 // TODO(johnniwinther): Should return the function type E func(F f): | |
| 487 Expect.equals(dynamicType, method3Parameter1.type()); | |
| 488 Expect.stringEquals("func1", method3Parameter1.simpleName(), | |
| 489 "Unexpected parameter simpleName"); | |
| 490 Expect.stringEquals("mirrors_helper.Baz.method3#func1", | |
| 491 method3Parameter1.qualifiedName(), | |
| 492 "Unexpected parameter qualifiedName"); | |
| 493 Expect.isFalse(method3Parameter1.hasDefaultValue(), | |
| 494 "Parameter has default value"); | |
| 495 Expect.isNull(method3Parameter1.defaultValue(), | |
| 496 "Parameter default value is non-null"); | |
| 497 Expect.isFalse(method3Parameter1.isOptional(), "Parameter is optional"); | |
| 498 | |
| 499 var method3Parameter2 = method3Parameters[1]; | |
| 500 Expect.isNotNull(method3Parameter2, "Parameter is null"); | |
| 501 var funcTypedef = method3Parameter2.type(); | |
| 502 Expect.isNotNull(funcTypedef, "Parameter type is null"); | |
| 503 Expect.stringEquals("Func", funcTypedef.simpleName(), | |
| 504 "Unexpected simpleName"); | |
| 505 Expect.stringEquals("mirrors_helper.Func", funcTypedef.qualifiedName(), | |
| 506 "Unexpected simpleName"); | |
| 507 Expect.isFalse(funcTypedef.isObject, "Typedef is Object"); | |
| 508 Expect.isFalse(funcTypedef.isDynamic, "Typedef is Dynamic"); | |
| 509 Expect.isFalse(funcTypedef.isVoid, "Typedef is void"); | |
| 510 Expect.isFalse(funcTypedef.isTypeVariable, "Typedef is a type variable"); | |
| 511 Expect.isTrue(funcTypedef.isTypedef, "Typedef is not a typedef"); | |
| 512 Expect.isFalse(funcTypedef.isFunction, "Typedef is a function"); | |
| 513 | |
| 514 Expect.equals(helperLibrary, funcTypedef.library(), | |
| 515 "Unexpected typedef library"); | |
| 516 Expect.isNull(funcTypedef.superclass(), "Non-null superclass on typedef"); | |
| 517 Expect.isNotNull(funcTypedef.interfaces(), | |
| 518 "Null interfaces map on typedef"); | |
| 519 Expect.isTrue(funcTypedef.interfaces().isEmpty(), | |
| 520 "Non-empty interfaces map on typedef"); | |
| 521 Expect.isNotNull(funcTypedef.declaredMembers(), | |
| 522 "Declared members map is null on type def"); | |
| 523 Expect.isTrue(funcTypedef.declaredMembers().isEmpty(), | |
| 524 "Non-empty declared members map on typedef"); | |
| 525 | |
| 526 // TODO(johnniwinther): Returned typedef should not be the declaration: | |
| 527 Expect.isTrue(funcTypedef.isDeclaration, "Typedef is not declaration"); | |
| 528 Expect.isFalse(funcTypedef.isClass, "Typedef is class"); | |
| 529 Expect.isFalse(funcTypedef.isInterface, "Typedef is interface"); | |
| 530 Expect.isFalse(funcTypedef.isPrivate, "Typedef is private"); | |
| 531 Expect.isNull(funcTypedef.defaultType(), | |
| 532 "Typedef default type is non-null"); | |
| 533 // TODO(johnniwinther): Should not throw an exception since the type should | |
| 534 // not be the declaration. | |
| 535 Expect.throws(() => funcTypedef.typeArguments(), | |
| 536 (exception) => true, | |
| 537 "Typedef has type arguments"); | |
| 538 Expect.isNotNull(funcTypedef.typeVariables(), "Type variables is null"); | |
| 539 // TODO(johnniwinther): Should return a non-empty map. | |
| 540 Expect.isTrue(funcTypedef.typeVariables().isEmpty(), | |
| 541 "Type variables is non-empty"); | |
| 542 // TODO(johnniwinther): Provide access to the definition type. | |
| 543 Expect.isNull(funcTypedef.definition(), "Typedef definition is not null"); | |
| 544 | |
| 545 Expect.stringEquals("func2", method3Parameter2.simpleName(), | |
| 546 "Unexpected parameter simpleName"); | |
| 547 Expect.stringEquals("mirrors_helper.Baz.method3#func2", | |
| 548 method3Parameter2.qualifiedName(), | |
| 549 "Unexpected parameter qualifiedName"); | |
| 550 Expect.isFalse(method3Parameter2.hasDefaultValue(), | |
| 551 "Parameter has default value"); | |
| 552 Expect.isNull(method3Parameter2.defaultValue(), | |
| 553 "Parameter default value is non-null"); | |
| 554 Expect.isFalse(method3Parameter2.isOptional(), "Parameter is optional"); | |
| 555 | |
| 556 //////////////////////////////////////////////////////////////////////////// | |
| 557 // bool operator==(Object other) => return false; | |
| 558 //////////////////////////////////////////////////////////////////////////// | |
| 559 var operator_eq = findMirror(bazClassMembers, "operator", operatorName: '=='); | |
| 560 Expect.isNotNull(operator_eq, "operator == not found"); | |
| 561 Expect.stringEquals('operator', operator_eq.simpleName(), | |
| 562 "Unexpected method simpleName"); | |
| 563 Expect.stringEquals('mirrors_helper.Baz.operator ==', | |
| 564 operator_eq.qualifiedName(), | |
| 565 "Unexpected method qualifiedName"); | |
| 566 Expect.equals(operator_eq.surroundingDeclaration(), bazClass, | |
| 567 "Unexpected surrounding declaration"); | |
| 568 Expect.isFalse(operator_eq.isTopLevel, "Method is top level"); | |
| 569 Expect.isFalse(operator_eq.isConstructor, "Method is constructor"); | |
| 570 Expect.isFalse(operator_eq.isField, "Method is field"); | |
| 571 Expect.isTrue(operator_eq.isMethod, "Method is not method"); | |
| 572 Expect.isFalse(operator_eq.isPrivate, "Method is private"); | |
| 573 Expect.isFalse(operator_eq.isStatic, "Method is static"); | |
| 574 Expect.isTrue(operator_eq is MethodMirror, "Method is not MethodMirror"); | |
| 575 Expect.isFalse(operator_eq.isConst, "Method is const"); | |
| 576 Expect.isFalse(operator_eq.isFactory, "Method is factory"); | |
| 577 Expect.isNull(operator_eq.constructorName, | |
| 578 "Method constructorName is non-null"); | |
| 579 Expect.isFalse(operator_eq.isGetter, "Method is getter"); | |
| 580 Expect.isFalse(operator_eq.isSetter, "Method is setter"); | |
| 581 Expect.isTrue(operator_eq.isOperator, "Method is not operator"); | |
| 582 Expect.stringEquals('==', operator_eq.operatorName, | |
| 583 "Unexpected operatorName"); | |
| 584 | |
| 585 //////////////////////////////////////////////////////////////////////////// | |
| 586 // Baz<E,F> operator negate() => this; | |
| 587 //////////////////////////////////////////////////////////////////////////// | |
| 588 var operator_negate = findMirror(bazClassMembers, "operator", | |
| 589 operatorName: 'negate'); | |
| 590 Expect.isNotNull(operator_negate, "operator < not found"); | |
| 591 Expect.stringEquals('operator', operator_negate.simpleName(), | |
| 592 "Unexpected method simpleName"); | |
| 593 Expect.stringEquals('mirrors_helper.Baz.operator negate', | |
| 594 operator_negate.qualifiedName(), | |
| 595 "Unexpected method qualifiedName"); | |
| 596 Expect.equals(operator_negate.surroundingDeclaration(), bazClass, | |
| 597 "Unexpected surrounding declaration"); | |
| 598 Expect.isFalse(operator_negate.isTopLevel, "Method is top level"); | |
| 599 Expect.isFalse(operator_negate.isConstructor, "Method is constructor"); | |
| 600 Expect.isFalse(operator_negate.isField, "Method is field"); | |
| 601 Expect.isTrue(operator_negate.isMethod, "Method is not method"); | |
| 602 Expect.isFalse(operator_negate.isPrivate, "Method is private"); | |
| 603 Expect.isFalse(operator_negate.isStatic, "Method is static"); | |
| 604 Expect.isTrue(operator_negate is MethodMirror, | |
| 605 "Method is not MethodMirror"); | |
| 606 Expect.isFalse(operator_negate.isConst, "Method is const"); | |
| 607 Expect.isFalse(operator_negate.isFactory, "Method is factory"); | |
| 608 Expect.isNull(operator_negate.constructorName, | |
| 609 "Method constructorName is non-null"); | |
| 610 Expect.isFalse(operator_negate.isGetter, "Method is getter"); | |
| 611 Expect.isFalse(operator_negate.isSetter, "Method is setter"); | |
| 612 Expect.isTrue(operator_negate.isOperator, "Method is not operator"); | |
| 613 Expect.stringEquals('negate', operator_negate.operatorName, | |
| 614 "Unexpected operatorName"); | |
| 615 | |
| 616 | |
| 617 var bazClassConstructors = bazClass.constructors(); | |
| 618 Expect.isNotNull(bazClassConstructors, "Constructors map is null"); | |
| 619 Expect.equals(3, bazClassConstructors.length, | |
| 620 "Unexpected number of constructors"); | |
| 621 // TODO(johnniwinther): Add tests of constructors. | |
| 622 } | |
| OLD | NEW |