Fri, 04 Jul 2008 15:06:27 -0700
Merge
1 /*
2 * Copyright 2005-2008 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.javac.file;
28 import java.io.File;
29 import java.io.IOException;
30 import java.io.InputStreamReader;
31 import java.io.Reader;
32 import java.nio.charset.CharsetDecoder;
33 import javax.lang.model.element.Modifier;
34 import javax.lang.model.element.NestingKind;
35 import javax.tools.JavaFileObject;
37 import static javax.tools.JavaFileObject.Kind.*;
39 public abstract class BaseFileObject implements JavaFileObject {
40 protected BaseFileObject(JavacFileManager fileManager) {
41 this.fileManager = fileManager;
42 }
44 public JavaFileObject.Kind getKind() {
45 String n = getName();
46 if (n.endsWith(CLASS.extension))
47 return CLASS;
48 else if (n.endsWith(SOURCE.extension))
49 return SOURCE;
50 else if (n.endsWith(HTML.extension))
51 return HTML;
52 else
53 return OTHER;
54 }
56 @Override
57 public String toString() {
58 return getPath();
59 }
61 /** @deprecated see bug 6410637 */
62 @Deprecated
63 public String getPath() {
64 return getName();
65 }
67 /** @deprecated see bug 6410637 */
68 @Deprecated
69 abstract public String getName();
71 public NestingKind getNestingKind() { return null; }
73 public Modifier getAccessLevel() { return null; }
75 public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
76 return new InputStreamReader(openInputStream(), getDecoder(ignoreEncodingErrors));
77 }
79 protected CharsetDecoder getDecoder(boolean ignoreEncodingErrors) {
80 throw new UnsupportedOperationException();
81 }
83 protected abstract String inferBinaryName(Iterable<? extends File> path);
85 protected static String removeExtension(String fileName) {
86 int lastDot = fileName.lastIndexOf(".");
87 return (lastDot == -1 ? fileName : fileName.substring(0, lastDot));
88 }
90 /** The file manager that created this JavaFileObject. */
91 protected final JavacFileManager fileManager;
93 }