如何使用 Eclipse 模板自动插入类符号?
有谁知道如何使用 Eclipse 模板在类签名上方插入“@RunWith 注解”?
例如:
@RunWith(Parameterized.class)
public class MyClassTest {
...
@Parameters
public static Collection<Object[]> parameters() {
List<Object[]> list = new ArrayList<Object[]>();
list.add(new Object[] { "mind!", "find!" });
list.add(new Object[] { "misunderstood", "understood" });
return list;
}
...
}
__
模板:
// TODO: move this '@RunWith(Parameterized.class)' to class anotation
@Parameters
public static Collection<Object[]> parameters() {
${type:elemType(collection)}<Object[]> parametersList = new ${type:elemType(collection)}<Object[]>();
${cursor}// TODO: populate collection
return parametersList;
}
__ 感谢您的帮助!
Does anybody know how to insert a "@RunWith anotation" above the class signature, using eclipse templates?
Ex.:
@RunWith(Parameterized.class)
public class MyClassTest {
...
@Parameters
public static Collection<Object[]> parameters() {
List<Object[]> list = new ArrayList<Object[]>();
list.add(new Object[] { "mind!", "find!" });
list.add(new Object[] { "misunderstood", "understood" });
return list;
}
...
}
__
Template:
// TODO: move this '@RunWith(Parameterized.class)' to class anotation
@Parameters
public static Collection<Object[]> parameters() {
${type:elemType(collection)}<Object[]> parametersList = new ${type:elemType(collection)}<Object[]>();
${cursor}// TODO: populate collection
return parametersList;
}
__ Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您无法使用 Eclipse 模板向现有的封闭类添加注释(至少据我所知是这样)。不过,有一个解决方法。下面是模板的修改版本:
要使用模板(假设其名为“Parameterized”):
Cntrl+Space
激活模板(您可能需要从模板列表中选择模板。我只有一个名为 Parameterized 的模板,因此 Eclipse 只使用它自动为我)。类定义将替换为包含
@RunWith
注释的定义。我使用 ${id:newName(reference)} 模板变量来使 Eclipse 自动添加所有必需的导入(的导入除外) ${baseCollectionType}
和${concreteCollectionType}
,您必须手动添加它们...谢天谢地Cntrl-Shift-M
)这真的很难描述。您必须尝试一下才能确切地了解它是如何工作的。如果我的指示需要澄清,请发表评论。
Unfortunately, you cannot use Eclipse templates to add an annotation to an existing enclosing class (at least, not that I know of). However, there is a workaround. Here is a modified version of your template:
To use the template (assuming its named "Parameterized"):
Cntrl+Space
to activate the template (you may have to select the template from the list of templates. I only have one template called Parameterized, so Eclipse just uses it automatically for me).The class definition will be replaced with a definition that includes the
@RunWith
annotation. I used the ${id:newName(reference)} template variable to cause Eclipse to automatically add all of the necessary imports (with the exception of the imports for${baseCollectionType}
and the${concreteCollectionType}
, you'll have to add those manually...thank goodness forCntrl-Shift-M
)This is really hard to describe. You'll have to try it to see exactly how it works. Post a comment if my instructions need to be clarified.