views:

108

answers:

2

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%5Fapi%5Fmanip.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?

A: 

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:".

Petr Gladkikh
A: 

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.

Dan Corneanu