@@ -44,6 +44,7 @@ import 'package:dartdoc/src/logging.dart';
44
44
import 'package:dartdoc/src/markdown_processor.dart' show Documentation;
45
45
import 'package:dartdoc/src/model_utils.dart' ;
46
46
import 'package:dartdoc/src/package_meta.dart' show PackageMeta, FileContents;
47
+ import 'package:dartdoc/src/special_elements.dart' ;
47
48
import 'package:dartdoc/src/utils.dart' ;
48
49
import 'package:dartdoc/src/warnings.dart' ;
49
50
import 'package:front_end/src/byte_store/byte_store.dart' ;
@@ -180,18 +181,17 @@ abstract class Inheritable implements ModelElement {
180
181
List <Class > get inheritance {
181
182
List <Class > inheritance = [];
182
183
inheritance.addAll ((enclosingElement as Class ).inheritanceChain);
184
+ Class object = packageGraph.specialClasses[SpecialClass .object];
183
185
if (! inheritance.contains (definingEnclosingElement) &&
184
186
definingEnclosingElement != null ) {
185
- assert (definingEnclosingElement == packageGraph.objectElement );
187
+ assert (definingEnclosingElement == object );
186
188
}
187
189
// Unless the code explicitly extends dart-core's Object, we won't get
188
190
// an entry here. So add it.
189
- if (inheritance.last != packageGraph.objectElement &&
190
- packageGraph.objectElement != null ) {
191
- inheritance.add (packageGraph.objectElement);
191
+ if (inheritance.last != object && object != null ) {
192
+ inheritance.add (object);
192
193
}
193
- assert (
194
- inheritance.where ((e) => e == packageGraph.objectElement).length == 1 );
194
+ assert (inheritance.where ((e) => e == object).length == 1 );
195
195
return inheritance;
196
196
}
197
197
}
@@ -1629,7 +1629,7 @@ abstract class GetterSetterCombo implements ModelElement {
1629
1629
buffer.write ('${getter .oneLineDoc }' );
1630
1630
}
1631
1631
if (hasPublicSetter && setter.oneLineDoc.isNotEmpty) {
1632
- buffer.write ('${getterSetterBothAvailable ? "" : setter .oneLineDoc }' );
1632
+ buffer.write ('${getterSetterBothAvailable ? "" : setter .oneLineDoc }' );
1633
1633
}
1634
1634
_oneLineDoc = buffer.toString ();
1635
1635
}
@@ -2587,21 +2587,6 @@ abstract class ModelElement extends Canonicalization
2587
2587
if (e is ClassElement ) {
2588
2588
if (! e.isEnum) {
2589
2589
newModelElement = new Class (e, library, packageGraph);
2590
- if (newModelElement.name == 'Object' &&
2591
- newModelElement.library.name == 'dart:core' ) {
2592
- // We've found Object. This is an important object, so save it in the package.
2593
- assert (
2594
- newModelElement.library.packageGraph._objectElement == null );
2595
- newModelElement.library.packageGraph._objectElement =
2596
- newModelElement;
2597
- }
2598
- if (newModelElement.name == 'Interceptor' &&
2599
- newModelElement.library.name == 'dart:_interceptors' ) {
2600
- // We've found Interceptor. Another important object.
2601
- assert (! newModelElement.library.packageGraph._interceptorUsed);
2602
- newModelElement.library.packageGraph.interceptor =
2603
- newModelElement;
2604
- }
2605
2590
} else {
2606
2591
newModelElement = new Enum (e, library, packageGraph);
2607
2592
}
@@ -4017,8 +4002,19 @@ class PackageGraph {
4017
4002
// TODO(jcollins-g): This constructor is convoluted. Clean this up by
4018
4003
// building Libraries and adding them to Packages, then adding Packages
4019
4004
// to this graph.
4020
- PackageGraph (Iterable <LibraryElement > libraryElements, this .config,
4021
- this .packageMeta, this ._packageWarningOptions, this .driver, this .sdk) {
4005
+
4006
+ /// Construct a package graph.
4007
+ /// [libraryElements] - Libraries to be documented.
4008
+ /// [specialLibraryElements] - Any libraries that may not be documented, but
4009
+ /// contain required [SpecialClass] es.
4010
+ PackageGraph (
4011
+ Iterable <LibraryElement > libraryElements,
4012
+ Iterable <LibraryElement > specialLibraryElements,
4013
+ this .config,
4014
+ this .packageMeta,
4015
+ this ._packageWarningOptions,
4016
+ this .driver,
4017
+ this .sdk) {
4022
4018
assert (_allConstructedModelElements.isEmpty);
4023
4019
assert (allLibraries.isEmpty);
4024
4020
_packageWarningCounter = new PackageWarningCounter (_packageWarningOptions);
@@ -4042,11 +4038,19 @@ class PackageGraph {
4042
4038
new Package .fromPackageMeta (packageMeta, this );
4043
4039
allLibrariesAdded = true ;
4044
4040
4041
+ // [findOrCreateLibraryFor] already adds to the proper structures.
4042
+ specialLibraryElements.forEach ((element) {
4043
+ findOrCreateLibraryFor (element);
4044
+ });
4045
+
4045
4046
// Go through docs of every ModelElement in package to pre-build the macros
4046
4047
// index.
4047
4048
allLocalModelElements.forEach ((m) => m.documentationLocal);
4048
4049
_macrosAdded = true ;
4049
4050
4051
+ // Scan all model elements to insure that interceptor and other special
4052
+ // objects are found.
4053
+ specialClasses = new SpecialClasses (this );
4050
4054
// After the allModelElements traversal to be sure that all packages
4051
4055
// are picked up.
4052
4056
documentedPackages.toList ().forEach ((package) {
@@ -4059,6 +4063,8 @@ class PackageGraph {
4059
4063
allImplementorsAdded = true ;
4060
4064
}
4061
4065
4066
+ SpecialClasses specialClasses;
4067
+
4062
4068
/// It is safe to cache values derived from the _implementors table if this
4063
4069
/// is true.
4064
4070
bool allImplementorsAdded = false ;
@@ -4497,31 +4503,6 @@ class PackageGraph {
4497
4503
return _localPublicLibraries;
4498
4504
}
4499
4505
4500
- // Written from ModelElement.from.
4501
- ModelElement _objectElement;
4502
-
4503
- // Return the element for "Object".
4504
- ModelElement get objectElement {
4505
- assert (_objectElement != null );
4506
- return _objectElement;
4507
- }
4508
-
4509
- // Don't let this be used for canonicalization before we find it.
4510
- bool _interceptorUsed = false ;
4511
- Class _interceptor;
4512
-
4513
- /// Return the element for "Interceptor", a Dart implementation class intended
4514
- /// to function the same as Object.
4515
- Class get interceptor {
4516
- _interceptorUsed = true ;
4517
- return _interceptor;
4518
- }
4519
-
4520
- set interceptor (Class newInterceptor) {
4521
- assert (_interceptorUsed == false );
4522
- _interceptor = newInterceptor;
4523
- }
4524
-
4525
4506
// Return the set of [Class]es objects should inherit through if they
4526
4507
// show up in the inheritance chain. Do not call before interceptorElement is
4527
4508
// found. Add classes here if they are similar to Interceptor in that they
@@ -4531,7 +4512,7 @@ class PackageGraph {
4531
4512
Set <Class > get inheritThrough {
4532
4513
if (_inheritThrough == null ) {
4533
4514
_inheritThrough = new Set ();
4534
- _inheritThrough.add (interceptor);
4515
+ _inheritThrough.add (specialClasses[ SpecialClass . interceptor] );
4535
4516
}
4536
4517
return _inheritThrough;
4537
4518
}
@@ -4746,16 +4727,16 @@ class PackageGraph {
4746
4727
return foundLibrary;
4747
4728
}
4748
4729
4749
- List <ModelElement > _allModelElements ;
4730
+ List <ModelElement > _allLocalModelElements ;
4750
4731
Iterable <ModelElement > get allLocalModelElements {
4751
4732
assert (allLibrariesAdded);
4752
- if (_allModelElements == null ) {
4753
- _allModelElements = [];
4733
+ if (_allLocalModelElements == null ) {
4734
+ _allLocalModelElements = [];
4754
4735
this .localLibraries.forEach ((library) {
4755
- _allModelElements .addAll (library.allModelElements);
4736
+ _allLocalModelElements .addAll (library.allModelElements);
4756
4737
});
4757
4738
}
4758
- return _allModelElements ;
4739
+ return _allLocalModelElements ;
4759
4740
}
4760
4741
4761
4742
List <ModelElement > _allCanonicalModelElements;
@@ -5512,9 +5493,16 @@ class PackageBuilder {
5512
5493
if (packageMeta.needsPubGet) {
5513
5494
packageMeta.runPubGet ();
5514
5495
}
5515
- Set <LibraryElement > libraries = await getLibraries (getFiles);
5516
- return new PackageGraph (libraries, config, config.topLevelPackageMeta,
5517
- getWarningOptions (), driver, sdk);
5496
+ Set <LibraryElement > libraries = new Set ();
5497
+ Set <LibraryElement > specialLibraries = new Set ();
5498
+ DartSdk findSpecialsSdk = sdk;
5499
+ if (embedderSdk != null && embedderSdk.urlMappings.isNotEmpty) {
5500
+ findSpecialsSdk = embedderSdk;
5501
+ }
5502
+ await getLibraries (libraries, specialLibraries, getFiles,
5503
+ specialLibraryFiles (findSpecialsSdk).toSet ());
5504
+ return new PackageGraph (libraries, specialLibraries, config,
5505
+ config.topLevelPackageMeta, getWarningOptions (), driver, sdk);
5518
5506
}
5519
5507
5520
5508
DartSdk _sdk;
@@ -5711,7 +5699,8 @@ class PackageBuilder {
5711
5699
return metas;
5712
5700
}
5713
5701
5714
- Future <List <LibraryElement >> _parseLibraries (Set <String > files) async {
5702
+ Future <List <LibraryElement >> _parseLibraries (Set <String > files,
5703
+ {bool throwErrors = true }) async {
5715
5704
Set <LibraryElement > libraries = new Set ();
5716
5705
Set <Source > originalSources;
5717
5706
Set <Source > sources = new Set <Source >();
@@ -5724,8 +5713,8 @@ class PackageBuilder {
5724
5713
driver.addFile (filename);
5725
5714
addedFiles.add (filename);
5726
5715
});
5727
- await Future
5728
- . wait ( files.map ((f) => processLibrary (f, libraries, sources)));
5716
+ await Future . wait (
5717
+ files.map ((f) => processLibrary (f, libraries, sources)));
5729
5718
5730
5719
/// We don't care about upstream analysis errors, so save the first
5731
5720
/// source list.
@@ -5747,7 +5736,7 @@ class PackageBuilder {
5747
5736
}
5748
5737
} while (! lastPass.containsAll (current));
5749
5738
5750
- await logAnalysisErrors (originalSources);
5739
+ if (throwErrors) await logAnalysisErrors (originalSources);
5751
5740
return libraries.toList ();
5752
5741
}
5753
5742
@@ -5824,9 +5813,18 @@ class PackageBuilder {
5824
5813
return new Set .from (files.map ((s) => new File (s).absolute.path));
5825
5814
}
5826
5815
5827
- Future <Set <LibraryElement >> getLibraries (Set <String > files) async {
5828
- Set <LibraryElement > libraries = new Set ();
5816
+ Future <void > getLibraries (
5817
+ Set <LibraryElement > libraries,
5818
+ Set <LibraryElement > specialLibraries,
5819
+ Set <String > files,
5820
+ Set <String > specialFiles) async {
5829
5821
libraries.addAll (await _parseLibraries (files));
5822
+
5823
+ /// Flutter doesn't seem to like being given the Interceptor library.
5824
+ /// But it doesn't need it, either. So just skip reporting errors here.
5825
+ specialLibraries.addAll (await _parseLibraries (
5826
+ specialFiles.difference (files),
5827
+ throwErrors: false ));
5830
5828
if (config.include.isNotEmpty) {
5831
5829
Iterable knownLibraryNames = libraries.map ((l) => l.name);
5832
5830
Set notFound = new Set .from (config.include)
@@ -5838,7 +5836,6 @@ class PackageBuilder {
5838
5836
}
5839
5837
libraries.removeWhere ((lib) => ! config.include.contains (lib.name));
5840
5838
}
5841
- return libraries;
5842
5839
}
5843
5840
5844
5841
/// If [dir] contains both a `lib` directory and a `pubspec.yaml` file treat
0 commit comments