我正在开发
Eclipse RCP应用程序,最近我开始在其中使用Groovy.所以99%的代码仍然是Java.
我读到可以使用Groovy覆盖并向Java类添加方法,我可以通过向java.lang.String添加一个方法来测试它.
但这仅在我在Groovy类中使用字符串时才有效.重写的方法不被视为在Java类中被重写.
这是一些代码:
/*
* This is a Java class
*/
public class CTabItem {
...
private API
...
public void setControl(Control control){
private API
}
}
/*
* This is also a Java class
*/
public class Control {
...
private API
...
}
/*
* This is also a Java class
*/
public class OtherClass {
...
private API
...
private void someMethodIDontKnow(){
Control control = new Control();
CTabItem tab = new CTabItem();
tab.setControl(control);
}
}
/*
* This is a Groovy class
*/
public class MyViewPart extends org.eclipse.ui.part.ViewPart {
....
public void createPartControl(Composite parent) {
/* parent (or the parent of parent) is a Control
which is set somewhere in a CTabItem to which
I don't get access */
}
}
我需要从控件中获取选项卡.但是,由于我不是谁实例化MyViewPart,而是一些私有API,我无法访问它.
Groovy能为我做些什么吗?欢迎任何建议或代码.谢谢!