Tue, 11 Aug 2009 01:13:14 +0100
6521805: Regression: JDK5/JDK6 javac allows write access to outer class reference
Summary: javac should warn/complain about identifiers with the same name as synthetic symbol
Reviewed-by: jjg
1 /*
2 * Copyright 2001-2009 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 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.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 }
107 if (position == Position.NOPOS)
108 return fn;
109 else
110 return fn + ":" + line();
111 }
112 }