如何使用Eclipse JDT Core重新定义导入 [英] How to redefine an import using Eclipse JDT Core

查看:159
本文介绍了如何使用Eclipse JDT Core重新定义导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个例子如何使用Eclipse JDT Core API重新定义java源文件中的导入?

Does anyone have an example how to redefine an import in a java source file using the Eclipse JDT Core API?

我有以下(不起作用)这让我很生气。

I have the following (which does not work) and it's driving me mad.

try {
    for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
        if (root.getElementName().equals("src")) {
            for (ICompilationUnit unit : root.getPackageFragment("soap.service.implementation.strongProfile.delegate").getCompilationUnits()) {
                System.out.println(unit.getElementName());
                for (IImportDeclaration dec : unit.getImports()) {
                    dec.rename("soap.service.implementation.strongProfile.reader.HeadlineReader", true, null);
                }
            }
        }
    }
}catch(Exception e) {
    e.printStackTrace();
}

我得到的例外是:

Java Model Exception: Java Model Status [Invalid name specified: soap.service.implementation.strongProfile.reader.HeadlineReader]

我将导入名称粘贴到我的java源文件中,它很完美,它不会给我任何错误。任何帮助或指导将不胜感激。

I take the import name and paste it in to my java source file and it's perfect, it doesn't give me any errors. Any help or guidance would be appreciated.

推荐答案

原来这是Eclipse中的一个错误。

Turns out this is a bug in Eclipse.

这篇关于如何使用Eclipse JDT Core重新定义导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆