Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Rewriting import decalarations from within plugin jar
Rewriting import decalarations from within plugin jar [message #248418] Fri, 05 October 2007 11:32 Go to next message
Eclipse UserFriend
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 #248424 is a reply to message #248418] Fri, 05 October 2007 15:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wharley.bea.com

"ZZ" <zinon.z@gmail.com> wrote in message
news:fe5lbs$nsa$1@build.eclipse.org...
> 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:
>
> [snip]
> 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.

It's hard to tell without more information about what you mean by "stops
working".

One thing to be aware of is that after you deploy a plug-in, you may want to
run Eclipse once with the -clean command line option, so that it blows away
any cached copies of your plug-in. Otherwise you might not be running the
code you think you're running.
Re: Rewriting import decalarations from within plugin jar [message #248430 is a reply to message #248424] Fri, 05 October 2007 16:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zinon.z.gmail.com

Walter Harley wrote:
> "ZZ" <zinon.z@gmail.com> wrote in message
> news:fe5lbs$nsa$1@build.eclipse.org...
>> 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:
>>
>> [snip]
>> 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.
>
> It's hard to tell without more information about what you mean by "stops
> working".
>
> One thing to be aware of is that after you deploy a plug-in, you may want to
> run Eclipse once with the -clean command line option, so that it blows away
> any cached copies of your plug-in. Otherwise you might not be running the
> code you think you're running.
>
>

Thanks for your reply Walter. That's all I had to do for it to work. (No
idea Eclipse did that)
Re: Rewriting import decalarations from within plugin jar [message #248433 is a reply to message #248430] Fri, 05 October 2007 16:51 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Custom hyper link detectors for stack traces in consoles
Next Topic:Error using ant from eclipse
Goto Forum:
  


Current Time: Wed May 14 15:14:16 EDT 2025

Powered by FUDForum. Page generated in 0.03265 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top