findClassNameByMethodName function

JSONString findClassNameByMethodName(
  1. String filePath,
  2. String methodName
)

Implementation

JSONString findClassNameByMethodName(String filePath, String methodName) {
  final file = File(filePath);
  if (!file.existsSync()) {
    throw Exception('File not found: $filePath');
  }

  final content = file.readAsStringSync();
  final result = parseString(
    content: content,
    featureSet: FeatureSet.latestLanguageVersion(),
    throwIfDiagnostics: false,
  );

  final unit = result.unit;
  final visitor = _ClassFinderVisitor(methodName);
  unit.accept(visitor);

  return visitor.foundClassName ?? "";
}