Files
sdk/pkg/compiler/lib/src/kernel/kernel_debug.dart
T
Konstantin Shcheglov 1170b117c9 Remember isFieldFormal informative flag in VariableDeclaration(s).
It is informative in the same way as documentation.

Yesterday I tried to make Analyzer and Analysis Server stop using
FieldFormalParameterElement(s) and found one important use case requested
by the Flutter team. We need to show documentation of a field when
user requests documentation on the corresponding field formal named
parameter. This happens outside of the file that declares the parameter
and the field, so we don't have AST available. Of course we could
resolve the unit, but it would cost us something. And if we decide
that it is OK, then maybe we don't need to have documenation comments
in elements at all.

This is of course more convenience, and we could store documentation
and parameter to field mappings outside, like we store index. Just a
compromise - convenience vs. purity.

R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com
BUG=

Review-Url: https://codereview.chromium.org/2983173002 .
2017-07-20 09:53:04 -07:00

78 lines
2.0 KiB
Dart

// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Helper for debug Kernel nodes.
library kernel.debug;
import 'package:kernel/ast.dart';
import 'package:kernel/visitor.dart';
import '../util/util.dart' show Indentation, Tagging;
class DebugPrinter extends Visitor with Indentation, Tagging<Node> {
StringBuffer sb = new StringBuffer();
void visitNodeWithChildren(Node node, String type, [Map params]) {
openNode(node, type, params);
node.visitChildren(this);
closeNode();
}
@override
void defaultNode(Node node) {
visitNodeWithChildren(node, '${node.runtimeType}');
}
@override
void visitName(Name node) {
openAndCloseNode(node, '${node.runtimeType}',
{'name': node.name, 'library': node.library?.name});
}
@override
void visitIntLiteral(IntLiteral node) {
openAndCloseNode(node, '${node.runtimeType}', {'value': '${node.value}'});
}
@override
void visitVariableGet(VariableGet node) {
openAndCloseNode(
node, '${node.runtimeType}', {'variable': '${node.variable}'});
}
@override
void visitStaticGet(StaticGet node) {
openAndCloseNode(node, '${node.runtimeType}', {'target': '${node.target}'});
}
@override
void visitVariableDeclaration(VariableDeclaration node) {
openNode(node, '${node.runtimeType}', {
'name': '${node.name ?? '--unnamed--'}',
'isFinal': '${node.isFinal}',
'isConst': '${node.isConst}',
'isFieldFormal': '${node.isFieldFormal}'
});
node.visitChildren(this);
closeNode();
}
@override
void visitInterfaceType(InterfaceType node) {
openNode(node, '${node.runtimeType}', {
'name': '${node.classNode.name}',
});
node.visitChildren(this);
closeNode();
}
/// Pretty-prints given node tree into string.
static String prettyPrint(Node node) {
var p = new DebugPrinter();
node.accept(p);
return p.sb.toString();
}
}