author | jjg |
Wed, 18 Jun 2008 07:23:25 -0700 | |
changeset 810 | e4b6a6d206e6 |
parent 731 | 1dd22bdb9ca5 |
child 815 | bcb5c0d7c1ab |
permissions | -rw-r--r-- |
10 | 1 |
/* |
2 |
* Copyright 2001-2006 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 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javadoc; |
|
27 |
||
28 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
29 |
import com.sun.tools.javac.file.JavacFileManager; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
30 |
import com.sun.tools.javac.file.ZipArchive.ZipFileObject; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
10
diff
changeset
|
31 |
import com.sun.tools.javac.file.Old199; |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
32 |
import com.sun.tools.javac.file.ZipFileIndexArchive; |
10 | 33 |
import com.sun.tools.javac.jvm.ClassReader; |
34 |
import com.sun.tools.javac.util.Context; |
|
35 |
||
36 |
import java.io.File; |
|
37 |
import java.util.EnumSet; |
|
38 |
import javax.tools.JavaFileObject; |
|
39 |
||
40 |
/** Javadoc uses an extended class reader that records package.html entries |
|
41 |
* @author Neal Gafter |
|
42 |
*/ |
|
43 |
class JavadocClassReader extends ClassReader { |
|
44 |
||
45 |
public static JavadocClassReader instance0(Context context) { |
|
46 |
ClassReader instance = context.get(classReaderKey); |
|
47 |
if (instance == null) |
|
48 |
instance = new JavadocClassReader(context); |
|
49 |
return (JavadocClassReader)instance; |
|
50 |
} |
|
51 |
||
52 |
public static void preRegister(final Context context) { |
|
53 |
context.put(classReaderKey, new Context.Factory<ClassReader>() { |
|
54 |
public ClassReader make() { |
|
55 |
return new JavadocClassReader(context); |
|
56 |
} |
|
57 |
}); |
|
58 |
} |
|
59 |
||
60 |
private DocEnv docenv; |
|
61 |
private EnumSet<JavaFileObject.Kind> all = EnumSet.of(JavaFileObject.Kind.CLASS, |
|
62 |
JavaFileObject.Kind.SOURCE, |
|
63 |
JavaFileObject.Kind.HTML); |
|
64 |
private EnumSet<JavaFileObject.Kind> noSource = EnumSet.of(JavaFileObject.Kind.CLASS, |
|
65 |
JavaFileObject.Kind.HTML); |
|
66 |
||
67 |
private JavadocClassReader(Context context) { |
|
68 |
super(context, true); |
|
69 |
docenv = DocEnv.instance(context); |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* Override getPackageFileKinds to include search for package.html |
|
74 |
*/ |
|
75 |
@Override |
|
76 |
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() { |
|
77 |
return docenv.docClasses ? noSource : all; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Override extraFileActions to check for package documentation |
|
82 |
*/ |
|
83 |
@Override |
|
84 |
protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) { |
|
85 |
CharSequence fileName = Old199.getName(fo); |
|
86 |
if (docenv != null && fileName.equals("package.html")) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
87 |
if (fo instanceof ZipFileObject) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
88 |
ZipFileObject zfo = (ZipFileObject) fo; |
10 | 89 |
String zipName = zfo.getZipName(); |
90 |
String entryName = zfo.getZipEntryName(); |
|
91 |
int lastSep = entryName.lastIndexOf("/"); |
|
92 |
String classPathName = entryName.substring(0, lastSep + 1); |
|
93 |
docenv.getPackageDoc(pack).setDocPath(zipName, classPathName); |
|
94 |
} |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
95 |
else if (fo instanceof ZipFileIndexArchive.ZipFileIndexFileObject) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
96 |
ZipFileIndexArchive.ZipFileIndexFileObject zfo = (ZipFileIndexArchive.ZipFileIndexFileObject) fo; |
10 | 97 |
String zipName = zfo.getZipName(); |
98 |
String entryName = zfo.getZipEntryName(); |
|
99 |
if (File.separatorChar != '/') { |
|
100 |
entryName = entryName.replace(File.separatorChar, '/'); |
|
101 |
} |
|
102 |
||
103 |
int lastSep = entryName.lastIndexOf("/"); |
|
104 |
String classPathName = entryName.substring(0, lastSep + 1); |
|
105 |
docenv.getPackageDoc(pack).setDocPath(zipName, classPathName); |
|
106 |
} |
|
107 |
else { |
|
108 |
File fileDir = new File(Old199.getPath(fo)).getParentFile(); |
|
109 |
docenv.getPackageDoc(pack).setDocPath(fileDir.getAbsolutePath()); |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
} |