KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > dom > BodyDeclarationRewrite


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.dom;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.text.edits.TextEditGroup;
16
17 import org.eclipse.jdt.core.dom.ASTNode;
18 import org.eclipse.jdt.core.dom.BodyDeclaration;
19 import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor;
20 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
21 import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
22
23
24 public class BodyDeclarationRewrite {
25
26     private ASTNode fTypeNode;
27     private ListRewrite fListRewrite;
28     
29     public static BodyDeclarationRewrite create(ASTRewrite rewrite, ASTNode typeNode) {
30         return new BodyDeclarationRewrite(rewrite, typeNode);
31     }
32     
33     private BodyDeclarationRewrite(ASTRewrite rewrite, ASTNode typeNode) {
34         ChildListPropertyDescriptor property= ASTNodes.getBodyDeclarationsProperty(typeNode);
35         fTypeNode= typeNode;
36         fListRewrite= rewrite.getListRewrite(typeNode, property);
37     }
38     
39     public void insert(BodyDeclaration decl, TextEditGroup description) {
40         List JavaDoc container= ASTNodes.getBodyDeclarations(fTypeNode);
41         int index= ASTNodes.getInsertionIndex(decl, container);
42         fListRewrite.insertAt(decl, index, description);
43     }
44 }
45
Popular Tags