author | jjg |
Mon, 07 Dec 2015 14:02:55 -0800 | |
changeset 34560 | b6a567b677f7 |
parent 25874 | 83c19f00452c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javadoc; |
|
27 |
||
1869 | 28 |
import java.io.File; |
29 |
import javax.tools.FileObject; |
|
30 |
||
10 | 31 |
import com.sun.javadoc.SourcePosition; |
32 |
import com.sun.tools.javac.util.Position; |
|
33 |
||
34 |
/** |
|
35 |
* A source position: filename, line number, and column number. |
|
36 |
* |
|
14260 | 37 |
* <p><b>This is NOT part of any supported API. |
38 |
* If you write code that depends on this, you do so at your own risk. |
|
39 |
* This code and its internal interfaces are subject to change or |
|
40 |
* deletion without notice.</b> |
|
41 |
* |
|
10 | 42 |
* @since J2SE1.4 |
43 |
* @author Neal M Gafter |
|
44 |
* @author Michael Van De Vanter (position representation changed to char offsets) |
|
45 |
*/ |
|
1869 | 46 |
public class SourcePositionImpl implements SourcePosition { |
47 |
FileObject filename; |
|
10 | 48 |
int position; |
49 |
Position.LineMap lineMap; |
|
50 |
||
51 |
/** The source file. Returns null if no file information is |
|
52 |
* available. */ |
|
53 |
public File file() { |
|
1869 | 54 |
return (filename == null) ? null : new File(filename.getName()); |
55 |
} |
|
56 |
||
57 |
/** The source file. Returns null if no file information is |
|
58 |
* available. */ |
|
59 |
public FileObject fileObject() { |
|
60 |
return filename; |
|
10 | 61 |
} |
62 |
||
63 |
/** The line in the source file. The first line is numbered 1; |
|
64 |
* 0 means no line number information is available. */ |
|
65 |
public int line() { |
|
66 |
if (lineMap == null) { |
|
67 |
return 0; |
|
68 |
} else { |
|
69 |
return lineMap.getLineNumber(position); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
/** The column in the source file. The first column is |
|
74 |
* numbered 1; 0 means no column information is available. |
|
75 |
* Columns count characters in the input stream; a tab |
|
76 |
* advances the column number to the next 8-column tab stop. |
|
77 |
*/ |
|
78 |
public int column() { |
|
79 |
if (lineMap == null) { |
|
80 |
return 0; |
|
81 |
}else { |
|
82 |
return lineMap.getColumnNumber(position); |
|
83 |
} |
|
84 |
} |
|
85 |
||
1869 | 86 |
private SourcePositionImpl(FileObject file, int position, |
10 | 87 |
Position.LineMap lineMap) { |
88 |
super(); |
|
89 |
this.filename = file; |
|
90 |
this.position = position; |
|
91 |
this.lineMap = lineMap; |
|
92 |
} |
|
93 |
||
1869 | 94 |
public static SourcePosition make(FileObject file, int pos, |
10 | 95 |
Position.LineMap lineMap) { |
96 |
if (file == null) return null; |
|
97 |
return new SourcePositionImpl(file, pos, lineMap); |
|
98 |
} |
|
99 |
||
100 |
public String toString() { |
|
1869 | 101 |
// Backwards compatibility hack. ZipFileObjects use the format |
102 |
// zipfile(zipentry) but javadoc has been using zipfile/zipentry |
|
3995
73af8b6fb8bc
6410637: Make decision on deprecated methods in DefaultFileManager and BaseFileObject.
jjg
parents:
2212
diff
changeset
|
103 |
String fn = filename.getName(); |
1869 | 104 |
if (fn.endsWith(")")) { |
105 |
int paren = fn.lastIndexOf("("); |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
106 |
if (paren != -1) { |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
107 |
int i = paren+1; |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
108 |
if (fn.charAt(i) == '/') |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
109 |
i++; |
1869 | 110 |
fn = fn.substring(0, paren) |
111 |
+ File.separatorChar |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
112 |
+ fn.substring(i, fn.length() - 1); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
25874
diff
changeset
|
113 |
} |
1869 | 114 |
} |
115 |
||
10 | 116 |
if (position == Position.NOPOS) |
1869 | 117 |
return fn; |
10 | 118 |
else |
1869 | 119 |
return fn + ":" + line(); |
10 | 120 |
} |
121 |
} |