Skip to content

Commit 3ab24d8

Browse files
committed
Merge pull request #794 from dart-lang/ddc_resource_api
use the new Resource api
2 parents 62ead6e + 38be28f commit 3ab24d8

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: dart
22
sudo: false
3-
dart:
3+
dart:
44
- dev
5-
- stable
5+
# - stable
66
env:
77
- GEN_SDK_DOCS=true
88
- GEN_SDK_DOCS=false

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class DartDoc {
151151
if (name.startsWith(Platform.pathSeparator)) name = name.substring(1);
152152
}
153153
print('parsing ${name}...');
154-
Source source = new FileBasedSource.con1(new JavaFile(filePath));
154+
Source source = new FileBasedSource(new JavaFile(filePath));
155155
sources.add(source);
156156
if (context.computeKindOf(source) == SourceKind.LIBRARY) {
157157
LibraryElement library = context.computeLibraryElement(source);

lib/resource_loader.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// TODO: Consider making this a stand-alone package, if useful.
6-
75
/// Make it possible to load resources, independent of how the Dart app is run.
86
///
97
/// Future<String> getTemplateFile(String templatePath) {
@@ -14,7 +12,7 @@ library dartdoc.resource_loader;
1412

1513
import 'dart:async' show Future;
1614
import 'dart:io' show Platform, File, Directory;
17-
import 'dart:typed_data';
15+
import 'dart:typed_data' show Uint8List;
1816

1917
import 'package:http/http.dart' as http;
2018
import 'package:path/path.dart' as p;
@@ -24,20 +22,27 @@ import 'package:pub_cache/pub_cache.dart';
2422
String packageRootPath;
2523

2624
/// Loads a `package:` resource as a String.
27-
Future<String> loadAsString(String path) async {
25+
Future<String> loadAsString(String path) {
2826
if (!path.startsWith('package:')) {
2927
throw new ArgumentError('path must begin with package:');
3028
}
31-
Uint8List bytes = await _doLoad(path);
32-
return new String.fromCharCodes(bytes);
29+
return new Resource(path).readAsString().catchError((_) async {
30+
// TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
31+
var bytes = await _doLoad(path);
32+
return new String.fromCharCodes(bytes);
33+
});
3334
}
3435

35-
/// Loads a `package:` resource as an [Uint8List].
36-
Future<Uint8List> loadAsBytes(String path) {
36+
/// Loads a `package:` resource as an [List<int>].
37+
Future<List<int>> loadAsBytes(String path) {
3738
if (!path.startsWith('package:')) {
3839
throw new ArgumentError('path must begin with package:');
3940
}
40-
return _doLoad(path);
41+
42+
return new Resource(path).readAsBytes().catchError((_) {
43+
// TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
44+
return _doLoad(path);
45+
});
4146
}
4247

4348
/// Determine how to do the load. HTTP? Snapshotted? From source?

lib/src/model.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'package:analyzer/src/generated/resolver.dart';
1111
import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind;
1212
import 'package:quiver/core.dart';
1313

14-
import 'debug.dart';
1514
import 'html_utils.dart';
1615
import 'model_utils.dart';
1716
import 'package_meta.dart';

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ author: Dart Team <[email protected]>
55
description: A documentation generator for Dart.
66
homepage: https://github.com/dart-lang/dartdoc
77
environment:
8-
sdk: '>=1.9.0 <2.0.0' # when we go to 1.12, bump analyzer version
8+
sdk: '>=1.12.0-dev.5.0 <2.0.0'
99
dependencies:
10-
analyzer: '>=0.25.0 <0.27.0'
10+
analyzer: '>=0.26.0 <0.27.0'
1111
args: ^0.13.0
1212
cli_util: ^0.0.1
1313
html: ^0.12.1

test/test_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class AnalyzerHelper {
6565
}
6666

6767
Source addSource(String filePath) {
68-
Source source = new FileBasedSource.con1(new JavaFile(filePath));
68+
Source source = new FileBasedSource(new JavaFile(filePath));
6969
ChangeSet changeSet = new ChangeSet();
7070
changeSet.addedSource(source);
7171
context.applyChanges(changeSet);

0 commit comments

Comments
 (0)