KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > dom > rewrite > TrackedNodePosition


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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.core.dom.rewrite;
12
13 import org.eclipse.text.edits.TextEdit;
14 import org.eclipse.text.edits.TextEditGroup;
15
16 import org.eclipse.jdt.core.dom.ASTNode;
17 import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;
18 import org.eclipse.jface.text.IRegion;
19
20 /**
21  *
22  */

23 public class TrackedNodePosition implements ITrackedNodePosition {
24
25     private final TextEditGroup group;
26     private final ASTNode node;
27     
28     public TrackedNodePosition(TextEditGroup group, ASTNode node) {
29         this.group= group;
30         this.node= node;
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.jdt.internal.corext.dom.ITrackedNodePosition#getStartPosition()
35      */

36     public int getStartPosition() {
37         if (this.group.isEmpty()) {
38             return this.node.getStartPosition();
39         }
40         IRegion coverage= TextEdit.getCoverage(this.group.getTextEdits());
41         if (coverage == null) {
42             return this.node.getStartPosition();
43         }
44         return coverage.getOffset();
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.jdt.internal.corext.dom.ITrackedNodePosition#getLength()
49      */

50     public int getLength() {
51         if (this.group.isEmpty()) {
52             return this.node.getLength();
53         }
54         IRegion coverage= TextEdit.getCoverage(this.group.getTextEdits());
55         if (coverage == null) {
56             return this.node.getLength();
57         }
58         return coverage.getLength();
59     }
60 }
61
Popular Tags