Bug 94304 - [code manipulation] Fails to create a class in enum
Summary: [code manipulation] Fails to create a class in enum
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-10 09:44 EDT by julien CLA
Modified: 2005-05-30 06:36 EDT (History)
1 user (show)

See Also:


Attachments
Apply on HEAD (1.56 KB, patch)
2005-05-16 18:30 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description julien CLA 2005-05-10 09:44:10 EDT
With Eclipse I20050506-1600, I run a problem to create a inner class in enum:
  1. select an enum in the package explorer
  2. call new wizard to create a inner class
  3. check the "Enclosing type"
  4. Put a name in the "Name:" Field
  5. Click the button "OK".

I got the following exception:

Caused by: java.lang.IllegalArgumentException: Node does not exist
	at org.eclipse.jdt.core.dom.rewrite.ListRewrite.insertBefore
(ListRewrite.java:205)
	at 
org.eclipse.jdt.internal.core.CreateElementInCUOperation.insertASTNode
(CreateElementInCUOperation.java:249)
	at 
org.eclipse.jdt.internal.core.CreateElementInCUOperation.generateNewCompilation
UnitAST(CreateElementInCUOperation.java:184)
	at 
org.eclipse.jdt.internal.core.CreateElementInCUOperation.executeOperation
(CreateElementInCUOperation.java:137)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:718)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1716)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation
(JavaModelOperation.java:782)
	at org.eclipse.jdt.internal.core.SourceType.createType
(SourceType.java:153)
	at org.eclipse.jdt.ui.wizards.NewTypeWizardPage.createType
(NewTypeWizardPage.java:1808)
	at 
org.eclipse.jdt.internal.ui.wizards.NewClassCreationWizard.finishPage
(NewClassCreationWizard.java:55)
	at org.eclipse.jdt.internal.ui.wizards.NewElementWizard$2.run
(NewElementWizard.java:114)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation
(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:718)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1716)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:3654)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run
(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:346)

The samething can be done in Java editor.
Comment 1 Olivier Thomann CLA 2005-05-11 08:41:35 EDT
I will investigate.
Comment 2 Olivier Thomann CLA 2005-05-12 16:16:29 EDT
Could not reproduce in I20050512-1200.
Closing as WORKSFORME. Please reopen if you get it again.
Comment 3 julien CLA 2005-05-14 15:45:31 EDT
I have tested with M7. The problem still exists. 
Comment 4 Olivier Thomann CLA 2005-05-15 19:09:43 EDT
Then provide steps to reproduce.
I followed the steps in comment 0 and I could not reproduce.
Are your project's settings 5.0 or 1.4?
Comment 5 julien CLA 2005-05-15 21:10:47 EDT
I remind you it occurs if you create a class/interface in an ENUM  It works in 
Java editor.
Comment 6 Olivier Thomann CLA 2005-05-16 15:40:55 EDT
This is exactly what I have done.
Comment 7 Olivier Thomann CLA 2005-05-16 15:58:40 EDT
Reproduced. I tried with an empty enum and it was working.
I am investigating.
Comment 8 Olivier Thomann CLA 2005-05-16 18:18:43 EDT
The problem comes from the new type wizard that sets the sibling of the new type
to be an enum constant declaration.
This leads to the error see in the log.

I think that the createType API should throw an INVALID_SIBLING java modl
exception in this case.

See bug 95480 for the corresponding problem on the JDT/Core side.

Move to JDT/UI
Comment 9 Olivier Thomann CLA 2005-05-16 18:30:57 EDT
Created attachment 21234 [details]
Apply on HEAD

Possible patch. For an enum type, I check the IFields and I select the first
one that is not an enum constant declaration as the sibling of the new type.
Comment 10 Martin Aeschlimann CLA 2005-05-24 09:48:22 EDT
released > 20050524

Thanks Olivier!
Comment 11 David Saff CLA 2005-05-30 06:09:31 EDT
Verifying...
Comment 12 David Saff CLA 2005-05-30 06:11:54 EDT
Verified in I20050527-1300.  Dirk, please update state to VERIFIED.
Comment 13 Dirk Baeumer CLA 2005-05-30 06:36:39 EDT
Marking as verified.