From 16e3518987e15acec16283c5ccc9874d98b3ee5e Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Mon, 11 Mar 2024 22:13:27 +0000 Subject: [PATCH] Remove EnumFieldRenderer. --- lib/src/model/enum.dart | 16 ++++++++++---- lib/src/render/enum_field_renderer.dart | 28 ------------------------- test/enum_test.dart | 4 +--- 3 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 lib/src/render/enum_field_renderer.dart diff --git a/lib/src/model/enum.dart b/lib/src/model/enum.dart index cbd4ed3fcf..df776dfe9d 100644 --- a/lib/src/model/enum.dart +++ b/lib/src/model/enum.dart @@ -6,7 +6,7 @@ import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/dart/element/element.dart'; import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/model_utils.dart' as model_utils; -import 'package:dartdoc/src/render/enum_field_renderer.dart'; +import 'package:meta/meta.dart'; class Enum extends InheritingContainer with Constructable, MixedInTypes { @override @@ -97,7 +97,7 @@ class EnumField extends Field { String get constantValueBase => element.library.featureSet.isEnabled(Feature.enhanced_enums) ? super.constantValueBase - : _fieldRenderer.renderValue(this); + : renderedName; @override List get documentationFrom { @@ -118,7 +118,10 @@ class EnumField extends Field { } @override - String get linkedName => _fieldRenderer.renderLinkedName(this); + String get linkedName { + var cssClass = isDeprecated ? ' class="deprecated"' : ''; + return '$name'; + } @override bool get isCanonical { @@ -137,5 +140,10 @@ class EnumField extends Field { @override Inheritable? get overriddenElement => null; - EnumFieldRenderer get _fieldRenderer => const EnumFieldRendererHtml(); + @visibleForTesting + String get renderedName => name == 'values' + ? 'const List<' + '${enclosingElement.name}' + '>' + : constantValue; } diff --git a/lib/src/render/enum_field_renderer.dart b/lib/src/render/enum_field_renderer.dart deleted file mode 100644 index 539390e70c..0000000000 --- a/lib/src/render/enum_field_renderer.dart +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2019, 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. - -import 'package:dartdoc/src/model/enum.dart'; - -abstract class EnumFieldRenderer { - String renderValue(EnumField field); - - String renderLinkedName(EnumField field); -} - -class EnumFieldRendererHtml implements EnumFieldRenderer { - const EnumFieldRendererHtml(); - - @override - String renderValue(EnumField field) => field.name == 'values' - ? 'const List<' - '${field.enclosingElement.name}' - '>' - : field.constantValue; - - @override - String renderLinkedName(EnumField field) { - var cssClass = field.isDeprecated ? ' class="deprecated"' : ''; - return '${field.name}'; - } -} diff --git a/test/enum_test.dart b/test/enum_test.dart index 215b83e342..4347cb9ca5 100644 --- a/test/enum_test.dart +++ b/test/enum_test.dart @@ -4,7 +4,6 @@ import 'package:dartdoc/src/model/model.dart'; import 'package:dartdoc/src/model_utils.dart'; -import 'package:dartdoc/src/render/enum_field_renderer.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -603,8 +602,7 @@ enum E { var oneValue = library.enums.named('E').publicEnumValues.named('one') as EnumField; expect(oneValue.linkedName, 'one'); - expect(oneValue.constantValue, - equals(EnumFieldRendererHtml().renderValue(oneValue))); + expect(oneValue.constantValue, equals(oneValue.renderedName)); } void test_values_haveIndices() async {