From b903d73c9b913d7fa9c4a3ed991b124db37eeaf8 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 6 Apr 2021 16:17:17 +0000 Subject: [PATCH] Migrate allowed status pages. Change-Id: If81a0e66a22f9219535420041b6cd7efe1aa3341 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194103 Commit-Queue: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- .../lib/src/status/ast_writer.dart | 27 ++++++++----------- .../lib/src/status/element_writer.dart | 14 +++++----- pkg/analysis_server/lib/src/status/pages.dart | 20 +++++++------- .../lib/src/status/tree_writer.dart | 14 +++++----- 4 files changed, 32 insertions(+), 43 deletions(-) diff --git a/pkg/analysis_server/lib/src/status/ast_writer.dart b/pkg/analysis_server/lib/src/status/ast_writer.dart index ef6cc8e7ac0..d3917ce968d 100644 --- a/pkg/analysis_server/lib/src/status/ast_writer.dart +++ b/pkg/analysis_server/lib/src/status/ast_writer.dart @@ -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 _computeProperties(AstNode node) { - Map properties = HashMap(); + Map _computeProperties(AstNode node) { + var properties = {}; 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) { diff --git a/pkg/analysis_server/lib/src/status/element_writer.dart b/pkg/analysis_server/lib/src/status/element_writer.dart index e75777c2fd0..dffcd49c10c 100644 --- a/pkg/analysis_server/lib/src/status/element_writer.dart +++ b/pkg/analysis_server/lib/src/status/element_writer.dart @@ -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 _computeProperties(Element element) { - Map properties = HashMap(); + Map _computeProperties(Element element) { + var properties = {}; properties['metadata'] = element.metadata; properties['nameOffset'] = element.nameOffset; diff --git a/pkg/analysis_server/lib/src/status/pages.dart b/pkg/analysis_server/lib/src/status/pages.dart index 2edec799920..61f47048ef5 100644 --- a/pkg/analysis_server/lib/src/status/pages.dart +++ b/pkg/analysis_server/lib/src/status/pages.dart @@ -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 asyncDiv(void Function() gen, {String classes}) async { + Future asyncDiv(void Function() gen, {String? classes}) async { if (classes != null) { buf.writeln('
'); } 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('
'); } else { @@ -68,7 +66,7 @@ abstract class Page { Future generatePage(Map params); - void h1(String text, {String classes}) { + void h1(String text, {String? classes}) { if (classes != null) { buf.writeln('

${escape(text)}

'); } 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('
');
     } else {
@@ -127,7 +125,7 @@ abstract class Page {
     });
   }
 
-  void ul(Iterable items, void Function(T item) gen, {String classes}) {
+  void ul(Iterable items, void Function(T item) gen, {String? classes}) {
     buf.writeln('');
     for (var item in items) {
       buf.write('
  • '); @@ -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); } diff --git a/pkg/analysis_server/lib/src/status/tree_writer.dart b/pkg/analysis_server/lib/src/status/tree_writer.dart index 25bd0249f49..ec2078038e1 100644 --- a/pkg/analysis_server/lib/src/status/tree_writer.dart +++ b/pkg/analysis_server/lib/src/status/tree_writer.dart @@ -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 exceptions = []; + /// 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('┊   '); @@ -36,7 +34,7 @@ mixin TreeWriter { } /// Write a representation of the given [properties] to the buffer. - void writeProperties(Map properties) { + void writeProperties(Map 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}")';