private FallbackParsingStrategy createFallbackStrategy()

in doc-architect/doc-architect-core/src/main/java/com/docarchitect/core/scanner/impl/dotnet/EntityFrameworkScanner.java [338:405]


    private FallbackParsingStrategy<EntityResult> createFallbackStrategy(Set<String> entityNames) {
        return (file, content) -> {
            List<EntityResult> results = new ArrayList<>();

            // Extract class name from content
            Matcher classMatcher = CLASS_PATTERN.matcher(content);
            if (!classMatcher.find()) {
                return results;
            }

            String className = classMatcher.group(1);

            // Only process if this is a known entity
            if (!entityNames.contains(className)) {
                return results;
            }

            // Extract properties using regex
            List<DataEntity.Field> fields = new ArrayList<>();
            List<Relationship> relationships = new ArrayList<>();

            Matcher propertyMatcher = PROPERTY_PATTERN.matcher(content);
            while (propertyMatcher.find()) {
                String type = propertyMatcher.group(1);
                String name = propertyMatcher.group(2);

                // Skip navigation properties
                if (type.startsWith(ICOLLECTION_TYPE) || type.startsWith(LIST_TYPE) || entityNames.contains(type)) {
                    // This is a navigation property - create relationship
                    if (type.startsWith(ICOLLECTION_TYPE) || type.startsWith(LIST_TYPE)) {
                        String targetEntity = extractGenericType(type);
                        if (targetEntity != null && entityNames.contains(targetEntity)) {
                            addRelationship(className, targetEntity, ONE_TO_MANY_DESCRIPTION, relationships);
                        }
                    } else if (entityNames.contains(type)) {
                        addRelationship(className, type, MANY_TO_ONE_DESCRIPTION, relationships);
                    }
                } else {
                    // Regular field
                    String sqlType = mapCSharpTypeToSql(type);
                    boolean nullable = type.contains("?");
                    fields.add(new DataEntity.Field(name, sqlType, nullable, null));
                }
            }

            // Try to find primary key
            String primaryKey = null;
            if (content.matches("(?s).*\\bpublic\\s+int\\s+Id\\s*\\{.*")) {
                primaryKey = "Id";
            } else if (content.matches("(?s).*\\bpublic\\s+int\\s+" + className + "Id\\s*\\{.*")) {
                primaryKey = className + "Id";
            }

            String tableName = toPlural(className);
            DataEntity entity = new DataEntity(
                className,
                tableName,
                ENTITY_TYPE,
                fields,
                primaryKey,
                "Entity Framework Entity: " + className
            );

            results.add(new EntityResult(entity, relationships));
            log.debug("Fallback parsing found entity: {} -> {}", className, tableName);
            return results;
        };
    }