为Eclipse编写Java加法器移除程序、方法代码模板
我有太多时间需要为列表编写加法器/移除器方法:为Eclipse编写Java加法器移除程序、方法代码模板,eclipse,code-templates,Eclipse,Code Templates,我有太多时间需要为列表编写加法器/移除器方法: public void addSomething(Something something){ somethings.add(something); } public void removeSomething(Something something){ somethings.remove(something); } 如果我做对了,那么Eclipse模板可以支持自动完成。。。例如,如果我有: Vector<Something&
public void addSomething(Something something){
somethings.add(something);
}
public void removeSomething(Something something){
somethings.remove(something);
}
如果我做对了,那么Eclipse模板可以支持自动完成。。。例如,如果我有:
Vector<Something> somethings=new Vector<Something>();
当我键入“添加”+(Ctrl+空格)时
你知道怎么做吗。。。也许可以给我指一本关于这类主题的阅读材料
**更新**
好吧,这就是我到目前为止得到的:
public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection}.add(${varName});
}
但问题是,如果我键入“添加”+(Ctrl+Space):
在类级别,集合被声明为字段,我得到一个空变量作为集合
public final void addtype(type type) {
collection.add(type);
}
public final void addtype(type type) {
collection.add(type);
}
在方法级别,集合被声明为字段,我得到一个空变量作为集合
public final void addtype(type type) {
collection.add(type);
}
public final void addtype(type type) {
collection.add(type);
}
在方法级别,集合引用是方法的局部变量,我得到了正确的语法,但是add方法在另一个方法中
public void method(...) {
public final void addSomething(Something something) {
this.somethings.add(something);
}
}
这意味着我没有获得字段级引用,我如何获得它
**更新2**
这也给出了相同的结果:
public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.add(${varName});
}
public final void remove${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.remove(${varName});
}
谢谢
Adam.您可以在中阅读有关可用模板变量的信息。您应该基于Eclipse中的现有模板设计模板,请参阅Eclipse中的“模板视图”。我建议您使用
Source>生成委托方法,这样您就不必为要生成的每个方法编写模板
每当您声明对象时,为生成委托方法
分配热键
List<Integer> integer = new ArrayList<Integer>();| <- your cursor
List integer=new ArrayList();| 我最终使用了以下内容:
public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.add(${varName});
}
public final void remove${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.remove(${varName});
}
我在一个方法中创建了它,并将其剪切到类级别…:) 好朋友,但不是我想要的。。。我想要的东西能完成100%的工作,而不是70%。:)谢谢,请看我的更新。我还想要一个不同的名字“addSomething(Something s)”,而不仅仅是add(Something s);这不是很清楚,尽管最后它提供了相当多的信息。