Skip to content

Commit 46f07e4

Browse files
authored
Merge pull request #1206 from keertip/abstract
Show 'abstract' for methods that are abstract
2 parents 0ed6627 + 214a3a0 commit 46f07e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+486
-76
lines changed

lib/src/html/template_data.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ class MethodTemplateData extends TemplateData<Method> {
306306
'${library.name} library - Dart API';
307307
@override
308308
String get layoutTitle =>
309-
_layoutTitle(method.name, 'method', method.isDeprecated);
309+
_layoutTitle(method.name, method.fullkind, method.isDeprecated);
310310
@override
311311
String get metaDescription =>
312312
'API docs for the ${method.name} method from the ${clazz.name} class, '

lib/src/model.dart

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,27 @@ import 'model_utils.dart';
2828
import 'package_meta.dart' show PackageMeta, FileContents;
2929
import 'utils.dart' show stripComments;
3030

31+
Map<String, Map<String, List<Map<String, dynamic>>>> __crossdartJson;
32+
3133
final Map<Class, List<Class>> _implementors = new Map();
3234

35+
Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
36+
if (__crossdartJson == null) {
37+
if (config != null) {
38+
var crossdartFile =
39+
new File(p.join(config.inputDir.path, "crossdart.json"));
40+
if (crossdartFile.existsSync()) {
41+
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
42+
} else {
43+
__crossdartJson = {};
44+
}
45+
} else {
46+
__crossdartJson = {};
47+
}
48+
}
49+
return __crossdartJson;
50+
}
51+
3352
int byName(Nameable a, Nameable b) =>
3453
compareAsciiLowerCaseNatural(a.name, b.name);
3554

@@ -666,7 +685,6 @@ abstract class Documentable {
666685
String get oneLineDoc;
667686
}
668687

669-
// TODO: how do we get rid of this class?
670688
class Dynamic extends ModelElement {
671689
Dynamic(Element element, Library library) : super(element, library);
672690

@@ -1218,6 +1236,11 @@ class Method extends ModelElement
12181236

12191237
String get fileName => "${name}.html";
12201238

1239+
String get fullkind {
1240+
if (_method.isAbstract) return 'abstract $kind';
1241+
return kind;
1242+
}
1243+
12211244
@override
12221245
String get href => '${library.dirName}/${enclosingElement.name}/${fileName}';
12231246

@@ -1249,7 +1272,6 @@ class Method extends ModelElement
12491272
MethodElement get _method => (element as MethodElement);
12501273
}
12511274

1252-
// TODO: rename this to Property
12531275
abstract class ModelElement implements Comparable, Nameable, Documentable {
12541276
final Element element;
12551277
final Library library;
@@ -1953,24 +1975,6 @@ class Parameter extends ModelElement implements EnclosedElement {
19531975
String toString() => element.name;
19541976
}
19551977

1956-
Map<String, Map<String, List<Map<String, dynamic>>>> __crossdartJson;
1957-
Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
1958-
if (__crossdartJson == null) {
1959-
if (config != null) {
1960-
var crossdartFile =
1961-
new File(p.join(config.inputDir.path, "crossdart.json"));
1962-
if (crossdartFile.existsSync()) {
1963-
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
1964-
} else {
1965-
__crossdartJson = {};
1966-
}
1967-
} else {
1968-
__crossdartJson = {};
1969-
}
1970-
}
1971-
return __crossdartJson;
1972-
}
1973-
19741978
abstract class SourceCodeMixin {
19751979
String _sourceCodeCache;
19761980
String get crossdartHtmlTag {
@@ -1987,10 +1991,6 @@ abstract class SourceCodeMixin {
19871991

19881992
Library get library;
19891993

1990-
void clearSourceCodeCache() {
1991-
_sourceCodeCache = null;
1992-
}
1993-
19941994
String get sourceCode {
19951995
if (_sourceCodeCache == null) {
19961996
String contents = getFileContentsFor(element);
@@ -2027,27 +2027,6 @@ abstract class SourceCodeMixin {
20272027
return _sourceCodeCache;
20282028
}
20292029

2030-
String get _crossdartUrl {
2031-
if (_lineNumber != null && _crossdartPath != null) {
2032-
String url = "//www.crossdart.info/p/${_crossdartPath}.html";
2033-
return "${url}#line-${_lineNumber}";
2034-
} else {
2035-
return null;
2036-
}
2037-
}
2038-
2039-
int get _lineNumber {
2040-
var node = element.computeNode();
2041-
if (node is Declaration && (node as Declaration).element != null) {
2042-
var element = (node as Declaration).element;
2043-
var lineNumber = lineNumberCache.lineNumber(
2044-
element.source.fullName, element.nameOffset);
2045-
return lineNumber + 1;
2046-
} else {
2047-
return null;
2048-
}
2049-
}
2050-
20512030
String get _crossdartPath {
20522031
var node = element.computeNode();
20532032
if (node is Declaration && (node as Declaration).element != null) {
@@ -2086,6 +2065,31 @@ abstract class SourceCodeMixin {
20862065
return null;
20872066
}
20882067
}
2068+
2069+
String get _crossdartUrl {
2070+
if (_lineNumber != null && _crossdartPath != null) {
2071+
String url = "//www.crossdart.info/p/${_crossdartPath}.html";
2072+
return "${url}#line-${_lineNumber}";
2073+
} else {
2074+
return null;
2075+
}
2076+
}
2077+
2078+
int get _lineNumber {
2079+
var node = element.computeNode();
2080+
if (node is Declaration && (node as Declaration).element != null) {
2081+
var element = (node as Declaration).element;
2082+
var lineNumber = lineNumberCache.lineNumber(
2083+
element.source.fullName, element.nameOffset);
2084+
return lineNumber + 1;
2085+
} else {
2086+
return null;
2087+
}
2088+
}
2089+
2090+
void clearSourceCodeCache() {
2091+
_sourceCodeCache = null;
2092+
}
20892093
}
20902094

20912095
/// Top-level variables. But also picks up getters and setters?

test/model_test.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ void main() {
592592
});
593593

594594
test('inherited methods,including from Object ', () {
595-
expect(B.inheritedMethods, hasLength(6));
595+
expect(B.inheritedMethods, hasLength(7));
596596
expect(B.hasInheritedMethods, isTrue);
597597
});
598598

@@ -632,10 +632,11 @@ void main() {
632632
});
633633

634634
test('F has many inherited methods', () {
635-
expect(F.inheritedMethods, hasLength(7));
635+
expect(F.inheritedMethods, hasLength(8));
636636
expect(
637637
F.inheritedMethods.map((im) => im.name),
638638
equals([
639+
'abstractMethod',
639640
'foo',
640641
'getClassA',
641642
'noSuchMethod',
@@ -821,8 +822,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
821822
});
822823

823824
group('Method', () {
824-
Class classB, klass, HasGenerics, CatString;
825-
Method m1, isGreaterThan, m4, m5, m6, m7, convertToMap;
825+
Class classB, klass, HasGenerics, Cat, CatString;
826+
Method m1, isGreaterThan, m4, m5, m6, m7, convertToMap, abstractMethod;
826827
Method inheritedClear, testGeneric;
827828

828829
setUp(() {
@@ -831,6 +832,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
831832
HasGenerics =
832833
fakeLibrary.classes.singleWhere((c) => c.name == 'HasGenerics');
833834
CatString = exLibrary.classes.singleWhere((c) => c.name == 'CatString');
835+
Cat = exLibrary.classes.singleWhere((c) => c.name == 'Cat');
834836
inheritedClear =
835837
CatString.inheritedMethods.singleWhere((m) => m.name == 'clear');
836838
m1 = classB.instanceMethods.singleWhere((m) => m.name == 'm1');
@@ -842,6 +844,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
842844
m5 = klass.instanceMethods.singleWhere((m) => m.name == 'another');
843845
m6 = klass.instanceMethods.singleWhere((m) => m.name == 'toString');
844846
m7 = classB.instanceMethods.singleWhere((m) => m.name == 'doNothing');
847+
abstractMethod =
848+
Cat.instanceMethods.singleWhere((m) => m.name == 'abstractMethod');
845849
testGeneric = exLibrary.classes
846850
.singleWhere((c) => c.name == 'Dog')
847851
.instanceMethods
@@ -861,6 +865,10 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
861865
expect(m1.fullyQualifiedName, 'ex.B.m1');
862866
});
863867

868+
test('has abstract kind', () {
869+
expect(abstractMethod.fullkind, 'abstract method');
870+
});
871+
864872
test(
865873
'an inherited method has class as the enclosing class, when superclass not in package',
866874
() {

testing/test_package/lib/example.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ const String COLOR_GREEN = 'green';
1616

1717
const String COLOR_ORANGE = 'orange';
1818

19-
const List<String> PRETTY_COLORS = const <String>[
20-
COLOR_GREEN,
21-
COLOR_ORANGE,
22-
'blue'
23-
];
24-
2519
const String COMPLEX_COLOR = 'red' + '-' + 'green' + '-' + 'blue';
2620

2721
/// top level var <nodoc>
@@ -32,7 +26,13 @@ const incorrectDocReference = 'same name as const from fake';
3226

3327
/// This should [not work].
3428
const incorrectDocReferenceFromEx = 'doh';
29+
3530
const ConstantCat MY_CAT = const ConstantCat('tabby');
31+
const List<String> PRETTY_COLORS = const <String>[
32+
COLOR_GREEN,
33+
COLOR_ORANGE,
34+
'blue'
35+
];
3636
@deprecated
3737
int deprecatedField;
3838

@@ -165,6 +165,8 @@ class B extends Apple with Cat {
165165

166166
abstract class Cat {
167167
bool get isImplemented;
168+
169+
void abstractMethod();
168170
}
169171

170172
class CatString extends StringBuffer {}
@@ -175,6 +177,10 @@ class ConstantCat implements Cat {
175177
const ConstantCat(this.name);
176178

177179
bool get isImplemented => true;
180+
181+
void abstractMethod() {
182+
// do nothing
183+
}
178184
}
179185

180186
/// implements [Cat], [E]

testing/test_package_docs/ex/B-class.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ <h2>Operators</h2>
279279
<section class="summary offset-anchor" id="instance-methods">
280280
<h2>Methods</h2>
281281
<dl class="callables">
282+
<dt id="abstractMethod" class="callable inherited">
283+
<span class="name"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></span><span class="signature">(<wbr>)
284+
<span class="returntype parameter">&#8594; void</span>
285+
</span>
286+
</dt>
287+
<dd class="inherited">
288+
<p></p>
289+
<div class="features">inherited</div>
290+
</dd>
282291
<dt id="doNothing" class="callable">
283292
<span class="name deprecated"><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></span><span class="signature">(<wbr>)
284293
<span class="returntype parameter">&#8594; Future</span>
@@ -387,6 +396,7 @@ <h5>B</h5>
387396
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
388397

389398
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
399+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
390400
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
391401
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
392402
<li><a href="ex/B/m1.html">m1</a></li>

testing/test_package_docs/ex/B/B.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
9696
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
9797

9898
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
99+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
99100
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
100101
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
101102
<li><a href="ex/B/m1.html">m1</a></li>

testing/test_package_docs/ex/B/autoCompress.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
9595
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
9696

9797
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
98+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
9899
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
99100
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
100101
<li><a href="ex/B/m1.html">m1</a></li>

testing/test_package_docs/ex/B/doNothing.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
9595
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
9696

9797
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
98+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
9899
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
99100
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
100101
<li><a href="ex/B/m1.html">m1</a></li>

testing/test_package_docs/ex/B/hashCode.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
9595
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
9696

9797
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
98+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
9899
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
99100
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
100101
<li><a href="ex/B/m1.html">m1</a></li>

testing/test_package_docs/ex/B/isImplemented.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
9595
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>
9696

9797
<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
98+
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
9899
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
99100
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
100101
<li><a href="ex/B/m1.html">m1</a></li>

0 commit comments

Comments
 (0)