New - Apex Class dialog validation based on selected template and user-provided name

Issue #1946 new
Dmytro Kurylo created an issue

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“)?

  1. If the class name ends with “…Exception” and selected template is not an “Exception Class“.
  2. 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)

  1. Scott Wells repo owner

    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!

  2. Scott Wells repo owner
    • removed version

    Another user logged something similar recently. Need to find that one and merge them.

  3. Log in to comment