src/share/classes/com/sun/tools/javadoc/PackageDocImpl.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.InputStream;
29 import java.io.IOException;
30 import javax.tools.FileObject;
31
28 import com.sun.javadoc.*; 32 import com.sun.javadoc.*;
29
30 import java.io.File;
31 import java.io.InputStream;
32 import java.io.FileInputStream;
33 import java.io.IOException;
34 import java.util.zip.ZipFile;
35 import java.util.zip.ZipEntry;
36 33
37 import com.sun.tools.javac.code.Attribute; 34 import com.sun.tools.javac.code.Attribute;
38 import com.sun.tools.javac.code.Scope; 35 import com.sun.tools.javac.code.Scope;
39 import com.sun.tools.javac.code.Symbol.ClassSymbol; 36 import com.sun.tools.javac.code.Symbol.ClassSymbol;
40 import com.sun.tools.javac.code.Symbol.PackageSymbol; 37 import com.sun.tools.javac.code.Symbol.PackageSymbol;
41 import com.sun.tools.javac.comp.AttrContext;
42 import com.sun.tools.javac.comp.Env;
43 import com.sun.tools.javac.tree.JCTree; 38 import com.sun.tools.javac.tree.JCTree;
39 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
44 import com.sun.tools.javac.util.List; 40 import com.sun.tools.javac.util.List;
45 import com.sun.tools.javac.util.ListBuffer; 41 import com.sun.tools.javac.util.ListBuffer;
46 import com.sun.tools.javac.util.Name; 42 import com.sun.tools.javac.util.Name;
47 import com.sun.tools.javac.util.Position; 43 import com.sun.tools.javac.util.Position;
48
49 import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
50
51 44
52 /** 45 /**
53 * Represents a java package. Provides access to information 46 * Represents a java package. Provides access to information
54 * about the package, the package's comment and tags, and the 47 * about the package, the package's comment and tags, and the
55 * classes in the package. 48 * classes in the package.
61 * @author Scott Seligman (package-info.java) 54 * @author Scott Seligman (package-info.java)
62 */ 55 */
63 56
64 public class PackageDocImpl extends DocImpl implements PackageDoc { 57 public class PackageDocImpl extends DocImpl implements PackageDoc {
65 58
66 private static final String PACKAGE_HTML_FILE_NAME = "package.html";
67
68 protected PackageSymbol sym; 59 protected PackageSymbol sym;
69 private JCCompilationUnit tree = null; // for source position 60 private JCCompilationUnit tree = null; // for source position
70 61
71 public String docPath = null; 62 public FileObject docPath = null;
72 public String zipDocPath = null;
73 public String zipDocEntry = null;
74 private boolean foundDoc; // found a doc comment in either 63 private boolean foundDoc; // found a doc comment in either
75 // package.html or package-info.java 64 // package.html or package-info.java
76 65
77 boolean isIncluded = false; // Set in RootDocImpl. 66 boolean isIncluded = false; // Set in RootDocImpl.
78 public boolean setDocPath = false; //Flag to avoid setting doc path multiple times. 67 public boolean setDocPath = false; //Flag to avoid setting doc path multiple times.
106 95
107 /** 96 /**
108 * Do lazy initialization of "documentation" string. 97 * Do lazy initialization of "documentation" string.
109 */ 98 */
110 String documentation() { 99 String documentation() {
111 if (documentation != null) return documentation; 100 if (documentation != null)
112 if (zipDocPath != null) { 101 return documentation;
113 try {
114 ZipFile f = new ZipFile(zipDocPath);
115 ZipEntry entry = f.getEntry(zipDocEntry);
116 if (entry != null) {
117 InputStream s = f.getInputStream(entry);
118 return (documentation = readHTMLDocumentation(s,
119 zipDocPath + File.separatorChar + zipDocEntry));
120 }
121 } catch (IOException exc) {
122 documentation = "";
123 env.error(null, "javadoc.File_Read_Error",
124 zipDocPath + File.separatorChar + zipDocEntry);
125 }
126 }
127 if (docPath != null) { 102 if (docPath != null) {
128 // read from file 103 // read from file
129 try { 104 try {
130 InputStream s = new FileInputStream(docPath); 105 InputStream s = docPath.openInputStream();
131 documentation = readHTMLDocumentation(s, docPath); 106 documentation = readHTMLDocumentation(s, docPath);
132 } catch (IOException exc) { 107 } catch (IOException exc) {
133 documentation = ""; 108 documentation = "";
134 env.error(null, "javadoc.File_Read_Error", docPath); 109 env.error(null, "javadoc.File_Read_Error", docPath.getName());
135 } 110 }
136 } else { 111 } else {
137 // no doc file to be had 112 // no doc file to be had
138 documentation = ""; 113 documentation = "";
139 } 114 }
361 } 336 }
362 337
363 /** 338 /**
364 * set doc path for an unzipped directory 339 * set doc path for an unzipped directory
365 */ 340 */
366 public void setDocPath(String path) { 341 public void setDocPath(FileObject path) {
367 setDocPath = true; 342 setDocPath = true;
368 if (path == null) 343 if (path == null)
369 return; 344 return;
370 String newDocPath = path + File.separatorChar + PACKAGE_HTML_FILE_NAME; 345 if (!path.equals(docPath)) {
371 if (!newDocPath.equals(docPath)) { 346 docPath = path;
372 docPath = newDocPath;
373 checkDoc();
374 }
375 }
376
377 /**
378 * set the doc path for zipped directory
379 */
380 public void setDocPath(String path, String entry) {
381 if (!path.equals(zipDocPath)) {
382 zipDocPath = path;
383 zipDocEntry = entry + PACKAGE_HTML_FILE_NAME;
384 checkDoc(); 347 checkDoc();
385 } 348 }
386 } 349 }
387 350
388 // Has checkDoc() sounded off yet? 351 // Has checkDoc() sounded off yet?
407 * Return the source position of the entity, or null if 370 * Return the source position of the entity, or null if
408 * no position is available. 371 * no position is available.
409 */ 372 */
410 public SourcePosition position() { 373 public SourcePosition position() {
411 return (tree != null) 374 return (tree != null)
412 ? SourcePositionImpl.make(tree.sourcefile + "", tree.pos, tree.lineMap) 375 ? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
413 : SourcePositionImpl.make(docPath, Position.NOPOS, null); 376 : SourcePositionImpl.make(docPath, Position.NOPOS, null);
414 } 377 }
415 } 378 }

mercurial