| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * To use it, from this directory, run: | 6 * To use it, from this directory, run: |
| 7 * | 7 * |
| 8 * $ ./dartdoc <path to .dart file> | 8 * $ ./dartdoc <path to .dart file> |
| 9 * | 9 * |
| 10 * This will create a "docs" directory with the docs for your libraries. To | 10 * This will create a "docs" directory with the docs for your libraries. To |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 */ | 787 */ |
| 788 md.Node resolveNameReference(String name, [Member member = null, | 788 md.Node resolveNameReference(String name, [Member member = null, |
| 789 Type type = null, Library library = null]) { | 789 Type type = null, Library library = null]) { |
| 790 makeLink(String href) { | 790 makeLink(String href) { |
| 791 final anchor = new md.Element.text('a', name); | 791 final anchor = new md.Element.text('a', name); |
| 792 anchor.attributes['href'] = relativePath(href); | 792 anchor.attributes['href'] = relativePath(href); |
| 793 anchor.attributes['class'] = 'crossref'; | 793 anchor.attributes['class'] = 'crossref'; |
| 794 return anchor; | 794 return anchor; |
| 795 } | 795 } |
| 796 | 796 |
| 797 findMember(Type type) { | 797 findMember(Type type, String memberName) { |
| 798 final member = type.members[name]; | 798 final member = type.members[memberName]; |
| 799 if (member == null) return null; | 799 if (member == null) return null; |
| 800 | 800 |
| 801 // Special case: if the member we've resolved is a property (i.e. it wraps | 801 // Special case: if the member we've resolved is a property (i.e. it wraps |
| 802 // a getter and/or setter then *that* member itself won't be on the docs, | 802 // a getter and/or setter then *that* member itself won't be on the docs, |
| 803 // just the getter or setter will be. So pick one of those to link to. | 803 // just the getter or setter will be. So pick one of those to link to. |
| 804 if (member.isProperty) { | 804 if (member.isProperty) { |
| 805 return member.canGet ? member.getter : member.setter; | 805 return member.canGet ? member.getter : member.setter; |
| 806 } | 806 } |
| 807 | 807 |
| 808 return member; | 808 return member; |
| 809 } | 809 } |
| 810 | 810 |
| 811 // See if it's a parameter of the current method. | 811 // See if it's a parameter of the current method. |
| 812 if (member != null) { | 812 if (member != null) { |
| 813 for (final parameter in member.parameters) { | 813 for (final parameter in member.parameters) { |
| 814 if (parameter.name == name) { | 814 if (parameter.name == name) { |
| 815 final element = new md.Element.text('span', name); | 815 final element = new md.Element.text('span', name); |
| 816 element.attributes['class'] = 'param'; | 816 element.attributes['class'] = 'param'; |
| 817 return element; | 817 return element; |
| 818 } | 818 } |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 | 821 |
| 822 // See if it's another member of the current type. | 822 // See if it's another member of the current type. |
| 823 if (type != null) { | 823 if (type != null) { |
| 824 final member = findMember(type); | 824 final member = findMember(type, name); |
| 825 if (member != null) { | 825 if (member != null) { |
| 826 return makeLink(memberUrl(member)); | 826 return makeLink(memberUrl(member)); |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 | 829 |
| 830 // See if it's another type in the current library. | 830 // See if it's another type or a member of another type in the current |
| 831 // library. |
| 831 if (library != null) { | 832 if (library != null) { |
| 833 // See if it's a constructor |
| 834 final constructorLink = (() { |
| 835 final match = new RegExp(@'new (\w+)(?:\.(\w+))?').firstMatch(name); |
| 836 if (match == null) return; |
| 837 final type = library.types[match[1]]; |
| 838 if (type == null) return; |
| 839 final constructor = type.getConstructor( |
| 840 match[2] == null ? '' : match[2]); |
| 841 if (constructor == null) return; |
| 842 return makeLink(memberUrl(constructor)); |
| 843 })(); |
| 844 if (constructorLink != null) return constructorLink; |
| 845 |
| 846 // See if it's a member of another type |
| 847 final foreignMemberLink = (() { |
| 848 final match = new RegExp(@'(\w+)\.(\w+)').firstMatch(name); |
| 849 if (match == null) return; |
| 850 final type = library.types[match[1]]; |
| 851 if (type == null) return; |
| 852 final member = findMember(type, match[2]); |
| 853 if (member == null) return; |
| 854 return makeLink(memberUrl(member)); |
| 855 })(); |
| 856 if (foreignMemberLink != null) return foreignMemberLink; |
| 857 |
| 832 final type = library.types[name]; | 858 final type = library.types[name]; |
| 833 if (type != null) { | 859 if (type != null) { |
| 834 return makeLink(typeUrl(type)); | 860 return makeLink(typeUrl(type)); |
| 835 } | 861 } |
| 836 | 862 |
| 837 // See if it's a top-level member in the current library. | 863 // See if it's a top-level member in the current library. |
| 838 final member = findMember(library.topType); | 864 final member = findMember(library.topType, name); |
| 839 if (member != null) { | 865 if (member != null) { |
| 840 return makeLink(memberUrl(member)); | 866 return makeLink(memberUrl(member)); |
| 841 } | 867 } |
| 842 } | 868 } |
| 843 | 869 |
| 844 // TODO(rnystrom): Should also consider: | 870 // TODO(rnystrom): Should also consider: |
| 845 // * Names imported by libraries this library imports. | 871 // * Names imported by libraries this library imports. |
| 846 // * Type parameters of the enclosing type. | 872 // * Type parameters of the enclosing type. |
| 847 | 873 |
| 848 return new md.Element.text('code', name); | 874 return new md.Element.text('code', name); |
| 849 } | 875 } |
| 850 | 876 |
| 851 // TODO(rnystrom): Move into SourceSpan? | 877 // TODO(rnystrom): Move into SourceSpan? |
| 852 int getSpanColumn(SourceSpan span) { | 878 int getSpanColumn(SourceSpan span) { |
| 853 final line = span.file.getLine(span.start); | 879 final line = span.file.getLine(span.start); |
| 854 return span.file.getColumn(line, span.start); | 880 return span.file.getColumn(line, span.start); |
| 855 } | 881 } |
| 856 } | 882 } |
| OLD | NEW |