visitClassDeclaration method

  1. @override
void visitClassDeclaration(
  1. ClassDeclaration node
)
override

Implementation

@override
void visitClassDeclaration(ClassDeclaration node) {
  final className = node.name.lexeme;
  _currentContainer = className;

  final classSymbolId = SymbolNode.buildId(filePath, className);
  final isTestFile = filePath.startsWith('test/');

  graph.addSymbol(SymbolNode(
    id: classSymbolId,
    filePath: filePath,
    symbolName: className,
    symbolType: 'class',
    isTest: isTestFile,
  ));

  final oldSymbolId = _currentSymbolId;
  _currentSymbolId = classSymbolId;

  if (node.extendsClause != null) {
    final superElement = node.extendsClause!.superclass.type?.element;
    final superId = _resolveElementSymbolId(superElement);
    if (superId != null) {
      graph.addInheritance(classSymbolId, superId);
    }
  }

  if (node.implementsClause != null) {
    for (final interfaceType in node.implementsClause!.interfaces) {
      final interfaceElement = interfaceType.type?.element;
      final interfaceId = _resolveElementSymbolId(interfaceElement);
      if (interfaceId != null) {
        graph.addInheritance(classSymbolId, interfaceId);
      }
    }
  }

  if (node.withClause != null) {
    for (final mixinType in node.withClause!.mixinTypes) {
      final mixinElement = mixinType.type?.element;
      final mixinId = _resolveElementSymbolId(mixinElement);
      if (mixinId != null) {
        graph.addInheritance(classSymbolId, mixinId);
      }
    }
  }

  super.visitClassDeclaration(node);
  _currentSymbolId = oldSymbolId;
  _currentContainer = null;
}