Skip to content

Commit 6391c68

Browse files
authored
Don't document elements with @internal (#4048)
Makes members with the `@internal` not part of the public interface. #2418
1 parent 2e124ad commit 6391c68

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

lib/src/model/model_element.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,12 @@ abstract class ModelElement
427427
}
428428
}
429429

430+
if (element.nonSynthetic2 case Annotatable(:var metadata2)) {
431+
if (metadata2.hasInternal) {
432+
return false;
433+
}
434+
}
435+
430436
return !element.hasPrivateName && !hasNodoc;
431437
}();
432438

test/end2end/model_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,35 @@ 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+
38043833
test('type arguments are correct', () {
38053834
var modelType = mapWithDynamicKeys.modelType as ParameterizedElementType;
38063835
expect(modelType.typeArguments, hasLength(2));

testing/test_package/lib/example.dart

Lines changed: 17 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;
1717

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

33+
/// top level internal variable
34+
// ignore: invalid_internal_annotation
35+
@internal
36+
final topLevelInternal = 'not documented';
37+
3338
/// This is the same name as a top-level const from the fake lib.
3439
const incorrectDocReference = 'same name as const from fake';
3540

@@ -122,6 +127,10 @@ class Apple {
122127

123128
/// @nodoc no docs
124129
int? notDocumented;
130+
131+
/// No public docs for this
132+
@internal
133+
int? internalField;
125134

126135
///Constructor
127136
Apple();
@@ -164,6 +173,11 @@ class Apple {
164173
* @nodoc method not documented
165174
*/
166175
void notAPublicMethod() {}
176+
177+
/// No public docs for this
178+
// ignore: invalid_internal_annotation
179+
@internal
180+
void internalMethod() {}
167181

168182
void paramFromExportLib(Helper helper) {}
169183

@@ -236,6 +250,8 @@ class B extends Apple with Cat {
236250

237251
@override
238252
void abstractMethod() {}
253+
254+
@override void internalMethod() {}
239255
}
240256

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

0 commit comments

Comments
 (0)