analyzeFile method

Future<DataFlowResult> analyzeFile({
  1. required String filePath,
  2. required int startLine,
  3. required int endLine,
  4. String methodName = '_extracted',
})

Analyzes a file on disk by file path and 1-based line bounds.

Implementation

Future<DataFlowResult> analyzeFile({
  required String filePath,
  required int startLine,
  required int endLine,
  String methodName = '_extracted',
}) async {
  final absPath = p.normalize(p.absolute(filePath));
  final file = File(absPath);
  if (!file.existsSync()) {
    throw FileSystemException('Target file does not exist', filePath);
  }

  final helper = AnalysisContextHelper(
    includedPaths: [absPath],
    sdkPath: sdkPath,
  );
  final unitResult = await helper.getRequiredResolvedUnit(absPath);

  return _analyzeResolvedUnit(
    unitResult: unitResult,
    filePath: filePath,
    startLine: startLine,
    endLine: endLine,
    methodName: methodName,
  );
}