New - Apex Class dialog validation based on selected template and user-provided name
Issue #1946
new
The New Apex class provides the ability to select a template and choose file name.
Is it possible to present a confirmation dialog that would ensure that the correct class template is selected judging by class name entered (there are cases that in a hurry the class template is not changed, so it defaults to “Class“)?
- If the class name ends with “…Exception” and selected template is not an “Exception Class“.
- If class name ends with “…Test“ or starts with “Test…“, and the selected template is not a “Unit Test Class”.
The confirmation dialog can say something like “We’ve detected that you probably want to use an ‘supposed_class_template' instead of the ‘actual_template_selected’ you’ve selected. Do you want to use the 'supposed_class_template' instead?“ (Yes/No).
Comments (6)
-
repo owner -
repo owner - removed version
Another user logged something similar recently. Need to find that one and merge them.
-
repo owner Issue
#2546was marked as a duplicate of this issue. -
repo owner - changed component to Code Generation
-
repo owner - changed title to New - Apex Class dialog validation based on selected template and user-provided name
-
repo owner - changed component to File Templates
- Log in to comment
Ah, this is a nice idea! The "must end with Exception" rule matches Apex and can certainly be added. The "must start or end with Test" is a bit trickier as that is a convention rather than a rule, and I know of several teams that don't apply that convention. Minimally that validation would need to be optional, or potentially even configurable in terms of the expected pattern. I can imagine that folks might want to add their own validation rules for custom templates, e.g., a trigger handler template must end with
TriggerHandler
.Let me chew on this a bit and see if I can figure out a good way to implement it, but I really like the idea because I've certainly used the wrong template myself in the past... Thanks for the suggestion!