1 /* 2 * @(#)SourcePositions.java 1.4 06/06/09 3 * 4 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 * 7 * Use and Distribution is subject to the Java Research License available 8 * at <http://wwws.sun.com/software/communitysource/jrl.html>. 9 */ 10 11 package com.sun.source.util; 12 13 import com.sun.source.tree.*; 14 15 /** 16 * Provides methods to obtain the position of a Tree within a CompilationUnit. 17 * A position is defined as a simple character offset from the start of a 18 * CompilationUnit where the first character is at offset 0. 19 * 20 * @author Peter von der Ahé 21 * @since 1.6 22 */ 23 public interface SourcePositions { 24 25 /** 26 * Gets the starting position of tree within file. If tree is not found within 27 * file, or if the starting position is not available, 28 * return {@link javax.tools.Diagnostic#NOPOS}. 29 * The returned position must be at the start of the yield of this tree, that 30 * is for any sub-tree of this tree, the following must hold: 31 * 32 * <p> 33 * {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br> 34 * {@code tree.getStartPosition() == NOPOS} or <br> 35 * {@code subtree.getStartPosition() == NOPOS} 36 * </p> 37 * 38 * @param file CompilationUnit in which to find tree. 39 * @param tree tree for which a position is sought. 40 * @return the start position of tree. 41 */ 42 long getStartPosition(CompilationUnitTree file, Tree tree); 43 44 /** 45 * Gets the ending position of tree within file. If tree is not found within 46 * file, or if the starting position is not available, 47 * return {@link javax.tools.Diagnostic#NOPOS}. 48 * The returned position must be at the end of the yield of this tree, 49 * that is for any sub-tree of this tree, the following must hold: 50 * 51 * <p> 52 * {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br> 53 * {@code tree.getEndPosition() == NOPOS} or <br> 54 * {@code subtree.getEndPosition() == NOPOS} 55 * </p> 56 * 57 * In addition, the following must hold: 58 * 59 * <p> 60 * {@code tree.getStartPosition() <= tree.getEndPosition()} or <br> 61 * {@code tree.getStartPosition() == NOPOS} or <br> 62 * {@code tree.getEndPosition() == NOPOS} 63 * </p> 64 * 65 * @param file CompilationUnit in which to find tree. 66 * @param tree tree for which a position is sought. 67 * @return the end position of tree. 68 */ 69 long getEndPosition(CompilationUnitTree file, Tree tree); 70 71 } 72