为类成员创建eclipse模板 [英] Create eclipse template for class members

查看:168
本文介绍了为类成员创建eclipse模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以如果我申报私人会员,例如

So if I declare a private member such as

private MyObject test;

我想创建一个将以以下格式生成代码的模板

I want to create a template that will generate code in the following format

public MyObject retrieveAllMyObjects() {
    return test.findAll();
}

我一直在弄乱模板,但我甚至无法弄清楚如何激活模板。当我做Ctrl + Space我只是没有模板提案消息

I have been messing around with the templates but I can't even figure out how to activate the templates. when I do the Ctrl+Space i just get no template proposals message

public ${return_type} retrieveAll${field}s() {

}

显然这只是一个起点,我是只是试图看看我是否可以得到eclipse来生成这个,然后我会从那里去,但没有这样的运气。我的模板不会显示在任何地方。使用的上下文是Java类型成员我做错了什么?

Obviously this is just a starting point, i was just trying to see if i could get eclipse to generate this and then I would go from there, but no such luck. My template doesn't show up anywhere. The context im using is "Java Type Members" what am I doing wrong??

推荐答案

也许你对这个解决方案感到满意:

Maybe you are happy with this solution:

private ${type} ${name};

public ${type} retrieveAll${type}s() {
    return  ${name}.findAll();
}

如何使用它:


  1. 设置名称为retrieveAll的代码模板

  2. 转到你的课程

  3. 输入'ret '

  4. 点击< ctrl> +< space>

  5. select retrieveAll

  6. < Enter>

  7. 键入所需的类型,例如字符串

  8. < Tab>

  9. 键入所需的字段名称,测试

  10. < Enter>

  1. Set up a code template with name 'retrieveAll'
  2. Go to your class
  3. type 'ret'
  4. hit <ctrl>+<space>
  5. select retrieveAll
  6. <Enter>
  7. type your desired Type, e.g. String
  8. <Tab>
  9. type your desired field name, e.g. test
  10. <Enter>

这篇关于为类成员创建eclipse模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆