Skip to content

Commit ca8fe9d

Browse files
authored
Fix constructor resolution regression and add test (#1868)
1 parent 06ad7ce commit ca8fe9d

File tree

257 files changed

+2267
-19
lines changed

Some content is hidden

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

257 files changed

+2267
-19
lines changed

lib/src/markdown_processor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,13 @@ class _MarkdownCommentReference {
690690
.where((m) => _ConsiderIfConstructor(m));
691691
if (codeRefChompedParts.first == c.name) {
692692
// [Foo...thing], a member of this class (possibly a parameter).
693-
membersToCheck.map((m) => _addCanonicalResult(m, tryClass));
693+
membersToCheck.forEach((m) => _addCanonicalResult(m, tryClass));
694694
} else if (codeRefChompedParts.length > 1 &&
695695
codeRefChompedParts[codeRefChompedParts.length - 2] == c.name) {
696696
// [....Foo.thing], a member of this class partially specified.
697697
membersToCheck
698698
.whereType<Constructor>()
699-
.map((m) => _addCanonicalResult(m, tryClass));
699+
.forEach((m) => _addCanonicalResult(m, tryClass));
700700
}
701701
results.remove(null);
702702
if (results.isNotEmpty) return;

lib/src/model.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,8 +4134,10 @@ abstract class ModelElement extends Canonicalization
41344134
// Count the number of invocations of tools in this dartdoc block,
41354135
// so that tools can differentiate different blocks from each other.
41364136
invocationIndex++;
4137-
return await config.tools.runner.run(args,
4138-
(String message) async => warn(PackageWarning.toolError, message: message),
4137+
return await config.tools.runner.run(
4138+
args,
4139+
(String message) async =>
4140+
warn(PackageWarning.toolError, message: message),
41394141
content: basicMatch[2],
41404142
environment: {
41414143
'SOURCE_LINE': lineAndColumn?.item1?.toString(),

lib/src/tool_runner.dart

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ final MultiFutureTracker _toolTracker = new MultiFutureTracker(4);
2525
class ToolTempFileTracker {
2626
final Directory temporaryDirectory;
2727

28-
ToolTempFileTracker._() : temporaryDirectory = Directory.systemTemp.createTempSync('dartdoc_tools_');
28+
ToolTempFileTracker._()
29+
: temporaryDirectory =
30+
Directory.systemTemp.createTempSync('dartdoc_tools_');
2931

3032
static ToolTempFileTracker _instance;
31-
static ToolTempFileTracker get instance => _instance ??= ToolTempFileTracker._();
33+
static ToolTempFileTracker get instance =>
34+
_instance ??= ToolTempFileTracker._();
3235

3336
int _temporaryFileCount = 0;
3437
Future<File> createTemporaryFile() async {
3538
_temporaryFileCount++;
3639
File tempFile = new File(pathLib.join(
37-
temporaryDirectory.absolute.path,
38-
'input_$_temporaryFileCount'));
40+
temporaryDirectory.absolute.path, 'input_$_temporaryFileCount'));
3941
await tempFile.create(recursive: true);
4042
return tempFile;
4143
}
@@ -60,7 +62,9 @@ class ToolRunner {
6062
final ToolConfiguration toolConfiguration;
6163

6264
void _runSetup(
63-
String name, ToolDefinition tool, Map<String, String> environment,
65+
String name,
66+
ToolDefinition tool,
67+
Map<String, String> environment,
6468
ToolErrorCallback toolErrorCallback) async {
6569
bool isDartSetup = ToolDefinition.isDartExecutable(tool.setupCommand[0]);
6670
var args = tool.setupCommand.toList();
@@ -71,12 +75,17 @@ class ToolRunner {
7175
} else {
7276
commandPath = args.removeAt(0);
7377
}
74-
await _runProcess(name, '', commandPath, args, environment, toolErrorCallback);
78+
await _runProcess(
79+
name, '', commandPath, args, environment, toolErrorCallback);
7580
tool.setupComplete = true;
7681
}
7782

78-
Future<String> _runProcess(String name, String content, String commandPath,
79-
List<String> args, Map<String, String> environment,
83+
Future<String> _runProcess(
84+
String name,
85+
String content,
86+
String commandPath,
87+
List<String> args,
88+
Map<String, String> environment,
8089
ToolErrorCallback toolErrorCallback) async {
8190
String commandString() => ([commandPath] + args).join(' ');
8291
try {
@@ -113,7 +122,8 @@ class ToolRunner {
113122
Future runner;
114123
// Prevent too many tools from running simultaneously.
115124
await _toolTracker.addFutureFromClosure(() {
116-
runner = _run(args, toolErrorCallback, content: content, environment: environment);
125+
runner = _run(args, toolErrorCallback,
126+
content: content, environment: environment);
117127
return runner;
118128
});
119129
return runner;
@@ -127,7 +137,8 @@ class ToolRunner {
127137
environment ??= <String, String>{};
128138
var tool = args.removeAt(0);
129139
if (!toolConfiguration.tools.containsKey(tool)) {
130-
toolErrorCallback('Unable to find definition for tool "$tool" in tool map. '
140+
toolErrorCallback(
141+
'Unable to find definition for tool "$tool" in tool map. '
131142
'Did you add it to dartdoc_options.yaml?');
132143
return '';
133144
}
@@ -193,12 +204,12 @@ class ToolRunner {
193204
}
194205

195206
if (callCompleter != null) {
196-
return _runProcess(
197-
tool, content, commandPath, argsWithInput, envWithInput, toolErrorCallback)
207+
return _runProcess(tool, content, commandPath, argsWithInput,
208+
envWithInput, toolErrorCallback)
198209
.whenComplete(callCompleter);
199210
} else {
200-
return _runProcess(
201-
tool, content, commandPath, argsWithInput, envWithInput, toolErrorCallback);
211+
return _runProcess(tool, content, commandPath, argsWithInput,
212+
envWithInput, toolErrorCallback);
202213
}
203214
}
204215
}

test/model_test.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
29192919
Constructor appleDefaultConstructor, constCatConstructor;
29202920
Constructor appleConstructorFromString;
29212921
Constructor constructorTesterDefault, constructorTesterFromSomething;
2922-
Class apple, constCat, constructorTester;
2922+
Class apple, constCat, constructorTester, referToADefaultConstructor;
29232923
setUpAll(() {
29242924
apple = exLibrary.classes.firstWhere((c) => c.name == 'Apple');
29252925
constCat = exLibrary.classes.firstWhere((c) => c.name == 'ConstantCat');
@@ -2934,6 +2934,20 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
29342934
.firstWhere((c) => c.name == 'ConstructorTester');
29352935
constructorTesterFromSomething = constructorTester.constructors
29362936
.firstWhere((c) => c.name == 'ConstructorTester.fromSomething');
2937+
referToADefaultConstructor = fakeLibrary.classes
2938+
.firstWhere((c) => c.name == 'ReferToADefaultConstructor');
2939+
});
2940+
2941+
test('calculates comment references to classes vs. constructors correctly',
2942+
() {
2943+
expect(
2944+
referToADefaultConstructor.documentationAsHtml,
2945+
contains(
2946+
'<a href="fake/ReferToADefaultConstructor-class.html">ReferToADefaultConstructor</a>'));
2947+
expect(
2948+
referToADefaultConstructor.documentationAsHtml,
2949+
contains(
2950+
'<a href="fake/ReferToADefaultConstructor/ReferToADefaultConstructor.html">ReferToADefaultConstructor.ReferToADefaultConstructor</a>'));
29372951
});
29382952

29392953
test('displays generic parameters correctly', () {

testing/test_package/lib/fake.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,15 @@ void paintImage2(String fooParam,
926926
// nothing to do here -
927927
}
928928

929+
/// This is to test referring to a constructor.
930+
///
931+
/// This should refer to a class: [ReferToADefaultConstructor].
932+
/// This should refer to the constructor: [ReferToADefaultConstructor.ReferToADefaultConstructor].
933+
class ReferToADefaultConstructor {
934+
/// A default constructor.
935+
ReferToADefaultConstructor();
936+
}
937+
929938
/// Test operator references: [OperatorReferenceClass.==].
930939
class OperatorReferenceClass {
931940
OperatorReferenceClass();

testing/test_package_docs/fake/ABaseClass-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassUsingASuperMixin-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassUsingNewStyleMixin-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AClassWithFancyProperties-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing/test_package_docs/fake/AMixinCallingSuper-class.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)