Intellij new Java Class opening a different dialog than usual

前端 未结 2 543
旧时难觅i
旧时难觅i 2021-01-12 22:26

When creating a new java class via new -> Java Class while using IntelliJ IDE, a random Dialog started appearing, and I can\'t find how to

相关标签:
2条回答
  • 2021-01-12 23:16

    Go to Settings/File and Code Templates -> class and change it to:

    #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
    #parse("File Header.java")
    public class ${NAME} {
    }
    

    You can also try hitting the reset to default button, as Adrian Romanelli suggested.

    0 讨论(0)
  • 2021-01-12 23:19

    I too had the same problem, the exact same dialog. In my case, it actually ended up not being a bug, but IJ acting properly (kinda).

    TL;DR: The template code for creating a "Class" object got automagically changed after an IJ update so that it would prompt for answers from the coder when creating a new class file. Changing it back in "Settings/File and Code Templates" to the default template code removes the problem, as the default template code does not use any variables that are prompted for upon class object creation (ex.: ${IMPORT_BLOCK}).

    Long version ...

    Bring up the Settings dialog for IJ, and in the search field type "template", and then select the "File and Code Templates" option. You'll see on the right side of the dialog the "Editor > File and Code Templates" area. If you select "Class" from the list of template types, to the right of that list of template types you'll see the template used when you create a class ...

    Now I don't know why, but after a particular IJ update some months back, via their Toolbox app, the default template text/code was different, so that it looked like this ...

    ... and that latter template code/text caused the second dialog to appear that you see.

    To fix the problem, highlight the "Class" template from the list, then click on the "Reset to Default" button that appears below the Files/Includes/Code/Other tabs (looks like a piece of paper with a 180 degree curving arrow on top of it), so that the template text goes back to what I have showing in the first screenshot, and then select the OK button.

    Assuming your "default" template for the Class template is not corrupted/bad, you should no longer see the dialog that you asked about.

    0 讨论(0)
提交回复
热议问题