intellij注释模板
如上所述这里 ,的IntelliJ的现场模板可以让你轻松地插入预定义的代码片段到你的源代码。
我在下面发布了一些我最常用的模板,链接到我在GitHub上的模板文件的完整列表(作为设置新IntelliJ环境时的参考),以及将IntelliJ设置文件添加到GitHub所采取的步骤。
例如,我设置了一个模板,以便可以键入test并单击tab,它将为我插入以下JUnit代码片段:
@Test
public void $NAME$() {$END$
}
这是一种JUnit测试方法,最初将光标放在“ public void”之后,可以键入测试名称。 然后,光标跳到{}之间,准备开始编写测试。
IntelliJ模板存储在以下位置的user.xml文件中:
~/Library/Preferences/<product name><version number>/templates
例如,对于IntelliJ13,它是
~/Library/Preferences/IntelliJIdea13/templates/user.xml
下面列出了我的其他一些模板,触发器以粗体显示。
为了可以在任何IntelliJ(例如工作和家庭)上使用这些模板,我在GitHub的此处检查了完整的列表。
之前
@Before
public void setup() {$END$
}
后
@After
public void tearDown() {$END$
}
yi
fail("Not yet implemented");
聚甲醛
public void $NAME$() {$END$
}
主要
public static void main(String[] args){$END$
}
我采取的将IntelliJ设置添加到GitHub的步骤
首先,我在GitHub上通过https://github.com/sabram/IntelliJ设置了一个新仓库。
然后,我遵循了这个StackOverflow帖子中有关如何将现有非空目录转换为Git工作目录的说明 :
cd ~/Library/Preferences/IntelliJIdea13
git init
git add templates/user.xml
git commit -m 'initial version of IntelliJ user.xml'
git remote add myIntelliJRepo https://github.com/sabram/IntelliJ.git
在这一点上,我遇到一个错误,提示我需要先进行git pull。 但是当我做一个
git pull saIntelliJ
我说错了
You asked to pull from the remote 'saIntelliJ', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
因此,我根据此发布内容对.git / config进行了编辑,以包括
[branch "master"]
remote = saIntelliJ
merge = refs/heads/master
然后我就可以
git pull saIntelliJ
git push -u saIntelliJ master
成功,并且可以继续使用git pull和git push,而无需每次都指定存储库名称(saIntelliJ)。
翻译自: https://www.javacodegeeks.com/2014/04/live-templates-in-intellij.html
intellij注释模板