1

我正在尝试创建一个 JavaUI.createTypeDialog() 来限制用户只选择属于特定接口的类型。我怎么能这样做?

4

1 回答 1

2

此答案显示了如何获取特定类型的类型层次结构。您可以使用类似的处理来获取接口的 TypeHierarchy,然后使用结果类型填充列表。

IProject project; //currently selected project

//get the java project and locate the interface type
JavaProject javaProject = JavaCore.create(project);
IType myInterface = 
    javaProject.findType("MyInterface","name.seller.rich");

//get the sub types from the interface's type hierarchy
ITypeHierarchy hierarchy =
    myInterface .newTypeHierarchy(new NullProgressMonitor());

IType[] subTypes = hierarchy.getAllSubtypes(myInterface );

//do something with the sub types
...
于 2009-09-25T14:27:02.673 回答