001    /*
002     * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.source.util;
027    
028    import com.sun.source.tree.*;
029    
030    /**
031     * Provides methods to obtain the position of a Tree within a CompilationUnit.
032     * A position is defined as a simple character offset from the start of a
033     * CompilationUnit where the first character is at offset 0.
034     *
035     * @author Peter von der Ahé
036     * @since 1.6
037     */
038    public interface SourcePositions {
039    
040        /**
041         * Gets the starting position of tree within file.  If tree is not found within
042         * file, or if the starting position is not available,
043         * return {@link javax.tools.Diagnostic#NOPOS}.
044         * The returned position must be at the start of the yield of this tree, that
045         * is for any sub-tree of this tree, the following must hold:
046         *
047         * <p>
048         * {@code tree.getStartPosition() <= subtree.getStartPosition()} or <br>
049         * {@code tree.getStartPosition() == NOPOS} or <br>
050         * {@code subtree.getStartPosition() == NOPOS}
051         * </p>
052         *
053         * @param file CompilationUnit in which to find tree.
054         * @param tree tree for which a position is sought.
055         * @return the start position of tree.
056         */
057         long getStartPosition(CompilationUnitTree file, Tree tree);
058    
059        /**
060         * Gets the ending position of tree within file.  If tree is not found within
061         * file, or if the starting position is not available,
062         * return {@link javax.tools.Diagnostic#NOPOS}.
063         * The returned position must be at the end of the yield of this tree,
064         * that is for any sub-tree of this tree, the following must hold:
065         *
066         * <p>
067         * {@code tree.getEndPosition() >= subtree.getEndPosition()} or <br>
068         * {@code tree.getEndPosition() == NOPOS} or <br>
069         * {@code subtree.getEndPosition() == NOPOS}
070         * </p>
071         *
072         * In addition, the following must hold:
073         *
074         * <p>
075         * {@code tree.getStartPosition() <= tree.getEndPosition()}  or <br>
076         * {@code tree.getStartPosition() == NOPOS} or <br>
077         * {@code tree.getEndPosition() == NOPOS}
078         * </p>
079         *
080         * @param file CompilationUnit in which to find tree.
081         * @param tree tree for which a position is sought.
082         * @return the end position of tree.
083         */
084         long getEndPosition(CompilationUnitTree file, Tree tree);
085    
086    }