1

Setting: I am doing a programming experiment where I need to display a different method signature (one line of code) to my test persons than the line of code actually exists. Example:

// this code should be visible
public def aFunction(def a, def b) {

// this line of code should be used
public void aFunction(String a, List<String> b) {

The intention is that everything works like when the source code included the second line (like code completion, errors etc.), but only the first line is visible. I've already tried patching the groovy editor I use and replacing some text on load and on save, but that just does not seem to do the job, using some code like

IDocument doc =this.getDocumentProvider().getDocument(this.getEditorInput()); doc.set(doc.get().replaceAll(...));

Sadly this leads to strange behavior like always marked as dirty files. I've also tried using the getCompilationUnit method that the groovy editor supplies, but somehow this does not help in any ways (maybe because the "wrong" code was still visible in the editor?).

Finally I tried to wrap the InputStream for the IFile underlying the IEditorInput in the doSetInput-method like

IFile resource = (IFile) input.getAdapter(IFile.class);
InputStream in = resource.getContents();
//...wrap stream
resource.setContents(in, false, true, null);

but this only leads to the editor being completely empty.

Anyone got an idea on how to solve that problem?

macsniper
  • 330
  • 1
  • 11

0 Answers0