Skip to content

Commit

Permalink
Merge branch 'master' into reftests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-g committed May 26, 2021
2 parents 0f8fc55 + 9d89c34 commit 191839d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/src/generator/templates.runtime_renderers.dart
Expand Up @@ -3794,6 +3794,19 @@ class _Renderer_ContainerAccessor extends RendererBase<ContainerAccessor> {
..._Renderer_Accessor.propertyMap<CT_>(),
..._Renderer_ContainerMember.propertyMap<CT_>(),
..._Renderer_Inheritable.propertyMap<CT_>(),
'characterLocation': Property(
getValue: (CT_ c) => c.characterLocation,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(
c, remainingNames, 'CharacterLocation'),
isNullValue: (CT_ c) => c.characterLocation == null,
renderValue:
(CT_ c, RendererBase<CT_> r, List<MustachioNode> ast) {
return renderSimple(c.characterLocation, ast, r.template,
parent: r);
},
),
'enclosingElement': Property(
getValue: (CT_ c) => c.enclosingElement,
renderVariable:
Expand Down
14 changes: 14 additions & 0 deletions lib/src/model/accessor.dart
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/element/member.dart' show ExecutableMember;
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
Expand Down Expand Up @@ -161,6 +162,19 @@ class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
return accessor;
}

/// The index and values fields are never declared, and must be special cased.
bool get _isEnumSynthetic =>
enclosingCombo is EnumField && (name == 'index' || name == 'values');

@override
CharacterLocation get characterLocation {
if (_isEnumSynthetic) return enclosingElement.characterLocation;
// TODO(jcollins-g): Remove the enclosingCombo case below once
// https://github.com/dart-lang/sdk/issues/46154 is fixed.
if (enclosingCombo is EnumField) return enclosingCombo.characterLocation;
return super.characterLocation;
}

ModelElement _enclosingElement;
bool _isInherited = false;

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: '>=2.11.99 <3.0.0'

dependencies:
analyzer: ^1.5.0
analyzer: ^1.7.1
args: ^2.0.0
charcode: ^1.2.0
collection: ^1.2.0
Expand All @@ -17,7 +17,7 @@ dependencies:
html: ^0.15.0
logging: ^1.0.0
markdown: ^4.0.0
meta: ^1.2.4
meta: ^1.3.0
package_config: ^2.0.0
path: ^1.3.0
pub_semver: ^2.0.0
Expand Down
34 changes: 34 additions & 0 deletions test/end2end/model_test.dart
Expand Up @@ -6,6 +6,7 @@ library dartdoc.model_test;

import 'dart:io';

import 'package:analyzer/source/line_info.dart';
import 'package:async/async.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/markdown_processor.dart';
Expand Down Expand Up @@ -3541,6 +3542,39 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
classB = exLibrary.classes.singleWhere((c) => c.name == 'B');
});

test('always has a valid location', () {
void expectValidLocation(CharacterLocation location) {
expect(location.lineNumber, greaterThanOrEqualTo(0));
expect(location.columnNumber, greaterThanOrEqualTo(0));
}

;
var simpleProperty =
fakeLibrary.properties.firstWhere((p) => p.name == 'simpleProperty');
expectValidLocation(simpleProperty.getter.characterLocation);
expectValidLocation(simpleProperty.setter.characterLocation);
expectValidLocation(onlyGetterGetter.characterLocation);
expectValidLocation(onlySetterSetter.characterLocation);

Iterable<Accessor> _expandAccessors(Field f) sync* {
if (f.hasGetter) yield f.getter;
if (f.hasSetter) yield f.setter;
}

// classB has a variety of inherited and partially overridden fields.
// All should have valid locations on their accessors.
for (var a in classB.allFields.expand(_expandAccessors)) {
expectValidLocation(a.characterLocation);
}

// Enums also have fields and have historically had problems.
var macrosFromAccessors =
fakeLibrary.enums.firstWhere((e) => e.name == 'MacrosFromAccessors');
for (var a in macrosFromAccessors.allFields.expand(_expandAccessors)) {
expectValidLocation(a.characterLocation);
}
});

test('are available on top-level variables', () {
expect(onlyGetterGetter.name, equals('justGetter'));
expect(onlyGetterSetter, isNull);
Expand Down
4 changes: 2 additions & 2 deletions test/mustachio/aot_compiler_builder_test.dart
Expand Up @@ -2,7 +2,7 @@
// 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.

@Timeout.factor(2)
@Timeout.factor(4)
import 'dart:convert';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/build.dart';
Expand Down Expand Up @@ -77,7 +77,7 @@ import 'package:mustachio/annotations.dart';
expect(
renderersLibrary.getTopLevelFunction('_renderFoo_partial_foo_header_0'),
isNotNull);
});
}, timeout: Timeout.factor(2));

test('builds a public API render function', () async {
writer = InMemoryAssetWriter();
Expand Down

0 comments on commit 191839d

Please sign in to comment.