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 java.io.IOException; |
|
30 import java.lang.reflect.Modifier; |
|
31 import java.net.URI; |
|
32 import java.util.HashSet; |
|
33 import java.util.Set; |
|
34 import javax.tools.FileObject; |
|
35 import javax.tools.JavaFileManager.Location; |
|
36 import javax.tools.StandardJavaFileManager; |
|
37 import javax.tools.StandardLocation; |
|
38 |
28 import com.sun.javadoc.*; |
39 import com.sun.javadoc.*; |
29 |
40 |
30 import static com.sun.javadoc.LanguageVersion.*; |
41 import static com.sun.javadoc.LanguageVersion.*; |
|
42 |
|
43 import com.sun.tools.javac.code.Flags; |
|
44 import com.sun.tools.javac.code.Kinds; |
|
45 import com.sun.tools.javac.code.Scope; |
|
46 import com.sun.tools.javac.code.Symbol; |
|
47 import com.sun.tools.javac.code.Symbol.*; |
|
48 import com.sun.tools.javac.code.Type; |
|
49 import com.sun.tools.javac.code.Type.ClassType; |
|
50 import com.sun.tools.javac.code.TypeTags; |
|
51 |
|
52 import com.sun.tools.javac.comp.AttrContext; |
|
53 import com.sun.tools.javac.comp.Env; |
|
54 |
|
55 import com.sun.tools.javac.tree.JCTree; |
|
56 import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
|
57 import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
|
58 import com.sun.tools.javac.tree.JCTree.JCImport; |
|
59 import com.sun.tools.javac.tree.TreeInfo; |
31 |
60 |
32 import com.sun.tools.javac.util.List; |
61 import com.sun.tools.javac.util.List; |
33 import com.sun.tools.javac.util.ListBuffer; |
62 import com.sun.tools.javac.util.ListBuffer; |
34 import com.sun.tools.javac.util.Name; |
63 import com.sun.tools.javac.util.Name; |
|
64 import com.sun.tools.javac.util.Names; |
35 import com.sun.tools.javac.util.Position; |
65 import com.sun.tools.javac.util.Position; |
36 |
66 |
37 import com.sun.tools.javac.code.Flags; |
|
38 import com.sun.tools.javac.code.Kinds; |
|
39 import com.sun.tools.javac.code.TypeTags; |
|
40 import com.sun.tools.javac.code.Type; |
|
41 import com.sun.tools.javac.code.Type.ClassType; |
|
42 import com.sun.tools.javac.code.Scope; |
|
43 import com.sun.tools.javac.code.Symbol; |
|
44 import com.sun.tools.javac.code.Symbol.*; |
|
45 |
|
46 import com.sun.tools.javac.comp.AttrContext; |
|
47 import com.sun.tools.javac.comp.Env; |
|
48 |
|
49 import com.sun.tools.javac.tree.JCTree; |
|
50 import com.sun.tools.javac.tree.JCTree.JCFieldAccess; |
|
51 import com.sun.tools.javac.tree.JCTree.JCImport; |
|
52 import com.sun.tools.javac.tree.JCTree.JCClassDecl; |
|
53 import com.sun.tools.javac.tree.TreeInfo; |
|
54 |
|
55 import com.sun.tools.javac.util.Names; |
|
56 import static com.sun.tools.javac.code.Flags.*; |
67 import static com.sun.tools.javac.code.Flags.*; |
57 import static com.sun.tools.javac.code.Kinds.*; |
68 import static com.sun.tools.javac.code.Kinds.*; |
58 |
|
59 import java.io.File; |
|
60 import java.util.Set; |
|
61 import java.util.HashSet; |
|
62 import java.lang.reflect.Modifier; |
|
63 |
69 |
64 /** |
70 /** |
65 * Represents a java class and provides access to information |
71 * Represents a java class and provides access to information |
66 * about the class, the class' comment and tags, and the |
72 * about the class, the class' comment and tags, and the |
67 * members of the class. A ClassDocImpl only exists if it was |
73 * members of the class. A ClassDocImpl only exists if it was |
269 /** |
275 /** |
270 * Return the package that this class is contained in. |
276 * Return the package that this class is contained in. |
271 */ |
277 */ |
272 public PackageDoc containingPackage() { |
278 public PackageDoc containingPackage() { |
273 PackageDocImpl p = env.getPackageDoc(tsym.packge()); |
279 PackageDocImpl p = env.getPackageDoc(tsym.packge()); |
274 SourcePosition po = position(); |
280 if (p.setDocPath == false) { |
275 if (po != null && p.setDocPath == false && p.zipDocPath == null) { |
281 FileObject docPath; |
276 //Set the package path if possible |
282 try { |
277 File packageDir = po.file().getParentFile(); |
283 Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH) |
278 if (packageDir != null |
284 ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; |
279 && (new File(packageDir, "package.html")).exists()) { |
285 |
280 p.setDocPath(packageDir.getPath()); |
286 docPath = env.fileManager.getFileForInput( |
281 } else { |
287 location, p.qualifiedName(), "package.html"); |
282 p.setDocPath(null); |
288 } catch (IOException e) { |
283 } |
289 docPath = null; |
|
290 } |
|
291 |
|
292 if (docPath == null) { |
|
293 // fall back on older semantics of looking in same directory as |
|
294 // source file for this class |
|
295 SourcePosition po = position(); |
|
296 if (env.fileManager instanceof StandardJavaFileManager && |
|
297 po instanceof SourcePositionImpl) { |
|
298 URI uri = ((SourcePositionImpl) po).filename.toUri(); |
|
299 if ("file".equals(uri.getScheme())) { |
|
300 File f = new File(uri.getPath()); |
|
301 File dir = f.getParentFile(); |
|
302 if (dir != null) { |
|
303 File pf = new File(dir, "package.html"); |
|
304 if (pf.exists()) { |
|
305 StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager; |
|
306 docPath = sfm.getJavaFileObjects(pf).iterator().next(); |
|
307 } |
|
308 } |
|
309 |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 p.setDocPath(docPath); |
284 } |
315 } |
285 return p; |
316 return p; |
286 } |
317 } |
287 |
318 |
288 /** |
319 /** |
1249 * Return the source position of the entity, or null if |
1280 * Return the source position of the entity, or null if |
1250 * no position is available. |
1281 * no position is available. |
1251 */ |
1282 */ |
1252 public SourcePosition position() { |
1283 public SourcePosition position() { |
1253 if (tsym.sourcefile == null) return null; |
1284 if (tsym.sourcefile == null) return null; |
1254 return SourcePositionImpl.make(tsym.sourcefile.toString(), |
1285 return SourcePositionImpl.make(tsym.sourcefile, |
1255 (tree==null) ? Position.NOPOS : tree.pos, |
1286 (tree==null) ? Position.NOPOS : tree.pos, |
1256 lineMap); |
1287 lineMap); |
1257 } |
1288 } |
1258 } |
1289 } |