Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 7383054

Browse files
committed
Support analyzer 0.29.0-alpha.0
1 parent 8a43a26 commit 7383054

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

lib/src/pretty_printer.dart

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,35 @@ part of code_builder;
1111
/// This is the _recommended_ output (but not required) when comparing ASTs
1212
/// to expected golden files/text blobs.
1313
String prettyToSource(AstNode astNode) {
14-
var writer = new PrintStringWriter();
15-
var visitor = new _PrettyToSourceVisitor(writer);
14+
var buffer = new StringBuffer();
15+
var visitor = new _PrettyToSourceVisitor(buffer);
1616
astNode.accept(visitor);
17-
return dartfmt(writer.toString());
17+
return dartfmt(buffer.toString());
1818
}
1919

2020
// TODO(matanl): Remove copied-pasted methods when API becomes available.
2121
// https://github.com/dart-lang/sdk/issues/27169
2222
class _PrettyToSourceVisitor extends ToSourceVisitor {
23-
// Removed in a new version of the analyzer, but due to dartfmt it's not
24-
// possible to refer to the newest analyzer and use dartfmt.
2523
// https://github.com/dart-lang/sdk/issues/27301
26-
final PrintStringWriter _writer;
24+
final StringBuffer _buffer;
2725

28-
_PrettyToSourceVisitor(PrintStringWriter writer)
29-
: _writer = writer,
30-
super(writer);
26+
_PrettyToSourceVisitor(StringBuffer buffer)
27+
: _buffer = buffer,
28+
super(buffer);
3129

3230
@override
3331
Object visitClassDeclaration(ClassDeclaration node) {
3432
_visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
3533
_visitTokenWithSuffix(node.abstractKeyword, " ");
36-
_writer.print("class ");
34+
_buffer.write("class ");
3735
_visitNode(node.name);
3836
_visitNode(node.typeParameters);
3937
_visitNodeWithPrefix(" ", node.extendsClause);
4038
_visitNodeWithPrefix(" ", node.withClause);
4139
_visitNodeWithPrefix(" ", node.implementsClause);
42-
_writer.print(" {");
40+
_buffer.write(" {");
4341
_visitNodeListWithSeparator(node.members, "\n\n");
44-
_writer.print("}");
42+
_buffer.write("}");
4543
return null;
4644
}
4745

@@ -58,7 +56,7 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
5856
int size = nodes.length;
5957
for (int i = 0; i < size; i++) {
6058
if (i > 0) {
61-
_writer.print(separator);
59+
_buffer.write(separator);
6260
}
6361
nodes[i].accept(this);
6462
}
@@ -74,11 +72,11 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
7472
if (size > 0) {
7573
for (int i = 0; i < size; i++) {
7674
if (i > 0) {
77-
_writer.print(separator);
75+
_buffer.write(separator);
7876
}
7977
nodes[i].accept(this);
8078
}
81-
_writer.print(suffix);
79+
_buffer.write(suffix);
8280
}
8381
}
8482
}
@@ -87,7 +85,7 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
8785
// is non-`null`.
8886
void _visitNodeWithPrefix(String prefix, AstNode node) {
8987
if (node != null) {
90-
_writer.print(prefix);
88+
_buffer.write(prefix);
9189
node.accept(this);
9290
}
9391
}
@@ -96,8 +94,8 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
9694
// is non-`null`.
9795
void _visitTokenWithSuffix(Token token, String suffix) {
9896
if (token != null) {
99-
_writer.print(token.lexeme);
100-
_writer.print(suffix);
97+
_buffer.write(token.lexeme);
98+
_buffer.write(suffix);
10199
}
102100
}
103101
}

pubspec.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: code_builder
2-
version: 0.1.0
2+
version: 0.1.0-dev
33
description: A fluent API for generating Dart code
44
author: Dart Team <[email protected]>
55
homepage: https://github.com/dart-lang/code_builder
@@ -8,10 +8,16 @@ environment:
88
sdk: '>=1.9.1 <2.0.0'
99

1010
dependencies:
11-
analyzer: ">=0.27.1 <0.29.0"
12-
dart_style: ^0.2.9+1
11+
analyzer:
12+
dart_style:
1313
matcher: ^0.12.0+2
1414
meta: ^1.0.2
1515

1616
dev_dependencies:
1717
test: ^0.12.0
18+
19+
dependency_overrides:
20+
# As of 9-13-2016, this is the internal SHA. This means we can't publish to
21+
# pub, but at least can develop with code that will work out of the box on
22+
# the internal repo.
23+
analyzer: 0.29.0-alpha.0

0 commit comments

Comments
 (0)