Rewriting import decalarations from within plugin jar [message #248418] |
Fri, 05 October 2007 11:32  |
Eclipse User |
|
|
|
Originally posted by: zinon.z.gmail.com
Hello,
I am fairly new to Eclipse and am developing a plugin which adds import
declarations to the source file currently open in the editor using the
following code:
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IEditorPart editor = page.getActiveEditor();
IFile fileInEditor = ((FileEditorInput)editor.getEditorInput()).getFile();
IJavaElement myJE = JavaCore.create(fileInEditor);
ICompilationUnit comp = (ICompilationUnit) myJE;
IBuffer buffer = ((IOpenable) comp).getBuffer();
Document document = new Document(comp.getSource());
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(comp);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
cu.recordModifications();
ImportRewrite rewriter = ImportRewrite.create(cu, true);
rewriter.addImport("an.import.dec.*");
TextEdit edits = rewriter.rewriteImports(null);
edits.apply(document);
cu.rewrite(document, null);
buffer.setContents(document.get());
comp.reconcile(ICompilationUnit.NO_AST, false, null, null);
comp.commitWorkingCopy(true, null);
The code works fine in a development environment, but when I package the
plugin in a jar file and deploy it, it stops working. Any ideas why this
might be.
Thanks
ZZ
|
|
|
|
|
Re: Rewriting import decalarations from within plugin jar [message #248433 is a reply to message #248430] |
Fri, 05 October 2007 16:51  |
Eclipse User |
|
|
|
Originally posted by: wharley.bea.com
"ZZ" <zinon.z@gmail.com> wrote in message
news:fe672n$5i1$1@build.eclipse.org...
> Thanks for your reply Walter. That's all I had to do for it to work. (No
> idea Eclipse did that)
Yeah, it took me a *long* time to figure that out the first time it bit me
:-(
I want some sort of watchdog process that looks at certain indicators of
frustration, like my blood pressure or the number of times in the last
minute I've hit F11, and checks me on various assumptions - "I notice you're
trying to use a deployed plugin. Did you run with -clean? I notice you've
got breakpoints in code in source code whose classes are being loaded from
somewhere else because of your runtime classpath. Is that what you meant?
I notice you've created some new directories but they're not in your
build.properties. Are you done yet?" And so forth.
|
|
|
Powered by
FUDForum. Page generated in 0.03265 seconds