src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java

Thu, 18 Sep 2008 18:39:44 -0700

author
jjg
date
Thu, 18 Sep 2008 18:39:44 -0700
changeset 115
829dea15ff99
parent 1
9a66ca7c79fa
child 197
1bf037016426
permissions
-rw-r--r--

6744408: Extra ouput is appearing in stderr
Reviewed-by: bpatel

     1 /*
     2  * Copyright 2001-2005 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.javadoc;
    28 import com.sun.javadoc.SourcePosition;
    29 import com.sun.tools.javac.util.Position;
    31 import java.io.File;
    33 /**
    34  * A source position: filename, line number, and column number.
    35  *
    36  * @since J2SE1.4
    37  * @author Neal M Gafter
    38  * @author Michael Van De Vanter (position representation changed to char offsets)
    39  */
    40 class SourcePositionImpl implements SourcePosition {
    41     String filename;
    42     int position;
    43     Position.LineMap lineMap;
    45     /** The source file. Returns null if no file information is
    46      *  available. */
    47     public File file() {
    48         return (filename == null) ? null : new File(filename);
    49     }
    51     /** The line in the source file. The first line is numbered 1;
    52      *  0 means no line number information is available. */
    53     public int line() {
    54         if (lineMap == null) {
    55             return 0;
    56         } else {
    57             return lineMap.getLineNumber(position);
    58         }
    59     }
    61     /** The column in the source file. The first column is
    62      *  numbered 1; 0 means no column information is available.
    63      *  Columns count characters in the input stream; a tab
    64      *  advances the column number to the next 8-column tab stop.
    65      */
    66     public int column() {
    67         if (lineMap == null) {
    68             return 0;
    69         }else {
    70             return lineMap.getColumnNumber(position);
    71         }
    72     }
    74     private SourcePositionImpl(String file, int position,
    75                                Position.LineMap lineMap) {
    76         super();
    77         this.filename = file;
    78         this.position = position;
    79         this.lineMap = lineMap;
    80     }
    82     public static SourcePosition make(String file, int pos,
    83                                       Position.LineMap lineMap) {
    84         if (file == null) return null;
    85         return new SourcePositionImpl(file, pos, lineMap);
    86     }
    88     public String toString() {
    89         if (position == Position.NOPOS)
    90             return filename;
    91         else
    92             return filename + ":" + line();
    93     }
    94 }

mercurial