@@ -2729,16 +2729,42 @@ abstract class ModelElement extends Canonicalization
27292729
27302730 /// Returns linked annotations from a given metadata set, with escaping.
27312731 List <String > annotationsFromMetadata (List <ElementAnnotation > md) {
2732- if (md == null ) return < String > [];
2733- return md.map ((ElementAnnotation a) {
2732+ List <String > annotationStrings = [];
2733+ if (md == null ) return annotationStrings;
2734+ for (ElementAnnotation a in md) {
27342735 String annotation = (const HtmlEscape ()).convert (a.toSource ());
2735- // a.element can be null if the element can't be resolved.
2736- var me = packageGraph
2737- .findCanonicalModelElementFor (a.element? .enclosingElement);
2738- if (me != null )
2739- annotation = annotation.replaceFirst (me.name, me.linkedName);
2740- return annotation;
2741- }).toList (growable: false );
2736+ Element annotationElement = a.element;
2737+
2738+ ClassElement annotationClassElement;
2739+ if (annotationElement is ExecutableElement ) {
2740+ annotationElement = (annotationElement as ExecutableElement )
2741+ .returnType
2742+ .element as ClassElement ;
2743+ }
2744+ if (annotationElement is ClassElement ) {
2745+ annotationClassElement = annotationElement;
2746+ }
2747+ ModelElement annotationModelElement =
2748+ packageGraph.findCanonicalModelElementFor (annotationElement);
2749+ // annotationElement can be null if the element can't be resolved.
2750+ Class annotationClass = packageGraph
2751+ .findCanonicalModelElementFor (annotationClassElement) as Class ;
2752+ if (annotationClass == null && annotationElement != null ) {
2753+ annotationClass =
2754+ new ModelElement .fromElement (annotationClassElement, packageGraph)
2755+ as Class ;
2756+ }
2757+ // Some annotations are intended to be invisible (@pragma)
2758+ if (annotationClass == null ||
2759+ ! packageGraph.invisibleAnnotations.contains (annotationClass)) {
2760+ if (annotationModelElement != null ) {
2761+ annotation = annotation.replaceFirst (
2762+ annotationModelElement.name, annotationModelElement.linkedName);
2763+ }
2764+ annotationStrings.add (annotation);
2765+ }
2766+ }
2767+ return annotationStrings;
27422768 }
27432769
27442770 bool _isPublic;
@@ -4510,12 +4536,13 @@ class PackageGraph {
45104536 return _localPublicLibraries;
45114537 }
45124538
4513- // Return the set of [Class]es objects should inherit through if they
4514- // show up in the inheritance chain. Do not call before interceptorElement is
4515- // found. Add classes here if they are similar to Interceptor in that they
4516- // are to be ignored even when they are the implementors of [Inheritable]s,
4517- // and the class these inherit from should instead claim implementation.
45184539 Set <Class > _inheritThrough;
4540+
4541+ /// Return the set of [Class] es objects should inherit through if they
4542+ /// show up in the inheritance chain. Do not call before interceptorElement is
4543+ /// found. Add classes here if they are similar to Interceptor in that they
4544+ /// are to be ignored even when they are the implementors of [Inheritable] s,
4545+ /// and the class these inherit from should instead claim implementation.
45194546 Set <Class > get inheritThrough {
45204547 if (_inheritThrough == null ) {
45214548 _inheritThrough = new Set ();
@@ -4524,6 +4551,18 @@ class PackageGraph {
45244551 return _inheritThrough;
45254552 }
45264553
4554+ Set <Class > _invisibleAnnotations;
4555+
4556+ /// Returns the set of [Class] objects that are similar to pragma
4557+ /// in that we should never count them as documentable annotations.
4558+ Set <Class > get invisibleAnnotations {
4559+ if (_invisibleAnnotations == null ) {
4560+ _invisibleAnnotations = new Set ();
4561+ _invisibleAnnotations.add (specialClasses[SpecialClass .pragma]);
4562+ }
4563+ return _invisibleAnnotations;
4564+ }
4565+
45274566 /// Looks up some [Library] that is reexporting this [Element] ; not
45284567 /// necessarily the canonical [Library] .
45294568 Library findLibraryFor (Element element) {
@@ -5007,8 +5046,10 @@ class Package extends LibraryContainer
50075046 // The full version string of the package.
50085047 case 'v' :
50095048 return packageMeta.version;
5049+ default :
5050+ assert (false , 'Unsupported case: ${m .group (1 )}' );
5051+ return null ;
50105052 }
5011- ;
50125053 });
50135054 if (! _baseHref.endsWith ('/' )) _baseHref = '${_baseHref }/' ;
50145055 } else {
0 commit comments