Live templates.
已回答
I have some questions about generating live templates.
1)
How can I have a live template for test classes that are created through the "Generate test class" action, from the mouse context menu?
The live template seems to be working when I manually create a new class from File-->New-->Java Class.
But not when I bring up the menu on a class name, and then select "Generate test class".
2). How can I create a live template for package-info.java? It doesn't seem to be generating it for that file.
请先登录再写评论。
Hello,
You may change the template for the generated test class in Preferences | Editor | File and Code Templates | Code | Junit5 Test Class.
and the template for package-info.java file can be modified here:
Thank you. That helped some.
But it's not doing the template how I want it to.
This was the template code:
// Copyright Blah blah blah
import static org.junit.jupiter.api.Assertions.*;
#parse("File Header.java")
class ${NAME} {
${BODY}
}
I want the test class to start with the "// Copyright Blah blah blah" line.
Instead, when it generated the test class, it put that line after the package line.
Hello Alakhotia,
You may create the copyright profile here: Preferences | Editor | Copyright | Copyright Profiles. And define it for particular scope here: Preferences | Editor | Copyright.
The copyright will be auto inserted when the file is generated.
I tried the copyright profile.
Here's what it outputs:
I don't want it to be in /* */ comments.
I want one line, like this:
// Copyright blah blah blah
Using Live Templates almost does this, except that for test classes and package-info, it's putting it after the package declaration, like I mentioned above.
Hello Alakhotia,
You may use "use line comment" setting in Preferences | Editor | Copyright | Formatting.
Thank you, I think I have gotten this to behave how I want it now.