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

Thu, 30 Jun 2011 14:33:45 -0700

author
ksrini
date
Thu, 30 Jun 2011 14:33:45 -0700
changeset 1051
b0909f992710
parent 554
9d9f26857129
child 1359
25e14ad23cef
permissions
-rw-r--r--

7059905: (javadoc) promote method visibility for netbeans usage
Reviewed-by: jjg, bpatel

     1 /*
     2  * Copyright (c) 2001, 2009, Oracle and/or its affiliates. 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.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.javadoc;
    28 import java.io.File;
    29 import javax.tools.FileObject;
    31 import com.sun.javadoc.SourcePosition;
    32 import com.sun.tools.javac.util.Position;
    34 /**
    35  * A source position: filename, line number, and column number.
    36  *
    37  * @since J2SE1.4
    38  * @author Neal M Gafter
    39  * @author Michael Van De Vanter (position representation changed to char offsets)
    40  */
    41 public class SourcePositionImpl implements SourcePosition {
    42     FileObject filename;
    43     int position;
    44     Position.LineMap lineMap;
    46     /** The source file. Returns null if no file information is
    47      *  available. */
    48     public File file() {
    49         return (filename == null) ? null : new File(filename.getName());
    50     }
    52     /** The source file. Returns null if no file information is
    53      *  available. */
    54     public FileObject fileObject() {
    55         return filename;
    56     }
    58     /** The line in the source file. The first line is numbered 1;
    59      *  0 means no line number information is available. */
    60     public int line() {
    61         if (lineMap == null) {
    62             return 0;
    63         } else {
    64             return lineMap.getLineNumber(position);
    65         }
    66     }
    68     /** The column in the source file. The first column is
    69      *  numbered 1; 0 means no column information is available.
    70      *  Columns count characters in the input stream; a tab
    71      *  advances the column number to the next 8-column tab stop.
    72      */
    73     public int column() {
    74         if (lineMap == null) {
    75             return 0;
    76         }else {
    77             return lineMap.getColumnNumber(position);
    78         }
    79     }
    81     private SourcePositionImpl(FileObject file, int position,
    82                                Position.LineMap lineMap) {
    83         super();
    84         this.filename = file;
    85         this.position = position;
    86         this.lineMap = lineMap;
    87     }
    89     public static SourcePosition make(FileObject file, int pos,
    90                                       Position.LineMap lineMap) {
    91         if (file == null) return null;
    92         return new SourcePositionImpl(file, pos, lineMap);
    93     }
    95     public String toString() {
    96         // Backwards compatibility hack. ZipFileObjects use the format
    97         // zipfile(zipentry) but javadoc has been using zipfile/zipentry
    98         String fn = filename.getName();
    99         if (fn.endsWith(")")) {
   100             int paren = fn.lastIndexOf("(");
   101             if (paren != -1)
   102                 fn = fn.substring(0, paren)
   103                         + File.separatorChar
   104                         + fn.substring(paren + 1, fn.length() - 1);
   105         }
   107         if (position == Position.NOPOS)
   108             return fn;
   109         else
   110             return fn + ":" + line();
   111     }
   112 }

mercurial