isTestSupportDeclaration function

bool isTestSupportDeclaration(
  1. AnnotatedNode node, [
  2. String? name
])

Checks if an element or AST node has test support annotations or conventions.

Checks for @visibleForTesting, @visibleForOverriding, @protected, or if name starts/ends with Fake or Mock.

Implementation

bool isTestSupportDeclaration(AnnotatedNode node, [String? name]) {
  final effectiveName = name ?? extractNodeName(node);
  if (effectiveName != null) {
    if (effectiveName.startsWith('Fake') ||
        effectiveName.startsWith('Mock') ||
        effectiveName.endsWith('Fake') ||
        effectiveName.endsWith('Mock')) {
      return true;
    }
  }

  return hasAnyAnnotation(node, const [
    'visibleForTesting',
    'VisibleForTesting',
    'visibleForOverriding',
    'VisibleForOverriding',
    'protected',
    'Protected',
  ]);
}