Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Side by Side Diff: client/lib/item.dart

Issue 273473002: Display function signatures instead of just "Function". (Closed) Base URL: https://github.com/dart-lang/dartdoc-viewer.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/lib/components/typedef.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library category_item; 5 library category_item;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:dartdoc_viewer/data.dart'; 10 import 'package:dartdoc_viewer/data.dart';
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 if (!isInherited || owner == null) return location; 834 if (!isInherited || owner == null) return location;
835 return owner.location..subMemberName = name; 835 return owner.location..subMemberName = name;
836 } 836 }
837 837
838 // Helper to determine if this method is actually an unnamed constructor. 838 // Helper to determine if this method is actually an unnamed constructor.
839 bool get isUnnamedConstructor => isConstructor && name == ''; 839 bool get isUnnamedConstructor => isConstructor && name == '';
840 840
841 String toString() => decoratedName; 841 String toString() => decoratedName;
842 } 842 }
843 843
844 /** The signature for a function that is passed in as a parameter to a method.*/
845 class Closure extends Parameterized {
846 List<Parameter> parameters;
847 final NestedType returnType;
848 final String name;
849
850 Closure(String name, Map yaml, [Item owner]) :
851 name = name,
852 returnType = new NestedType(yaml['return'].first),
853 super('closure', null) {
854 parameters = getParameters(yaml['parameters']);
855 _owner = owner;
856 }
857
858 // For a method parameter we use the special anchor @method,parameter
859 // because the parameter name may not be unique on the page
860 DocsLocation get anchorHrefLocation {
861 if (owner == null) return null;
862
863 var ownerLocation = owner.anchorHrefLocation;
864 var ownerAnchor = ownerLocation.anchor;
865 ownerLocation.anchor = ownerAnchor == null ?
866 hashDecoratedName : "$ownerAnchor$hashDecoratedName";
867 return ownerLocation;
868 }
869
870 String get anchorHref => anchorHrefLocation.withAnchor;
871
872 String get hashDecoratedName => "$PARAMETER_SEPARATOR$name";
873 }
874
844 /** 875 /**
845 * A single parameter to a [Method]. 876 * A single parameter to a [Method].
846 */ 877 */
847 class Parameter extends Item { 878 class Parameter extends Item {
848 879
849 final bool isOptional; 880 final bool isOptional;
850 final bool isNamed; 881 final bool isNamed;
851 final bool hasDefault; 882 final bool hasDefault;
852 final NestedType type; 883 final NestedType type;
853 final String defaultValue; 884 final String defaultValue;
854 final AnnotationGroup annotations; 885 final AnnotationGroup annotations;
886 final Closure functionDeclaration;
855 887
856 Parameter(String name, Map yaml, [Item owner]) 888 Parameter(String name, Map yaml, [Item owner])
857 : isOptional = _boolFor('optional', yaml), 889 : isOptional = _boolFor('optional', yaml),
858 isNamed = _boolFor('named', yaml), 890 isNamed = _boolFor('named', yaml),
859 hasDefault = _boolFor('default', yaml), 891 hasDefault = _boolFor('default', yaml),
860 type = new NestedType(yaml['type'].first), 892 type = new NestedType(yaml['type'].first),
861 defaultValue = yaml['value'], 893 defaultValue = yaml['value'],
862 annotations = new AnnotationGroup(yaml['annotations']), 894 annotations = new AnnotationGroup(yaml['annotations']),
895 functionDeclaration = yaml['functionDeclaration'] == null? null
896 : new Closure(name, yaml['functionDeclaration'], owner),
863 super(name, null) { 897 super(name, null) {
864 _owner = owner; 898 _owner = owner;
865 } 899 }
866 900
867 String get decoratedName => '$name$decoration'; 901 String get decoratedName => '$name$decoration';
868 902
869 String get decoration { 903 String get decoration {
870 if (hasDefault) { 904 if (hasDefault) {
871 return isNamed ? ': $defaultValue' : '=$defaultValue'; 905 return isNamed ? ': $defaultValue' : '=$defaultValue';
872 } 906 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 } 1062 }
1029 1063
1030 1064
1031 bool _boolFor(String key, Map input) { 1065 bool _boolFor(String key, Map input) {
1032 var value = input[key]; 1066 var value = input[key];
1033 if (value == true || value == 'true') return true; 1067 if (value == true || value == 'true') return true;
1034 if (value == null || value == false || value == 'false') return false; 1068 if (value == null || value == false || value == 'false') return false;
1035 throw new FormatException("Invalid format, expected boolean key: $key" 1069 throw new FormatException("Invalid format, expected boolean key: $key"
1036 " value: $value"); 1070 " value: $value");
1037 } 1071 }
OLDNEW
« no previous file with comments | « client/lib/components/typedef.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698