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