Skip to content

Commit 966f85b

Browse files
committed
Flatten change
1 parent b299577 commit 966f85b

File tree

368 files changed

+7026
-4933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

368 files changed

+7026
-4933
lines changed

bin/dartdoc.dart

+3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ main(List<String> arguments) async {
261261
reexportMinConfidence:
262262
double.parse(args['ambiguous-reexport-scorer-min-confidence']),
263263
verboseWarnings: args['verbose-warnings'],
264+
excludePackages: args['exclude-packages'],
264265
dropTextFrom: dropTextFrom);
265266

266267
DartDoc dartdoc = new DartDoc(inputDir, excludeLibraries, sdkDir, generators,
@@ -325,6 +326,8 @@ ArgParser _createArgsParser() {
325326
'(optional text next to the package name and version).');
326327
parser.addOption('exclude',
327328
allowMultiple: true, splitCommas: true, help: 'Library names to ignore.');
329+
parser.addOption('exclude-packages',
330+
allowMultiple: true, splitCommas: true, help: 'Package names to ignore.');
328331
parser.addOption('include',
329332
allowMultiple: true,
330333
splitCommas: true,

lib/dartdoc.dart

+91-67
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ class DartDoc {
120120

121121
Stream<String> get onCheckProgress => _onCheckProgress.stream;
122122

123+
bool isExcluded(String name) => excludes.any((pattern) => name == pattern);
124+
125+
Iterable<LibraryElement> filterExcludesFrom(Iterable<LibraryElement> libraries) sync* {
126+
for (LibraryElement l in libraries) {
127+
if (isExcluded(l.source.uri.toString()) ||
128+
config.excludePackages.contains(Library.getPackageMeta(l)?.name)) {
129+
continue;
130+
}
131+
yield l;
132+
}
133+
}
134+
123135
/// Generate DartDoc documentation.
124136
///
125137
/// [DartDocResults] is returned if dartdoc succeeds. [DartDocFailure] is
@@ -129,52 +141,63 @@ class DartDoc {
129141
Future<DartDocResults> generateDocs() async {
130142
_stopwatch = new Stopwatch()..start();
131143

132-
List<String> files = packageMeta.isSdk
133-
? const []
134-
: findFilesToDocumentInPackage(rootDir.path).toList();
135-
136-
// TODO(jcollins-g): seems like most of this belongs in the Package constructor
137-
List<LibraryElement> libraries = _parseLibraries(files, includeExternals);
138-
139-
if (includes != null && includes.isNotEmpty) {
140-
Iterable knownLibraryNames = libraries.map((l) => l.name);
141-
Set notFound =
142-
new Set.from(includes).difference(new Set.from(knownLibraryNames));
143-
if (notFound.isNotEmpty) {
144-
throw 'Did not find: [${notFound.join(', ')}] in '
145-
'known libraries: [${knownLibraryNames.join(', ')}]';
146-
}
147-
libraries.removeWhere((lib) => !includes.contains(lib.name));
148-
} else {
149-
// remove excluded libraries
150-
excludes.forEach((pattern) {
151-
libraries.removeWhere((lib) {
152-
return lib.name.startsWith(pattern) || lib.name == pattern;
153-
});
154-
});
155-
}
156-
157144
PackageWarningOptions warningOptions = new PackageWarningOptions();
158145
// TODO(jcollins-g): explode this into detailed command line options.
159146
if (config != null && config.showWarnings) {
160147
for (PackageWarning kind in PackageWarning.values) {
161148
warningOptions.warn(kind);
162149
}
163150
}
151+
164152
Package package;
165-
if (config != null && config.autoIncludeDependencies) {
166-
package = Package.withAutoIncludedDependencies(
167-
libraries, packageMeta, warningOptions);
168-
libraries = package.libraries.map((l) => l.element).toList();
169-
// remove excluded libraries again, in case they are picked up through
170-
// dependencies.
171-
excludes.forEach((pattern) {
172-
libraries.removeWhere((lib) {
173-
return lib.name.startsWith(pattern) || lib.name == pattern;
174-
});
175-
});
153+
// TODO(jcollins-g): seems like most of this belongs in the Package constructor
154+
Set<String> rootDirsPrev = new Set();
155+
Set<String> rootDirs = new Set()..add(rootDir.path);
156+
Set<LibraryElement> libraries = new Set();
157+
Set<String> files = new Set();
158+
Set<String> filesPrev = new Set();
159+
while (!rootDirsPrev.containsAll(rootDirs)) {
160+
for (String rootDirPath in rootDirs.difference(rootDirsPrev)) {
161+
files.addAll(packageMeta.isSdk
162+
? new Set()
163+
: findFilesToDocumentInPackage(rootDirPath));
164+
}
165+
166+
libraries.addAll(_parseLibraries(files.difference(filesPrev), includeExternals, rootDirsPrev.isEmpty));
167+
168+
if (includes != null && includes.isNotEmpty) {
169+
Iterable knownLibraryNames = libraries.map((l) => l.name);
170+
Set notFound =
171+
new Set.from(includes).difference(new Set.from(knownLibraryNames));
172+
if (notFound.isNotEmpty) {
173+
throw 'Did not find: [${notFound.join(', ')}] in '
174+
'known libraries: [${knownLibraryNames.join(', ')}]';
175+
}
176+
libraries.removeWhere((lib) => !includes.contains(lib.name));
177+
} else {
178+
libraries = filterExcludesFrom(libraries).toSet();
179+
}
180+
/*
181+
if (config != null && config.autoIncludeDependencies) {
182+
package = Package.withAutoIncludedDependencies(
183+
libraries, packageMeta, warningOptions);
184+
// remove excluded libraries again, in case they are picked up through
185+
// dependencies.
186+
libraries = filterExcludesFrom(package.publicLibraries.map((l) => l.element as LibraryElement)).toSet();
187+
}
188+
rootDirsPrev = rootDirs.toSet();
189+
for (Library lib in package.publicLibraries) {
190+
if (libraries.contains(lib.element)) {
191+
PackageMeta meta = lib.packageMeta;
192+
if (meta != null) rootDirs.add(meta.dir.path);
193+
}
194+
}
195+
filesPrev = files.toSet();
196+
*/
197+
rootDirsPrev = rootDirs.toSet();
198+
filesPrev = files.toSet();
176199
}
177-
package = new Package(libraries, packageMeta, warningOptions);
200+
package = new Package(libraries, packageMeta, warningOptions, context);
178201

179202
// Go through docs of every model element in package to prebuild the macros index
180203
// TODO(jcollins-g): move index building into a cached-on-demand generation
@@ -201,10 +224,10 @@ class DartDoc {
201224

202225
double seconds = _stopwatch.elapsedMilliseconds / 1000.0;
203226
logInfo(
204-
"Documented ${package.libraries.length} librar${package.libraries.length == 1 ? 'y' : 'ies'} "
227+
"Documented ${package.publicLibraries.length} librar${package.publicLibraries.length == 1 ? 'y' : 'ies'} "
205228
"in ${seconds.toStringAsFixed(1)} seconds");
206229

207-
if (package.libraries.isEmpty) {
230+
if (package.publicLibraries.isEmpty) {
208231
throw new DartDocFailure(
209232
"dartdoc could not find any libraries to document. Run `pub get` and try again.");
210233
}
@@ -412,6 +435,7 @@ class DartDoc {
412435
}
413436

414437
Map<String, Set<ModelElement>> _hrefs;
438+
AnalysisContext context;
415439

416440
/// Don't call this method more than once, and only after you've
417441
/// generated all docs for the Package.
@@ -428,7 +452,7 @@ class DartDoc {
428452
}
429453

430454
List<LibraryElement> _parseLibraries(
431-
List<String> files, List<String> includeExternals) {
455+
Iterable<String> files, List<String> includeExternals, [bool parseEmbedders = true]) {
432456
Set<LibraryElement> libraries = new Set();
433457
DartSdk sdk = new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE,
434458
PhysicalResourceProvider.INSTANCE.getFolder(sdkDir.path));
@@ -470,13 +494,18 @@ class DartDoc {
470494

471495
AnalysisEngine.instance.processRequiredPlugins();
472496

473-
AnalysisContext context = AnalysisEngine.instance.createAnalysisContext()
497+
context = AnalysisEngine.instance.createAnalysisContext()
474498
..analysisOptions = options
475499
..sourceFactory = sourceFactory;
476500

477501
if (packageMeta.isSdk) {
478502
libraries
479503
.addAll(new Set()..addAll(getSdkLibrariesToDocument(sdk, context)));
504+
} else if (embedderSdk == null || embedderSdk.urlMappings.isEmpty) {
505+
// TODO(jcollins-g): make this work for embedders?
506+
// Make sure that Interceptor gets found so that the Package can collect
507+
// it later and cloak that class completely.
508+
libraries.addAll(getSdkLibrariesToDocument(sdk, context).where((l) => l.name == '_interceptors'));
480509
}
481510

482511
List<Source> sources = [];
@@ -512,7 +541,7 @@ class DartDoc {
512541

513542
files.forEach(processLibrary);
514543

515-
if ((embedderSdk != null) && (embedderSdk.urlMappings.length > 0)) {
544+
if (parseEmbedders && (embedderSdk != null) && (embedderSdk.urlMappings.length > 0)) {
516545
embedderSdk.urlMappings.keys.forEach((String dartUri) {
517546
Source source = embedderSdk.mapDartUri(dartUri);
518547
processLibrary(source.fullName);
@@ -531,42 +560,38 @@ class DartDoc {
531560
String libraryName = Library.getLibraryName(library);
532561
var fullPath = source.fullName;
533562

563+
if (libraryName.contains('analyzer')) {
564+
1+1;
565+
}
534566
if (includeExternals.any((string) => fullPath.endsWith(string))) {
535567
if (libraries.map(Library.getLibraryName).contains(libraryName)) {
536568
continue;
537569
}
538570
libraries.add(library);
539-
} else if (config != null &&
540-
config.autoIncludeDependencies &&
541-
libraryName != '') {
542-
File searchFile = new File(fullPath);
543-
searchFile =
544-
new File(path.join(searchFile.parent.path, 'pubspec.yaml'));
545-
bool foundLibSrc = false;
546-
while (!foundLibSrc && searchFile.parent != null) {
547-
if (searchFile.existsSync()) break;
548-
List<String> pathParts = path.split(searchFile.parent.path);
549-
// This is a pretty intensely hardcoded convention, but there seems to
550-
// to be no other way to identify what might be a "top level" library
551-
// here. If lib/src is in the path between the file and the pubspec,
552-
// assume that this is supposed to be private.
553-
if (pathParts.length < 2) break;
554-
pathParts = pathParts.sublist(pathParts.length - 2, pathParts.length);
555-
foundLibSrc =
556-
path.join(pathParts[0], pathParts[1]) == path.join('lib', 'src');
557-
searchFile = new File(
558-
path.join(searchFile.parent.parent.path, 'pubspec.yaml'));
559-
}
560-
if (foundLibSrc) continue;
561-
libraries.add(library);
562571
}
563572
}
564573

574+
libraries = filterExcludesFrom(libraries).toSet();
565575
List<AnalysisErrorInfo> errorInfos = [];
566576

577+
// TODO(jcollins-g): figure out why sources can't contain includeExternals
578+
// or embedded SDK components without having spurious(?) analysis errors.
579+
// That seems wrong.
567580
for (Source source in sources) {
568581
context.computeErrors(source);
569-
errorInfos.add(context.getErrors(source));
582+
AnalysisErrorInfo info = context.getErrors(source);
583+
errorInfos.add(info);
584+
List<_Error> errors = [info].expand((AnalysisErrorInfo info) {
585+
return info.errors.map((error) =>
586+
new _Error(error, info.lineInfo, packageMeta.dir.path));
587+
})
588+
.where((_Error error) => error.isError)
589+
.toList()
590+
..sort();
591+
if (errors.isNotEmpty) {
592+
logWarning('analysis errors from source: ${source.uri.toString()} (${source.toString()}');
593+
errors.forEach(logWarning);
594+
}
570595
}
571596

572597
List<_Error> errors = errorInfos
@@ -584,7 +609,6 @@ class DartDoc {
584609
_stopwatch.reset();
585610

586611
if (errors.isNotEmpty) {
587-
errors.forEach(logWarning);
588612
int len = errors.length;
589613
throw new DartDocFailure(
590614
"encountered ${len} analysis error${len == 1 ? '' : 's'}");

lib/src/config.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Config {
1818
final double reexportMinConfidence;
1919
final bool verboseWarnings;
2020
final List<String> dropTextFrom;
21+
final List<String> excludePackages;
2122
Config._(
2223
this.inputDir,
2324
this.showWarnings,
@@ -29,7 +30,8 @@ class Config {
2930
this.categoryOrder,
3031
this.reexportMinConfidence,
3132
this.verboseWarnings,
32-
this.dropTextFrom);
33+
this.dropTextFrom,
34+
this.excludePackages);
3335
}
3436

3537
Config _config;
@@ -46,7 +48,8 @@ void setConfig(
4648
List<String> categoryOrder,
4749
double reexportMinConfidence: 0.1,
4850
bool verboseWarnings: true,
49-
List<String> dropTextFrom}) {
51+
List<String> dropTextFrom,
52+
List<String> excludePackages}) {
5053
_config = new Config._(
5154
inputDir,
5255
showWarnings,
@@ -58,5 +61,6 @@ void setConfig(
5861
categoryOrder ?? const <String>[],
5962
reexportMinConfidence,
6063
verboseWarnings,
61-
dropTextFrom ?? const <String>[]);
64+
dropTextFrom ?? const <String>[],
65+
excludePackages ?? const <String> []);
6266
}

lib/src/element_type.dart

+24-3
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ import 'package:analyzer/dart/element/type.dart';
1010

1111
import 'model.dart';
1212

13-
class ElementType {
13+
class ElementType extends Privacy {
1414
final DartType _type;
1515
final ModelElement element;
1616
String _linkedName;
1717

18-
ElementType(this._type, this.element);
18+
ElementType(this._type, this.element) {
19+
assert(element != null);
20+
}
21+
22+
DartType get type => _type;
1923

2024
bool get isDynamic => _type.isDynamic;
2125

@@ -25,6 +29,15 @@ class ElementType {
2529

2630
bool get isParameterType => (_type is TypeParameterType);
2731

32+
/// This type is a public type if the underlying, canonical element is public.
33+
/// This avoids discarding the resolved type information as canonicalization
34+
/// would ordinarily do.
35+
@override
36+
bool get isPublic {
37+
Class canonicalClass = element.package.findCanonicalModelElementFor(element.element) ?? element;
38+
return canonicalClass.isPublic;
39+
}
40+
2841
String get linkedName {
2942
if (_linkedName == null) {
3043
StringBuffer buf = new StringBuffer();
@@ -56,7 +69,10 @@ class ElementType {
5669
return _linkedName;
5770
}
5871

59-
String get name => _type.name;
72+
String get name {
73+
if (_type.name == null) return _type.element.name;
74+
return _type.name;
75+
}
6076

6177
ModelElement get returnElement {
6278
Element e;
@@ -129,6 +145,11 @@ class ElementType {
129145
// can happen if element is dynamic
130146
if (f.element.library != null) {
131147
lib = new ModelElement.from(f.element.library, element.library);
148+
} else {
149+
// TODO(jcollins-g): Assigning libraries to dynamics doesn't make sense,
150+
// really, but is needed for .package.
151+
assert(f.element.kind == ElementKind.DYNAMIC);
152+
lib = element.library;
132153
}
133154
return new ElementType(f, new ModelElement.from(f.element, lib));
134155
}

0 commit comments

Comments
 (0)