简体   繁体   English

以编程方式修改Java源代码

[英]Modify Java source code programmatically


I used the EMF ANT-Task XSD2Java to generate Java code from an existing XSD.我使用 EMF ANT-Task XSD2Java 从现有的 XSD 生成 Java 代码。 Unfortunately the ANT-Task works not as correct as the manual tool and generates a package like 'org.example.interface.something'.不幸的是,ANT-Task 的工作方式不如手动工具正确,它会生成 package,如“org.example.interface.something”。 Thus the key-word 'interface' is not allowd as a package name I want to refactor it to make the code run.因此,不允许将关键字“接口”作为 package 名称我想重构它以使代码运行。 (btw doing it via the UI the package name is 'org.example.interface_.something') My question is: How to refactor the package name including dependencies in the source files? (顺便说一句,通过 UI package 名称是“org.example.interface_.something”)我的问题是:如何重构 package 名称,包括源文件中的依赖项? Can I use JDT and if, how?我可以使用 JDT,如果,如何使用? Thanks for any hints.感谢您的任何提示。
Kai

Right-click the package name in the package explorer.右键单击 package 资源管理器中的 package 名称。 Then from the menu click Refactor -> Rename.然后从菜单中单击重构 -> 重命名。

在此处输入图像描述

As tjameson suggested,正如 tjameson 建议的那样,

find -name *.java | 
xargs sed -i s/org.example.interface.something/org.example.interface_.something/g

will work?将工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM