开发者

Can I use Eclipse JDT to create new 'working copies' of source files in memory only?

开发者 https://www.devze.com 2022-12-13 19:42 出处:网络
I\'m using Eclipse JDT to build a Java refactoring platform, for exploring different refactorings in memory before choosing one and saving it. I can create collections of working copies of the source

I'm using Eclipse JDT to build a Java refactoring platform, for exploring different refactorings in memory before choosing one and saving it. I can create collections of working copies of the source files, edit them in memory, and commit the changes to disk using the JDT framework.

However, I also want to generate new 'working copy' source files in memory as part of refactorings, and only create the corresponding real source file if I commit the working copy. I have seen various hints that this is possible, e.g. http://www.jarvana.com/jarvana/view/org/eclipse/jdt/doc/isv/3.3.0-v20070613/isv-3.3.0-v20070613.jar!/guide/jdt_api_manip.htm says "Note that the compilation unit does not need to exist in the Java model in order for a working copy to be created".

So far I have only been able to create a new real file, i.e.

ICompilationUnit newICompilationUnit = myPackage.createCompilationUnit(newName, "package piffle; public class Baz{private int i=0;}", false, null);

This is 开发者_如何学编程not what I want. Does anyone know how to create a new 'working copy' source file, that does not appear in my file system until I commit it? Or any other mechanism to achieve the same thing?


This might be not complete solution to your problem but Eclipse handles resources via EFS (extensible file system layer). Implementations of file systems are pluggable. So you may create link in your workspace that points to a in-memory file system and eclipse will show these resources as any other so you can edit, compile them or do whatever you usually do with files in Eclipse. Except that these files will not survive Eclipse restarts.

Other option might be implementing your own file system that can commit and rollback at will. But this route might be overkill.

Here is how to create resource link in workspace

Here is implementation of in-memory file system (note that source have to be checked out from CVS and the path in repository on that page is outdated - use CVS browser to find right path).

Note that EFS implementation is chosen on URI scheme name so to point to memory FS you should start target URI of link with "memory:".


You can have a look at this link http://wiki.eclipse.org/index.php/EFS#UI_Examples:_Zip_and_Memory_file_systems

There you'll find a sample implementation of a in memory EFS.

0

精彩评论

暂无评论...
验证码 换一张
取 消