4
4
5
5
library dartdoc.model_utils;
6
6
7
+ import 'dart:io' ;
8
+
7
9
import 'package:analyzer/src/generated/element.dart' ;
8
10
import 'package:analyzer/src/generated/engine.dart' ;
9
11
import 'package:analyzer/src/generated/sdk.dart' ;
10
12
import 'package:analyzer/src/generated/source_io.dart' ;
11
13
12
- bool isPrivate ( Element e) => e.name. startsWith ( '_' ) ;
14
+ final Map < String , String > _fileContents = < String , String > {} ;
13
15
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
- }
16
+ List <InterfaceType > getAllSupertypes (ClassElement c) => c.allSupertypes;
30
17
31
- var docComment = e.computeDocumentationComment ();
32
- if (docComment != null && docComment.contains ('<nodoc>' )) return false ;
33
- return true ;
18
+ String getFileContentsFor (Element e) {
19
+ var location = e.source.fullName;
20
+ if (! _fileContents.containsKey (location)) {
21
+ var contents = new File (location).readAsStringSync ();
22
+ _fileContents.putIfAbsent (location, () => contents);
23
+ }
24
+ return _fileContents[location];
34
25
}
35
26
36
27
Iterable <LibraryElement > getSdkLibrariesToDocument (
@@ -48,22 +39,34 @@ Iterable<LibraryElement> getSdkLibrariesToDocument(
48
39
}
49
40
}
50
41
51
- List <InterfaceType > getAllSupertypes (ClassElement c) => c.allSupertypes;
52
-
53
42
bool isInExportedLibraries (
54
43
List <LibraryElement > libraries, LibraryElement library) {
55
44
return libraries
56
45
.any ((lib) => lib == library || lib.exportedLibraries.contains (library));
57
46
}
58
47
59
- /// Strip the common indent from the given source fragment.
60
- String stripIndentFromSource (String source) {
61
- String remainer = source.trimLeft ();
62
- String indent = source.substring (0 , source.length - remainer.length);
63
- return source.split ('\n ' ).map ((line) {
64
- line = line.trimRight ();
65
- return line.startsWith (indent) ? line.substring (indent.length) : line;
66
- }).join ('\n ' );
48
+ bool isPrivate (Element e) => e.name.startsWith ('_' );
49
+
50
+ bool isPublic (Element e) {
51
+ if (isPrivate (e)) return false ;
52
+ // check to see if element is part of the public api, that is it does not
53
+ // have a '#nodoc' in the documentation comment
54
+ if (e is PropertyAccessorElement && e.isSynthetic) {
55
+ var accessor = (e as PropertyAccessorElement );
56
+ if (accessor.correspondingSetter != null &&
57
+ ! accessor.correspondingSetter.isSynthetic) {
58
+ e = accessor.correspondingSetter;
59
+ } else if (accessor.correspondingGetter != null &&
60
+ ! accessor.correspondingGetter.isSynthetic) {
61
+ e = accessor.correspondingGetter;
62
+ } else {
63
+ e = accessor.variable;
64
+ }
65
+ }
66
+
67
+ var docComment = e.computeDocumentationComment ();
68
+ if (docComment != null && docComment.contains ('<nodoc>' )) return false ;
69
+ return true ;
67
70
}
68
71
69
72
/// Strip leading dartdoc comments from the given source code.
@@ -89,3 +92,13 @@ String stripDartdocCommentsFromSource(String source) {
89
92
return true ;
90
93
}).join ('\n ' );
91
94
}
95
+
96
+ /// Strip the common indent from the given source fragment.
97
+ String stripIndentFromSource (String source) {
98
+ String remainer = source.trimLeft ();
99
+ String indent = source.substring (0 , source.length - remainer.length);
100
+ return source.split ('\n ' ).map ((line) {
101
+ line = line.trimRight ();
102
+ return line.startsWith (indent) ? line.substring (indent.length) : line;
103
+ }).join ('\n ' );
104
+ }
0 commit comments