Skip to content

Don't document elements with @internal #4048

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ abstract class ModelElement
}
}

if (element.isInternal) {
return false;
}
return !element.hasPrivateName && !hasNodoc;
}();

Expand Down Expand Up @@ -748,8 +751,7 @@ abstract class ModelElement
late final List<Parameter> parameters = () {
final e = element;
if (!isCallable) {
throw StateError(
'$e (${e.runtimeType}) cannot have parameters');
throw StateError('$e (${e.runtimeType}) cannot have parameters');
}

final List<FormalParameterElement> params;
Expand Down
29 changes: 29 additions & 0 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3801,6 +3801,35 @@ String? topLevelFunction(int param1, bool param2, Cool coolBeans,
equals('Setter docs should be shown.'));
});

test('@internal annotation hides element from docs', () {
expect(exLibrary.properties.named('topLevelInternal').isPublic, false);

expect(
exLibrary.classes
.named('Apple')
.allFields
.named('internalField')
.isPublic,
isFalse);

expect(
exLibrary.classes
.named('Apple')
.instanceMethods
.named('internalMethod')
.isPublicAndPackageDocumented,
isFalse);

// The overridden method is not internal, and thus exposed.
expect(
exLibrary.classes
.named('B')
.instanceMethods
.named('internalMethod')
.isPublicAndPackageDocumented,
isTrue);
});

test('type arguments are correct', () {
var modelType = mapWithDynamicKeys.modelType as ParameterizedElementType;
expect(modelType.typeArguments, hasLength(2));
Expand Down
18 changes: 17 additions & 1 deletion testing/test_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:test_package_imported/main.dart';

export 'package:args/args.dart' show ArgParser;
export 'dart:core' show deprecated, Deprecated;
import 'package:meta/meta.dart' show protected, factory;
import 'package:meta/meta.dart' show protected, factory, internal;

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

/// top level internal variable
// ignore: invalid_internal_annotation
@internal
final topLevelInternal = 'not documented';

/// This is the same name as a top-level const from the fake lib.
const incorrectDocReference = 'same name as const from fake';

Expand Down Expand Up @@ -122,6 +127,10 @@ class Apple {

/// @nodoc no docs
int? notDocumented;

/// No public docs for this
@internal
int? internalField;

///Constructor
Apple();
Expand Down Expand Up @@ -164,6 +173,11 @@ class Apple {
* @nodoc method not documented
*/
void notAPublicMethod() {}

/// No public docs for this
// ignore: invalid_internal_annotation
@internal
void internalMethod() {}

void paramFromExportLib(Helper helper) {}

Expand Down Expand Up @@ -236,6 +250,8 @@ class B extends Apple with Cat {

@override
void abstractMethod() {}

@override void internalMethod() {}
}

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