Skip to content

Commit 3965647

Browse files
committed
check for the <nodoc> tag in comments to generate docs for an element
1 parent 6cef892 commit 3965647

File tree

8 files changed

+68
-13
lines changed

8 files changed

+68
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.8.5
2+
* [enhancement] do not document if there is a <nodoc> in the doc comment.
3+
14
## 0.8.4
25
* [enhancement] Only include generator metadata in the package `index.html` file.
36
* [bug] Fixed the display of deprecated properties.

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export 'src/package_meta.dart';
3939

4040
const String name = 'dartdoc';
4141
// Update when pubspec version changes.
42-
const String version = '0.8.4';
42+
const String version = '0.8.4-dev';
4343

4444
final String defaultOutDir = p.join('doc', 'api');
4545

lib/src/model.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,13 @@ class Package implements Nameable, Documentable {
510510

511511
Package(Iterable<LibraryElement> libraryElements, this.packageMeta) {
512512
libraryElements.forEach((element) {
513-
var lib = new Library(element, this);
514-
Library._libraryMap.putIfAbsent(lib.name, () => lib);
515-
elementLibaryMap.putIfAbsent('${lib.kind}.${lib.name}', () => lib);
516-
_libraries.add(lib);
513+
// add only if the element should be included in the public api
514+
if (isPublic(element)) {
515+
var lib = new Library(element, this);
516+
Library._libraryMap.putIfAbsent(lib.name, () => lib);
517+
elementLibaryMap.putIfAbsent('${lib.kind}.${lib.name}', () => lib);
518+
_libraries.add(lib);
519+
}
517520
});
518521

519522
_libraries.forEach((library) {
@@ -689,8 +692,8 @@ class Library extends ModelElement {
689692
_exportedNamespace.definedNames.values.forEach((element) {
690693
if (element is PropertyAccessorElement) elements.add(element.variable);
691694
});
692-
elements..removeWhere(isPrivate);
693695
_variables = elements
696+
.where(isPublic)
694697
.map((e) => new TopLevelVariable(e, this))
695698
.toList(growable: false)..sort(byName);
696699

@@ -766,8 +769,7 @@ class Library extends ModelElement {
766769
elements.addAll(_exportedNamespace.definedNames.values
767770
.where((element) => element is FunctionElement));
768771

769-
elements..removeWhere(isPrivate);
770-
_functions = elements.map((e) {
772+
_functions = elements.where(isPublic).map((e) {
771773
return new ModelFunction(e, this);
772774
}).toList(growable: false)..sort(byName);
773775

@@ -1133,7 +1135,7 @@ class Class extends ModelElement implements EnclosedElement {
11331135
for (ExecutableElement value in vs) {
11341136
if (value != null &&
11351137
value is MethodElement &&
1136-
!value.isPrivate &&
1138+
isPublic(value) &&
11371139
!value.isOperator &&
11381140
value.enclosingElement != null) {
11391141
if (!package.isDocumented(value.enclosingElement)) {
@@ -1261,7 +1263,7 @@ class Class extends ModelElement implements EnclosedElement {
12611263
for (var value in vs) {
12621264
if (value != null &&
12631265
value is PropertyAccessorElement &&
1264-
!value.isPrivate &&
1266+
isPublic(value) &&
12651267
value.enclosingElement != null) {
12661268
// TODO: why is this here?
12671269
var e = value.variable;

lib/src/model_utils.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,27 @@ import 'package:analyzer/src/generated/source_io.dart';
1111

1212
bool isPrivate(Element e) => e.name.startsWith('_');
1313

14-
bool isPublic(Element e) => !isPrivate(e);
14+
bool isPublic(Element e) {
15+
if (isPrivate(e)) return false;
16+
// check to see if element is part of the public api, that is it does not
17+
// have a '#nodoc' in the documentation comment
18+
if (e is PropertyAccessorElement && e.isSynthetic) {
19+
var accessor = (e as PropertyAccessorElement);
20+
if (accessor.correspondingSetter != null &&
21+
!accessor.correspondingSetter.isSynthetic) {
22+
e = accessor.correspondingSetter;
23+
} else if (accessor.correspondingGetter != null &&
24+
!accessor.correspondingGetter.isSynthetic) {
25+
e = accessor.correspondingGetter;
26+
} else {
27+
e = accessor.variable;
28+
}
29+
}
30+
31+
var docComment = e.computeDocumentationComment();
32+
if (docComment != null && docComment.contains('<nodoc>')) return false;
33+
return true;
34+
}
1535

1636
Iterable<LibraryElement> getSdkLibrariesToDocument(
1737
DartSdk sdk, AnalysisContext context) sync* {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dartdoc
22
# Also update the `version` field in lib/dartdoc.dart.
3-
version: 0.8.4
3+
version: 0.8.4-dev
44
author: Dart Team <[email protected]>
55
description: A documentation generator for Dart.
66
homepage: https://github.com/dart-lang/dartdoc

test_package/lib/example.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ int function1(String s, bool b, lastParam) => 5;
1111

1212
double number;
1313

14+
/// top level var <nodoc>
15+
const DO_NOT_DOCUMENT = 'not documented';
16+
1417
get y => 2;
1518

1619
const String COLOR = 'red';
@@ -36,6 +39,13 @@ void set deprecatedSetter(int value) {}
3639
@deprecated
3740
int deprecatedField;
3841

42+
/**
43+
* class <nodoc>
44+
*/
45+
class unDocumented {
46+
String s;
47+
}
48+
3949
/// Sample class [String]
4050
class Apple {
4151
static const int n = 5;
@@ -45,6 +55,9 @@ class Apple {
4555
/// The read-write field `m`.
4656
int m = 0;
4757

58+
/// <nodoc> no docs
59+
int notDocumented;
60+
4861
///Constructor
4962
Apple();
5063

@@ -71,6 +84,11 @@ class Apple {
7184
/// new Apple().m1();
7285
void m1() {}
7386

87+
/**
88+
* <nodoc> method not documented
89+
*/
90+
void notAPublicMethod() {}
91+
7492
operator *(Apple other) => this;
7593

7694
void printMsg(String msg, [bool linebreak]) {}

test_package/lib/excluded.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// This library is excluded from the documentation
2+
/// even though it is located in the lib folder by
3+
/// using the <nodoc> tag
4+
library excluded;
5+
6+
export 'example.dart' show Apple;
7+
8+
const EXCLUDE = 'exclude';
9+
10+
class Excluded {
11+
void excludedMethod(String s) {}
12+
}

test_package_docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7-
<meta name="generator" content="made with love by dartdoc 0.8.4">
7+
<meta name="generator" content="made with love by dartdoc 0.8.4-dev">
88
<meta name="description" content="test_package API docs, for the Dart programming language.">
99
<title>test_package - Dart API docs</title>
1010

0 commit comments

Comments
 (0)