Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Support analyzer 0.29.0-alpha.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matanlurey committed Sep 13, 2016
1 parent 8a43a26 commit 7383054
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
34 changes: 16 additions & 18 deletions lib/src/pretty_printer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@ part of code_builder;
/// This is the _recommended_ output (but not required) when comparing ASTs
/// to expected golden files/text blobs.
String prettyToSource(AstNode astNode) {
var writer = new PrintStringWriter();
var visitor = new _PrettyToSourceVisitor(writer);
var buffer = new StringBuffer();
var visitor = new _PrettyToSourceVisitor(buffer);
astNode.accept(visitor);
return dartfmt(writer.toString());
return dartfmt(buffer.toString());
}

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

_PrettyToSourceVisitor(PrintStringWriter writer)
: _writer = writer,
super(writer);
_PrettyToSourceVisitor(StringBuffer buffer)
: _buffer = buffer,
super(buffer);

@override
Object visitClassDeclaration(ClassDeclaration node) {
_visitNodeListWithSeparatorAndSuffix(node.metadata, " ", " ");
_visitTokenWithSuffix(node.abstractKeyword, " ");
_writer.print("class ");
_buffer.write("class ");
_visitNode(node.name);
_visitNode(node.typeParameters);
_visitNodeWithPrefix(" ", node.extendsClause);
_visitNodeWithPrefix(" ", node.withClause);
_visitNodeWithPrefix(" ", node.implementsClause);
_writer.print(" {");
_buffer.write(" {");
_visitNodeListWithSeparator(node.members, "\n\n");
_writer.print("}");
_buffer.write("}");
return null;
}

Expand All @@ -58,7 +56,7 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
int size = nodes.length;
for (int i = 0; i < size; i++) {
if (i > 0) {
_writer.print(separator);
_buffer.write(separator);
}
nodes[i].accept(this);
}
Expand All @@ -74,11 +72,11 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
if (size > 0) {
for (int i = 0; i < size; i++) {
if (i > 0) {
_writer.print(separator);
_buffer.write(separator);
}
nodes[i].accept(this);
}
_writer.print(suffix);
_buffer.write(suffix);
}
}
}
Expand All @@ -87,7 +85,7 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
// is non-`null`.
void _visitNodeWithPrefix(String prefix, AstNode node) {
if (node != null) {
_writer.print(prefix);
_buffer.write(prefix);
node.accept(this);
}
}
Expand All @@ -96,8 +94,8 @@ class _PrettyToSourceVisitor extends ToSourceVisitor {
// is non-`null`.
void _visitTokenWithSuffix(Token token, String suffix) {
if (token != null) {
_writer.print(token.lexeme);
_writer.print(suffix);
_buffer.write(token.lexeme);
_buffer.write(suffix);
}
}
}
12 changes: 9 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: code_builder
version: 0.1.0
version: 0.1.0-dev
description: A fluent API for generating Dart code
author: Dart Team <[email protected]>
homepage: https://github.com/dart-lang/code_builder
Expand All @@ -8,10 +8,16 @@ environment:
sdk: '>=1.9.1 <2.0.0'

dependencies:
analyzer: ">=0.27.1 <0.29.0"
dart_style: ^0.2.9+1
analyzer:
dart_style:
matcher: ^0.12.0+2
meta: ^1.0.2

dev_dependencies:
test: ^0.12.0

dependency_overrides:
# As of 9-13-2016, this is the internal SHA. This means we can't publish to
# pub, but at least can develop with code that will work out of the box on
# the internal repo.
analyzer: 0.29.0-alpha.0

0 comments on commit 7383054

Please sign in to comment.