Migrate allowed status pages.

Change-Id: If81a0e66a22f9219535420041b6cd7efe1aa3341
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194103
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov
2021-04-06 16:17:17 +00:00
committed by commit-bot@chromium.org
parent 9558ac12bb
commit b903d73c9b
4 changed files with 32 additions and 43 deletions
@@ -2,10 +2,6 @@
// 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.
// @dart = 2.9
import 'dart:collection';
import 'package:analysis_server/src/status/tree_writer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
@@ -13,11 +9,12 @@ import 'package:analyzer/src/dart/ast/ast.dart';
/// A visitor that will produce an HTML representation of an AST structure.
class AstWriter extends UnifyingAstVisitor with TreeWriter {
@override
final StringBuffer buffer;
/// Initialize a newly created element writer to write the HTML representation
/// of visited nodes on the given [buffer].
AstWriter(StringBuffer buffer) {
this.buffer = buffer;
}
AstWriter(this.buffer);
@override
void visitNode(AstNode node) {
@@ -33,8 +30,8 @@ class AstWriter extends UnifyingAstVisitor with TreeWriter {
/// Write a representation of the properties of the given [node] to the
/// buffer.
Map<String, Object> _computeProperties(AstNode node) {
Map<String, Object> properties = HashMap<String, Object>();
Map<String, Object?> _computeProperties(AstNode node) {
var properties = <String, Object?>{};
properties['name'] = _getName(node);
if (node is ArgumentListImpl) {
@@ -150,26 +147,24 @@ class AstWriter extends UnifyingAstVisitor with TreeWriter {
/// Return the name of the given [node], or `null` if the given node is not a
/// declaration.
String _getName(AstNode node) {
String? _getName(AstNode node) {
if (node is ClassTypeAlias) {
return node.name.name;
} else if (node is ClassDeclaration) {
return node.name.name;
} else if (node is ConstructorDeclaration) {
if (node.name == null) {
var name = node.name;
if (name == null) {
return node.returnType.name;
} else {
return node.returnType.name + '.' + node.name.name;
return node.returnType.name + '.' + name.name;
}
} else if (node is ConstructorName) {
return node.toSource();
} else if (node is FieldDeclaration) {
return _getNames(node.fields);
} else if (node is FunctionDeclaration) {
var nameNode = node.name;
if (nameNode != null) {
return nameNode.name;
}
return node.name.name;
} else if (node is FunctionTypeAlias) {
return node.name.name;
} else if (node is Identifier) {
@@ -2,9 +2,6 @@
// 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.
// @dart = 2.9
import 'dart:collection';
import 'dart:convert';
import 'package:analysis_server/src/status/tree_writer.dart';
@@ -14,11 +11,12 @@ import 'package:analyzer/src/dart/element/element.dart';
/// A visitor that will produce an HTML representation of an element structure.
class ElementWriter extends GeneralizingElementVisitor with TreeWriter {
@override
final StringBuffer buffer;
/// Initialize a newly created element writer to write the HTML representation
/// of visited elements on the given [buffer].
ElementWriter(StringBuffer buffer) {
this.buffer = buffer;
}
ElementWriter(this.buffer);
@override
void visitElement(Element element) {
@@ -34,8 +32,8 @@ class ElementWriter extends GeneralizingElementVisitor with TreeWriter {
/// Write a representation of the properties of the given [node] to the
/// buffer.
Map<String, Object> _computeProperties(Element element) {
Map<String, Object> properties = HashMap<String, Object>();
Map<String, Object?> _computeProperties(Element element) {
var properties = <String, Object?>{};
properties['metadata'] = element.metadata;
properties['nameOffset'] = element.nameOffset;
+9 -11
View File
@@ -2,8 +2,6 @@
// 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.
// @dart = 2.9
import 'dart:convert';
import 'dart:io';
@@ -11,7 +9,7 @@ import 'package:intl/intl.dart';
final NumberFormat numberFormat = NumberFormat.decimalPattern();
String escape(String text) => text == null ? '' : htmlEscape.convert(text);
String escape(String? text) => text == null ? '' : htmlEscape.convert(text);
String printInteger(int value) => numberFormat.format(value);
@@ -26,13 +24,13 @@ abstract class Page {
final String id;
final String title;
final String description;
final String? description;
Page(this.id, this.title, {this.description});
String get path => '/$id';
Future<void> asyncDiv(void Function() gen, {String classes}) async {
Future<void> asyncDiv(void Function() gen, {String? classes}) async {
if (classes != null) {
buf.writeln('<div class="$classes">');
} else {
@@ -48,7 +46,7 @@ abstract class Page {
div(() => buf.writeln(str), classes: 'blankslate');
}
void div(void Function() gen, {String classes}) {
void div(void Function() gen, {String? classes}) {
if (classes != null) {
buf.writeln('<div class="$classes">');
} else {
@@ -68,7 +66,7 @@ abstract class Page {
Future<void> generatePage(Map<String, String> params);
void h1(String text, {String classes}) {
void h1(String text, {String? classes}) {
if (classes != null) {
buf.writeln('<h1 class="$classes">${escape(text)}</h1>');
} else {
@@ -100,7 +98,7 @@ abstract class Page {
bool isCurrentPage(String pathToTest) => path == pathToTest;
void p(String text, {String style, bool raw = false, String classes}) {
void p(String text, {String? style, bool raw = false, String? classes}) {
var c = classes == null ? '' : ' class="$classes"';
if (style != null) {
@@ -110,7 +108,7 @@ abstract class Page {
}
}
void pre(void Function() gen, {String classes}) {
void pre(void Function() gen, {String? classes}) {
if (classes != null) {
buf.write('<pre class="$classes">');
} else {
@@ -127,7 +125,7 @@ abstract class Page {
});
}
void ul<T>(Iterable<T> items, void Function(T item) gen, {String classes}) {
void ul<T>(Iterable<T> items, void Function(T item) gen, {String? classes}) {
buf.writeln('<ul${classes == null ? '' : ' class=$classes'}>');
for (var item in items) {
buf.write('<li>');
@@ -213,7 +211,7 @@ abstract class Site {
HttpRequest request, {
int code = HttpStatus.ok,
}) async {
if (request.headers.contentType.subType == 'json') {
if (request.headers.contentType?.subType == 'json') {
return respondJson(request, {'success': true}, code);
}
@@ -2,8 +2,6 @@
// 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.
// @dart = 2.9
import 'dart:convert';
import 'package:analyzer/exception/exception.dart';
@@ -13,9 +11,6 @@ import 'package:analyzer/src/generated/source.dart';
/// Utility methods that can be mixed in to classes that produce an HTML
/// representation of a tree structure.
mixin TreeWriter {
/// The buffer on which the HTML is to be written.
StringBuffer buffer;
/// The current level of indentation.
int indentLevel = 0;
@@ -23,6 +18,9 @@ mixin TreeWriter {
/// write out the tree structure.
List<CaughtException> exceptions = <CaughtException>[];
/// The buffer on which the HTML is to be written.
StringBuffer get buffer;
void indent([int extra = 0]) {
for (var i = 0; i < indentLevel; i++) {
buffer.write('&#x250A;&nbsp;&nbsp;&nbsp;');
@@ -36,7 +34,7 @@ mixin TreeWriter {
}
/// Write a representation of the given [properties] to the buffer.
void writeProperties(Map<String, Object> properties) {
void writeProperties(Map<String, Object?> properties) {
var propertyNames = properties.keys.toList();
propertyNames.sort();
for (var propertyName in propertyNames) {
@@ -45,7 +43,7 @@ mixin TreeWriter {
}
/// Write the [value] of the property with the given [name].
void writeProperty(String name, Object value) {
void writeProperty(String name, Object? value) {
if (value != null) {
indent(2);
buffer.write('$name = ');
@@ -54,7 +52,7 @@ mixin TreeWriter {
}
}
String _toString(Object value) {
String? _toString(Object? value) {
try {
if (value is Source) {
return 'Source (uri="${value.uri}", path="${value.fullName}")';