ADFA-2456 | Add hierarchy validator for layout editor nesting rules#1100
ADFA-2456 | Add hierarchy validator for layout editor nesting rules#1100
Conversation
refactor: centralize drag-drop hierarchy handling in DesignEditor
📝 WalkthroughRelease Notes: Hierarchy Validator for Layout EditorNew Features
Technical Changes
Risks & Considerations
WalkthroughThe PR refactors drag-and-drop hierarchy incompatibility checking from inline Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/DesignEditor.kt (1)
275-287:⚠️ Potential issue | 🟠 MajorValidate against the final drop target for both insert and move flows.
On Line 331 the validator runs before Lines 347-348 can rewrite
parentfromDesignEditorto the real root container, so drops on the editor surface can be checked against the wrong parent. ThedraggedView == nullguard also means reparenting an existing widget still bypasses the new hierarchy rules entirely, even though Line 419 can place it under the same crash-prone parents. Please run the hierarchy check after the final parent is resolved and cover the existing-view path too; for moves, that likely means validating before Line 287 detaches the view or restoring the original parent when a drop is rejected.Also applies to: 328-349, 419-419
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/DesignEditor.kt` around lines 275 - 287, The drop validation currently runs against the initial 'parent' and skips existing-view moves (when 'draggedView' != null), so move drops can bypass final-hierarchy rules; change the flow in DesignEditor.kt so you resolve the real target container first (the code path that rewrites 'parent' to the actual root container) and then call the hierarchy validator (the same validation used for inserts) against that final parent for both insert and move flows; for moves, validate before calling parent.removeView(draggedView) or, if you must remove first, capture the original parent and restore it when validation fails so rejected drops do not leave the view detached.
🧹 Nitpick comments (1)
layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/validation/HierarchyValidator.kt (1)
25-109: Please pin this rule matrix with focused tests.This validator is now the source of truth for hierarchy safety, but the behavior depends on ordered rules plus string normalization (
cleanWidgetName()and thecontains(...)checks). A small parameterized test table covering each block/warn case and the*Design/ fully-qualified-name normalization paths would make future rule updates much safer.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/validation/HierarchyValidator.kt` around lines 25 - 109, Add a focused parameterized test suite that pins the HierarchyValidator rule matrix: write tests that call HierarchyValidator.validate(childClassName, parent) (or a small wrapper) covering each blockingRules and warningRules entry and their expected outcomes, including cases that exercise cleanWidgetName() normalization paths (plain class name, fully-qualified name, and names ending with "Design") and isCrashProneParent() variants (ToolbarDesign, FrameLayoutDesign, and scrollview-containing names); ensure tests assert rule ordering by checking that a blocking rule takes precedence over a warning when both would match and include explicit cases for drawerlayout/viewpager, list/grid/recyclerview inside vertical ScrollView, nested vertical ScrollView, and nested HorizontalScrollView.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/DesignEditor.kt`:
- Around line 275-287: The drop validation currently runs against the initial
'parent' and skips existing-view moves (when 'draggedView' != null), so move
drops can bypass final-hierarchy rules; change the flow in DesignEditor.kt so
you resolve the real target container first (the code path that rewrites
'parent' to the actual root container) and then call the hierarchy validator
(the same validation used for inserts) against that final parent for both insert
and move flows; for moves, validate before calling
parent.removeView(draggedView) or, if you must remove first, capture the
original parent and restore it when validation fails so rejected drops do not
leave the view detached.
---
Nitpick comments:
In
`@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/validation/HierarchyValidator.kt`:
- Around line 25-109: Add a focused parameterized test suite that pins the
HierarchyValidator rule matrix: write tests that call
HierarchyValidator.validate(childClassName, parent) (or a small wrapper)
covering each blockingRules and warningRules entry and their expected outcomes,
including cases that exercise cleanWidgetName() normalization paths (plain class
name, fully-qualified name, and names ending with "Design") and
isCrashProneParent() variants (ToolbarDesign, FrameLayoutDesign, and
scrollview-containing names); ensure tests assert rule ordering by checking that
a blocking rule takes precedence over a warning when both would match and
include explicit cases for drawerlayout/viewpager, list/grid/recyclerview inside
vertical ScrollView, nested vertical ScrollView, and nested
HorizontalScrollView.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 68c35241-5fd7-450c-ae80-b5ec23d38d11
📒 Files selected for processing (3)
layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/DesignEditor.ktlayouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/validation/HierarchyValidator.ktlayouteditor/src/main/res/values/strings.xml
Description
Introduced a dedicated
HierarchyValidatorto centralize drag-and-drop hierarchy checks in the layout editor.This change blocks only known crash-prone nestings, surfaces non-blocking warnings for problematic hierarchies, and removes the previous ad hoc compatibility logic from
DesignEditorto keep the flow cleaner and easier to extend.Details
Added
HierarchyResulthandling to distinguish between valid, warning, and invalid hierarchy outcomes.Also added a new warning string resource so the editor can notify users about potentially problematic nesting without preventing insertion.
document_5040066168199579336.mp4
Ticket
ADFA-2456
Observation
The new validator is intentionally crash-focused for blocking behavior, while still preserving user feedback for risky but non-fatal hierarchies.
The handling logic is now centralized, which should make future hierarchy rule updates safer and more maintainable.