in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/dotnet/util/CSharpAstParser.java [410:457]
private static List<DotNetAst.Method> extractMethodsRegex(String classBody) {
List<DotNetAst.Method> methods = new ArrayList<>();
// Split by lines to better handle attributes
String[] lines = classBody.split("\n");
List<DotNetAst.Attribute> currentAttributes = new ArrayList<>();
for (int i = 0; i < lines.length; i++) {
String line = lines[i].trim();
// Check if line contains an attribute
if (line.startsWith("[") && line.contains("]")) {
Pattern attrPattern = Pattern.compile("\\[(\\w+)(?:\\(([^)]*)\\))?\\]");
Matcher attrMatcher = attrPattern.matcher(line);
while (attrMatcher.find()) {
String attrName = attrMatcher.group(1);
String args = attrMatcher.group(2);
List<String> argList = args != null && !args.trim().isEmpty() ?
List.of(args) : List.of();
currentAttributes.add(new DotNetAst.Attribute(attrName, argList));
}
continue;
}
// Check if line contains a method declaration
// Support: public [static] [async] [virtual|override] ReturnType MethodName(params)
Pattern methodPattern = Pattern.compile(
"public\\s+(?:static\\s+)?(?:async\\s+)?(?:virtual\\s+|override\\s+)?(\\w+(?:<[^>]+>)?)\\s+(\\w+)\\s*\\(([^)]*)\\)"
);
Matcher matcher = methodPattern.matcher(line);
if (matcher.find()) {
String returnType = matcher.group(1);
String name = matcher.group(2);
String params = matcher.group(3);
List<DotNetAst.Parameter> parameters = extractParameters(params);
methods.add(new DotNetAst.Method(name, returnType, parameters, new ArrayList<>(currentAttributes)));
currentAttributes.clear();
} else if (!line.isEmpty() && !line.startsWith("//") && !line.startsWith("/*")) {
// Non-empty, non-comment line that's not an attribute or method - clear attributes
if (!line.startsWith("[")) {
currentAttributes.clear();
}
}
}
return methods;
}