Community
Participate
Working Groups
From : Alexander Pavlov (bug 86906 comment 3) Another issue has risen in the I200502171619. Consider this enum: public enum MyEnum { VALUE1 } We call createField("int someField=0;\n", null, true, null). It fails because of the following intermediate search call to make the VALUE1 enum constant declaration a sibling: SourceField.findNode(CompilationUnit) line: 40 CreateFieldOperation(CreateElementInCUOperation).insertASTNode (ASTRewrite, ASTNode, ASTNode) line: 255 CreateFieldOperation (CreateElementInCUOperation).generateNewCompilationUnitAST(ICompilationUnit) line: 184 CreateFieldOperation(CreateElementInCUOperation).executeOperation() line: 137 CreateFieldOperation(JavaModelOperation).run(IProgressMonitor) line: 710 Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 1702 CreateFieldOperation(JavaModelOperation).runOperation(IProgressMonitor) line: 771 SourceType.createField(String, IJavaElement, boolean, IProgressMonitor) line: 117 The reason is this: the SourceType method public ASTNode findNode(org.eclipse.jdt.core.dom.CompilationUnit ast) { // For field declarations, a variable declaration fragment is returned // Return the FieldDeclaration instead ASTNode node = super.findNode(ast); if (node == null) return null; return node.getParent(); } does find the EnumConstantDeclaration but does not return one, taking its parent (i.e. EnumDeclaration) as the final result. A check should be made to handle the enum constant case properly and return the constant declaration itself, not its parent node (something like if (node instanceof VariableDeclarationFragment) { return node.getParent(); } else { return node; } ).
To work, the createField() method needs to know if the inserted field is an enum constant or a real field.
Defer post 3.2
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.