@@ -28,8 +28,27 @@ import 'model_utils.dart';
2828import 'package_meta.dart' show PackageMeta, FileContents;
2929import 'utils.dart' show stripComments;
3030
31+ Map <String , Map <String , List <Map <String , dynamic >>>> __crossdartJson;
32+
3133final Map <Class , List <Class >> _implementors = new Map ();
3234
35+ Map <String , Map <String , List <Map <String , dynamic >>>> get _crossdartJson {
36+ if (__crossdartJson == null ) {
37+ if (config != null ) {
38+ var crossdartFile =
39+ new File (p.join (config.inputDir.path, "crossdart.json" ));
40+ if (crossdartFile.existsSync ()) {
41+ __crossdartJson = JSON .decode (crossdartFile.readAsStringSync ());
42+ } else {
43+ __crossdartJson = {};
44+ }
45+ } else {
46+ __crossdartJson = {};
47+ }
48+ }
49+ return __crossdartJson;
50+ }
51+
3352int byName (Nameable a, Nameable b) =>
3453 compareAsciiLowerCaseNatural (a.name, b.name);
3554
@@ -342,7 +361,7 @@ class Class extends ModelElement implements EnclosedElement {
342361 return _inheritedMethods;
343362 }
344363
345- List <Operator > get inheritedOperators {
364+ List <Method > get inheritedOperators {
346365 if (_inheritedOperators != null ) return _inheritedOperators;
347366 InheritanceManager manager = new InheritanceManager (element.library);
348367 MemberMap cmap = manager.getMapOfMembersInheritedFromClasses (element);
@@ -666,7 +685,6 @@ abstract class Documentable {
666685 String get oneLineDoc;
667686}
668687
669- // TODO: how do we get rid of this class?
670688class Dynamic extends ModelElement {
671689 Dynamic (Element element, Library library) : super (element, library);
672690
@@ -690,25 +708,26 @@ abstract class EnclosedElement {
690708}
691709
692710class Enum extends Class {
693- List <EnumField > _enumFields;
711+ @override
712+ List <EnumField > _constants;
694713
695714 Enum (ClassElement element, Library library) : super (element, library);
696715
697716 @override
698717 List <EnumField > get constants {
699- if (_enumFields != null ) return _enumFields ;
718+ if (_constants != null ) return _constants ;
700719
701720 // This is a hack to give 'values' an index of -1 and all other fields
702721 // their expected indicies. https://github.com/dart-lang/dartdoc/issues/1176
703722 var index = - 1 ;
704723
705- _enumFields = _cls.fields
724+ _constants = _cls.fields
706725 .where (isPublic)
707726 .where ((f) => f.isConst)
708727 .map ((field) => new EnumField .forConstant (index++ , field, library))
709728 .toList (growable: false )..sort (byName);
710729
711- return _enumFields ;
730+ return _constants ;
712731 }
713732
714733 @override
@@ -992,8 +1011,8 @@ class Library extends ModelElement {
9921011 if (_functions != null ) return _functions;
9931012
9941013 Set <FunctionElement > elements = new Set ();
995- elements.addAll (_libraryElement .definingCompilationUnit.functions);
996- for (CompilationUnitElement cu in _libraryElement .parts) {
1014+ elements.addAll (_library .definingCompilationUnit.functions);
1015+ for (CompilationUnitElement cu in _library .parts) {
9971016 elements.addAll (cu.functions);
9981017 }
9991018 elements.addAll (_exportedNamespace.definedNames.values
@@ -1027,7 +1046,7 @@ class Library extends ModelElement {
10271046
10281047 bool get isDocumented => oneLineDoc.isNotEmpty;
10291048
1030- bool get isInSdk => _libraryElement .isInSdk;
1049+ bool get isInSdk => _library .isInSdk;
10311050
10321051 @override
10331052 String get kind => 'library' ;
@@ -1041,7 +1060,7 @@ class Library extends ModelElement {
10411060
10421061 // handle the case of an anonymous library
10431062 if (element.name == null || element.name.isEmpty) {
1044- _name = _libraryElement .definingCompilationUnit.name;
1063+ _name = _library .definingCompilationUnit.name;
10451064 if (_name.endsWith ('.dart' )) {
10461065 _name = _name.substring (0 , _name.length - '.dart' .length);
10471066 }
@@ -1054,15 +1073,15 @@ class Library extends ModelElement {
10541073 // name is to get source.encoding.
10551074 // This may be wrong or misleading, but developers expect the name
10561075 // of dart:____
1057- var source = _libraryElement .definingCompilationUnit.source;
1076+ var source = _library .definingCompilationUnit.source;
10581077 _name = source.isInSystemLibrary ? source.encoding : _name;
10591078
10601079 return _name;
10611080 }
10621081
10631082 String get packageName {
10641083 if (_packageName == null ) {
1065- String sourcePath = _libraryElement .source.fullName;
1084+ String sourcePath = _library .source.fullName;
10661085 File file = new File (sourcePath);
10671086 if (file.existsSync ()) {
10681087 _packageName = _getPackageName (file.parent);
@@ -1075,7 +1094,7 @@ class Library extends ModelElement {
10751094 return _packageName;
10761095 }
10771096
1078- String get path => _libraryElement .definingCompilationUnit.name;
1097+ String get path => _library .definingCompilationUnit.name;
10791098
10801099 /// All variables ("properties") except constants.
10811100 List <TopLevelVariable > get properties {
@@ -1087,9 +1106,8 @@ class Library extends ModelElement {
10871106 if (_typeDefs != null ) return _typeDefs;
10881107
10891108 Set <FunctionTypeAliasElement > elements = new Set ();
1090- elements
1091- .addAll (_libraryElement.definingCompilationUnit.functionTypeAliases);
1092- for (CompilationUnitElement cu in _libraryElement.parts) {
1109+ elements.addAll (_library.definingCompilationUnit.functionTypeAliases);
1110+ for (CompilationUnitElement cu in _library.parts) {
10931111 elements.addAll (cu.functionTypeAliases);
10941112 }
10951113
@@ -1107,11 +1125,11 @@ class Library extends ModelElement {
11071125 if (_classes != null ) return _classes;
11081126
11091127 Set <ClassElement > types = new Set ();
1110- types.addAll (_libraryElement .definingCompilationUnit.types);
1111- for (CompilationUnitElement cu in _libraryElement .parts) {
1128+ types.addAll (_library .definingCompilationUnit.types);
1129+ for (CompilationUnitElement cu in _library .parts) {
11121130 types.addAll (cu.types);
11131131 }
1114- for (LibraryElement le in _libraryElement .exportedLibraries) {
1132+ for (LibraryElement le in _library .exportedLibraries) {
11151133 types.addAll (le.definingCompilationUnit.types
11161134 .where ((t) => _exportedNamespace.definedNames.values.contains (t.name))
11171135 .toList ());
@@ -1128,7 +1146,7 @@ class Library extends ModelElement {
11281146 return _classes;
11291147 }
11301148
1131- LibraryElement get _libraryElement => (element as LibraryElement );
1149+ LibraryElement get _library => (element as LibraryElement );
11321150
11331151 Class getClassByName (String name) {
11341152 return _allClasses.firstWhere ((it) => it.name == name, orElse: () => null );
@@ -1150,8 +1168,8 @@ class Library extends ModelElement {
11501168 if (_variables != null ) return _variables;
11511169
11521170 Set <TopLevelVariableElement > elements = new Set ();
1153- elements.addAll (_libraryElement .definingCompilationUnit.topLevelVariables);
1154- for (CompilationUnitElement cu in _libraryElement .parts) {
1171+ elements.addAll (_library .definingCompilationUnit.topLevelVariables);
1172+ for (CompilationUnitElement cu in _library .parts) {
11551173 elements.addAll (cu.topLevelVariables);
11561174 }
11571175 _exportedNamespace.definedNames.values.forEach ((element) {
@@ -1218,6 +1236,11 @@ class Method extends ModelElement
12181236
12191237 String get fileName => "${name }.html" ;
12201238
1239+ String get fullkind {
1240+ if (_method.isAbstract) return 'abstract $kind ' ;
1241+ return kind;
1242+ }
1243+
12211244 @override
12221245 String get href => '${library .dirName }/${enclosingElement .name }/${fileName }' ;
12231246
@@ -1249,23 +1272,22 @@ class Method extends ModelElement
12491272 MethodElement get _method => (element as MethodElement );
12501273}
12511274
1252- // TODO: rename this to Property
12531275abstract class ModelElement implements Comparable , Nameable , Documentable {
1254- final Element _element ;
1255- final Library _library ;
1276+ final Element element ;
1277+ final Library library ;
12561278
12571279 ElementType _modelType;
12581280 String _rawDocs;
12591281 Documentation __documentation;
1260- List < Parameter > _parameters;
1282+ List _parameters;
12611283 String _linkedName;
12621284
12631285 String _fullyQualifiedName;
12641286
12651287 // WARNING: putting anything into the body of this seems
12661288 // to lead to stack overflows. Need to make a registry of ModelElements
12671289 // somehow.
1268- ModelElement (this ._element , this ._library );
1290+ ModelElement (this .element , this .library );
12691291
12701292 factory ModelElement .from (Element e, Library library) {
12711293 if (e.kind == ElementKind .DYNAMIC ) {
@@ -1363,8 +1385,6 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
13631385 return _rawDocs;
13641386 }
13651387
1366- Element get element => _element;
1367-
13681388 @override
13691389 String get documentationAsHtml => _documentation.asHtml;
13701390
@@ -1436,8 +1456,6 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
14361456 /// A human-friendly name for the kind of element this is.
14371457 String get kind;
14381458
1439- Library get library => _library;
1440-
14411459 String get linkedName {
14421460 if (_linkedName == null ) {
14431461 _linkedName = _calculateLinkedName ();
@@ -1888,7 +1906,7 @@ class Package implements Nameable, Documentable {
18881906 }
18891907}
18901908
1891- class PackageCategory implements Comparable < PackageCategory > {
1909+ class PackageCategory implements Comparable {
18921910 final String name;
18931911 final List <Library > _libraries = [];
18941912
@@ -1957,25 +1975,6 @@ class Parameter extends ModelElement implements EnclosedElement {
19571975 String toString () => element.name;
19581976}
19591977
1960- Map <String , Map <String , List <Map <String , dynamic >>>> __crossdartJson;
1961- Map <String , Map <String , List <Map <String , dynamic >>>> get _crossdartJson {
1962- if (__crossdartJson == null ) {
1963- if (config != null ) {
1964- var crossdartFile =
1965- new File (p.join (config.inputDir.path, "crossdart.json" ));
1966- if (crossdartFile.existsSync ()) {
1967- __crossdartJson = JSON .decode (crossdartFile.readAsStringSync ())
1968- as Map <String , Map <String , List <Map <String , dynamic >>>>;
1969- } else {
1970- __crossdartJson = {};
1971- }
1972- } else {
1973- __crossdartJson = {};
1974- }
1975- }
1976- return __crossdartJson;
1977- }
1978-
19791978abstract class SourceCodeMixin {
19801979 String _sourceCodeCache;
19811980 String get crossdartHtmlTag {
@@ -1992,10 +1991,6 @@ abstract class SourceCodeMixin {
19921991
19931992 Library get library;
19941993
1995- void clearSourceCodeCache () {
1996- _sourceCodeCache = null ;
1997- }
1998-
19991994 String get sourceCode {
20001995 if (_sourceCodeCache == null ) {
20011996 String contents = getFileContentsFor (element);
@@ -2032,31 +2027,10 @@ abstract class SourceCodeMixin {
20322027 return _sourceCodeCache;
20332028 }
20342029
2035- String get _crossdartUrl {
2036- if (_lineNumber != null && _crossdartPath != null ) {
2037- String url = "//www.crossdart.info/p/${_crossdartPath }.html" ;
2038- return "${url }#line-${_lineNumber }" ;
2039- } else {
2040- return null ;
2041- }
2042- }
2043-
2044- int get _lineNumber {
2045- var node = element.computeNode ();
2046- if (node is Declaration && node.element != null ) {
2047- var element = node.element;
2048- var lineNumber = lineNumberCache.lineNumber (
2049- element.source.fullName, element.nameOffset);
2050- return lineNumber + 1 ;
2051- } else {
2052- return null ;
2053- }
2054- }
2055-
20562030 String get _crossdartPath {
20572031 var node = element.computeNode ();
2058- if (node is Declaration && node.element != null ) {
2059- var source = (node.element.source as FileBasedSource );
2032+ if (node is Declaration && ( node as Declaration ) .element != null ) {
2033+ var source = (( node as Declaration ) .element.source as FileBasedSource );
20602034 var file = source.file.toString ();
20612035 var uri = source.uri.toString ();
20622036 var packageMeta = library.package.packageMeta;
@@ -2091,6 +2065,31 @@ abstract class SourceCodeMixin {
20912065 return null ;
20922066 }
20932067 }
2068+
2069+ String get _crossdartUrl {
2070+ if (_lineNumber != null && _crossdartPath != null ) {
2071+ String url = "//www.crossdart.info/p/${_crossdartPath }.html" ;
2072+ return "${url }#line-${_lineNumber }" ;
2073+ } else {
2074+ return null ;
2075+ }
2076+ }
2077+
2078+ int get _lineNumber {
2079+ var node = element.computeNode ();
2080+ if (node is Declaration && (node as Declaration ).element != null ) {
2081+ var element = (node as Declaration ).element;
2082+ var lineNumber = lineNumberCache.lineNumber (
2083+ element.source.fullName, element.nameOffset);
2084+ return lineNumber + 1 ;
2085+ } else {
2086+ return null ;
2087+ }
2088+ }
2089+
2090+ void clearSourceCodeCache () {
2091+ _sourceCodeCache = null ;
2092+ }
20942093}
20952094
20962095/// Top-level variables. But also picks up getters and setters?
0 commit comments