Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/com/sun/tools/javadoc/SourcePositionImpl.java
38899 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.javadoc;2627import java.io.File;28import javax.tools.FileObject;2930import com.sun.javadoc.SourcePosition;31import com.sun.tools.javac.util.Position;3233/**34* A source position: filename, line number, and column number.35*36* <p><b>This is NOT part of any supported API.37* If you write code that depends on this, you do so at your own risk.38* This code and its internal interfaces are subject to change or39* deletion without notice.</b>40*41* @since J2SE1.442* @author Neal M Gafter43* @author Michael Van De Vanter (position representation changed to char offsets)44*/45public class SourcePositionImpl implements SourcePosition {46FileObject filename;47int position;48Position.LineMap lineMap;4950/** The source file. Returns null if no file information is51* available. */52public File file() {53return (filename == null) ? null : new File(filename.getName());54}5556/** The source file. Returns null if no file information is57* available. */58public FileObject fileObject() {59return filename;60}6162/** The line in the source file. The first line is numbered 1;63* 0 means no line number information is available. */64public int line() {65if (lineMap == null) {66return 0;67} else {68return lineMap.getLineNumber(position);69}70}7172/** The column in the source file. The first column is73* numbered 1; 0 means no column information is available.74* Columns count characters in the input stream; a tab75* advances the column number to the next 8-column tab stop.76*/77public int column() {78if (lineMap == null) {79return 0;80}else {81return lineMap.getColumnNumber(position);82}83}8485private SourcePositionImpl(FileObject file, int position,86Position.LineMap lineMap) {87super();88this.filename = file;89this.position = position;90this.lineMap = lineMap;91}9293public static SourcePosition make(FileObject file, int pos,94Position.LineMap lineMap) {95if (file == null) return null;96return new SourcePositionImpl(file, pos, lineMap);97}9899public String toString() {100// Backwards compatibility hack. ZipFileObjects use the format101// zipfile(zipentry) but javadoc has been using zipfile/zipentry102String fn = filename.getName();103if (fn.endsWith(")")) {104int paren = fn.lastIndexOf("(");105if (paren != -1)106fn = fn.substring(0, paren)107+ File.separatorChar108+ fn.substring(paren + 1, fn.length() - 1);109}110111if (position == Position.NOPOS)112return fn;113else114return fn + ":" + line();115}116}117118119