Is there a Eclipse template variable for short ver

2019-06-28 05:37发布

I would like to create a constructor template in Eclipse for Java classes. I've got a version that works for most classes. Although it doesn't work for classes nested in other classes. (see class Inner below) How do I get the short version of the class name?

Not working template

public ${newType:enclosing_type}() {
    ${cursor}
}

Example failing class

public class Outer {
    public class Inner {
        // Current template expands to the following
        public Outer.Inner() {
        }
    }
}

1条回答
做个烂人
2楼-- · 2019-06-28 06:21

I checked on Indigo. You can't. Your only option, as far as i know, is to introduce a new variable in template list in order to get inner class name without the outer class(es) name(s).

If you accept the effort of writing a bit of code (read plugin) to get your goal, you can start from:

or if you are lazy like me, you can start downloading this project: https://github.com/aabeling/template-variables and customizing it as your needs.

查看更多
登录 后发表回答