Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/html/template_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class MethodTemplateData extends TemplateData<Method> {
'${library.name} library - Dart API';
@override
String get layoutTitle =>
_layoutTitle(method.name, 'method', method.isDeprecated);
_layoutTitle(method.name, method.fullkind, method.isDeprecated);
@override
String get metaDescription =>
'API docs for the ${method.name} method from the ${clazz.name} class, '
Expand Down
94 changes: 49 additions & 45 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,27 @@ import 'model_utils.dart';
import 'package_meta.dart' show PackageMeta, FileContents;
import 'utils.dart' show stripComments;

Map<String, Map<String, List<Map<String, dynamic>>>> __crossdartJson;

final Map<Class, List<Class>> _implementors = new Map();

Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a comment for this PR, but this nesting of generics is too deep. I don't know what they're maps of list of strings to -

if (__crossdartJson == null) {
if (config != null) {
var crossdartFile =
new File(p.join(config.inputDir.path, "crossdart.json"));
if (crossdartFile.existsSync()) {
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
} else {
__crossdartJson = {};
}
} else {
__crossdartJson = {};
}
}
return __crossdartJson;
}

int byName(Nameable a, Nameable b) =>
compareAsciiLowerCaseNatural(a.name, b.name);

Expand Down Expand Up @@ -666,7 +685,6 @@ abstract class Documentable {
String get oneLineDoc;
}

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

Expand Down Expand Up @@ -1218,6 +1236,11 @@ class Method extends ModelElement

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

String get fullkind {
if (_method.isAbstract) return 'abstract $kind';
return kind;
}

@override
String get href => '${library.dirName}/${enclosingElement.name}/${fileName}';

Expand Down Expand Up @@ -1249,7 +1272,6 @@ class Method extends ModelElement
MethodElement get _method => (element as MethodElement);
}

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

Map<String, Map<String, List<Map<String, dynamic>>>> __crossdartJson;
Map<String, Map<String, List<Map<String, dynamic>>>> get _crossdartJson {
if (__crossdartJson == null) {
if (config != null) {
var crossdartFile =
new File(p.join(config.inputDir.path, "crossdart.json"));
if (crossdartFile.existsSync()) {
__crossdartJson = JSON.decode(crossdartFile.readAsStringSync());
} else {
__crossdartJson = {};
}
} else {
__crossdartJson = {};
}
}
return __crossdartJson;
}

abstract class SourceCodeMixin {
String _sourceCodeCache;
String get crossdartHtmlTag {
Expand All @@ -1987,10 +1991,6 @@ abstract class SourceCodeMixin {

Library get library;

void clearSourceCodeCache() {
_sourceCodeCache = null;
}

String get sourceCode {
if (_sourceCodeCache == null) {
String contents = getFileContentsFor(element);
Expand Down Expand Up @@ -2027,27 +2027,6 @@ abstract class SourceCodeMixin {
return _sourceCodeCache;
}

String get _crossdartUrl {
if (_lineNumber != null && _crossdartPath != null) {
String url = "//www.crossdart.info/p/${_crossdartPath}.html";
return "${url}#line-${_lineNumber}";
} else {
return null;
}
}

int get _lineNumber {
var node = element.computeNode();
if (node is Declaration && (node as Declaration).element != null) {
var element = (node as Declaration).element;
var lineNumber = lineNumberCache.lineNumber(
element.source.fullName, element.nameOffset);
return lineNumber + 1;
} else {
return null;
}
}

String get _crossdartPath {
var node = element.computeNode();
if (node is Declaration && (node as Declaration).element != null) {
Expand Down Expand Up @@ -2086,6 +2065,31 @@ abstract class SourceCodeMixin {
return null;
}
}

String get _crossdartUrl {
if (_lineNumber != null && _crossdartPath != null) {
String url = "//www.crossdart.info/p/${_crossdartPath}.html";
return "${url}#line-${_lineNumber}";
} else {
return null;
}
}

int get _lineNumber {
var node = element.computeNode();
if (node is Declaration && (node as Declaration).element != null) {
var element = (node as Declaration).element;
var lineNumber = lineNumberCache.lineNumber(
element.source.fullName, element.nameOffset);
return lineNumber + 1;
} else {
return null;
}
}

void clearSourceCodeCache() {
_sourceCodeCache = null;
}
}

/// Top-level variables. But also picks up getters and setters?
Expand Down
16 changes: 12 additions & 4 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void main() {
});

test('inherited methods,including from Object ', () {
expect(B.inheritedMethods, hasLength(6));
expect(B.inheritedMethods, hasLength(7));
expect(B.hasInheritedMethods, isTrue);
});

Expand Down Expand Up @@ -632,10 +632,11 @@ void main() {
});

test('F has many inherited methods', () {
expect(F.inheritedMethods, hasLength(7));
expect(F.inheritedMethods, hasLength(8));
expect(
F.inheritedMethods.map((im) => im.name),
equals([
'abstractMethod',
'foo',
'getClassA',
'noSuchMethod',
Expand Down Expand Up @@ -821,8 +822,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
});

group('Method', () {
Class classB, klass, HasGenerics, CatString;
Method m1, isGreaterThan, m4, m5, m6, m7, convertToMap;
Class classB, klass, HasGenerics, Cat, CatString;
Method m1, isGreaterThan, m4, m5, m6, m7, convertToMap, abstractMethod;
Method inheritedClear, testGeneric;

setUp(() {
Expand All @@ -831,6 +832,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
HasGenerics =
fakeLibrary.classes.singleWhere((c) => c.name == 'HasGenerics');
CatString = exLibrary.classes.singleWhere((c) => c.name == 'CatString');
Cat = exLibrary.classes.singleWhere((c) => c.name == 'Cat');
inheritedClear =
CatString.inheritedMethods.singleWhere((m) => m.name == 'clear');
m1 = classB.instanceMethods.singleWhere((m) => m.name == 'm1');
Expand All @@ -842,6 +844,8 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
m5 = klass.instanceMethods.singleWhere((m) => m.name == 'another');
m6 = klass.instanceMethods.singleWhere((m) => m.name == 'toString');
m7 = classB.instanceMethods.singleWhere((m) => m.name == 'doNothing');
abstractMethod =
Cat.instanceMethods.singleWhere((m) => m.name == 'abstractMethod');
testGeneric = exLibrary.classes
.singleWhere((c) => c.name == 'Dog')
.instanceMethods
Expand All @@ -861,6 +865,10 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(m1.fullyQualifiedName, 'ex.B.m1');
});

test('has abstract kind', () {
expect(abstractMethod.fullkind, 'abstract method');
});

test(
'an inherited method has class as the enclosing class, when superclass not in package',
() {
Expand Down
18 changes: 12 additions & 6 deletions testing/test_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ const String COLOR_GREEN = 'green';

const String COLOR_ORANGE = 'orange';

const List<String> PRETTY_COLORS = const <String>[
COLOR_GREEN,
COLOR_ORANGE,
'blue'
];

const String COMPLEX_COLOR = 'red' + '-' + 'green' + '-' + 'blue';

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

/// This should [not work].
const incorrectDocReferenceFromEx = 'doh';

const ConstantCat MY_CAT = const ConstantCat('tabby');
const List<String> PRETTY_COLORS = const <String>[
COLOR_GREEN,
COLOR_ORANGE,
'blue'
];
@deprecated
int deprecatedField;

Expand Down Expand Up @@ -165,6 +165,8 @@ class B extends Apple with Cat {

abstract class Cat {
bool get isImplemented;

void abstractMethod();
}

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

bool get isImplemented => true;

void abstractMethod() {
// do nothing
}
}

/// implements [Cat], [E]
Expand Down
10 changes: 10 additions & 0 deletions testing/test_package_docs/ex/B-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ <h2>Operators</h2>
<section class="summary offset-anchor" id="instance-methods">
<h2>Methods</h2>
<dl class="callables">
<dt id="abstractMethod" class="callable inherited">
<span class="name"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></span><span class="signature">(<wbr>)
<span class="returntype parameter">&#8594; void</span>
</span>
</dt>
<dd class="inherited">
<p></p>
<div class="features">inherited</div>
</dd>
<dt id="doNothing" class="callable">
<span class="name deprecated"><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></span><span class="signature">(<wbr>)
<span class="returntype parameter">&#8594; Future</span>
Expand Down Expand Up @@ -387,6 +396,7 @@ <h5>B</h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/B.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/autoCompress.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/doNothing.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/hashCode.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/isImplemented.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/m1.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/noSuchMethod.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/operator_equals.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/runtimeType.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/toString.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_docs/ex/B/writeMsg.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h5><a href="ex/B-class.html">B</a></h5>
<li class="inherited"><a href="ex/B/operator_equals.html">operator ==</a></li>

<li class="section-title"><a href="ex/B-class.html#instance-methods">Methods</a></li>
<li class="inherited"><a href="ex/Cat/abstractMethod.html">abstractMethod</a></li>
<li><a class="deprecated" href="ex/B/doNothing.html">doNothing</a></li>
<li class="inherited"><a href="ex/Apple/isGreaterThan.html">isGreaterThan</a></li>
<li><a href="ex/B/m1.html">m1</a></li>
Expand Down
Loading