0

我开发了 PDT 插件的扩展。我只需要带有接口的对话框(而不是类)。基本代码如下所示:

OpenTypeSelectionDialog2 dialog = new OpenTypeSelectionDialog2(
    DLTKUIPlugin.getActiveWorkbenchShell(), 
    multi, 
    PlatformUI.getWorkbench().getProgressService(), 
    null, 
    type, 
    PHPUILanguageToolkit.getInstance());

它工作正常,但我将类和接口放在一起(类型变量)。有什么方法可以过滤吗?我在 PDT 中找不到这种机制,但可以正确识别类和接口(名称旁边的图标)。

4

1 回答 1

0

我不知道它是否是最好的解决方案,但它有效。

int falseFlags = 0;
int trueFlags = 0;

IDLTKSearchScope scope = SearchEngine.createSearchScope(getScriptFolder().getScriptProject());

trueFlags = PHPFlags.AccInterface;

OpenTypeSelectionDialog2 dialog = new OpenTypeSelectionDialog2(
    DLTKUIPlugin.getActiveWorkbenchShell(), 
    multi,
    PlatformUI.getWorkbench().getProgressService(), 
    scope, 
    IDLTKSearchConstants.TYPE,
    new PHPTypeSelectionExtension(trueFlags, falseFlags), 
    PHPUILanguageToolkit.getInstance());

PHPTypeSelectionExtension 看起来像这样:

public class PHPTypeSelectionExtension extends TypeSelectionExtension {

/**
 * @see PHPFlags
 */
private int trueFlags = 0;
private int falseFlags = 0;

public PHPTypeSelectionExtension() {
}

public PHPTypeSelectionExtension(int trueFlags, int falseFlags) {
    super();
    this.trueFlags = trueFlags;
    this.falseFlags = falseFlags;
}

@Override
public ITypeInfoFilterExtension getFilterExtension() {
    return new ITypeInfoFilterExtension() {
        @Override
        public boolean select(ITypeInfoRequestor typeInfoRequestor) {
            if (falseFlags != 0 && (falseFlags & typeInfoRequestor.getModifiers()) != 0) {

                // Try to filter by black list.
                return false;
            } else if (trueFlags == 0 || (trueFlags & typeInfoRequestor.getModifiers()) != 0) {

                // Try to filter by white list, if trueFlags == 0 this is fine 'couse we pass black list.
                return true;
            } else {

                // Rest is filter out.
                return false;
            }
        }
    };
}

@SuppressWarnings("restriction")
@Override
public ISelectionStatusValidator getSelectionValidator() {
    return new TypedElementSelectionValidator(new Class[] {IType.class, INamespace.class}, false);
}

}
于 2012-10-06T12:37:42.867 回答