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

changeset 197
1bf037016426
parent 1
9a66ca7c79fa
child 229
03bcd66bd8e7
equal deleted inserted replaced
196:1ca2dc8584e1 197:1bf037016426
23 * have any questions. 23 * have any questions.
24 */ 24 */
25 25
26 package com.sun.tools.javadoc; 26 package com.sun.tools.javadoc;
27 27
28 import java.io.File;
29 import javax.tools.FileObject;
30
28 import com.sun.javadoc.SourcePosition; 31 import com.sun.javadoc.SourcePosition;
29 import com.sun.tools.javac.util.Position; 32 import com.sun.tools.javac.util.Position;
30
31 import java.io.File;
32 33
33 /** 34 /**
34 * A source position: filename, line number, and column number. 35 * A source position: filename, line number, and column number.
35 * 36 *
36 * @since J2SE1.4 37 * @since J2SE1.4
37 * @author Neal M Gafter 38 * @author Neal M Gafter
38 * @author Michael Van De Vanter (position representation changed to char offsets) 39 * @author Michael Van De Vanter (position representation changed to char offsets)
39 */ 40 */
40 class SourcePositionImpl implements SourcePosition { 41 public class SourcePositionImpl implements SourcePosition {
41 String filename; 42 FileObject filename;
42 int position; 43 int position;
43 Position.LineMap lineMap; 44 Position.LineMap lineMap;
44 45
45 /** The source file. Returns null if no file information is 46 /** The source file. Returns null if no file information is
46 * available. */ 47 * available. */
47 public File file() { 48 public File file() {
48 return (filename == null) ? null : new File(filename); 49 return (filename == null) ? null : new File(filename.getName());
50 }
51
52 /** The source file. Returns null if no file information is
53 * available. */
54 public FileObject fileObject() {
55 return filename;
49 } 56 }
50 57
51 /** The line in the source file. The first line is numbered 1; 58 /** The line in the source file. The first line is numbered 1;
52 * 0 means no line number information is available. */ 59 * 0 means no line number information is available. */
53 public int line() { 60 public int line() {
69 }else { 76 }else {
70 return lineMap.getColumnNumber(position); 77 return lineMap.getColumnNumber(position);
71 } 78 }
72 } 79 }
73 80
74 private SourcePositionImpl(String file, int position, 81 private SourcePositionImpl(FileObject file, int position,
75 Position.LineMap lineMap) { 82 Position.LineMap lineMap) {
76 super(); 83 super();
77 this.filename = file; 84 this.filename = file;
78 this.position = position; 85 this.position = position;
79 this.lineMap = lineMap; 86 this.lineMap = lineMap;
80 } 87 }
81 88
82 public static SourcePosition make(String file, int pos, 89 public static SourcePosition make(FileObject file, int pos,
83 Position.LineMap lineMap) { 90 Position.LineMap lineMap) {
84 if (file == null) return null; 91 if (file == null) return null;
85 return new SourcePositionImpl(file, pos, lineMap); 92 return new SourcePositionImpl(file, pos, lineMap);
86 } 93 }
87 94
88 public String toString() { 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.toString();
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 }
106
89 if (position == Position.NOPOS) 107 if (position == Position.NOPOS)
90 return filename; 108 return fn;
91 else 109 else
92 return filename + ":" + line(); 110 return fn + ":" + line();
93 } 111 }
94 } 112 }

mercurial