From b25a93990f22fa45dae90541d4c2a07972989bd0 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Thu, 23 Feb 2017 13:49:53 -0800 Subject: [PATCH 01/11] A basic working version, but not cleaned up or extensively tested --- lib/src/model.dart | 160 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 140 insertions(+), 20 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index e6ee522e90..21892256ca 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -9,8 +9,10 @@ import 'dart:convert'; import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart' - show AnnotatedNode, Annotation, Declaration; + show AnnotatedNode, Annotation, Declaration, FormalParameter, FieldDeclaration, + VariableDeclaration, VariableDeclarationList; import 'package:analyzer/dart/element/element.dart'; +import 'package:analyzer/src/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/generated/resolver.dart' show Namespace, NamespaceBuilder, InheritanceManager; @@ -913,9 +915,39 @@ class Field extends ModelElement bool get writeOnly => hasSetter && !hasGetter; + @override + List get annotations { + if (element is PropertyInducingElement && super.annotations.isEmpty) { + var pie = element as PropertyInducingElement; + var all_annotations = new List(); + all_annotations.addAll(annotations_from_EAmetadata(pie.getter?.metadata)); + all_annotations.addAll(annotations_from_EAmetadata(pie.setter?.metadata)); + return all_annotations; + } else { + return super.annotations; + } + } + @override Set get features { - Set all_features = super.features; + if (element.toString().contains('iconSet')) { + ///print('calling super'); + } + if (element.toString().contains('iconSet')) { + ///print('here we go'); + ///print(element.toString()); + ///print(element.runtimeType); + ///print(element is PropertyInducingElement); + } + if (element is PropertyInducingElement && !hasAnnotations) { + var pie = element as PropertyInducingElement; + List gmd = pie.getter?.metadata; + List smd = pie.setter?.metadata; + ///print(gmd); + ///print(smd); + } + Set all_features = new Set(); + 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'); @@ -1477,34 +1509,122 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { List get annotations { // Check https://code.google.com/p/dart/issues/detail?id=23181 // If that is fixed, this code might get a lot easier + + if (element.computeNode() != null) { + if (element.computeNode() is FormalParameter) { + //var n1 = element.computeNode(); + //if (n1.metadata.isNotEmpty) { + // print(n1.metadata); + //} + } else if (!(element.computeNode() is AnnotatedNode)) { + ///print('wtf'); + ///print(element + /// .computeNode() + /// .runtimeType + /// .toString()); + } else { + if (element is PropertyInducingElement) { + } + var n1 = element.computeNode() as AnnotatedNode; + if (n1.toString().contains('iconSet')) { + //print(n1); + //print(element.computeNode().runtimeType); + if (n1.parent is AnnotatedNode) { + //print (n1.parent.runtimeType); + var n2 = n1.parent as AnnotatedNode; + if (n2.parent is AnnotatedNode) { + //print(n2.parent.runtimeType); + var n3 = n2.parent as AnnotatedNode; + //print(n3.metadata); + } + } + ///print((n2.parent as AnnotatedNode).metadata); + ///var n3 = n2.parent as AnnotatedNode; + } + } + } + if (element.computeNode() != null && element.computeNode() is AnnotatedNode) { - return (element.computeNode() as AnnotatedNode) - .metadata - .map((Annotation a) { - var annotationString = a.toSource().substring(1); // remove the @ - var e = a.element; - if (e != null && (e is ConstructorElement)) { - var me = new ModelElement.from( - e.enclosingElement, package._getLibraryFor(e.enclosingElement)); - if (me.href != null) { - return annotationString.replaceAll(me.name, me.linkedName); - } + AnnotatedNode node = element.computeNode() as AnnotatedNode; + while ((node is VariableDeclaration || + node is VariableDeclarationList) && + node is! FieldDeclaration) { + if (null == (node as AnnotatedNode).parent) { + break; } - return annotationString; - }).toList(growable: false); + node = node.parent; + } + return annotations_from_metadata(node.metadata); } else { - return element.metadata.map((ElementAnnotation a) { - // TODO link to the element's href - return a.element.name; - }).toList(growable: false); - } + return annotations_from_EAmetadata(element.metadata); + } + } + + List annotations_from_EAmetadata(List md) { + if (md == null) { + return new List(); + } + return md.map((ElementAnnotation ea) { + // TODO link to the element's href + Annotation a = (ea as ElementAnnotationImpl).annotationAst; + var annotationString = a.toSource().substring(1); // remove the @ + var ae = a.element; + if (ae != null && (ae is ConstructorElement)) { + var me = new ModelElement.from(ae, package._getLibraryFor(ae)); + if(annotationString.contains('Input')) { + print('----'); + print(me.fullyQualifiedNameWithoutLibrary); + print(me.nameWithGenerics); + print(me.element.runtimeType); + print(me.element); + print(me.element.computeNode().metadata); + print(a); + //print((a as ElementAnnotationImpl).annotationAst); + ///print(me.href); + } + /*if(annotationString.contains('Input')) { + ///print(ae.computeNode().childEntities.toString()); + print(ae.computeNode().childEntities.elementAt(0).runtimeType); + }*/ + } + if (ae != null && (ae is ConstructorElement)) { + var me = new ModelElement.from( + ae.enclosingElement, package._getLibraryFor(ae.enclosingElement)); + if (me.href != null) { + return annotationString.replaceAll(me.name, me.linkedName); + } + } + return annotationString; + }).toList(growable: false); + } + + List annotations_from_metadata(List md) { + if (md == null) { + return new List(); + } + return md + .map((Annotation a) { + var annotationString = a.toSource().substring(1); // remove the @ + var ae = a.element; + if (ae != null && (ae is ConstructorElement)) { + var me = new ModelElement.from( + ae.enclosingElement, package._getLibraryFor(ae.enclosingElement)); + if (me.href != null) { + return annotationString.replaceAll(me.name, me.linkedName); + } + } + return annotationString; + }).toList(growable: false); } /// const and static are not needed here because const/static elements get /// their own sections in the doc. Set get features { Set all_features = new Set(); + ///if (annotations.isNotEmpty) { + /// print(annotations); + ///} all_features.addAll(annotations); /// override as an annotation should be replaced with direct information /// from the analyzer if we decide to display it at this level. From f508659be45893ced5083a7067c72e7050680f33 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 24 Feb 2017 16:00:17 -0800 Subject: [PATCH 02/11] Cleaned up code, but now depends on a change in analyzer --- lib/src/model.dart | 119 ++++++--------------------------------------- 1 file changed, 15 insertions(+), 104 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 21892256ca..afc26cebd3 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -12,7 +12,6 @@ import 'package:analyzer/dart/ast/ast.dart' show AnnotatedNode, Annotation, Declaration, FormalParameter, FieldDeclaration, VariableDeclaration, VariableDeclarationList; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/src/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/generated/resolver.dart' show Namespace, NamespaceBuilder, InheritanceManager; @@ -920,8 +919,8 @@ class Field extends ModelElement if (element is PropertyInducingElement && super.annotations.isEmpty) { var pie = element as PropertyInducingElement; var all_annotations = new List(); - all_annotations.addAll(annotations_from_EAmetadata(pie.getter?.metadata)); - all_annotations.addAll(annotations_from_EAmetadata(pie.setter?.metadata)); + all_annotations.addAll(annotationsFromMetadata(pie.getter?.metadata)); + all_annotations.addAll(annotationsFromMetadata(pie.setter?.metadata)); return all_annotations; } else { return super.annotations; @@ -930,23 +929,7 @@ class Field extends ModelElement @override Set get features { - if (element.toString().contains('iconSet')) { - ///print('calling super'); - } - if (element.toString().contains('iconSet')) { - ///print('here we go'); - ///print(element.toString()); - ///print(element.runtimeType); - ///print(element is PropertyInducingElement); - } - if (element is PropertyInducingElement && !hasAnnotations) { - var pie = element as PropertyInducingElement; - List gmd = pie.getter?.metadata; - List smd = pie.setter?.metadata; - ///print(gmd); - ///print(smd); - } - Set all_features = new Set(); + 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'); @@ -1507,43 +1490,6 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { } List get annotations { - // Check https://code.google.com/p/dart/issues/detail?id=23181 - // If that is fixed, this code might get a lot easier - - if (element.computeNode() != null) { - if (element.computeNode() is FormalParameter) { - //var n1 = element.computeNode(); - //if (n1.metadata.isNotEmpty) { - // print(n1.metadata); - //} - } else if (!(element.computeNode() is AnnotatedNode)) { - ///print('wtf'); - ///print(element - /// .computeNode() - /// .runtimeType - /// .toString()); - } else { - if (element is PropertyInducingElement) { - } - var n1 = element.computeNode() as AnnotatedNode; - if (n1.toString().contains('iconSet')) { - //print(n1); - //print(element.computeNode().runtimeType); - if (n1.parent is AnnotatedNode) { - //print (n1.parent.runtimeType); - var n2 = n1.parent as AnnotatedNode; - if (n2.parent is AnnotatedNode) { - //print(n2.parent.runtimeType); - var n3 = n2.parent as AnnotatedNode; - //print(n3.metadata); - } - } - ///print((n2.parent as AnnotatedNode).metadata); - ///var n3 = n2.parent as AnnotatedNode; - } - } - } - if (element.computeNode() != null && element.computeNode() is AnnotatedNode) { AnnotatedNode node = element.computeNode() as AnnotatedNode; @@ -1555,56 +1501,24 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { } node = node.parent; } - return annotations_from_metadata(node.metadata); - } else { - return annotations_from_EAmetadata(element.metadata); - } - } - - List annotations_from_EAmetadata(List md) { - if (md == null) { + return annotationsFromMetadata(node.metadata); + } else if (element.computeNode() is FormalParameter) { + /// TODO(jcollins-g): This is special cased to suppress annotations + /// in constructor documentation. Do we want to do + /// this? return new List(); + } else { + return annotationsFromMetadata(element.metadata); } - return md.map((ElementAnnotation ea) { - // TODO link to the element's href - Annotation a = (ea as ElementAnnotationImpl).annotationAst; - var annotationString = a.toSource().substring(1); // remove the @ - var ae = a.element; - if (ae != null && (ae is ConstructorElement)) { - var me = new ModelElement.from(ae, package._getLibraryFor(ae)); - if(annotationString.contains('Input')) { - print('----'); - print(me.fullyQualifiedNameWithoutLibrary); - print(me.nameWithGenerics); - print(me.element.runtimeType); - print(me.element); - print(me.element.computeNode().metadata); - print(a); - //print((a as ElementAnnotationImpl).annotationAst); - ///print(me.href); - } - /*if(annotationString.contains('Input')) { - ///print(ae.computeNode().childEntities.toString()); - print(ae.computeNode().childEntities.elementAt(0).runtimeType); - }*/ - } - if (ae != null && (ae is ConstructorElement)) { - var me = new ModelElement.from( - ae.enclosingElement, package._getLibraryFor(ae.enclosingElement)); - if (me.href != null) { - return annotationString.replaceAll(me.name, me.linkedName); - } - } - return annotationString; - }).toList(growable: false); } - List annotations_from_metadata(List md) { + /// dynamic parameter since ElementAnnotation and Annotation have no common + /// class for calling toSource() and element. + List annotationsFromMetadata(List md) { if (md == null) { return new List(); } - return md - .map((Annotation a) { + return md.map((dynamic a) { var annotationString = a.toSource().substring(1); // remove the @ var ae = a.element; if (ae != null && (ae is ConstructorElement)) { @@ -1615,16 +1529,13 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { } } return annotationString; - }).toList(growable: false); + }).toList(growable: false) as List; } /// const and static are not needed here because const/static elements get /// their own sections in the doc. Set get features { Set all_features = new Set(); - ///if (annotations.isNotEmpty) { - /// print(annotations); - ///} all_features.addAll(annotations); /// override as an annotation should be replaced with direct information /// from the analyzer if we decide to display it at this level. From 0cab2c07b413c772cde405f2222548e6ec5dcf8b Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 24 Feb 2017 16:31:49 -0800 Subject: [PATCH 03/11] Formatting for model.dart changes --- lib/src/model.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/model.dart b/lib/src/model.dart index afc26cebd3..d355e80902 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -2606,6 +2606,7 @@ class TopLevelVariable extends ModelElement @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'); From 3a3368c951e12856638506ccf774be742e52634a Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 24 Feb 2017 16:52:36 -0800 Subject: [PATCH 04/11] Update test package docs --- testing/test_package_docs/ex/B-class.html | 4 ++-- testing/test_package_docs/ex/ConstantCat-class.html | 2 +- testing/test_package_docs/ex/Dog-class.html | 10 +++++----- .../test_package_docs/ex/Dog/aProtectedFinalField.html | 2 +- testing/test_package_docs/ex/Dog/deprecatedField.html | 2 +- testing/test_package_docs/ex/F-class.html | 10 +++++----- .../test_package_docs/ex/MyErrorImplements-class.html | 2 +- .../fake/onlyPositionalWithNoDefaultNoType.html | 2 +- testing/test_package_docs/fake/paintImage1.html | 2 +- testing/test_package_docs/fake/paintImage2.html | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/testing/test_package_docs/ex/B-class.html b/testing/test_package_docs/ex/B-class.html index 659412040f..0bba6d2e60 100644 --- a/testing/test_package_docs/ex/B-class.html +++ b/testing/test_package_docs/ex/B-class.html @@ -198,7 +198,7 @@

Properties

-
read-only
+
override, read-only
list @@ -214,7 +214,7 @@

Properties

-
read-only
+
override, read-only
fieldWithTypedef diff --git a/testing/test_package_docs/ex/ConstantCat-class.html b/testing/test_package_docs/ex/ConstantCat-class.html index b69af3a481..46e220044c 100644 --- a/testing/test_package_docs/ex/ConstantCat-class.html +++ b/testing/test_package_docs/ex/ConstantCat-class.html @@ -181,7 +181,7 @@

Properties

-
read-only
+
override, read-only
name diff --git a/testing/test_package_docs/ex/Dog-class.html b/testing/test_package_docs/ex/Dog-class.html index 48f6a207d9..80b16319d1 100644 --- a/testing/test_package_docs/ex/Dog-class.html +++ b/testing/test_package_docs/ex/Dog-class.html @@ -274,7 +274,7 @@

Properties

-
final
+
protected, final
deprecatedField @@ -282,7 +282,7 @@

Properties

-
read / write
+
deprecated, read / write
deprecatedGetter @@ -290,7 +290,7 @@

Properties

-
read-only
+
deprecated, read-only
deprecatedSetter @@ -298,7 +298,7 @@

Properties

-
write-only
+
deprecated, write-only
isImplemented @@ -306,7 +306,7 @@

Properties

-
read-only
+
override, read-only
name diff --git a/testing/test_package_docs/ex/Dog/aProtectedFinalField.html b/testing/test_package_docs/ex/Dog/aProtectedFinalField.html index 742aabe156..9b5822ece3 100644 --- a/testing/test_package_docs/ex/Dog/aProtectedFinalField.html +++ b/testing/test_package_docs/ex/Dog/aProtectedFinalField.html @@ -124,7 +124,7 @@
Dog
int - aProtectedFinalField
final
+ aProtectedFinalField
protected, final
diff --git a/testing/test_package_docs/ex/Dog/deprecatedField.html b/testing/test_package_docs/ex/Dog/deprecatedField.html index 22424713d6..d012e98017 100644 --- a/testing/test_package_docs/ex/Dog/deprecatedField.html +++ b/testing/test_package_docs/ex/Dog/deprecatedField.html @@ -124,7 +124,7 @@
Dog
int - deprecatedField
read / write
+ deprecatedField
deprecated, read / write
diff --git a/testing/test_package_docs/ex/F-class.html b/testing/test_package_docs/ex/F-class.html index 7b9b71b6a2..a94128e5af 100644 --- a/testing/test_package_docs/ex/F-class.html +++ b/testing/test_package_docs/ex/F-class.html @@ -196,7 +196,7 @@

Properties

-
final, inherited
+
protected, final, inherited
deprecatedField @@ -204,7 +204,7 @@

Properties

-
read / write, inherited
+
deprecated, read / write, inherited
deprecatedGetter @@ -212,7 +212,7 @@

Properties

-
read-only, inherited
+
deprecated, read-only, inherited
deprecatedSetter @@ -220,7 +220,7 @@

Properties

-
write-only, inherited
+
deprecated, write-only, inherited
hashCode @@ -236,7 +236,7 @@

Properties

-
read-only, inherited
+
override, read-only, inherited
name diff --git a/testing/test_package_docs/ex/MyErrorImplements-class.html b/testing/test_package_docs/ex/MyErrorImplements-class.html index d95d81fb83..b97ff33c3b 100644 --- a/testing/test_package_docs/ex/MyErrorImplements-class.html +++ b/testing/test_package_docs/ex/MyErrorImplements-class.html @@ -180,7 +180,7 @@

Properties

-
read-only
+
override, read-only
hashCode diff --git a/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html b/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html index 7f3ba65fb9..8870ba5cc4 100644 --- a/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html +++ b/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html @@ -151,7 +151,7 @@
fake
void - onlyPositionalWithNoDefaultNoType([@greatestAnnotation anything ]) + onlyPositionalWithNoDefaultNoType([anything ])

A single optional positional param, no type annotation, no default value.

diff --git a/testing/test_package_docs/fake/paintImage1.html b/testing/test_package_docs/fake/paintImage1.html index 582e7ccf2b..30fb43e287 100644 --- a/testing/test_package_docs/fake/paintImage1.html +++ b/testing/test_package_docs/fake/paintImage1.html @@ -146,7 +146,7 @@
fake
void - paintImage1({@required String canvas, @required int rect, @required ExtraSpecialList image, BaseForDocComments colorFilter, String repeat: LongFirstLine.THING }) + paintImage1({String canvas, int rect, ExtraSpecialList image, BaseForDocComments colorFilter, String repeat: LongFirstLine.THING })

Paints an image into the given rectangle in the canvas.

diff --git a/testing/test_package_docs/fake/paintImage2.html b/testing/test_package_docs/fake/paintImage2.html index 8ae249bfe0..fb174cc395 100644 --- a/testing/test_package_docs/fake/paintImage2.html +++ b/testing/test_package_docs/fake/paintImage2.html @@ -146,7 +146,7 @@
fake
void - paintImage2(String fooParam, [ @required String canvas, @required int rect, @required ExtraSpecialList image, BaseForDocComments colorFilter, String repeat = LongFirstLine.THING ]) + paintImage2(String fooParam, [ String canvas, int rect, ExtraSpecialList image, BaseForDocComments colorFilter, String repeat = LongFirstLine.THING ])

Paints an image into the given rectangle in the canvas.

From a98bcbfbdf07c0880bf669f297a475bbdf3069fa Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 27 Feb 2017 15:20:27 -0800 Subject: [PATCH 05/11] Add @ to the beginning of annotations --- lib/resources/styles.css | 4 ---- lib/src/model.dart | 28 ++++++++++++++-------------- test/model_test.dart | 6 +++--- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/resources/styles.css b/lib/resources/styles.css index 57d325501c..fd65cf0cf3 100644 --- a/lib/resources/styles.css +++ b/lib/resources/styles.css @@ -456,10 +456,6 @@ nav .self-name { display: inline; } -.annotation-list li:before { - content: "@"; -} - .comma-separated { list-style: none; padding: 0; diff --git a/lib/src/model.dart b/lib/src/model.dart index d355e80902..76675bc12f 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -1503,9 +1503,9 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { } return annotationsFromMetadata(node.metadata); } else if (element.computeNode() is FormalParameter) { - /// TODO(jcollins-g): This is special cased to suppress annotations - /// in constructor documentation. Do we want to do - /// this? + /// TODO(jcollins-g): This is special cased to suppress annotations for + /// parameters in constructor documentation. Do we + /// want to do this? return new List(); } else { return annotationsFromMetadata(element.metadata); @@ -1519,17 +1519,17 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { return new List(); } return md.map((dynamic a) { - var annotationString = a.toSource().substring(1); // remove the @ - var ae = a.element; - if (ae != null && (ae is ConstructorElement)) { + String annotationString = a.toSource(); + if (a.element != null && (a.element is ConstructorElement)) { var me = new ModelElement.from( - ae.enclosingElement, package._getLibraryFor(ae.enclosingElement)); - if (me.href != null) { - return annotationString.replaceAll(me.name, me.linkedName); - } + a.element.enclosingElement, + package._getLibraryFor(a.element.enclosingElement)); + return annotationString.replaceFirst( + "${me.name}", + "${me.linkedName}"); } return annotationString; - }).toList(growable: false) as List; + }).toList(growable: false); } /// const and static are not needed here because const/static elements get @@ -1539,10 +1539,10 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { all_features.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'); + all_features.remove('@override'); /// Drop the plain "deprecated" annotation, that's indicated via /// strikethroughs. Custom @Deprecated() will still appear. - all_features.remove('deprecated'); + all_features.remove('@deprecated'); if (isFinal) all_features.add('final'); return all_features; } @@ -1780,7 +1780,7 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { buf.write(''); if (showMetadata && param.hasAnnotations) { param.annotations.forEach((String annotation) { - buf.write('@$annotation '); + buf.write('$annotation '); }); } if (param.modelType.isFunctionType) { diff --git a/test/model_test.dart b/test/model_test.dart index a1634d9442..b817b39aae 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -1649,20 +1649,20 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, expect( forAnnotation.annotations.first, equals( - 'ForAnnotation(\'my value\')')); + '@ForAnnotation(\'my value\')')); }); test('methods has the right annotation', () { var m = dog.instanceMethods.singleWhere((m) => m.name == 'getClassA'); expect(m.hasAnnotations, isTrue); - expect(m.annotations.first, equals('deprecated')); + expect(m.annotations.first, equals('@deprecated')); }); test('method annotations have the right link', () { expect( ctr.annotations[0], equals( - 'Deprecated("Internal use")')); + '@Deprecated("Internal use")')); }); }); From c220462eca0c42598e4d82d3a4206e76608bbae8 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Mon, 27 Feb 2017 16:12:23 -0800 Subject: [PATCH 06/11] Fix all tests, clean up code --- lib/src/model.dart | 59 +++++++++---------- testing/test_package_docs/ex/B-class.html | 4 +- .../ex/B/abstractMethod.html | 2 +- testing/test_package_docs/ex/B/doNothing.html | 2 +- testing/test_package_docs/ex/B/m1.html | 2 +- .../ex/ConstantCat-class.html | 2 +- .../ex/ConstantCat/abstractMethod.html | 2 +- testing/test_package_docs/ex/Dog-class.html | 14 ++--- .../ex/Dog/aProtectedFinalField.html | 2 +- .../ex/Dog/abstractMethod.html | 2 +- .../test_package_docs/ex/Dog/createDog.html | 2 +- .../ex/Dog/deprecatedField.html | 2 +- .../ex/Dog/getAnotherClassD.html | 2 +- .../test_package_docs/ex/Dog/getClassA.html | 2 +- .../ex/Dog/operator_equals.html | 2 +- testing/test_package_docs/ex/F-class.html | 12 ++-- .../ex/HasAnnotation-class.html | 2 +- testing/test_package_docs/ex/Klass-class.html | 6 +- .../ex/Klass/anotherMethod.html | 2 +- .../ex/Klass/imAFactoryNoReally.html | 2 +- .../ex/Klass/imProtected.html | 2 +- .../test_package_docs/ex/Klass/toString.html | 2 +- .../ex/MyErrorImplements-class.html | 2 +- .../test.html | 2 +- .../ex/ShapeType/toString.html | 2 +- testing/test_package_docs/fake/Doh-class.html | 2 +- .../test_package_docs/fake/FakeProcesses.html | 2 +- .../fake/LongFirstLine-class.html | 2 +- .../fake/LongFirstLine/noParams.html | 2 +- .../operator_equals.html | 2 +- .../fake/SuperAwesomeClass-class.html | 2 +- .../test_package_docs/fake/fake-library.html | 2 +- .../onlyPositionalWithNoDefaultNoType.html | 2 +- .../fake/topLevelFunction.html | 2 +- .../static-assets/styles.css | 4 -- 35 files changed, 76 insertions(+), 81 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 76675bc12f..31c0b1accb 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -9,8 +9,8 @@ import 'dart:convert'; import 'dart:io'; import 'package:analyzer/dart/ast/ast.dart' - show AnnotatedNode, Annotation, Declaration, FormalParameter, FieldDeclaration, - VariableDeclaration, VariableDeclarationList; + show AnnotatedNode, Declaration, FormalParameter, FieldDeclaration, + VariableDeclaration, VariableDeclarationList; import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/generated/resolver.dart' @@ -916,15 +916,18 @@ class Field extends ModelElement @override List get annotations { - if (element is PropertyInducingElement && super.annotations.isEmpty) { + List all_annotations = new List(); + all_annotations.addAll(super.annotations); + + if (element is PropertyInducingElement) { var pie = element as PropertyInducingElement; - var all_annotations = new List(); + if (super.annotations.isNotEmpty) { + assert(pie.getter == null && pie.setter == null); + } all_annotations.addAll(annotationsFromMetadata(pie.getter?.metadata)); all_annotations.addAll(annotationsFromMetadata(pie.setter?.metadata)); - return all_annotations; - } else { - return super.annotations; } + return all_annotations.toList(growable: false); } @override @@ -1490,45 +1493,39 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { } List get annotations { - if (element.computeNode() != null && - element.computeNode() is AnnotatedNode) { + List metadata; + if (element.computeNode() is AnnotatedNode) { AnnotatedNode node = element.computeNode() as AnnotatedNode; - while ((node is VariableDeclaration || - node is VariableDeclarationList) && + + /// Declarations are contained inside FieldDeclarations, and that is where + /// the actual annotations are. + while ((node is VariableDeclaration || node is VariableDeclarationList) && node is! FieldDeclaration) { - if (null == (node as AnnotatedNode).parent) { - break; - } + if (null == (node as AnnotatedNode).parent) break; node = node.parent; } - return annotationsFromMetadata(node.metadata); - } else if (element.computeNode() is FormalParameter) { + metadata = node.metadata; + } else if (element.computeNode() is! FormalParameter) { /// TODO(jcollins-g): This is special cased to suppress annotations for /// parameters in constructor documentation. Do we /// want to do this? - return new List(); - } else { - return annotationsFromMetadata(element.metadata); + metadata = element.metadata; } + return annotationsFromMetadata(metadata); } /// dynamic parameter since ElementAnnotation and Annotation have no common /// class for calling toSource() and element. List annotationsFromMetadata(List md) { - if (md == null) { - return new List(); - } + if (md == null) md = new List(); return md.map((dynamic a) { - String annotationString = a.toSource(); - if (a.element != null && (a.element is ConstructorElement)) { - var me = new ModelElement.from( - a.element.enclosingElement, + String annotation = a.toSource(); + if (a.element is ConstructorElement) { + var me = new ModelElement.from(a.element.enclosingElement, package._getLibraryFor(a.element.enclosingElement)); - return annotationString.replaceFirst( - "${me.name}", - "${me.linkedName}"); + annotation = annotation.replaceFirst(me.name, me.linkedName); } - return annotationString; + return annotation; }).toList(growable: false); } @@ -1537,9 +1534,11 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { Set get features { Set all_features = new Set(); all_features.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'); + /// Drop the plain "deprecated" annotation, that's indicated via /// strikethroughs. Custom @Deprecated() will still appear. all_features.remove('@deprecated'); diff --git a/testing/test_package_docs/ex/B-class.html b/testing/test_package_docs/ex/B-class.html index 0bba6d2e60..3bfed6d883 100644 --- a/testing/test_package_docs/ex/B-class.html +++ b/testing/test_package_docs/ex/B-class.html @@ -198,7 +198,7 @@

Properties

-
override, read-only
+
@override, read-only
list @@ -214,7 +214,7 @@

Properties

-
override, read-only
+
@override, read-only
fieldWithTypedef diff --git a/testing/test_package_docs/ex/B/abstractMethod.html b/testing/test_package_docs/ex/B/abstractMethod.html index a069013a6d..ea29395775 100644 --- a/testing/test_package_docs/ex/B/abstractMethod.html +++ b/testing/test_package_docs/ex/B/abstractMethod.html @@ -116,7 +116,7 @@
B
    -
  1. override
  2. +
  3. @override
void diff --git a/testing/test_package_docs/ex/B/doNothing.html b/testing/test_package_docs/ex/B/doNothing.html index 2fd8943dd2..1f502d8b6f 100644 --- a/testing/test_package_docs/ex/B/doNothing.html +++ b/testing/test_package_docs/ex/B/doNothing.html @@ -116,7 +116,7 @@
B
    -
  1. deprecated
  2. +
  3. @deprecated
Future diff --git a/testing/test_package_docs/ex/B/m1.html b/testing/test_package_docs/ex/B/m1.html index 6657d1a61e..84c90d82d4 100644 --- a/testing/test_package_docs/ex/B/m1.html +++ b/testing/test_package_docs/ex/B/m1.html @@ -116,7 +116,7 @@
B
    -
  1. override
  2. +
  3. @override
void diff --git a/testing/test_package_docs/ex/ConstantCat-class.html b/testing/test_package_docs/ex/ConstantCat-class.html index 46e220044c..b7ef423cf6 100644 --- a/testing/test_package_docs/ex/ConstantCat-class.html +++ b/testing/test_package_docs/ex/ConstantCat-class.html @@ -181,7 +181,7 @@

Properties

-
override, read-only
+
@override, read-only
name diff --git a/testing/test_package_docs/ex/ConstantCat/abstractMethod.html b/testing/test_package_docs/ex/ConstantCat/abstractMethod.html index e06d248e0a..b8c1da71af 100644 --- a/testing/test_package_docs/ex/ConstantCat/abstractMethod.html +++ b/testing/test_package_docs/ex/ConstantCat/abstractMethod.html @@ -102,7 +102,7 @@
ConstantCat
    -
  1. override
  2. +
  3. @override
void diff --git a/testing/test_package_docs/ex/Dog-class.html b/testing/test_package_docs/ex/Dog-class.html index 80b16319d1..7468e18e23 100644 --- a/testing/test_package_docs/ex/Dog-class.html +++ b/testing/test_package_docs/ex/Dog-class.html @@ -224,7 +224,7 @@

Static Methods

-
Deprecated("Internal use")
+
@Deprecated("Internal use")
@@ -274,7 +274,7 @@

Properties

-
protected, final
+
@protected, final
deprecatedField @@ -282,7 +282,7 @@

Properties

-
deprecated, read / write
+
@deprecated, read / write
deprecatedGetter @@ -290,7 +290,7 @@

Properties

-
deprecated, read-only
+
@deprecated, read-only
deprecatedSetter @@ -298,7 +298,7 @@

Properties

-
deprecated, write-only
+
@deprecated, write-only
isImplemented @@ -306,7 +306,7 @@

Properties

-
override, read-only
+
@override, read-only
name @@ -378,7 +378,7 @@

Methods

-
Deprecated('before v27.3')
+
@Deprecated('before v27.3')
getClassA() diff --git a/testing/test_package_docs/ex/Dog/aProtectedFinalField.html b/testing/test_package_docs/ex/Dog/aProtectedFinalField.html index 9b5822ece3..34403128ca 100644 --- a/testing/test_package_docs/ex/Dog/aProtectedFinalField.html +++ b/testing/test_package_docs/ex/Dog/aProtectedFinalField.html @@ -124,7 +124,7 @@
Dog
int - aProtectedFinalField
protected, final
+ aProtectedFinalField
@protected, final
diff --git a/testing/test_package_docs/ex/Dog/abstractMethod.html b/testing/test_package_docs/ex/Dog/abstractMethod.html index b68bb0ca65..ab519952e8 100644 --- a/testing/test_package_docs/ex/Dog/abstractMethod.html +++ b/testing/test_package_docs/ex/Dog/abstractMethod.html @@ -124,7 +124,7 @@
Dog
    -
  1. override
  2. +
  3. @override
void diff --git a/testing/test_package_docs/ex/Dog/createDog.html b/testing/test_package_docs/ex/Dog/createDog.html index cbf6b02271..9ba6298518 100644 --- a/testing/test_package_docs/ex/Dog/createDog.html +++ b/testing/test_package_docs/ex/Dog/createDog.html @@ -124,7 +124,7 @@
Dog
    -
  1. Deprecated("Internal use")
  2. +
  3. @Deprecated("Internal use")
Dog diff --git a/testing/test_package_docs/ex/Dog/deprecatedField.html b/testing/test_package_docs/ex/Dog/deprecatedField.html index d012e98017..61d7048250 100644 --- a/testing/test_package_docs/ex/Dog/deprecatedField.html +++ b/testing/test_package_docs/ex/Dog/deprecatedField.html @@ -124,7 +124,7 @@
Dog
int - deprecatedField
deprecated, read / write
+ deprecatedField
@deprecated, read / write
diff --git a/testing/test_package_docs/ex/Dog/getAnotherClassD.html b/testing/test_package_docs/ex/Dog/getAnotherClassD.html index f79a88d162..afcd963328 100644 --- a/testing/test_package_docs/ex/Dog/getAnotherClassD.html +++ b/testing/test_package_docs/ex/Dog/getAnotherClassD.html @@ -124,7 +124,7 @@
Dog
    -
  1. Deprecated('before v27.3')
  2. +
  3. @Deprecated('before v27.3')
List<Dog> diff --git a/testing/test_package_docs/ex/Dog/getClassA.html b/testing/test_package_docs/ex/Dog/getClassA.html index 7707d352cf..b8e12f18d0 100644 --- a/testing/test_package_docs/ex/Dog/getClassA.html +++ b/testing/test_package_docs/ex/Dog/getClassA.html @@ -124,7 +124,7 @@
Dog
    -
  1. deprecated
  2. +
  3. @deprecated
List<Apple> diff --git a/testing/test_package_docs/ex/Dog/operator_equals.html b/testing/test_package_docs/ex/Dog/operator_equals.html index add426e3fc..521a97cc2c 100644 --- a/testing/test_package_docs/ex/Dog/operator_equals.html +++ b/testing/test_package_docs/ex/Dog/operator_equals.html @@ -124,7 +124,7 @@
Dog
    -
  1. override
  2. +
  3. @override
dynamic diff --git a/testing/test_package_docs/ex/F-class.html b/testing/test_package_docs/ex/F-class.html index a94128e5af..9dfd19ced3 100644 --- a/testing/test_package_docs/ex/F-class.html +++ b/testing/test_package_docs/ex/F-class.html @@ -196,7 +196,7 @@

Properties

-
protected, final, inherited
+
@protected, final, inherited
deprecatedField @@ -204,7 +204,7 @@

Properties

-
deprecated, read / write, inherited
+
@deprecated, read / write, inherited
deprecatedGetter @@ -212,7 +212,7 @@

Properties

-
deprecated, read-only, inherited
+
@deprecated, read-only, inherited
deprecatedSetter @@ -220,7 +220,7 @@

Properties

-
deprecated, write-only, inherited
+
@deprecated, write-only, inherited
hashCode @@ -236,7 +236,7 @@

Properties

-
override, read-only, inherited
+
@override, read-only, inherited
name @@ -309,7 +309,7 @@

Methods

-
Deprecated('before v27.3'), inherited
+
@Deprecated('before v27.3'), inherited
getClassA() diff --git a/testing/test_package_docs/ex/HasAnnotation-class.html b/testing/test_package_docs/ex/HasAnnotation-class.html index 6f4748b644..3ea60f5cc5 100644 --- a/testing/test_package_docs/ex/HasAnnotation-class.html +++ b/testing/test_package_docs/ex/HasAnnotation-class.html @@ -147,7 +147,7 @@
ex
Annotations
diff --git a/testing/test_package_docs/ex/Klass-class.html b/testing/test_package_docs/ex/Klass-class.html index 1d370f7268..350dd7fe6d 100644 --- a/testing/test_package_docs/ex/Klass-class.html +++ b/testing/test_package_docs/ex/Klass-class.html @@ -216,7 +216,7 @@

Methods

A method with a custom annotation

-
aThingToDo('from', 'thing')
+
@aThingToDo('from', 'thing')
imAFactoryNoReally() @@ -225,7 +225,7 @@

Methods

Not really a factory, but...

-
factory
+
@factory
imProtected() @@ -234,7 +234,7 @@

Methods

A protected method

-
protected
+
@protected
method() diff --git a/testing/test_package_docs/ex/Klass/anotherMethod.html b/testing/test_package_docs/ex/Klass/anotherMethod.html index 0cda0e25b3..994cb7c466 100644 --- a/testing/test_package_docs/ex/Klass/anotherMethod.html +++ b/testing/test_package_docs/ex/Klass/anotherMethod.html @@ -104,7 +104,7 @@
Klass
    -
  1. aThingToDo('from', 'thing')
  2. +
  3. @aThingToDo('from', 'thing')
dynamic diff --git a/testing/test_package_docs/ex/Klass/imAFactoryNoReally.html b/testing/test_package_docs/ex/Klass/imAFactoryNoReally.html index 91595a8423..e38d8826d6 100644 --- a/testing/test_package_docs/ex/Klass/imAFactoryNoReally.html +++ b/testing/test_package_docs/ex/Klass/imAFactoryNoReally.html @@ -104,7 +104,7 @@
Klass
    -
  1. factory
  2. +
  3. @factory
dynamic diff --git a/testing/test_package_docs/ex/Klass/imProtected.html b/testing/test_package_docs/ex/Klass/imProtected.html index 321fb6b2f5..90cc90017e 100644 --- a/testing/test_package_docs/ex/Klass/imProtected.html +++ b/testing/test_package_docs/ex/Klass/imProtected.html @@ -104,7 +104,7 @@
Klass
    -
  1. protected
  2. +
  3. @protected
dynamic diff --git a/testing/test_package_docs/ex/Klass/toString.html b/testing/test_package_docs/ex/Klass/toString.html index fd3327feae..bd00daafe9 100644 --- a/testing/test_package_docs/ex/Klass/toString.html +++ b/testing/test_package_docs/ex/Klass/toString.html @@ -104,7 +104,7 @@
Klass
    -
  1. override
  2. +
  3. @override
dynamic diff --git a/testing/test_package_docs/ex/MyErrorImplements-class.html b/testing/test_package_docs/ex/MyErrorImplements-class.html index b97ff33c3b..a4cdb8d77e 100644 --- a/testing/test_package_docs/ex/MyErrorImplements-class.html +++ b/testing/test_package_docs/ex/MyErrorImplements-class.html @@ -180,7 +180,7 @@

Properties

-
override, read-only
+
@override, read-only
hashCode diff --git a/testing/test_package_docs/ex/PublicClassImplementsPrivateInterface/test.html b/testing/test_package_docs/ex/PublicClassImplementsPrivateInterface/test.html index 92c141b242..68d3b37895 100644 --- a/testing/test_package_docs/ex/PublicClassImplementsPrivateInterface/test.html +++ b/testing/test_package_docs/ex/PublicClassImplementsPrivateInterface/test.html @@ -100,7 +100,7 @@
PublicClassImp
    -
  1. override
  2. +
  3. @override
void diff --git a/testing/test_package_docs/ex/ShapeType/toString.html b/testing/test_package_docs/ex/ShapeType/toString.html index 0b44f3869e..90b34700e6 100644 --- a/testing/test_package_docs/ex/ShapeType/toString.html +++ b/testing/test_package_docs/ex/ShapeType/toString.html @@ -101,7 +101,7 @@
ShapeType
    -
  1. override
  2. +
  3. @override
String diff --git a/testing/test_package_docs/fake/Doh-class.html b/testing/test_package_docs/fake/Doh-class.html index 8f873ca1bb..73856bc4ff 100644 --- a/testing/test_package_docs/fake/Doh-class.html +++ b/testing/test_package_docs/fake/Doh-class.html @@ -169,7 +169,7 @@
fake
Annotations
    -
  • deprecated
  • +
  • @deprecated
diff --git a/testing/test_package_docs/fake/FakeProcesses.html b/testing/test_package_docs/fake/FakeProcesses.html index 6fdb15f3c8..d5e1f76390 100644 --- a/testing/test_package_docs/fake/FakeProcesses.html +++ b/testing/test_package_docs/fake/FakeProcesses.html @@ -147,7 +147,7 @@
fake
    -
  1. deprecated
  2. +
  3. @deprecated
String diff --git a/testing/test_package_docs/fake/LongFirstLine-class.html b/testing/test_package_docs/fake/LongFirstLine-class.html index a501d61e96..a44d3dde8b 100644 --- a/testing/test_package_docs/fake/LongFirstLine-class.html +++ b/testing/test_package_docs/fake/LongFirstLine-class.html @@ -185,7 +185,7 @@
fake
Annotations
diff --git a/testing/test_package_docs/fake/LongFirstLine/noParams.html b/testing/test_package_docs/fake/LongFirstLine/noParams.html index 88394a5cfd..2e79ea17e3 100644 --- a/testing/test_package_docs/fake/LongFirstLine/noParams.html +++ b/testing/test_package_docs/fake/LongFirstLine/noParams.html @@ -123,7 +123,7 @@
LongFirstLine
    -
  1. deprecated
  2. +
  3. @deprecated
void diff --git a/testing/test_package_docs/fake/OperatorReferenceClass/operator_equals.html b/testing/test_package_docs/fake/OperatorReferenceClass/operator_equals.html index 134f9150d3..f835889dfd 100644 --- a/testing/test_package_docs/fake/OperatorReferenceClass/operator_equals.html +++ b/testing/test_package_docs/fake/OperatorReferenceClass/operator_equals.html @@ -99,7 +99,7 @@
OperatorReferenceClass<
    -
  1. override
  2. +
  3. @override
bool diff --git a/testing/test_package_docs/fake/SuperAwesomeClass-class.html b/testing/test_package_docs/fake/SuperAwesomeClass-class.html index cb5d6359f9..42a92df840 100644 --- a/testing/test_package_docs/fake/SuperAwesomeClass-class.html +++ b/testing/test_package_docs/fake/SuperAwesomeClass-class.html @@ -167,7 +167,7 @@
fake
Annotations
    -
  • deprecated
  • +
  • @deprecated
diff --git a/testing/test_package_docs/fake/fake-library.html b/testing/test_package_docs/fake/fake-library.html index 4150d03bf1..9f8bc5f6f8 100644 --- a/testing/test_package_docs/fake/fake-library.html +++ b/testing/test_package_docs/fake/fake-library.html @@ -408,7 +408,7 @@

Functions

A single optional positional param, no type annotation, no default value.

-
greatAnnotation
+
@greatAnnotation
paintImage1({String canvas, int rect, ExtraSpecialList image, BaseForDocComments colorFilter, String repeat: LongFirstLine.THING }) diff --git a/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html b/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html index 8870ba5cc4..7868a11a8b 100644 --- a/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html +++ b/testing/test_package_docs/fake/onlyPositionalWithNoDefaultNoType.html @@ -147,7 +147,7 @@
fake
    -
  1. greatAnnotation
  2. +
  3. @greatAnnotation
void diff --git a/testing/test_package_docs/fake/topLevelFunction.html b/testing/test_package_docs/fake/topLevelFunction.html index 871c6016fa..eff312d7ed 100644 --- a/testing/test_package_docs/fake/topLevelFunction.html +++ b/testing/test_package_docs/fake/topLevelFunction.html @@ -147,7 +147,7 @@
fake
    -
  1. deprecated
  2. +
  3. @deprecated
String diff --git a/testing/test_package_docs/static-assets/styles.css b/testing/test_package_docs/static-assets/styles.css index 57d325501c..fd65cf0cf3 100644 --- a/testing/test_package_docs/static-assets/styles.css +++ b/testing/test_package_docs/static-assets/styles.css @@ -456,10 +456,6 @@ nav .self-name { display: inline; } -.annotation-list li:before { - content: "@"; -} - .comma-separated { list-style: none; padding: 0; From 136f2cf87a71d089b77dc2d2905766e4eb6c3cc4 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Tue, 28 Feb 2017 09:56:37 -0800 Subject: [PATCH 07/11] Escape everything, update tests, and add to changelog --- CHANGELOG.md | 3 +++ lib/src/model.dart | 35 +++++++++++++++++------------------ test/model_test.dart | 8 ++++---- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97cce79f7e..86c6ef737c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* fix multiple annotations related issues with a refactor of annotation/feature + list handling (#1268, #1162) + ## 0.9.12 * add print styles diff --git a/lib/src/model.dart b/lib/src/model.dart index 31c0b1accb..0039a20aa7 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -921,9 +921,6 @@ class Field extends ModelElement if (element is PropertyInducingElement) { var pie = element as PropertyInducingElement; - if (super.annotations.isNotEmpty) { - assert(pie.getter == null && pie.setter == null); - } all_annotations.addAll(annotationsFromMetadata(pie.getter?.metadata)); all_annotations.addAll(annotationsFromMetadata(pie.setter?.metadata)); } @@ -1497,29 +1494,31 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { if (element.computeNode() is AnnotatedNode) { AnnotatedNode node = element.computeNode() as AnnotatedNode; - /// Declarations are contained inside FieldDeclarations, and that is where - /// the actual annotations are. + // Declarations are contained inside FieldDeclarations, and that is where + // the actual annotations are. while ((node is VariableDeclaration || node is VariableDeclarationList) && node is! FieldDeclaration) { - if (null == (node as AnnotatedNode).parent) break; + assert (null != (node as AnnotatedNode).parent); node = node.parent; } metadata = node.metadata; } else if (element.computeNode() is! FormalParameter) { - /// TODO(jcollins-g): This is special cased to suppress annotations for - /// parameters in constructor documentation. Do we - /// want to do this? + // TODO(jcollins-g): This is special cased to suppress annotations for + // parameters in constructor documentation. Do we + // want to do this? metadata = element.metadata; } return annotationsFromMetadata(metadata); } - /// dynamic parameter since ElementAnnotation and Annotation have no common - /// class for calling toSource() and element. + /// Returns annotations from a given metadata set, with escaping. + /// md is a dynamic parameter since ElementAnnotation and Annotation have no + /// common class for calling toSource() and element. List annotationsFromMetadata(List md) { + const HtmlEscape sanitizer = const HtmlEscape(); if (md == null) md = new List(); return md.map((dynamic a) { - String annotation = a.toSource(); + String annotation = sanitizer.convert(a.toSource()); if (a.element is ConstructorElement) { var me = new ModelElement.from(a.element.enclosingElement, package._getLibraryFor(a.element.enclosingElement)); @@ -1529,19 +1528,19 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { }).toList(growable: false); } - /// const and static are not needed here because const/static elements get - /// their own sections in the doc. Set get features { Set all_features = new Set(); all_features.addAll(annotations); - /// override as an annotation should be replaced with direct information - /// from the analyzer if we decide to display it at this level. + // 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'); - /// Drop the plain "deprecated" annotation, that's indicated via - /// strikethroughs. Custom @Deprecated() will still appear. + // Drop the plain "deprecated" annotation, that's indicated via + // strikethroughs. Custom @Deprecated() will still appear. all_features.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; } diff --git a/test/model_test.dart b/test/model_test.dart index b817b39aae..b67f3917aa 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -1645,11 +1645,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, test('has one annotation', () => expect(forAnnotation.annotations, hasLength(1))); - test('has the right annotation', () { + test('has the right annotation and is escaped', () { expect( forAnnotation.annotations.first, equals( - '@ForAnnotation(\'my value\')')); + '@ForAnnotation('my value')')); }); test('methods has the right annotation', () { @@ -1658,11 +1658,11 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, expect(m.annotations.first, equals('@deprecated')); }); - test('method annotations have the right link', () { + test('method annotations have the right link and are escaped', () { expect( ctr.annotations[0], equals( - '@Deprecated("Internal use")')); + '@Deprecated("Internal use")')); }); }); From 7521a8d309c89bdc747dbdc44d6cd47986f24494 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Tue, 28 Feb 2017 09:57:58 -0800 Subject: [PATCH 08/11] Add escaping to test package docs --- testing/test_package_docs/ex/Dog-class.html | 4 ++-- testing/test_package_docs/ex/Dog/createDog.html | 2 +- testing/test_package_docs/ex/Dog/getAnotherClassD.html | 2 +- testing/test_package_docs/ex/F-class.html | 2 +- testing/test_package_docs/ex/HasAnnotation-class.html | 2 +- testing/test_package_docs/ex/Klass-class.html | 2 +- testing/test_package_docs/ex/Klass/anotherMethod.html | 2 +- testing/test_package_docs/fake/LongFirstLine-class.html | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/testing/test_package_docs/ex/Dog-class.html b/testing/test_package_docs/ex/Dog-class.html index 7468e18e23..1c27c7cd07 100644 --- a/testing/test_package_docs/ex/Dog-class.html +++ b/testing/test_package_docs/ex/Dog-class.html @@ -224,7 +224,7 @@

Static Methods

-
@Deprecated("Internal use")
+
@Deprecated("Internal use")
@@ -378,7 +378,7 @@

Methods

-
@Deprecated('before v27.3')
+
@Deprecated('before v27.3')
getClassA() diff --git a/testing/test_package_docs/ex/Dog/createDog.html b/testing/test_package_docs/ex/Dog/createDog.html index 9ba6298518..6a224e6e4b 100644 --- a/testing/test_package_docs/ex/Dog/createDog.html +++ b/testing/test_package_docs/ex/Dog/createDog.html @@ -124,7 +124,7 @@
Dog
    -
  1. @Deprecated("Internal use")
  2. +
  3. @Deprecated("Internal use")
Dog diff --git a/testing/test_package_docs/ex/Dog/getAnotherClassD.html b/testing/test_package_docs/ex/Dog/getAnotherClassD.html index afcd963328..624fa04e3a 100644 --- a/testing/test_package_docs/ex/Dog/getAnotherClassD.html +++ b/testing/test_package_docs/ex/Dog/getAnotherClassD.html @@ -124,7 +124,7 @@
Dog
    -
  1. @Deprecated('before v27.3')
  2. +
  3. @Deprecated('before v27.3')
List<Dog> diff --git a/testing/test_package_docs/ex/F-class.html b/testing/test_package_docs/ex/F-class.html index 9dfd19ced3..c4dd133c82 100644 --- a/testing/test_package_docs/ex/F-class.html +++ b/testing/test_package_docs/ex/F-class.html @@ -309,7 +309,7 @@

Methods

-
@Deprecated('before v27.3'), inherited
+
@Deprecated('before v27.3'), inherited
getClassA() diff --git a/testing/test_package_docs/ex/HasAnnotation-class.html b/testing/test_package_docs/ex/HasAnnotation-class.html index 3ea60f5cc5..cb674f0770 100644 --- a/testing/test_package_docs/ex/HasAnnotation-class.html +++ b/testing/test_package_docs/ex/HasAnnotation-class.html @@ -147,7 +147,7 @@
ex
Annotations
diff --git a/testing/test_package_docs/ex/Klass-class.html b/testing/test_package_docs/ex/Klass-class.html index 350dd7fe6d..0aff23fe2a 100644 --- a/testing/test_package_docs/ex/Klass-class.html +++ b/testing/test_package_docs/ex/Klass-class.html @@ -216,7 +216,7 @@

Methods

A method with a custom annotation

-
@aThingToDo('from', 'thing')
+
@aThingToDo('from', 'thing')
imAFactoryNoReally() diff --git a/testing/test_package_docs/ex/Klass/anotherMethod.html b/testing/test_package_docs/ex/Klass/anotherMethod.html index 994cb7c466..d89d4fec21 100644 --- a/testing/test_package_docs/ex/Klass/anotherMethod.html +++ b/testing/test_package_docs/ex/Klass/anotherMethod.html @@ -104,7 +104,7 @@
Klass
    -
  1. @aThingToDo('from', 'thing')
  2. +
  3. @aThingToDo('from', 'thing')
dynamic diff --git a/testing/test_package_docs/fake/LongFirstLine-class.html b/testing/test_package_docs/fake/LongFirstLine-class.html index a44d3dde8b..c912e01a29 100644 --- a/testing/test_package_docs/fake/LongFirstLine-class.html +++ b/testing/test_package_docs/fake/LongFirstLine-class.html @@ -185,7 +185,7 @@
fake
Annotations
From d34a4bfbdfe431b4b20d4b3c1b5e0084a8a66d93 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Tue, 28 Feb 2017 10:57:35 -0800 Subject: [PATCH 09/11] const variables are canonicalized, no need for temp --- lib/src/model.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/model.dart b/lib/src/model.dart index 0039a20aa7..34c03ec12b 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -1515,10 +1515,9 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { /// md is a dynamic parameter since ElementAnnotation and Annotation have no /// common class for calling toSource() and element. List annotationsFromMetadata(List md) { - const HtmlEscape sanitizer = const HtmlEscape(); if (md == null) md = new List(); return md.map((dynamic a) { - String annotation = sanitizer.convert(a.toSource()); + String annotation = (const HtmlEscape()).convert(a.toSource()); if (a.element is ConstructorElement) { var me = new ModelElement.from(a.element.enclosingElement, package._getLibraryFor(a.element.enclosingElement)); From cf282da1c01b391f39459bb599694ceb2eca1965 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Tue, 28 Feb 2017 13:25:24 -0800 Subject: [PATCH 10/11] Update pubspec, Changelog, and test package docs for 0.9.13 --- CHANGELOG.md | 6 ++++-- lib/dartdoc.dart | 2 +- pubspec.lock | 20 +++++++++++++++++++- pubspec.yaml | 2 +- testing/test_package_docs/index.html | 2 +- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86c6ef737c..f6b6e85416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ -* fix multiple annotations related issues with a refactor of annotation/feature - list handling (#1268, #1162) +## 0.9.13 + +* fix multiple annotations related issues in annotation/feature list handling + (#1268, #1162, #1081) ## 0.9.12 diff --git a/lib/dartdoc.dart b/lib/dartdoc.dart index af8c6dd84d..350938454e 100644 --- a/lib/dartdoc.dart +++ b/lib/dartdoc.dart @@ -40,7 +40,7 @@ export 'src/package_meta.dart'; const String name = 'dartdoc'; // Update when pubspec version changes. -const String version = '0.9.12'; +const String version = '0.9.13'; final String defaultOutDir = path.join('doc', 'api'); diff --git a/pubspec.lock b/pubspec.lock index 5869f9db12..7324faa9f7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -6,7 +6,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.29.0" + version: "0.29.8" ansicolor: description: name: ansicolor @@ -43,6 +43,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + cli_util: + description: + name: cli_util + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" collection: description: name: collection @@ -301,6 +307,18 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.4" + when: + description: + name: when + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" + which: + description: + name: which + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" yaml: description: name: yaml diff --git a/pubspec.yaml b/pubspec.yaml index 5c6cbd3b2a..f26e286479 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ homepage: https://github.com/dart-lang/dartdoc environment: sdk: '>=1.14.0 <2.0.0' dependencies: - analyzer: ^0.29.0 + analyzer: ^0.29.8 args: ^0.13.0 collection: ^1.2.0 html: '>=0.12.1 <0.14.0' diff --git a/testing/test_package_docs/index.html b/testing/test_package_docs/index.html index 0456f2df4c..9f0ad8ddd5 100644 --- a/testing/test_package_docs/index.html +++ b/testing/test_package_docs/index.html @@ -4,7 +4,7 @@ - + test_package - Dart API docs From eb3acf8fb61385bb9de77090d419cd5fe5f3db98 Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Tue, 28 Feb 2017 13:51:46 -0800 Subject: [PATCH 11/11] brevity --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6b6e85416..2bd3129630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ ## 0.9.13 -* fix multiple annotations related issues in annotation/feature list handling - (#1268, #1162, #1081) +* fix multiple issues in annotation/feature list handling (#1268, #1162, #1081) ## 0.9.12