private String findNextFunctionDefinition()

in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/python/FastAPIScanner.java [348:389]


    private String findNextFunctionDefinition(List<String> lines, int startIndex) {
        for (int i = startIndex; i < Math.min(startIndex + MAX_FUNCTION_SEARCH_LINES, lines.size()); i++) {
            String line = lines.get(i).trim();
            // Check for both "def" and "async def"
            if (line.startsWith(FUNCTION_PREFIX) || line.startsWith(ASYNC_FUNCTION_PREFIX)) {
                // Check if this is a complete single-line function definition
                // Handle both ): and ) -> Type: patterns
                if (line.contains(")") && line.contains(":")) {
                    // Find the colon that ends the function signature (after the closing paren)
                    int colonIndex = findFunctionEndingColon(line);
                    if (colonIndex > 0) {
                        return line.substring(0, colonIndex + 1);
                    }
                }

                // Multi-line function definition - collect until we find : after )
                StringBuilder functionDef = new StringBuilder(line);
                boolean foundClosingParen = line.contains(")");

                for (int j = i + 1; j < Math.min(i + MAX_FUNCTION_SEARCH_LINES, lines.size()); j++) {
                    String nextLine = lines.get(j).trim();
                    functionDef.append(" ").append(nextLine);

                    if (!foundClosingParen && nextLine.contains(")")) {
                        foundClosingParen = true;
                    }

                    if (foundClosingParen && nextLine.contains(":")) {
                        // Found the end of the function signature
                        String fullDef = functionDef.toString();
                        int colonIndex = findFunctionEndingColon(fullDef);
                        if (colonIndex > 0) {
                            return fullDef.substring(0, colonIndex + 1);
                        }
                    }
                }
                // If we didn't find closing, return null
                return null;
            }
        }
        return null;
    }