diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index f9ee455aea..6081f4d7b2 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -15,7 +15,9 @@ class ElementType { final ModelElement element; String _linkedName; - ElementType(this._type, this.element); + ElementType(this._type, this.element) { + assert(element != null); + } bool get isDynamic => _type.isDynamic; @@ -82,7 +84,9 @@ class ElementType { } else { typeArguments = type.typeFormals.map((f) => f.type); } - return typeArguments.map(_getElementTypeFrom).toList(); + return typeArguments + .map(_getElementTypeFrom) + .toList(); } else { return (_type as ParameterizedType) .typeArguments @@ -129,6 +133,11 @@ class ElementType { // can happen if element is dynamic if (f.element.library != null) { lib = new ModelElement.from(f.element.library, element.library); + } else { + // TODO(jcollins-g): Assigning libraries to dynamics doesn't make sense, + // really, but is needed for .package. + assert(f.element.kind == ElementKind.DYNAMIC); + lib = element.library; } return new ElementType(f, new ModelElement.from(f.element, lib)); } diff --git a/lib/src/html/html_generator_instance.dart b/lib/src/html/html_generator_instance.dart index 61185acaa7..bfbb4344d8 100644 --- a/lib/src/html/html_generator_instance.dart +++ b/lib/src/html/html_generator_instance.dart @@ -53,6 +53,9 @@ class HtmlGeneratorInstance implements HtmlOptions { await _copyResources(); if (faviconPath != null) { var bytes = new File(faviconPath).readAsBytesSync(); + // Allow overwrite of favicon. + String filename = path.join(out.path, 'static-assets', 'favicon.png'); + writtenFiles.remove(filename); _writeFile(path.join(out.path, 'static-assets', 'favicon.png'), bytes); } } diff --git a/lib/src/model.dart b/lib/src/model.dart index b0ae49b9eb..54fd815a45 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -206,6 +206,13 @@ class InheritableAccessor extends Accessor with Inheritable { } return _enclosingElement; } + + @override + Set get features { + Set allFeatures = super.features; + if (isInherited) allFeatures.add('inherited'); + return allFeatures; + } } /// Getters and setters. @@ -217,18 +224,72 @@ class Accessor extends ModelElement Accessor(PropertyAccessorElement element, Library library) : super(element, library); - ModelElement get enclosingCombo => _enclosingCombo; + get linkedReturnType { + assert(isGetter); + return modelType.createLinkedReturnTypeName(); + } + + GetterSetterCombo get enclosingCombo { + if (_enclosingCombo == null) { + if (enclosingElement is Class) { + // TODO(jcollins-g): this side effect is rather hacky. Make sure + // enclosingCombo always gets set at accessor creation time, somehow, to + // avoid this. + // TODO(jcollins-g): This also doesn't work for private accessors sometimes. + (enclosingElement as Class).allFields; + } + assert(_enclosingCombo != null); + } + return _enclosingCombo; + } /// Call exactly once to set the enclosing combo for this Accessor. - void set enclosingCombo(GetterSetterCombo combo) { - assert(_enclosingCombo == null || combo == _enclosingCombo); - _enclosingCombo = combo; + set enclosingCombo(GetterSetterCombo combo) { + assert(_enclosingCombo == null || combo == _enclosingCombo); + assert(combo != null); + _enclosingCombo = combo; + } + + bool get isSynthetic => element.isSynthetic; + + @override + String get sourceCode { + if (_sourceCodeCache == null) { + if (isSynthetic) { + _sourceCodeCache = + sourceCodeFor((element as PropertyAccessorElement).variable); + } else { + _sourceCodeCache = super.sourceCode; + } + } + return _sourceCodeCache; + } + + @override + List get computeDocumentationFrom { + if (isSynthetic) return [this]; + return super.computeDocumentationFrom; } @override String get computeDocumentationComment { - if (element.isSynthetic) { - return (element as PropertyAccessorElement).variable.documentationComment; + if (isSynthetic) { + String docComment = (element as PropertyAccessorElement).variable.documentationComment; + // If we're a setter, only display something if we have something different than the getter. + // TODO(jcollins-g): modify analyzer to do this itself? + if (isGetter || + // TODO(jcollins-g): @nodoc reading from comments is at the wrong abstraction level here. + (docComment != null && + (docComment.contains('') || + docComment.contains('@nodoc'))) || + (isSetter && + enclosingCombo.hasGetter && + enclosingCombo.getter.computeDocumentationComment != + docComment)) { + return stripComments(docComment); + } else { + return ''; + } } return stripComments(super.computeDocumentationComment); } @@ -272,6 +333,7 @@ class Accessor extends ModelElement } bool get isGetter => _accessor.isGetter; + bool get isSetter => _accessor.isSetter; bool _overriddenElementIsSet = false; ModelElement _overriddenElement; @@ -422,6 +484,15 @@ class Class extends ModelElement implements EnclosedElement { bool get allInstancePropertiesInherited => instanceProperties.every((f) => f.isInherited); + Iterable get allAccessors { + return allInstanceProperties.expand((f) { + List getterSetters = []; + if (f.hasGetter) getterSetters.add(f.getter); + if (f.hasSetter) getterSetters.add(f.setter); + return getterSetters; + }); + } + List get allOperators { if (_allOperators != null) return _allOperators; _allOperators = [] @@ -438,7 +509,7 @@ class Class extends ModelElement implements EnclosedElement { List get constants { if (_constants != null) return _constants; - _constants = _allFields.where((f) => f.isConst).toList(growable: false) + _constants = allFields.where((f) => f.isConst).toList(growable: false) ..sort(byName); return _constants; @@ -466,6 +537,7 @@ class Class extends ModelElement implements EnclosedElement { _allModelElements ..addAll(allInstanceMethods) ..addAll(allInstanceProperties) + ..addAll(allAccessors) ..addAll(allOperators) ..addAll(constants) ..addAll(constructors) @@ -684,7 +756,7 @@ class Class extends ModelElement implements EnclosedElement { List get inheritedProperties { if (_inheritedProperties == null) { - _inheritedProperties = _allFields.where((f) => f.isInherited).toList() + _inheritedProperties = allFields.where((f) => f.isInherited).toList() ..sort(byName); } return _inheritedProperties; @@ -704,7 +776,7 @@ class Class extends ModelElement implements EnclosedElement { List get instanceProperties { if (_instanceFields != null) return _instanceFields; - _instanceFields = _allFields + _instanceFields = allFields .where((f) => !f.isStatic && !f.isInherited && !f.isConst) .toList(growable: false) ..sort(byName); @@ -814,7 +886,7 @@ class Class extends ModelElement implements EnclosedElement { List get staticProperties { if (_staticFields != null) return _staticFields; - _staticFields = _allFields + _staticFields = allFields .where((f) => f.isStatic) .where((f) => !f.isConst) .toList(growable: false) @@ -857,7 +929,7 @@ class Class extends ModelElement implements EnclosedElement { ElementType get supertype => _supertype; - List get _allFields { + List get allFields { if (_fields != null) return _fields; _fields = []; Map cmap = @@ -1186,7 +1258,7 @@ class EnumField extends Field { } class Field extends ModelElement - with GetterSetterCombo, Inheritable + with GetterSetterCombo, Inheritable, SourceCodeMixin implements EnclosedElement { String _constantValue; bool _isInherited = false; @@ -1231,7 +1303,7 @@ class Field extends ModelElement var v = _field.computeNode().toSource(); if (v == null) return null; var string = v.substring(v.indexOf('=') + 1, v.length).trim(); - _constantValue = string.replaceAll(modelType.name, modelType.linkedName); + _constantValue = string.replaceAll("${modelType.name}", "${modelType.linkedName}"); return _constantValue; } @@ -1297,24 +1369,18 @@ class Field extends ModelElement @override Set get features { - Set all_features = super.features; - all_features.addAll(annotations); - - /// final/const implies read-only, so don't display both strings. - if (readOnly && !isFinal && !isConst) all_features.add('read-only'); - if (writeOnly) all_features.add('write-only'); - if (readWrite) all_features.add('read / write'); + Set allFeatures = super.features..addAll(comboFeatures); if (hasPublicGetter && hasPublicSetter) { if (getter.isInherited && setter.isInherited) { - all_features.add('inherited'); + allFeatures.add('inherited'); } else { - if (getter.isInherited) all_features.add('inherited-getter'); - if (setter.isInherited) all_features.add('inherited-setter'); + if (getter.isInherited) allFeatures.add('inherited-getter'); + if (setter.isInherited) allFeatures.add('inherited-setter'); } } else { - if (isInherited) all_features.add('inherited'); + if (isInherited) allFeatures.add('inherited'); } - return all_features; + return allFeatures; } @override @@ -1328,13 +1394,35 @@ class Field extends ModelElement String get _fileName => isConst ? '$name-constant.html' : '$name.html'; + @override + String get sourceCode { + if (_sourceCodeCache == null) { + // We could use a set to figure the dupes out, but that would lose ordering. + String fieldSourceCode = sourceCodeFor(element) ?? ''; + String getterSourceCode = getter?.sourceCode ?? ''; + String setterSourceCode = setter?.sourceCode ?? ''; + StringBuffer buffer = new StringBuffer(); + if (fieldSourceCode.isNotEmpty) { + buffer.write(fieldSourceCode); + } + if (buffer.isNotEmpty) buffer.write('\n\n'); + if (fieldSourceCode != getterSourceCode) { + if (getterSourceCode != setterSourceCode) { + buffer.write(getterSourceCode); + if (buffer.isNotEmpty) buffer.write('\n\n'); + } + } + if (fieldSourceCode != setterSourceCode) { + buffer.write(setterSourceCode); + } + _sourceCodeCache = buffer.toString(); + } + return _sourceCodeCache; + } + void _setModelType() { if (hasGetter) { - var t = (getter.element as PropertyAccessorElement).returnType; - _modelType = new ElementType( - t, - new ModelElement.from( - t.element, _findOrCreateEnclosingLibraryFor(t.element))); + _modelType = getter.modelType; } } } @@ -1343,6 +1431,17 @@ class Field extends ModelElement abstract class GetterSetterCombo implements ModelElement { Accessor get getter; + Set get comboFeatures { + Set allFeatures = new Set(); + if (hasExplicitGetter) allFeatures.addAll(getter.features); + if (hasExplicitSetter) allFeatures.addAll(setter.features); + if (readOnly && !isFinal && !isConst) allFeatures.add('read-only'); + if (writeOnly) allFeatures.add('write-only'); + if (readWrite) allFeatures.add('read / write'); + return allFeatures; + } + + @override ModelElement enclosingElement; bool get isInherited; @@ -1367,12 +1466,10 @@ abstract class GetterSetterCombo implements ModelElement { if (_documentationFrom == null) { _documentationFrom = []; if (hasPublicGetter) { - _documentationFrom.addAll(getter.documentationFrom.where((e) => - e.computeDocumentationComment != computeDocumentationComment)); + _documentationFrom.addAll(getter.documentationFrom); + } else if (hasPublicSetter) { + _documentationFrom.addAll(setter.documentationFrom); } - if (hasPublicSetter) - _documentationFrom.addAll(setter.documentationFrom.where((e) => - e.computeDocumentationComment != computeDocumentationComment)); if (_documentationFrom.length == 0 || _documentationFrom.every((e) => e.documentation == '')) _documentationFrom = computeDocumentationFrom; @@ -1380,24 +1477,22 @@ abstract class GetterSetterCombo implements ModelElement { return _documentationFrom; } + bool get hasAccessorsWithDocs => + (hasPublicGetter && getter.documentation.isNotEmpty || + hasPublicSetter && setter.documentation.isNotEmpty); + bool get getterSetterBothAvailable => (hasPublicGetter && + getter.documentation.isNotEmpty && + hasPublicSetter && + setter.documentation.isNotEmpty); + String _oneLineDoc; @override String get oneLineDoc { if (_oneLineDoc == null) { - bool hasAccessorsWithDocs = - (hasPublicGetter && getter.oneLineDoc.isNotEmpty || - hasPublicSetter && setter.oneLineDoc.isNotEmpty); if (!hasAccessorsWithDocs) { _oneLineDoc = _documentation.asOneLiner; } else { StringBuffer buffer = new StringBuffer(); - bool getterSetterBothAvailable = false; - if (hasPublicGetter && - getter.oneLineDoc.isNotEmpty && - hasPublicSetter && - setter.oneLineDoc.isNotEmpty) { - getterSetterBothAvailable = true; - } if (hasPublicGetter && getter.oneLineDoc.isNotEmpty) { buffer.write('${getter.oneLineDoc}'); } @@ -1413,7 +1508,7 @@ abstract class GetterSetterCombo implements ModelElement { String get getterSetterDocumentationComment { var buffer = new StringBuffer(); - if (hasPublicGetter && !getter.element.isSynthetic) { + if (hasPublicGetter && !getter.isSynthetic) { assert(getter.documentationFrom.length == 1); // We have to check against dropTextFrom here since documentationFrom // doesn't yield the real elements for GetterSetterCombos. @@ -1425,7 +1520,7 @@ abstract class GetterSetterCombo implements ModelElement { } } - if (hasPublicSetter && !setter.element.isSynthetic) { + if (hasPublicSetter && !setter.isSynthetic) { assert(setter.documentationFrom.length == 1); if (!config.dropTextFrom .contains(setter.documentationFrom.first.element.library.name)) { @@ -1441,8 +1536,11 @@ abstract class GetterSetterCombo implements ModelElement { } String get linkedReturnType { - if (hasGetter) return modelType.linkedName; - return null; + if (hasGetter) { + return getter.linkedReturnType; + } else { + return setter.linkedParamsNoMetadataOrNames; + } } @override @@ -1463,14 +1561,16 @@ abstract class GetterSetterCombo implements ModelElement { return null; } - bool get hasExplicitGetter => hasPublicGetter && !getter.element.isSynthetic; + bool get hasExplicitGetter => hasPublicGetter && !getter.isSynthetic; - bool get hasExplicitSetter => hasPublicSetter && !setter.element.isSynthetic; - bool get hasImplicitSetter => hasPublicSetter && setter.element.isSynthetic; + bool get hasExplicitSetter => hasPublicSetter && !setter.isSynthetic; + bool get hasImplicitSetter => hasPublicSetter && setter.isSynthetic; + bool get hasImplicitGetter => hasPublicGetter && getter.isSynthetic; bool get hasGetter => getter != null; - bool get hasNoGetterSetter => !hasExplicitGetter && !hasExplicitSetter; + bool get hasNoGetterSetter => !hasGetterOrSetter; + bool get hasGetterOrSetter => hasExplicitGetter || hasExplicitSetter; bool get hasSetter => setter != null; @@ -2022,9 +2122,9 @@ class Method extends ModelElement @override Set get features { - Set all_features = super.features; - if (isInherited) all_features.add('inherited'); - return all_features; + Set allFeatures = super.features; + if (isInherited) allFeatures.add('inherited'); + return allFeatures; } @override @@ -2426,25 +2526,25 @@ abstract class ModelElement extends Nameable } Set get features { - Set all_features = new Set(); - all_features.addAll(annotations); + Set allFeatures = new Set(); + allFeatures.addAll(annotations); // override as an annotation should be replaced with direct information // from the analyzer if we decide to display it at this level. - all_features.remove('@override'); + allFeatures.remove('@override'); // Drop the plain "deprecated" annotation, that's indicated via // strikethroughs. Custom @Deprecated() will still appear. - all_features.remove('@deprecated'); + allFeatures.remove('@deprecated'); // const and static are not needed here because const/static elements get // their own sections in the doc. - if (isFinal) all_features.add('final'); - return all_features; + if (isFinal) allFeatures.add('final'); + return allFeatures; } String get featuresAsString { - List all_features = features.toList()..sort(byFeatureOrdering); - return all_features.join(', '); + List allFeatures = features.toList()..sort(byFeatureOrdering); + return allFeatures.join(', '); } bool get canHaveParameters => @@ -2758,7 +2858,25 @@ abstract class ModelElement extends Nameable return linkedParams(showMetadata: false, showNames: false); } - ElementType get modelType => _modelType; + ElementType get modelType { + if (_modelType == null) { + if (element is ExecutableElement || + element is FunctionTypedElement || + element is ParameterElement || + element is TypeDefiningElement || + element is PropertyInducingElement) { + Library lib; + // TODO(jcollins-g): get rid of dynamic special casing + if (element.kind != ElementKind.DYNAMIC) { + lib = _findOrCreateEnclosingLibraryFor((element as dynamic).type.element); + } + _modelType = new ElementType( + (element as dynamic).type, new ModelElement.from((element as dynamic).type.element, lib)); + } + } + return _modelType; + } + @override String get name => element.name; @@ -3303,6 +3421,9 @@ class ModelFunctionTyped extends ModelElement return '<${typeParameters.map((t) => t.name).join(', ')}>'; } + // Food for mustache. TODO(jcollins-g): what about enclosing elements? + bool get isInherited => false; + FunctionTypedElement get _func => (element as FunctionTypedElement); } @@ -3742,6 +3863,7 @@ class Package extends Nameable with Documentable, Warnable { // only here, but since the warnings that depend on this debug // canonicalization problems, don't limit ourselves in case an href is // generated for something non-canonical. + if (modelElement is Dynamic) continue; if (modelElement.href == null) continue; hrefMap.putIfAbsent(modelElement.href, () => new Set()); hrefMap[modelElement.href].add(modelElement); @@ -4162,37 +4284,41 @@ abstract class SourceCodeMixin { Library get library; - String get sourceCode { - if (_sourceCodeCache == null) { - String contents = getFileContentsFor(element); - var node = element.computeNode(); - if (node != null) { - // Find the start of the line, so that we can line up all the indents. - int i = node.offset; - while (i > 0) { - i -= 1; - if (contents[i] == '\n' || contents[i] == '\r') { - i += 1; - break; - } + String sourceCodeFor(Element element) { + String contents = getFileContentsFor(element); + var node = element.computeNode(); + if (node != null) { + // Find the start of the line, so that we can line up all the indents. + int i = node.offset; + while (i > 0) { + i -= 1; + if (contents[i] == '\n' || contents[i] == '\r') { + i += 1; + break; } + } - // Trim the common indent from the source snippet. - var start = node.offset - (node.offset - i); - String source = contents.substring(start, node.end); - - if (config != null && config.addCrossdart) { - source = crossdartifySource(_crossdartJson, source, element, start); - } else { - source = const HtmlEscape().convert(source); - } - source = stripIndentFromSource(source); - source = stripDartdocCommentsFromSource(source); + // Trim the common indent from the source snippet. + var start = node.offset - (node.offset - i); + String source = contents.substring(start, node.end); - _sourceCodeCache = source.trim(); + if (config != null && config.addCrossdart) { + source = crossdartifySource(_crossdartJson, source, element, start); } else { - _sourceCodeCache = ''; + source = const HtmlEscape().convert(source); } + source = stripIndentFromSource(source); + source = stripDartdocCommentsFromSource(source); + + return source.trim(); + } else { + return ''; + } + } + + String get sourceCode { + if (_sourceCodeCache == null) { + _sourceCodeCache = sourceCodeFor(element); } return _sourceCodeCache; @@ -4253,7 +4379,7 @@ abstract class SourceCodeMixin { /// Top-level variables. But also picks up getters and setters? class TopLevelVariable extends ModelElement - with GetterSetterCombo + with GetterSetterCombo, SourceCodeMixin implements EnclosedElement { @override final Accessor getter; @@ -4263,22 +4389,14 @@ class TopLevelVariable extends ModelElement TopLevelVariable(TopLevelVariableElement element, Library library, this.getter, this.setter) : super(element, library) { - if (hasGetter) { - var t = _variable.getter.returnType; - - _modelType = new ElementType( - t, - new ModelElement.from( - t.element, package.findOrCreateLibraryFor(t.element))); - } else { - var s = _variable.setter.parameters.first.type; - _modelType = new ElementType( - s, - new ModelElement.from( - s.element, package.findOrCreateLibraryFor(s.element))); + if (getter != null) { + getter.enclosingCombo = this; + assert(getter.enclosingCombo != null); + } + if (setter != null) { + setter.enclosingCombo = this; + assert(setter.enclosingCombo != null); } - if (getter != null) getter.enclosingCombo = this; - if (setter != null) setter.enclosingCombo = this; } @override @@ -4328,15 +4446,7 @@ class TopLevelVariable extends ModelElement String get kind => 'top-level property'; @override - Set get features { - Set all_features = super.features; - - /// final/const implies read-only, so don't display both strings. - if (readOnly && !isFinal && !isConst) all_features.add('read-only'); - if (writeOnly) all_features.add('write-only'); - if (readWrite) all_features.add('read / write'); - return all_features; - } + Set get features => super.features..addAll(comboFeatures); @override String get computeDocumentationComment { @@ -4383,6 +4493,9 @@ class Typedef extends ModelElement return '${canonicalLibrary.dirName}/$fileName'; } + // Food for mustache. + bool get isInherited => false; + @override String get kind => 'typedef'; diff --git a/lib/templates/_accessor_getter.html b/lib/templates/_accessor_getter.html index 123bc635b4..4bc9e08e2d 100644 --- a/lib/templates/_accessor_getter.html +++ b/lib/templates/_accessor_getter.html @@ -1,9 +1,13 @@ +{{#getter}}
{{{ linkedReturnType }}} {{>name_summary}} + {{>features}}
{{>documentation}} +{{>source_code}}
+{{/getter}} diff --git a/lib/templates/_accessor_setter.html b/lib/templates/_accessor_setter.html index 7eca23fccd..7e0bd49bb5 100644 --- a/lib/templates/_accessor_setter.html +++ b/lib/templates/_accessor_setter.html @@ -1,9 +1,13 @@ +{{#setter}}
void {{>name_summary}}({{{ linkedParamsNoMetadata }}}) + {{>features}}
{{>documentation}} +{{>source_code}}
+{{/setter}} diff --git a/lib/templates/_property.html b/lib/templates/_property.html index 4d88ba4bbc..184be87084 100644 --- a/lib/templates/_property.html +++ b/lib/templates/_property.html @@ -1,16 +1,7 @@ -{{ #hasPublicSetter }} -
- {{{linkedName}}}{{{genericParameters}}} - {{{ arrow }}} {{ #hasExplicitSetter }} {{{ linkedParamsNoMetadata }}} {{/hasExplicitSetter}} {{#hasImplicitSetter}} {{{linkedParamsNoMetadataOrNames}}} {{/hasImplicitSetter}} - -
-{{ /hasPublicSetter }} -{{ #hasPublicGetterNoSetter }}
{{{linkedName}}} {{{ arrow }}} {{{ linkedReturnType }}}
-{{ /hasPublicGetterNoSetter }} {{{ oneLineDoc }}} {{>features}} diff --git a/lib/templates/_source_code.html b/lib/templates/_source_code.html index 831540f9af..007041c47c 100644 --- a/lib/templates/_source_code.html +++ b/lib/templates/_source_code.html @@ -1,5 +1,5 @@ {{#hasSourceCode}}

Source {{{crossdartHtmlTag}}}

-
{{{ sourceCode }}}
+
{{{ sourceCode }}}
{{/hasSourceCode}} diff --git a/lib/templates/property.html b/lib/templates/property.html index cbae158a64..0bcf2448ab 100644 --- a/lib/templates/property.html +++ b/lib/templates/property.html @@ -6,31 +6,27 @@
{{parent.kind}} {{parent.name}}
- - {{#property.hasNoGetterSetter}} -
- {{{ linkedReturnType }}} - {{>name_summary}} - {{>features}} -
- - {{>documentation}} - {{/property.hasNoGetterSetter}} - - {{#property.hasExplicitGetter}} - {{#property.getter}} - {{>accessor_getter}} - {{>source_code}} - {{/property.getter}} - {{/property.hasExplicitGetter}} - - {{#property.hasExplicitSetter}} - {{#property.setter}} - {{>accessor_setter}} - {{>source_code}} - {{/property.setter}} - {{/property.hasExplicitSetter}} - + {{#self}} + {{#hasNoGetterSetter}} +
+ {{{ linkedReturnType }}} + {{>name_summary}} + {{>features}} +
+ {{>documentation}} + {{>source_code}} + {{/hasNoGetterSetter}} + + {{#hasGetterOrSetter}} + {{#hasGetter}} + {{>accessor_getter}} + {{/hasGetter}} + + {{#hasSetter}} + {{>accessor_setter}} + {{/hasSetter}} + {{/hasGetterOrSetter}} + {{/self}}
- - {{#property.hasNoGetterSetter}} -
- {{{ linkedReturnType }}} - {{>name_summary}} - {{>features}} -
- - {{>documentation}} - {{/property.hasNoGetterSetter}} - - {{#property.hasExplicitGetter}} - {{#property.getter}} - {{>accessor_getter}} - {{>source_code}} - {{/property.getter}} - {{/property.hasExplicitGetter}} - - {{#property.hasExplicitSetter}} - {{#property.setter}} - {{>accessor_setter}} - {{>source_code}} - {{/property.setter}} - {{/property.hasExplicitSetter}} - + {{#self}} + {{#hasNoGetterSetter}} +
+ {{{ linkedReturnType }}} + {{>name_summary}} + {{>features}} +
+ {{>documentation}} + {{>source_code}} + {{/hasNoGetterSetter}} + + {{#hasExplicitGetter}} + {{>accessor_getter}} + {{/hasExplicitGetter}} + + {{#hasExplicitSetter}} + {{>accessor_setter}} + {{/hasExplicitSetter}} + {{/self}}
-{{>footer}} +{{>footer}} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index e0e550ebfa..46a165396d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -174,7 +174,7 @@ packages: name: mustache4dart url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "2.1.0" node_preamble: description: name: node_preamble diff --git a/pubspec.yaml b/pubspec.yaml index 0d522590ce..a4b6f94cfb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: http_parser: '>=3.0.3 <4.0.0' logging: ^0.11.3+1 markdown: ^0.11.2 - mustache4dart: ^1.1.0 + mustache4dart: ^2.1.0 package_config: '>=0.1.5 <2.0.0' path: ^1.3.0 resource: ^1.1.0 diff --git a/test/model_test.dart b/test/model_test.dart index 2ef588ad96..d39a34a2b2 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -1297,6 +1297,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, Field sFromApple, mFromApple, mInB, autoCompress; Field isEmpty; Field implicitGetterExplicitSetter, explicitGetterImplicitSetter; + Field explicitGetterSetter; Field explicitNonDocumentedInBaseClassGetter; Field documentedPartialFieldInSubclassOnly; Field ExtraSpecialListLength; @@ -1316,6 +1317,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, .firstWhere((e) => e.name == 'implicitGetterExplicitSetter'); explicitGetterImplicitSetter = UnusualProperties.allModelElements .firstWhere((e) => e.name == 'explicitGetterImplicitSetter'); + explicitGetterSetter = UnusualProperties.allModelElements + .firstWhere((e) => e.name == 'explicitGetterSetter'); explicitNonDocumentedInBaseClassGetter = UnusualProperties.allModelElements.firstWhere( (e) => e.name == 'explicitNonDocumentedInBaseClassGetter'); @@ -1356,6 +1359,20 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, .firstWhere((f) => f.name == 'length'); }); + test('annotations from getters and setters are accumulated in Fields', () { + expect( + explicitGetterSetter.featuresAsString.contains('a Getter Annotation'), + isTrue); + expect( + explicitGetterSetter.featuresAsString.contains('a Setter Annotation'), + isTrue); + }); + + test('Docs from inherited implicit accessors are preserved', () { + expect(explicitGetterImplicitSetter.setter.computeDocumentationComment, + isNot('')); + }); + test('@nodoc on simple property works', () { Field simpleHidden = UnusualProperties.allModelElements .firstWhere((e) => e.name == 'simpleHidden', orElse: () => null); @@ -1428,10 +1445,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, expect(explicitGetterImplicitSetter.oneLineDoc, equals('Getter doc for explicitGetterImplicitSetter')); // Even though we have some new setter docs, getter still takes priority. - expect( - explicitGetterImplicitSetter.documentation, - equals( - 'Docs for explicitGetterImplicitSetter from ImplicitProperties.')); + expect(explicitGetterImplicitSetter.documentation, + equals('Getter doc for explicitGetterImplicitSetter')); }); test('has a fully qualified name', () { @@ -1502,11 +1517,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, equals('Only a setter, with a single param, of type double.')); }); - test('explicit getter and setter docs are unified', () { - expect(lengthX.documentation, contains('Sets the length.')); - expect(lengthX.documentation, contains('Returns a length.')); - }); - test('Field with no explicit getter/setter has documentation', () { expect(autoCompress.documentation, contains('To enable, set `autoCompress` to `true`')); @@ -1683,11 +1693,6 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, equals('Just a setter. No partner getter.')); }); - test('a distinct getter and setters docs appear in the propertys docs', () { - expect(setAndGet.documentation, contains('The getter for setAndGet.')); - expect(setAndGet.documentation, contains('The setter for setAndGet.')); - }); - test('has a getter accessor', () { expect(setAndGet.getter, isNotNull); expect(setAndGet.getter.name, equals('setAndGet')); diff --git a/testing/test_package/lib/fake.dart b/testing/test_package/lib/fake.dart index 7b07e5259c..04b77690a2 100644 --- a/testing/test_package/lib/fake.dart +++ b/testing/test_package/lib/fake.dart @@ -255,6 +255,7 @@ class ClassWithUnusualProperties extends ImplicitProperties { String get explicitNonDocumentedInBaseClassGetter => "something else"; /// Getter doc for explicitGetterSetter. + @Annotation('a Getter Annotation') myCoolTypedef get explicitGetterSetter { return _aFunction; } @@ -269,6 +270,7 @@ class ClassWithUnusualProperties extends ImplicitProperties { String get explicitNodocGetterSetter => "something"; /// This property is not synthetic, so it might reference [f] -- display it. + @Annotation('a Setter Annotation') set explicitGetterSetter(myCoolTypedef f) => _aFunction = f; /// This property only has a getter and no setter; no parameters to print. diff --git a/testing/test_package_docs/css/css-library.html b/testing/test_package_docs/css/css-library.html index d5761a2cb3..715a19926c 100644 --- a/testing/test_package_docs/css/css-library.html +++ b/testing/test_package_docs/css/css-library.html @@ -67,9 +67,8 @@

Properties

- theOnlyThingInTheLibrary - String - + theOnlyThingInTheLibrary + ↔ String
diff --git a/testing/test_package_docs/css/theOnlyThingInTheLibrary.html b/testing/test_package_docs/css/theOnlyThingInTheLibrary.html index 27b2bac8c9..b1cf684cf6 100644 --- a/testing/test_package_docs/css/theOnlyThingInTheLibrary.html +++ b/testing/test_package_docs/css/theOnlyThingInTheLibrary.html @@ -50,13 +50,11 @@
library css
- -
- String - theOnlyThingInTheLibrary
read / write
-
- - +
+ String + theOnlyThingInTheLibrary
read / write
+
+
diff --git a/testing/test_package_docs/ex/Animal/hashCode.html b/testing/test_package_docs/ex/Animal/hashCode.html index 6bdd6504ea..192bc2ff53 100644 --- a/testing/test_package_docs/ex/Animal/hashCode.html +++ b/testing/test_package_docs/ex/Animal/hashCode.html @@ -66,17 +66,16 @@
enum Animal
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
- m - int - + m + ↔ int
The read-write field m.
read / write
- s - String something - + s + ↔ String
The getter for s @@ -297,9 +295,8 @@

Static Properties

- string - String - + string + ↔ String
diff --git a/testing/test_package_docs/ex/Apple/fieldWithTypedef.html b/testing/test_package_docs/ex/Apple/fieldWithTypedef.html index 54a5f27c91..a91d0df1a9 100644 --- a/testing/test_package_docs/ex/Apple/fieldWithTypedef.html +++ b/testing/test_package_docs/ex/Apple/fieldWithTypedef.html @@ -76,17 +76,14 @@
class Apple
- -
- ParameterizedTypedef<bool> - fieldWithTypedef
final
-
- -
-

fieldWithTypedef docs here

-
- - +
+ ParameterizedTypedef<bool> + fieldWithTypedef
final
+
+
+

fieldWithTypedef docs here

+
+
diff --git a/testing/test_package_docs/ex/Apple/hashCode.html b/testing/test_package_docs/ex/Apple/hashCode.html index aaaa1158f4..253dc5e949 100644 --- a/testing/test_package_docs/ex/Apple/hashCode.html +++ b/testing/test_package_docs/ex/Apple/hashCode.html @@ -77,17 +77,16 @@
class Apple
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
- -
- int - m
read / write
-
- -
-

The read-write field m.

-
- - +
+ int + m
read / write
+
+
+

The read-write field m.

+
+
diff --git a/testing/test_package_docs/ex/Apple/runtimeType.html b/testing/test_package_docs/ex/Apple/runtimeType.html index 290638dfcc..5b7b603680 100644 --- a/testing/test_package_docs/ex/Apple/runtimeType.html +++ b/testing/test_package_docs/ex/Apple/runtimeType.html @@ -77,17 +77,16 @@
class Apple
- -
- -
- Type - runtimeType
- -
- - - +
+ +
+ Type + runtimeType
inherited
+
+ + +
+
- -
- String - string
read / write
-
- - - +
+ String + string
read / write
+
+
diff --git a/testing/test_package_docs/ex/B-class.html b/testing/test_package_docs/ex/B-class.html index eb0e71ceeb..6b8494ad57 100644 --- a/testing/test_package_docs/ex/B-class.html +++ b/testing/test_package_docs/ex/B-class.html @@ -145,9 +145,8 @@

Properties

- autoCompress - bool - + autoCompress + ↔ bool
The default value is false (compression disabled). @@ -160,25 +159,23 @@

Properties

-
@override, read-only
+
read-only
- list - List<String> - + list + ↔ List<String>
A list of Strings
read / write
- s - String something - + s + ↔ String
The getter for s -
@override, inherited-setter, read / write
+
inherited-setter, read / write, inherited
fieldWithTypedef @@ -197,9 +194,8 @@

Properties

read-only, inherited
- m - int - + m + ↔ int
The read-write field m. diff --git a/testing/test_package_docs/ex/B/autoCompress.html b/testing/test_package_docs/ex/B/autoCompress.html index a0b7f44d17..9633956601 100644 --- a/testing/test_package_docs/ex/B/autoCompress.html +++ b/testing/test_package_docs/ex/B/autoCompress.html @@ -77,18 +77,15 @@
class B
- -
- bool - autoCompress
read / write
-
- -
-

The default value is false (compression disabled). +

+ bool + autoCompress
read / write
+
+
+

The default value is false (compression disabled). To enable, set autoCompress to true.

-
- - +
+
diff --git a/testing/test_package_docs/ex/B/isImplemented.html b/testing/test_package_docs/ex/B/isImplemented.html index 69d20ce2d2..3a61c752f1 100644 --- a/testing/test_package_docs/ex/B/isImplemented.html +++ b/testing/test_package_docs/ex/B/isImplemented.html @@ -78,17 +78,16 @@
class B
- -
- -
- bool - isImplemented
- -
- - - +
+ +
+ bool + isImplemented +
+ + +
+
- -
- List<String> - list
read / write
-
- -
-

A list of Strings

-
- - +
+ List<String> + list
read / write
+
+
+

A list of Strings

+
+
diff --git a/testing/test_package_docs/ex/B/s.html b/testing/test_package_docs/ex/B/s.html index 5380f58afc..5ec4a3563c 100644 --- a/testing/test_package_docs/ex/B/s.html +++ b/testing/test_package_docs/ex/B/s.html @@ -78,33 +78,33 @@
class B
- -
- -
- String - s
- -
+
+ +
+ String + s +
+ +

The getter for s

+ +
+ +
+ +
+ void + s=(String something) +
inherited
- - -
- -
- void - s=(String something) -
- -
+ +

The setter for s

-
- -
+ +
-
@override, read-only
+
read-only
name diff --git a/testing/test_package_docs/ex/ConstantCat/hashCode.html b/testing/test_package_docs/ex/ConstantCat/hashCode.html index c8012d1a1e..4f2a31a685 100644 --- a/testing/test_package_docs/ex/ConstantCat/hashCode.html +++ b/testing/test_package_docs/ex/ConstantCat/hashCode.html @@ -65,17 +65,16 @@
class ConstantCat
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
- deprecatedField - int - + deprecatedField + ↔ int
-
@deprecated, read / write
+
read / write
deprecatedGetter @@ -196,16 +195,15 @@

Properties

-
@deprecated, read-only
+
read-only
- deprecatedSetter - int value - + deprecatedSetter + int
-
@deprecated, write-only
+
write-only
isImplemented @@ -213,12 +211,11 @@

Properties

-
@override, read-only
+
read-only
- name - String - + name + ↔ String
@@ -376,9 +373,8 @@

Static Properties

final
- staticGetterSetter - x - + staticGetterSetter + ↔ int
diff --git a/testing/test_package_docs/ex/Dog/aFinalField.html b/testing/test_package_docs/ex/Dog/aFinalField.html index 7b621f2a76..3eb6fe637a 100644 --- a/testing/test_package_docs/ex/Dog/aFinalField.html +++ b/testing/test_package_docs/ex/Dog/aFinalField.html @@ -86,14 +86,11 @@
class Dog
- -
- int - aFinalField
final
-
- - - +
+ int + aFinalField
final
+
+
diff --git a/testing/test_package_docs/ex/Dog/aGetterReturningRandomThings.html b/testing/test_package_docs/ex/Dog/aGetterReturningRandomThings.html index 1c6fc38d73..b6829d3afd 100644 --- a/testing/test_package_docs/ex/Dog/aGetterReturningRandomThings.html +++ b/testing/test_package_docs/ex/Dog/aGetterReturningRandomThings.html @@ -87,17 +87,16 @@
class Dog
- -
- -
- int - aGetterReturningRandomThings
- -
- - - +
+ +
+ int + aGetterReturningRandomThings +
+ + +
+
- -
- int - aProtectedFinalField
@protected, final
-
- - - +
+ int + aProtectedFinalField
@protected, final
+
+
diff --git a/testing/test_package_docs/ex/Dog/deprecatedField.html b/testing/test_package_docs/ex/Dog/deprecatedField.html index 26175ee1d2..4d4fd698df 100644 --- a/testing/test_package_docs/ex/Dog/deprecatedField.html +++ b/testing/test_package_docs/ex/Dog/deprecatedField.html @@ -86,14 +86,11 @@
class Dog
- -
- int - deprecatedField
@deprecated, read / write
-
- - - +
+ int + deprecatedField
read / write
+
+
diff --git a/testing/test_package_docs/ex/Dog/deprecatedGetter.html b/testing/test_package_docs/ex/Dog/deprecatedGetter.html index 37d38023bf..ee27beb87e 100644 --- a/testing/test_package_docs/ex/Dog/deprecatedGetter.html +++ b/testing/test_package_docs/ex/Dog/deprecatedGetter.html @@ -87,17 +87,16 @@
class Dog
- -
- -
- int - deprecatedGetter
- -
- - - +
+ +
+ int + deprecatedGetter +
+ + +
+
- deprecatedField - int - + deprecatedField + ↔ int
-
@deprecated, read / write, inherited
+
read / write, inherited
deprecatedGetter @@ -174,16 +173,15 @@

Properties

-
@deprecated, read-only, inherited
+
read-only, inherited
- deprecatedSetter - int value - + deprecatedSetter + int
-
@deprecated, write-only, inherited
+
write-only, inherited
hashCode @@ -199,12 +197,11 @@

Properties

-
@override, read-only, inherited
+
read-only, inherited
- name - String - + name + ↔ String
diff --git a/testing/test_package_docs/ex/ForAnnotation/hashCode.html b/testing/test_package_docs/ex/ForAnnotation/hashCode.html index 579372a26d..9f96790248 100644 --- a/testing/test_package_docs/ex/ForAnnotation/hashCode.html +++ b/testing/test_package_docs/ex/ForAnnotation/hashCode.html @@ -63,17 +63,16 @@
class ForAnnotation
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
-
@override, read-only
+
read-only
hashCode diff --git a/testing/test_package_docs/ex/MyErrorImplements/hashCode.html b/testing/test_package_docs/ex/MyErrorImplements/hashCode.html index 4eae2ac83d..92656e83c7 100644 --- a/testing/test_package_docs/ex/MyErrorImplements/hashCode.html +++ b/testing/test_package_docs/ex/MyErrorImplements/hashCode.html @@ -63,17 +63,16 @@
class MyErrorImplements
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
@@ -219,7 +219,7 @@

Constants

- const ShapeType._internal("Rect") + const ShapeType._internal("Rect")
diff --git a/testing/test_package_docs/ex/ShapeType/ellipse-constant.html b/testing/test_package_docs/ex/ShapeType/ellipse-constant.html index 4f95d74482..6016e80d91 100644 --- a/testing/test_package_docs/ex/ShapeType/ellipse-constant.html +++ b/testing/test_package_docs/ex/ShapeType/ellipse-constant.html @@ -67,7 +67,7 @@
class ShapeType
ShapeType ellipse = - const ShapeType._internal("Ellipse") + const ShapeType._internal("Ellipse")
diff --git a/testing/test_package_docs/ex/ShapeType/hashCode.html b/testing/test_package_docs/ex/ShapeType/hashCode.html index 1c558c4efc..e67c12e6a1 100644 --- a/testing/test_package_docs/ex/ShapeType/hashCode.html +++ b/testing/test_package_docs/ex/ShapeType/hashCode.html @@ -64,17 +64,16 @@
class ShapeType
- -
- -
- int - hashCode
- -
- - - +
+ +
+ int + hashCode
inherited
+
+ + +
+
- -
- String - name
final, inherited
-
- - - +
+ String + name
final, inherited
+
+
diff --git a/testing/test_package_docs/ex/ShapeType/rect-constant.html b/testing/test_package_docs/ex/ShapeType/rect-constant.html index ac05543084..d3ec27916a 100644 --- a/testing/test_package_docs/ex/ShapeType/rect-constant.html +++ b/testing/test_package_docs/ex/ShapeType/rect-constant.html @@ -67,7 +67,7 @@
class ShapeType
ShapeType rect = - const ShapeType._internal("Rect") + const ShapeType._internal("Rect")
diff --git a/testing/test_package_docs/ex/ShapeType/runtimeType.html b/testing/test_package_docs/ex/ShapeType/runtimeType.html index 8dfe476eaa..a36f06eaf5 100644 --- a/testing/test_package_docs/ex/ShapeType/runtimeType.html +++ b/testing/test_package_docs/ex/ShapeType/runtimeType.html @@ -64,17 +64,16 @@
class ShapeType
- -
- -
- Type - runtimeType
- -
- - - +
+ +
+ Type + runtimeType
inherited
+
+ + +
+