Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SourceCodeRenderer and TypeParametersRenderer. #3683

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/src/model/accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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 'dart:convert';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/line_info.dart';
// ignore: implementation_imports
Expand All @@ -10,7 +12,6 @@ import 'package:collection/collection.dart' show IterableExtension;
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/source_code_renderer.dart';
import 'package:dartdoc/src/utils.dart';
import 'package:dartdoc/src/warnings.dart';

Expand Down Expand Up @@ -49,8 +50,6 @@ class Accessor extends ModelElement implements EnclosedElement {

bool get isSynthetic => element.isSynthetic;

SourceCodeRenderer get _sourceCodeRenderer => const SourceCodeRendererHtml();

// The [enclosingCombo] where this element was defined.
late final GetterSetterCombo definingCombo =
getModelForElement(element.variable) as GetterSetterCombo;
Expand All @@ -62,7 +61,7 @@ class Accessor extends ModelElement implements EnclosedElement {
var modelNode = packageGraph.getModelNodeFor(definingCombo.element);
return modelNode == null
? ''
: _sourceCodeRenderer.renderSourceCode(modelNode.sourceCode);
: const HtmlEscape().convert(modelNode.sourceCode);
}

@override
Expand Down
7 changes: 3 additions & 4 deletions lib/src/model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// 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 'dart:convert';

import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/model/attribute.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/source_code_renderer.dart';

class Field extends ModelElement
with GetterSetterCombo, ContainerMember, Inheritable
Expand Down Expand Up @@ -149,16 +150,14 @@ class Field extends ModelElement
@override
String? get belowSidebarPath => null;

SourceCodeRenderer get _sourceCodeRenderer => const SourceCodeRendererHtml();

late final String _sourceCode = () {
// We could use a set to figure the dupes out, but that would lose ordering.
var fieldSourceCode = modelNode?.sourceCode ?? '';
var getterSourceCode = getter?.sourceCode ?? '';
var setterSourceCode = setter?.sourceCode ?? '';
var buffer = StringBuffer();
if (fieldSourceCode.isNotEmpty) {
fieldSourceCode = _sourceCodeRenderer.renderSourceCode(fieldSourceCode);
fieldSourceCode = const HtmlEscape().convert(fieldSourceCode);
buffer.write(fieldSourceCode);
}
if (buffer.isNotEmpty) buffer.write('\n\n');
Expand Down
6 changes: 1 addition & 5 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:dartdoc/src/model/prefix.dart';
import 'package:dartdoc/src/model_utils.dart' as utils;
import 'package:dartdoc/src/render/model_element_renderer.dart';
import 'package:dartdoc/src/render/parameter_renderer.dart';
import 'package:dartdoc/src/render/source_code_renderer.dart';
import 'package:dartdoc/src/runtime_stats.dart';
import 'package:dartdoc/src/source_linker.dart';
import 'package:dartdoc/src/special_elements.dart';
Expand Down Expand Up @@ -686,8 +685,6 @@ abstract class ModelElement extends Canonicalization
ParameterRenderer get _parameterRendererDetailed =>
const ParameterRendererHtmlList();

SourceCodeRenderer get _sourceCodeRenderer => const SourceCodeRendererHtml();

String get linkedParams => _parameterRenderer.renderLinkedParams(parameters);

String get linkedParamsLines =>
Expand Down Expand Up @@ -757,8 +754,7 @@ abstract class ModelElement extends Canonicalization
}();

@override
late final String sourceCode =
_sourceCodeRenderer.renderSourceCode(super.sourceCode);
late final String sourceCode = const HtmlEscape().convert(super.sourceCode);

@override
int compareTo(Object other) {
Expand Down
27 changes: 20 additions & 7 deletions lib/src/model/type_parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/type_parameters_renderer.dart';

class TypeParameter extends ModelElement with HasNoPage {
@override
Expand Down Expand Up @@ -73,14 +72,28 @@ mixin TypeParameters implements ModelElement {

bool get hasGenericParameters => typeParameters.isNotEmpty;

String get genericParameters =>
_typeParametersRenderer.renderGenericParameters(this);
String get genericParameters => _renderTypeParameters();

String get linkedGenericParameters =>
_typeParametersRenderer.renderLinkedGenericParameters(this);
String get linkedGenericParameters => _renderTypeParameters(isLinked: true);

List<TypeParameter> get typeParameters;

TypeParametersRenderer get _typeParametersRenderer =>
const TypeParametersRendererHtml();
String _renderTypeParameters({bool isLinked = false}) {
if (typeParameters.isEmpty) {
return '';
}
var joined = typeParameters
.map((t) => [
...t.annotations.map((a) => a.linkedNameWithParameters),
isLinked ? t.linkedName : t.name
].join(' '))
.join('</span>, <span class="type-parameter">');
var typeParametersString =
'&lt;<wbr><span class="type-parameter">$joined</span>&gt;';
if (isLinked) {
typeParametersString =
'<span class="signature">$typeParametersString</span>';
}
return typeParametersString;
}
}
27 changes: 0 additions & 27 deletions lib/src/render/source_code_renderer.dart

This file was deleted.

45 changes: 0 additions & 45 deletions lib/src/render/type_parameters_renderer.dart

This file was deleted.

Loading