Skip to content
Merged
9 changes: 7 additions & 2 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ abstract class ModelElement
}
}

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

Expand Down Expand Up @@ -748,8 +754,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
58 changes: 58 additions & 0 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3801,6 +3801,64 @@ 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('@visibleForTesting annotation hides element from docs', () {
expect(exLibrary.functions.named('testingMethod').isPublic, false);

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

expect(
exLibrary.classes
.named('Apple')
.instanceMethods
.named('testMethod')
.isPublic,
isFalse);

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

test('type arguments are correct', () {
var modelType = mapWithDynamicKeys.modelType as ParameterizedElementType;
expect(modelType.typeArguments, hasLength(2));
Expand Down
30 changes: 29 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, visibleForTesting;

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

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

/// top level testing function
@visibleForTesting
String testingMethod() => '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 +130,14 @@ class Apple {

/// @nodoc no docs
int? notDocumented;

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

/// No public docs for this
@visibleForTesting
int? testField

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

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

/// No public docs for this
@visibleForTesting
void testMethod() {}

void paramFromExportLib(Helper helper) {}

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

@override
void abstractMethod() {}

@override void internalMethod() {}

@override void testMethod() {}
}

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