@@ -2266,22 +2266,37 @@ void main() {
2266
2266
theOnlyThingInTheLibrary;
2267
2267
Constructor aNonDefaultConstructor,
2268
2268
defaultConstructor,
2269
- aConstructorShadowed;
2269
+ aConstructorShadowed,
2270
+ anotherName,
2271
+ anotherConstructor,
2272
+ factoryConstructorThingsDefault;
2270
2273
Class Apple ,
2271
2274
BaseClass ,
2272
2275
baseForDocComments,
2273
2276
ExtraSpecialList ,
2277
+ FactoryConstructorThings ,
2274
2278
string,
2275
2279
metaUseResult;
2276
- Method doAwesomeStuff, anotherMethod;
2280
+ Method doAwesomeStuff, anotherMethod, aMethod ;
2277
2281
// ignore: unused_local_variable
2278
2282
Operator bracketOperator, bracketOperatorOtherClass;
2279
- Parameter doAwesomeStuffParam;
2283
+ Parameter doAwesomeStuffParam,
2284
+ aName,
2285
+ anotherNameParameter,
2286
+ anotherDifferentName,
2287
+ differentName,
2288
+ redHerring,
2289
+ yetAnotherName,
2290
+ somethingShadowyParameter;
2280
2291
Field forInheriting,
2281
2292
action,
2282
2293
initializeMe,
2283
2294
somethingShadowy,
2284
- aConstructorShadowedField;
2295
+ aConstructorShadowedField,
2296
+ aNameField,
2297
+ anotherNameField,
2298
+ yetAnotherNameField,
2299
+ initViaFieldFormal;
2285
2300
2286
2301
setUpAll (() async {
2287
2302
mylibpub = packageGraph.allLibraries.values
@@ -2309,6 +2324,8 @@ void main() {
2309
2324
(c) => c.name == 'BaseForDocComments.aNonDefaultConstructor' );
2310
2325
defaultConstructor = baseForDocComments.constructors
2311
2326
.firstWhere ((c) => c.name == 'BaseForDocComments' );
2327
+ somethingShadowyParameter = defaultConstructor.allParameters
2328
+ .firstWhere ((p) => p.name == 'somethingShadowy' );
2312
2329
initializeMe = baseForDocComments.allFields
2313
2330
.firstWhere ((f) => f.name == 'initializeMe' );
2314
2331
somethingShadowy = baseForDocComments.allFields
@@ -2361,6 +2378,106 @@ void main() {
2361
2378
(c) => c.name == 'BaseForDocComments.aConstructorShadowed' );
2362
2379
aConstructorShadowedField = baseForDocComments.allFields
2363
2380
.firstWhere ((f) => f.name == 'aConstructorShadowed' );
2381
+
2382
+ FactoryConstructorThings = fakeLibrary.classes
2383
+ .firstWhere ((c) => c.name == 'FactoryConstructorThings' );
2384
+ anotherName = FactoryConstructorThings .constructors.firstWhere (
2385
+ (c) => c.name == 'FactoryConstructorThings.anotherName' );
2386
+ anotherConstructor = FactoryConstructorThings .constructors.firstWhere (
2387
+ (c) => c.name == 'FactoryConstructorThings.anotherConstructor' );
2388
+ factoryConstructorThingsDefault = FactoryConstructorThings .constructors
2389
+ .firstWhere ((c) => c.name == 'FactoryConstructorThings' );
2390
+
2391
+ aName = anotherName.allParameters.firstWhere ((p) => p.name == 'aName' );
2392
+ anotherNameParameter = anotherName.allParameters
2393
+ .firstWhere ((p) => p.name == 'anotherName' );
2394
+ anotherDifferentName = anotherName.allParameters
2395
+ .firstWhere ((p) => p.name == 'anotherDifferentName' );
2396
+ differentName = anotherName.allParameters
2397
+ .firstWhere ((p) => p.name == 'differentName' );
2398
+ redHerring = anotherConstructor.allParameters
2399
+ .firstWhere ((p) => p.name == 'redHerring' );
2400
+
2401
+ aNameField = FactoryConstructorThings .allFields
2402
+ .firstWhere ((f) => f.name == 'aName' );
2403
+ anotherNameField = FactoryConstructorThings .allFields
2404
+ .firstWhere ((f) => f.name == 'anotherName' );
2405
+ yetAnotherNameField = FactoryConstructorThings .allFields
2406
+ .firstWhere ((f) => f.name == 'yetAnotherName' );
2407
+ initViaFieldFormal = FactoryConstructorThings .allFields
2408
+ .firstWhere ((f) => f.name == 'initViaFieldFormal' );
2409
+
2410
+ aMethod = FactoryConstructorThings .instanceMethods
2411
+ .firstWhere ((m) => m.name == 'aMethod' );
2412
+ yetAnotherName =
2413
+ aMethod.allParameters.firstWhere ((p) => p.name == 'yetAnotherName' );
2414
+ });
2415
+
2416
+ group ('Parameter references work properly' , () {
2417
+ test ('in class scope overridden by fields' , () {
2418
+ expect (bothLookup (FactoryConstructorThings , 'aName' ),
2419
+ equals (MatchingLinkResult (aNameField)));
2420
+ expect (bothLookup (FactoryConstructorThings , 'anotherName' ),
2421
+ equals (MatchingLinkResult (anotherNameField)));
2422
+ expect (bothLookup (FactoryConstructorThings , 'yetAnotherName' ),
2423
+ equals (MatchingLinkResult (yetAnotherNameField)));
2424
+ expect (bothLookup (FactoryConstructorThings , 'initViaFieldFormal' ),
2425
+ equals (MatchingLinkResult (initViaFieldFormal)));
2426
+ expect (bothLookup (FactoryConstructorThings , 'redHerring' ),
2427
+ equals (MatchingLinkResult (redHerring)));
2428
+ });
2429
+
2430
+ test ('in class scope overridden by constructors when specified' , () {
2431
+ expect (
2432
+ bothLookup (FactoryConstructorThings ,
2433
+ 'new FactoryConstructorThings.anotherName' ),
2434
+ equals (MatchingLinkResult (anotherName)));
2435
+ });
2436
+
2437
+ test (
2438
+ 'in default constructor scope referring to a field formal parameter' ,
2439
+ () {
2440
+ expect (
2441
+ newLookup (factoryConstructorThingsDefault, 'initViaFieldFormal' ),
2442
+ equals (MatchingLinkResult (initViaFieldFormal)));
2443
+ });
2444
+
2445
+ test ('in factory constructor scope referring to parameters' , () {
2446
+ expect (newLookup (anotherName, 'aName' ),
2447
+ equals (MatchingLinkResult (aName)));
2448
+ expect (bothLookup (anotherName, 'anotherName' ),
2449
+ equals (MatchingLinkResult (anotherNameParameter)));
2450
+ expect (bothLookup (anotherName, 'anotherDifferentName' ),
2451
+ equals (MatchingLinkResult (anotherDifferentName)));
2452
+ expect (bothLookup (anotherName, 'differentName' ),
2453
+ equals (MatchingLinkResult (differentName)));
2454
+ expect (bothLookup (anotherName, 'redHerring' ),
2455
+ equals (MatchingLinkResult (redHerring)));
2456
+ });
2457
+
2458
+ test ('in factory constructor scope referring to constructors' , () {
2459
+ // A bare constructor reference is OK because there is no conflict.
2460
+ expect (bothLookup (anotherName, 'anotherConstructor' ),
2461
+ equals (MatchingLinkResult (anotherConstructor)));
2462
+ // A conflicting constructor has to be explicit.
2463
+ expect (
2464
+ bothLookup (
2465
+ anotherName, 'new FactoryConstructorThings.anotherName' ),
2466
+ equals (MatchingLinkResult (anotherName)));
2467
+ });
2468
+
2469
+ test ('in method scope referring to parameters and variables' , () {
2470
+ expect (bothLookup (aMethod, 'yetAnotherName' ),
2471
+ equals (MatchingLinkResult (yetAnotherName)));
2472
+ expect (bothLookup (aMethod, 'FactoryConstructorThings.yetAnotherName' ),
2473
+ equals (MatchingLinkResult (yetAnotherNameField)));
2474
+ expect (
2475
+ bothLookup (
2476
+ aMethod, 'FactoryConstructorThings.anotherName.anotherName' ),
2477
+ equals (MatchingLinkResult (anotherNameParameter)));
2478
+ expect (bothLookup (aMethod, 'aName' ),
2479
+ equals (MatchingLinkResult (aNameField)));
2480
+ });
2364
2481
});
2365
2482
2366
2483
test ('Referring to a renamed library directly works' , () {
@@ -2425,11 +2542,17 @@ void main() {
2425
2542
equals (MatchingLinkResult (defaultConstructor)));
2426
2543
2427
2544
// We don't want the parameter on the default constructor, here.
2428
- expect (
2429
- bothLookup (
2430
- baseForDocComments, 'BaseForDocComments. somethingShadowy' ),
2545
+ expect (bothLookup (fakeLibrary, 'BaseForDocComments.somethingShadowy' ),
2546
+ equals ( MatchingLinkResult (somethingShadowy)));
2547
+ expect ( bothLookup ( baseForDocComments, 'somethingShadowy' ),
2431
2548
equals (MatchingLinkResult (somethingShadowy)));
2432
2549
2550
+ // Allow specific reference if necessary
2551
+ expect (
2552
+ newLookup (baseForDocComments,
2553
+ 'BaseForDocComments.BaseForDocComments.somethingShadowy' ),
2554
+ equals (MatchingLinkResult (somethingShadowyParameter)));
2555
+
2433
2556
expect (bothLookup (doAwesomeStuff, 'aNonDefaultConstructor' ),
2434
2557
equals (MatchingLinkResult (aNonDefaultConstructor)));
2435
2558
0 commit comments