protected boolean shouldScanFile()

in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/java/KafkaScanner.java [126:176]


    protected boolean shouldScanFile(Path file) {
        // Priority 1: Filename convention (fastest check, no I/O)
        String fileName = file.getFileName().toString();
        if (fileName.endsWith("Listener.java") ||
            fileName.endsWith("Consumer.java") ||
            fileName.endsWith("Producer.java") ||
            fileName.endsWith("MessageHandler.java") ||
            fileName.contains("Kafka") ||
            (fileName.contains("Config") && fileName.endsWith(".java"))) {
            log.debug("Including file by naming convention: {}", fileName);
            return true;
        }

        // Skip test files unless they contain Kafka patterns
        String filePath = file.toString();
        boolean isTestFile = filePath.contains("/test/") || filePath.contains("\\test\\");

        try {
            String content = readFileContent(file);

            // Priority 2-5: Check for Kafka imports, annotations, and classes
            boolean hasApacheKafkaImport = content.contains("org.apache.kafka");
            boolean hasSpringKafkaImport = content.contains("org.springframework.kafka");
            boolean hasKafkaAnnotations =
                content.contains("@KafkaListener") ||
                content.contains("@EnableKafka") ||
                content.contains("@SendTo");
            boolean hasKafkaClasses = content.contains("KafkaTemplate");

            boolean hasKafkaPatterns = hasApacheKafkaImport || hasSpringKafkaImport ||
                                      hasKafkaAnnotations || hasKafkaClasses;

            if (hasKafkaPatterns) {
                log.debug("Including file with Kafka patterns: {} (apacheImport={}, springImport={}, annotations={}, classes={})",
                    fileName, hasApacheKafkaImport, hasSpringKafkaImport, hasKafkaAnnotations, hasKafkaClasses);
            } else {
                log.debug("Skipping file without Kafka patterns: {}", fileName);
            }

            // For test files, require Kafka patterns
            // For non-test files, allow if they have Kafka patterns
            if (isTestFile) {
                return hasKafkaPatterns;
            }

            return hasKafkaPatterns;
        } catch (IOException e) {
            log.debug("Failed to read file for pre-filtering: {}", file);
            return false;
        }
    }