1 11 package org.eclipse.jdt.core.dom.rewrite; 12 13 import org.eclipse.jdt.core.dom.ASTNode; 14 import org.eclipse.jdt.core.dom.CompilationUnit; 15 16 38 public class TargetSourceRangeComputer { 39 40 46 public static final class SourceRange { 47 51 private int startPosition; 52 53 57 private int length; 58 59 67 public SourceRange(int startPosition, int length) { 68 this.startPosition = startPosition; 69 this.length = length; 70 } 71 72 78 public int getStartPosition() { 79 return this.startPosition; 80 } 81 82 88 public int getLength() { 89 return this.length; 90 } 91 } 92 93 96 public TargetSourceRangeComputer() { 97 } 99 100 127 public SourceRange computeSourceRange(ASTNode node) { 128 ASTNode root= node.getRoot(); 129 if (root instanceof CompilationUnit) { 130 CompilationUnit cu= (CompilationUnit) root; 131 return new SourceRange(cu.getExtendedStartPosition(node), cu.getExtendedLength(node)); 132 } 133 return new SourceRange(node.getStartPosition(), node.getLength()); 134 } 135 } 136 | Popular Tags |