<extension
point="org.eclipse.ui.editors.templates">
<contextType
name="java"
class="org.eclipse.jdt.internal.corext.template.java.JavaContextType"
id="java">
</contextType>
<include
file="templates/default-templates.xml"
translations="$nl$/templates/default-templates.properties">
</include>
<include
file="templates/default-codetemplates.xml"
translations="$nl$/templates/default-templates.properties">
</include>
<include
file="templates/default-swttemplates.xml"
translations="$nl$/templates/default-templates.properties">
</include>
<resolver
class="org.eclipse.jdt.internal.corext.template.java.ExceptionVariableNameResolver"
contextTypeId="java"
description="%templates.java.resolvers.ExceptionVariableName.description"
name="%templates.java.resolvers.ExceptionVariableName.name"
type="exception_variable_name">
</resolver>
</extension>
在写java代码的时候,我们写sysout然后按alt+?就会自动出现System.out.println();
这个功能就是通过上面的扩展点完成的,我们也可以自定义这样的功能。
打开模板会看到sysout对应的是System.out.println(${word_selection}${});${cursor},${}里面是变量都是通过resolver扩展点或者contextType内部的addResolver添加进来的,resolver通过contextTypeId与相应的contextType对应,在运行时把变量换成具体的值。tamplate里面定义的都被保存到include的文件里面