Skip to content

Commit 8b22cc7

Browse files
committed
Don't document elements with @internal or @visibleForTesting
1 parent e4f9451 commit 8b22cc7

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

lib/src/model/model_element.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ abstract class ModelElement
429429
}
430430
}
431431

432+
if (element.isInternal) {
433+
return false;
434+
}
435+
if (element.isVisibleForTesting) {
436+
return false;
437+
}
432438
return !element.hasPrivateName && !hasNodoc;
433439
}();
434440

@@ -748,8 +754,7 @@ abstract class ModelElement
748754
late final List<Parameter> parameters = () {
749755
final e = element;
750756
if (!isCallable) {
751-
throw StateError(
752-
'$e (${e.runtimeType}) cannot have parameters');
757+
throw StateError('$e (${e.runtimeType}) cannot have parameters');
753758
}
754759

755760
final List<FormalParameterElement> params;

test/end2end/model_test.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,64 @@ String? topLevelFunction(int param1, bool param2, Cool coolBeans,
38013801
equals('Setter docs should be shown.'));
38023802
});
38033803

3804+
test('@internal annotation hides element from docs', () {
3805+
expect(exLibrary.properties.named('topLevelInternal').isPublic, false);
3806+
3807+
expect(
3808+
exLibrary.classes
3809+
.named('Apple')
3810+
.allFields
3811+
.named('internalField')
3812+
.isPublic,
3813+
isFalse);
3814+
3815+
expect(
3816+
exLibrary.classes
3817+
.named('Apple')
3818+
.instanceMethods
3819+
.named('internalMethod')
3820+
.isPublicAndPackageDocumented,
3821+
isFalse);
3822+
3823+
// The overridden method is not internal, and thus exposed.
3824+
expect(
3825+
exLibrary.classes
3826+
.named('B')
3827+
.instanceMethods
3828+
.named('internalMethod')
3829+
.isPublicAndPackageDocumented,
3830+
isTrue);
3831+
});
3832+
3833+
test('@visibleForTesting annotation hides element from docs', () {
3834+
expect(exLibrary.functions.named('testingMethod').isPublic, false);
3835+
3836+
expect(
3837+
exLibrary.classes
3838+
.named('Apple')
3839+
.allFields
3840+
.named('testField')
3841+
.isPublic,
3842+
isFalse);
3843+
3844+
expect(
3845+
exLibrary.classes
3846+
.named('Apple')
3847+
.instanceMethods
3848+
.named('testMethod')
3849+
.isPublic,
3850+
isFalse);
3851+
3852+
// The overridden method is not internal, and thus exposed.
3853+
expect(
3854+
exLibrary.classes
3855+
.named('B')
3856+
.instanceMethods
3857+
.named('testMethod')
3858+
.isPublic,
3859+
isTrue);
3860+
});
3861+
38043862
test('type arguments are correct', () {
38053863
var modelType = mapWithDynamicKeys.modelType as ParameterizedElementType;
38063864
expect(modelType.typeArguments, hasLength(2));

testing/test_package/lib/example.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:test_package_imported/main.dart';
1313

1414
export 'package:args/args.dart' show ArgParser;
1515
export 'dart:core' show deprecated, Deprecated;
16-
import 'package:meta/meta.dart' show protected, factory;
16+
import 'package:meta/meta.dart' show protected, factory, internal, visibleForTesting;
1717

1818
export 'fake.dart' show Cool, ClassTemplateOneLiner;
1919
export 'src/mylib.dart' show Helper;
@@ -30,6 +30,14 @@ const String COMPLEX_COLOR = 'red' + '-' + 'green' + '-' + 'blue';
3030
/// @nodoc
3131
const DO_NOT_DOCUMENT = 'not documented';
3232

33+
/// top level internal variable
34+
@internal
35+
final topLevelInternal = 'not documented';
36+
37+
/// top level testing function
38+
@visibleForTesting
39+
String testingMethod() => 'not documented'
40+
3341
/// This is the same name as a top-level const from the fake lib.
3442
const incorrectDocReference = 'same name as const from fake';
3543

@@ -122,6 +130,14 @@ class Apple {
122130

123131
/// @nodoc no docs
124132
int? notDocumented;
133+
134+
/// No public docs for this
135+
@internal
136+
int? internalField
137+
138+
/// No public docs for this
139+
@visibleForTesting
140+
int? testField
125141

126142
///Constructor
127143
Apple();
@@ -164,6 +180,14 @@ class Apple {
164180
* @nodoc method not documented
165181
*/
166182
void notAPublicMethod() {}
183+
184+
/// No public docs for this
185+
@internal
186+
void internalMethod() {}
187+
188+
/// No public docs for this
189+
@visibleForTesting
190+
void testMethod() {}
167191

168192
void paramFromExportLib(Helper helper) {}
169193

@@ -236,6 +260,10 @@ class B extends Apple with Cat {
236260

237261
@override
238262
void abstractMethod() {}
263+
264+
@override void internalMethod() {}
265+
266+
@override void testMethod() {}
239267
}
240268

241269
/// Reference to nullable type: [Apple?] and null-checked variable [myNumber!].

0 commit comments

Comments
 (0)