mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-19 18:44:38 +02:00
6794582: javadoc should read files using a FileManager
Reviewed-by: darcy, bpatel
This commit is contained in:
parent
19b769a375
commit
981f025a85
13 changed files with 301 additions and 225 deletions
|
@ -25,12 +25,11 @@
|
||||||
|
|
||||||
package com.sun.tools.doclets.formats.html.markup;
|
package com.sun.tools.doclets.formats.html.markup;
|
||||||
|
|
||||||
import com.sun.tools.doclets.internal.toolkit.*;
|
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import com.sun.tools.doclets.internal.toolkit.util.*;
|
|
||||||
|
import com.sun.javadoc.*;
|
||||||
|
import com.sun.tools.doclets.internal.toolkit.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,8 +55,9 @@ public abstract class HtmlDocWriter extends HtmlWriter {
|
||||||
super(configuration,
|
super(configuration,
|
||||||
null, configuration.destDirName + filename,
|
null, configuration.destDirName + filename,
|
||||||
configuration.docencoding);
|
configuration.docencoding);
|
||||||
|
// use File to normalize file separators
|
||||||
configuration.message.notice("doclet.Generating_0",
|
configuration.message.notice("doclet.Generating_0",
|
||||||
configuration.destDirName + filename);
|
new File(configuration.destDirName, filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
public HtmlDocWriter(Configuration configuration,
|
public HtmlDocWriter(Configuration configuration,
|
||||||
|
@ -65,10 +65,10 @@ public abstract class HtmlDocWriter extends HtmlWriter {
|
||||||
super(configuration,
|
super(configuration,
|
||||||
configuration.destDirName + path, filename,
|
configuration.destDirName + path, filename,
|
||||||
configuration.docencoding);
|
configuration.docencoding);
|
||||||
|
// use File to normalize file separators
|
||||||
configuration.message.notice("doclet.Generating_0",
|
configuration.message.notice("doclet.Generating_0",
|
||||||
configuration.destDirName +
|
new File(configuration.destDirName,
|
||||||
((path.length() > 0)?
|
((path.length() > 0)? path + File.separator: "") + filename));
|
||||||
path + File.separator: "") + filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,10 +25,12 @@
|
||||||
|
|
||||||
package com.sun.tools.doclets.internal.toolkit.util;
|
package com.sun.tools.doclets.internal.toolkit.util;
|
||||||
|
|
||||||
import com.sun.tools.doclets.internal.toolkit.*;
|
|
||||||
import com.sun.javadoc.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import javax.tools.FileObject;
|
||||||
|
|
||||||
|
import com.sun.javadoc.*;
|
||||||
|
import com.sun.tools.doclets.internal.toolkit.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts Java Source Code to HTML.
|
* Converts Java Source Code to HTML.
|
||||||
|
@ -123,16 +125,27 @@ public class SourceToHTMLConverter {
|
||||||
if (cd == null || outputdir == null) {
|
if (cd == null || outputdir == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file;
|
|
||||||
SourcePosition sp = cd.position();
|
|
||||||
if (sp == null || (file = sp.file()) == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
SourcePosition sp = cd.position();
|
||||||
|
if (sp == null)
|
||||||
|
return;
|
||||||
|
Reader r;
|
||||||
|
// temp hack until we can update SourcePosition API.
|
||||||
|
if (sp instanceof com.sun.tools.javadoc.SourcePositionImpl) {
|
||||||
|
FileObject fo = ((com.sun.tools.javadoc.SourcePositionImpl) sp).fileObject();
|
||||||
|
if (fo == null)
|
||||||
|
return;
|
||||||
|
r = fo.openReader(true);
|
||||||
|
} else {
|
||||||
|
File file = sp.file();
|
||||||
|
if (file == null)
|
||||||
|
return;
|
||||||
|
r = new FileReader(file);
|
||||||
|
}
|
||||||
|
LineNumberReader reader = new LineNumberReader(r);
|
||||||
int lineno = 1;
|
int lineno = 1;
|
||||||
String line;
|
String line;
|
||||||
StringBuffer output = new StringBuffer();
|
StringBuffer output = new StringBuffer();
|
||||||
LineNumberReader reader = new LineNumberReader(new FileReader(file));
|
|
||||||
try {
|
try {
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
output.append(formatLine(line, configuration.sourcetab, lineno));
|
output.append(formatLine(line, configuration.sourcetab, lineno));
|
||||||
|
|
|
@ -25,10 +25,11 @@
|
||||||
|
|
||||||
package com.sun.tools.doclets.internal.toolkit.util;
|
package com.sun.tools.doclets.internal.toolkit.util;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
import com.sun.tools.doclets.internal.toolkit.*;
|
import com.sun.tools.doclets.internal.toolkit.*;
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities Class for Doclets.
|
* Utilities Class for Doclets.
|
||||||
|
@ -579,7 +580,7 @@ public class Util {
|
||||||
* @param docencoding Encoding to be used for this file.
|
* @param docencoding Encoding to be used for this file.
|
||||||
* @exception IOException Exception raised by the FileWriter is passed on
|
* @exception IOException Exception raised by the FileWriter is passed on
|
||||||
* to next level.
|
* to next level.
|
||||||
* @exception UnSupportedEncodingException Exception raised by the
|
* @exception UnsupportedEncodingException Exception raised by the
|
||||||
* OutputStreamWriter is passed on to next level.
|
* OutputStreamWriter is passed on to next level.
|
||||||
* @return Writer Writer for the file getting generated.
|
* @return Writer Writer for the file getting generated.
|
||||||
* @see java.io.FileOutputStream
|
* @see java.io.FileOutputStream
|
||||||
|
@ -598,8 +599,7 @@ public class Util {
|
||||||
fos = new FileOutputStream(filename);
|
fos = new FileOutputStream(filename);
|
||||||
}
|
}
|
||||||
if (docencoding == null) {
|
if (docencoding == null) {
|
||||||
OutputStreamWriter oswriter = new OutputStreamWriter(fos);
|
return new OutputStreamWriter(fos);
|
||||||
return oswriter;
|
|
||||||
} else {
|
} else {
|
||||||
return new OutputStreamWriter(fos, docencoding);
|
return new OutputStreamWriter(fos, docencoding);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,42 +25,48 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.tools.FileObject;
|
||||||
|
import javax.tools.JavaFileManager.Location;
|
||||||
|
import javax.tools.StandardJavaFileManager;
|
||||||
|
import javax.tools.StandardLocation;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
import static com.sun.javadoc.LanguageVersion.*;
|
import static com.sun.javadoc.LanguageVersion.*;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.List;
|
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
|
||||||
import com.sun.tools.javac.util.Name;
|
|
||||||
import com.sun.tools.javac.util.Position;
|
|
||||||
|
|
||||||
import com.sun.tools.javac.code.Flags;
|
import com.sun.tools.javac.code.Flags;
|
||||||
import com.sun.tools.javac.code.Kinds;
|
import com.sun.tools.javac.code.Kinds;
|
||||||
import com.sun.tools.javac.code.TypeTags;
|
|
||||||
import com.sun.tools.javac.code.Type;
|
|
||||||
import com.sun.tools.javac.code.Type.ClassType;
|
|
||||||
import com.sun.tools.javac.code.Scope;
|
import com.sun.tools.javac.code.Scope;
|
||||||
import com.sun.tools.javac.code.Symbol;
|
import com.sun.tools.javac.code.Symbol;
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
|
import com.sun.tools.javac.code.Type;
|
||||||
|
import com.sun.tools.javac.code.Type.ClassType;
|
||||||
|
import com.sun.tools.javac.code.TypeTags;
|
||||||
|
|
||||||
import com.sun.tools.javac.comp.AttrContext;
|
import com.sun.tools.javac.comp.AttrContext;
|
||||||
import com.sun.tools.javac.comp.Env;
|
import com.sun.tools.javac.comp.Env;
|
||||||
|
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCImport;
|
import com.sun.tools.javac.tree.JCTree.JCImport;
|
||||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
|
||||||
import com.sun.tools.javac.tree.TreeInfo;
|
import com.sun.tools.javac.tree.TreeInfo;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.util.List;
|
||||||
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
|
import com.sun.tools.javac.util.Name;
|
||||||
import com.sun.tools.javac.util.Names;
|
import com.sun.tools.javac.util.Names;
|
||||||
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
import static com.sun.tools.javac.code.Flags.*;
|
import static com.sun.tools.javac.code.Flags.*;
|
||||||
import static com.sun.tools.javac.code.Kinds.*;
|
import static com.sun.tools.javac.code.Kinds.*;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a java class and provides access to information
|
* Represents a java class and provides access to information
|
||||||
* about the class, the class' comment and tags, and the
|
* about the class, the class' comment and tags, and the
|
||||||
|
@ -271,16 +277,41 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
|
||||||
*/
|
*/
|
||||||
public PackageDoc containingPackage() {
|
public PackageDoc containingPackage() {
|
||||||
PackageDocImpl p = env.getPackageDoc(tsym.packge());
|
PackageDocImpl p = env.getPackageDoc(tsym.packge());
|
||||||
SourcePosition po = position();
|
if (p.setDocPath == false) {
|
||||||
if (po != null && p.setDocPath == false && p.zipDocPath == null) {
|
FileObject docPath;
|
||||||
//Set the package path if possible
|
try {
|
||||||
File packageDir = po.file().getParentFile();
|
Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
|
||||||
if (packageDir != null
|
? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
|
||||||
&& (new File(packageDir, "package.html")).exists()) {
|
|
||||||
p.setDocPath(packageDir.getPath());
|
docPath = env.fileManager.getFileForInput(
|
||||||
} else {
|
location, p.qualifiedName(), "package.html");
|
||||||
p.setDocPath(null);
|
} catch (IOException e) {
|
||||||
|
docPath = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (docPath == null) {
|
||||||
|
// fall back on older semantics of looking in same directory as
|
||||||
|
// source file for this class
|
||||||
|
SourcePosition po = position();
|
||||||
|
if (env.fileManager instanceof StandardJavaFileManager &&
|
||||||
|
po instanceof SourcePositionImpl) {
|
||||||
|
URI uri = ((SourcePositionImpl) po).filename.toUri();
|
||||||
|
if ("file".equals(uri.getScheme())) {
|
||||||
|
File f = new File(uri.getPath());
|
||||||
|
File dir = f.getParentFile();
|
||||||
|
if (dir != null) {
|
||||||
|
File pf = new File(dir, "package.html");
|
||||||
|
if (pf.exists()) {
|
||||||
|
StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
|
||||||
|
docPath = sfm.getJavaFileObjects(pf).iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.setDocPath(docPath);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1282,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
|
||||||
*/
|
*/
|
||||||
public SourcePosition position() {
|
public SourcePosition position() {
|
||||||
if (tsym.sourcefile == null) return null;
|
if (tsym.sourcefile == null) return null;
|
||||||
return SourcePositionImpl.make(tsym.sourcefile.toString(),
|
return SourcePositionImpl.make(tsym.sourcefile,
|
||||||
(tree==null) ? Position.NOPOS : tree.pos,
|
(tree==null) ? Position.NOPOS : tree.pos,
|
||||||
lineMap);
|
lineMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,9 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.*;
|
||||||
|
import javax.tools.JavaFileManager;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
|
@ -40,7 +41,6 @@ import com.sun.tools.javac.util.Context;
|
||||||
import com.sun.tools.javac.util.Names;
|
import com.sun.tools.javac.util.Names;
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the environment for a run of javadoc.
|
* Holds the environment for a run of javadoc.
|
||||||
* Holds only the information needed throughout the
|
* Holds only the information needed throughout the
|
||||||
|
@ -103,6 +103,7 @@ public class DocEnv {
|
||||||
|
|
||||||
Check chk;
|
Check chk;
|
||||||
Types types;
|
Types types;
|
||||||
|
JavaFileManager fileManager;
|
||||||
|
|
||||||
/** Allow documenting from class files? */
|
/** Allow documenting from class files? */
|
||||||
boolean docClasses = false;
|
boolean docClasses = false;
|
||||||
|
@ -133,6 +134,7 @@ public class DocEnv {
|
||||||
externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
|
externalizableSym = reader.enterClass(names.fromString("java.io.Externalizable"));
|
||||||
chk = Check.instance(context);
|
chk = Check.instance(context);
|
||||||
types = Types.instance(context);
|
types = Types.instance(context);
|
||||||
|
fileManager = context.get(JavaFileManager.class);
|
||||||
|
|
||||||
// Default. Should normally be reset with setLocale.
|
// Default. Should normally be reset with setLocale.
|
||||||
this.doclocale = new DocLocale(this, "", breakiterator);
|
this.doclocale = new DocLocale(this, "", breakiterator);
|
||||||
|
|
|
@ -25,11 +25,13 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.CollationKey;
|
import java.text.CollationKey;
|
||||||
|
import javax.tools.FileObject;
|
||||||
|
|
||||||
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +45,7 @@ import com.sun.tools.javac.util.Position;
|
||||||
* @author Atul M Dambalkar
|
* @author Atul M Dambalkar
|
||||||
* @author Neal Gafter (rewrite)
|
* @author Neal Gafter (rewrite)
|
||||||
*/
|
*/
|
||||||
abstract class DocImpl implements Doc, Comparable<Object> {
|
public abstract class DocImpl implements Doc, Comparable<Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Doc environment
|
* Doc environment
|
||||||
|
@ -163,7 +165,7 @@ abstract class DocImpl implements Doc, Comparable<Object> {
|
||||||
/**
|
/**
|
||||||
* Utility for subclasses which read HTML documentation files.
|
* Utility for subclasses which read HTML documentation files.
|
||||||
*/
|
*/
|
||||||
String readHTMLDocumentation(InputStream input, String filename) throws IOException {
|
String readHTMLDocumentation(InputStream input, FileObject filename) throws IOException {
|
||||||
int filesize = input.available();
|
int filesize = input.available();
|
||||||
byte[] filecontents = new byte[filesize];
|
byte[] filecontents = new byte[filesize];
|
||||||
input.read(filecontents, 0, filesize);
|
input.read(filecontents, 0, filesize);
|
||||||
|
|
|
@ -25,20 +25,18 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.text.CollationKey;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.code.Flags;
|
||||||
|
import com.sun.tools.javac.code.Symbol.*;
|
||||||
|
import com.sun.tools.javac.code.Type;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
import com.sun.tools.javac.code.Flags;
|
|
||||||
import com.sun.tools.javac.code.Type;
|
|
||||||
import com.sun.tools.javac.code.Symbol;
|
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
|
||||||
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
|
|
||||||
|
|
||||||
import java.text.CollationKey;
|
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a method or constructor of a java class.
|
* Represents a method or constructor of a java class.
|
||||||
|
@ -267,7 +265,7 @@ public abstract class ExecutableMemberDocImpl
|
||||||
*/
|
*/
|
||||||
public SourcePosition position() {
|
public SourcePosition position() {
|
||||||
if (sym.enclClass().sourcefile == null) return null;
|
if (sym.enclClass().sourcefile == null) return null;
|
||||||
return SourcePositionImpl.make(sym.enclClass().sourcefile.toString(),
|
return SourcePositionImpl.make(sym.enclClass().sourcefile,
|
||||||
(tree==null) ? 0 : tree.pos,
|
(tree==null) ? 0 : tree.pos,
|
||||||
lineMap);
|
lineMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
import static com.sun.javadoc.LanguageVersion.*;
|
import static com.sun.javadoc.LanguageVersion.*;
|
||||||
|
@ -38,9 +40,6 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
|
||||||
|
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a field in a java class.
|
* Represents a field in a java class.
|
||||||
*
|
*
|
||||||
|
@ -260,7 +259,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
|
||||||
*/
|
*/
|
||||||
public SourcePosition position() {
|
public SourcePosition position() {
|
||||||
if (sym.enclClass().sourcefile == null) return null;
|
if (sym.enclClass().sourcefile == null) return null;
|
||||||
return SourcePositionImpl.make(sym.enclClass().sourcefile.toString(),
|
return SourcePositionImpl.make(sym.enclClass().sourcefile,
|
||||||
(tree==null) ? 0 : tree.pos,
|
(tree==null) ? 0 : tree.pos,
|
||||||
lineMap);
|
lineMap);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,18 +25,13 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
|
||||||
import com.sun.tools.javac.file.JavacFileManager;
|
|
||||||
import com.sun.tools.javac.file.ZipArchive.ZipFileObject;
|
|
||||||
import com.sun.tools.javac.file.Old199;
|
|
||||||
import com.sun.tools.javac.file.ZipFileIndexArchive;
|
|
||||||
import com.sun.tools.javac.jvm.ClassReader;
|
|
||||||
import com.sun.tools.javac.util.Context;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import javax.tools.JavaFileObject;
|
import javax.tools.JavaFileObject;
|
||||||
|
|
||||||
|
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
||||||
|
import com.sun.tools.javac.jvm.ClassReader;
|
||||||
|
import com.sun.tools.javac.util.Context;
|
||||||
|
|
||||||
/** Javadoc uses an extended class reader that records package.html entries
|
/** Javadoc uses an extended class reader that records package.html entries
|
||||||
* @author Neal Gafter
|
* @author Neal Gafter
|
||||||
*/
|
*/
|
||||||
|
@ -82,32 +77,7 @@ class JavadocClassReader extends ClassReader {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
|
protected void extraFileActions(PackageSymbol pack, JavaFileObject fo) {
|
||||||
CharSequence fileName = Old199.getName(fo);
|
if (fo.isNameCompatible("package", JavaFileObject.Kind.HTML))
|
||||||
if (docenv != null && fileName.equals("package.html")) {
|
docenv.getPackageDoc(pack).setDocPath(fo);
|
||||||
if (fo instanceof ZipFileObject) {
|
|
||||||
ZipFileObject zfo = (ZipFileObject) fo;
|
|
||||||
String zipName = zfo.getZipName();
|
|
||||||
String entryName = zfo.getZipEntryName();
|
|
||||||
int lastSep = entryName.lastIndexOf("/");
|
|
||||||
String classPathName = entryName.substring(0, lastSep + 1);
|
|
||||||
docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
|
|
||||||
}
|
|
||||||
else if (fo instanceof ZipFileIndexArchive.ZipFileIndexFileObject) {
|
|
||||||
ZipFileIndexArchive.ZipFileIndexFileObject zfo = (ZipFileIndexArchive.ZipFileIndexFileObject) fo;
|
|
||||||
String zipName = zfo.getZipName();
|
|
||||||
String entryName = zfo.getZipEntryName();
|
|
||||||
if (File.separatorChar != '/') {
|
|
||||||
entryName = entryName.replace(File.separatorChar, '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
int lastSep = entryName.lastIndexOf("/");
|
|
||||||
String classPathName = entryName.substring(0, lastSep + 1);
|
|
||||||
docenv.getPackageDoc(pack).setDocPath(zipName, classPathName);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
File fileDir = new File(Old199.getPath(fo)).getParentFile();
|
|
||||||
docenv.getPackageDoc(pack).setDocPath(fileDir.getAbsolutePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,17 +25,29 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.tools.JavaFileManager.Location;
|
||||||
|
import javax.tools.JavaFileObject;
|
||||||
|
import javax.tools.StandardJavaFileManager;
|
||||||
|
import javax.tools.StandardLocation;
|
||||||
|
|
||||||
import com.sun.tools.javac.code.Symbol.*;
|
import com.sun.tools.javac.code.Symbol.CompletionFailure;
|
||||||
import com.sun.tools.javac.comp.*;
|
import com.sun.tools.javac.comp.Annotate;
|
||||||
import com.sun.tools.javac.file.Paths;
|
|
||||||
import com.sun.tools.javac.parser.DocCommentScanner;
|
import com.sun.tools.javac.parser.DocCommentScanner;
|
||||||
import com.sun.tools.javac.tree.*;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||||
import com.sun.tools.javac.util.*;
|
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||||
|
import com.sun.tools.javac.util.Abort;
|
||||||
|
import com.sun.tools.javac.util.Context;
|
||||||
|
import com.sun.tools.javac.util.List;
|
||||||
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +65,6 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
final JavadocClassReader reader;
|
final JavadocClassReader reader;
|
||||||
final JavadocEnter enter;
|
final JavadocEnter enter;
|
||||||
final Annotate annotate;
|
final Annotate annotate;
|
||||||
private final Paths paths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new JavaCompiler processor, using appropriately
|
* Construct a new JavaCompiler processor, using appropriately
|
||||||
|
@ -66,7 +77,6 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
reader = JavadocClassReader.instance0(context);
|
reader = JavadocClassReader.instance0(context);
|
||||||
enter = JavadocEnter.instance0(context);
|
enter = JavadocEnter.instance0(context);
|
||||||
annotate = Annotate.instance(context);
|
annotate = Annotate.instance(context);
|
||||||
paths = Paths.instance(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,7 +130,7 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
boolean quiet) throws IOException {
|
boolean quiet) throws IOException {
|
||||||
docenv = DocEnv.instance(context);
|
docenv = DocEnv.instance(context);
|
||||||
docenv.showAccess = filter;
|
docenv.showAccess = filter;
|
||||||
docenv.quiet = quiet;
|
docenv.quiet = quiet;
|
||||||
docenv.breakiterator = breakiterator;
|
docenv.breakiterator = breakiterator;
|
||||||
docenv.setLocale(doclocale);
|
docenv.setLocale(doclocale);
|
||||||
docenv.setEncoding(encoding);
|
docenv.setEncoding(encoding);
|
||||||
|
@ -133,12 +143,14 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
|
ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
|
||||||
for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
|
for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
|
||||||
String name = it.head;
|
String name = it.head;
|
||||||
if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
|
if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
|
||||||
|
JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
|
||||||
docenv.notice("main.Loading_source_file", name);
|
docenv.notice("main.Loading_source_file", name);
|
||||||
JCCompilationUnit tree = parse(name);
|
JCCompilationUnit tree = parse(fo);
|
||||||
classTrees.append(tree);
|
classTrees.append(tree);
|
||||||
} else if (isValidPackageName(name)) {
|
} else if (isValidPackageName(name)) {
|
||||||
names = names.append(name);
|
names = names.append(name);
|
||||||
} else if (name.endsWith(".java")) {
|
} else if (name.endsWith(".java")) {
|
||||||
|
@ -151,12 +163,14 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
if (!docClasses) {
|
if (!docClasses) {
|
||||||
// Recursively search given subpackages. If any packages
|
// Recursively search given subpackages. If any packages
|
||||||
//are found, add them to the list.
|
//are found, add them to the list.
|
||||||
searchSubPackages(subPackages, names, excludedPackages);
|
Map<String,List<JavaFileObject>> packageFiles =
|
||||||
|
searchSubPackages(subPackages, names, excludedPackages);
|
||||||
|
|
||||||
// Parse the packages
|
// Parse the packages
|
||||||
for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
|
for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
|
||||||
// Parse sources ostensibly belonging to package.
|
// Parse sources ostensibly belonging to package.
|
||||||
parsePackageClasses(packs.head, packTrees, excludedPackages);
|
String packageName = packs.head;
|
||||||
|
parsePackageClasses(packageName, packageFiles.get(packageName), packTrees, excludedPackages);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messager.nerrors() != 0) return null;
|
if (messager.nerrors() != 0) return null;
|
||||||
|
@ -167,7 +181,8 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
}
|
}
|
||||||
} catch (Abort ex) {}
|
} catch (Abort ex) {}
|
||||||
|
|
||||||
if (messager.nerrors() != 0) return null;
|
if (messager.nerrors() != 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
if (docClasses)
|
if (docClasses)
|
||||||
return new RootDocImpl(docenv, javaNames, options);
|
return new RootDocImpl(docenv, javaNames, options);
|
||||||
|
@ -185,66 +200,129 @@ public class JavadocTool extends com.sun.tools.javac.main.JavaCompiler {
|
||||||
return isValidClassName(s);
|
return isValidClassName(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final static char pathSep = File.pathSeparatorChar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search all directories in path for subdirectory name. Add all
|
* search all directories in path for subdirectory name. Add all
|
||||||
* .java files found in such a directory to args.
|
* .java files found in such a directory to args.
|
||||||
*/
|
*/
|
||||||
private void parsePackageClasses(String name,
|
private void parsePackageClasses(String name,
|
||||||
ListBuffer<JCCompilationUnit> trees,
|
Iterable<JavaFileObject> files,
|
||||||
List<String> excludedPackages)
|
ListBuffer<JCCompilationUnit> trees,
|
||||||
throws IOException {
|
List<String> excludedPackages)
|
||||||
|
throws IOException {
|
||||||
if (excludedPackages.contains(name)) {
|
if (excludedPackages.contains(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasFiles = false;
|
boolean hasFiles = false;
|
||||||
docenv.notice("main.Loading_source_files_for_package", name);
|
docenv.notice("main.Loading_source_files_for_package", name);
|
||||||
name = name.replace('.', File.separatorChar);
|
|
||||||
for (File pathname : paths.sourceSearchPath()) {
|
if (files == null) {
|
||||||
File f = new File(pathname, name);
|
Location location = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
|
||||||
String names[] = f.list();
|
? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
|
||||||
// if names not null, then found directory with source files
|
ListBuffer<JavaFileObject> lb = new ListBuffer<JavaFileObject>();
|
||||||
if (names != null) {
|
for (JavaFileObject fo: docenv.fileManager.list(
|
||||||
String dir = f.getAbsolutePath();
|
location, name, EnumSet.of(JavaFileObject.Kind.SOURCE), false)) {
|
||||||
if (!dir.endsWith(File.separator))
|
String binaryName = docenv.fileManager.inferBinaryName(location, fo);
|
||||||
dir = dir + File.separator;
|
String simpleName = getSimpleName(binaryName);
|
||||||
for (int j = 0; j < names.length; j++) {
|
if (isValidClassName(simpleName)) {
|
||||||
if (isValidJavaSourceFile(names[j])) {
|
lb.append(fo);
|
||||||
String fn = dir + names[j];
|
|
||||||
// messager.notice("main.Loading_source_file", fn);
|
|
||||||
trees.append(parse(fn));
|
|
||||||
hasFiles = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
files = lb.toList();
|
||||||
}
|
}
|
||||||
if (!hasFiles)
|
|
||||||
|
for (JavaFileObject fo : files) {
|
||||||
|
// messager.notice("main.Loading_source_file", fn);
|
||||||
|
trees.append(parse(fo));
|
||||||
|
hasFiles = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasFiles) {
|
||||||
messager.warning(null, "main.no_source_files_for_package",
|
messager.warning(null, "main.no_source_files_for_package",
|
||||||
name.replace(File.separatorChar, '.'));
|
name.replace(File.separatorChar, '.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively search all directories in path for subdirectory name.
|
* Recursively search all directories in path for subdirectory name.
|
||||||
* Add all packages found in such a directory to packages list.
|
* Add all packages found in such a directory to packages list.
|
||||||
*/
|
*/
|
||||||
private void searchSubPackages(List<String> subPackages,
|
private Map<String,List<JavaFileObject>> searchSubPackages(
|
||||||
ListBuffer<String> packages,
|
List<String> subPackages,
|
||||||
List<String> excludedPackages) {
|
ListBuffer<String> packages,
|
||||||
// FIXME: This search path is bogus.
|
List<String> excludedPackages)
|
||||||
// Only the effective source path should be searched for sources.
|
throws IOException {
|
||||||
// Only the effective class path should be searched for classes.
|
Map<String,List<JavaFileObject>> packageFiles =
|
||||||
// Should the bootclasspath/extdirs also be searched for classes?
|
new HashMap<String,List<JavaFileObject>>();
|
||||||
java.util.List<File> pathnames = new java.util.ArrayList<File>();
|
|
||||||
if (paths.sourcePath() != null)
|
|
||||||
for (File elt : paths.sourcePath())
|
|
||||||
pathnames.add(elt);
|
|
||||||
for (File elt : paths.userClassPath())
|
|
||||||
pathnames.add(elt);
|
|
||||||
|
|
||||||
for (String subPackage : subPackages)
|
Map<String,Boolean> includedPackages = new HashMap<String,Boolean>();
|
||||||
searchSubPackage(subPackage, packages, excludedPackages, pathnames);
|
includedPackages.put("", true);
|
||||||
|
for (String p: excludedPackages)
|
||||||
|
includedPackages.put(p, false);
|
||||||
|
|
||||||
|
if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
|
||||||
|
searchSubPackages(subPackages,
|
||||||
|
includedPackages,
|
||||||
|
packages, packageFiles,
|
||||||
|
StandardLocation.SOURCE_PATH,
|
||||||
|
EnumSet.of(JavaFileObject.Kind.SOURCE));
|
||||||
|
searchSubPackages(subPackages,
|
||||||
|
includedPackages,
|
||||||
|
packages, packageFiles,
|
||||||
|
StandardLocation.CLASS_PATH,
|
||||||
|
EnumSet.of(JavaFileObject.Kind.CLASS));
|
||||||
|
} else {
|
||||||
|
searchSubPackages(subPackages,
|
||||||
|
includedPackages,
|
||||||
|
packages, packageFiles,
|
||||||
|
StandardLocation.CLASS_PATH,
|
||||||
|
EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS));
|
||||||
|
}
|
||||||
|
return packageFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void searchSubPackages(List<String> subPackages,
|
||||||
|
Map<String,Boolean> includedPackages,
|
||||||
|
ListBuffer<String> packages,
|
||||||
|
Map<String, List<JavaFileObject>> packageFiles,
|
||||||
|
StandardLocation location, Set<JavaFileObject.Kind> kinds)
|
||||||
|
throws IOException {
|
||||||
|
for (String subPackage: subPackages) {
|
||||||
|
if (!isIncluded(subPackage, includedPackages))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (JavaFileObject fo: docenv.fileManager.list(location, subPackage, kinds, true)) {
|
||||||
|
String binaryName = docenv.fileManager.inferBinaryName(location, fo);
|
||||||
|
String packageName = getPackageName(binaryName);
|
||||||
|
String simpleName = getSimpleName(binaryName);
|
||||||
|
if (isIncluded(packageName, includedPackages) && isValidClassName(simpleName)) {
|
||||||
|
List<JavaFileObject> list = packageFiles.get(packageName);
|
||||||
|
list = (list == null ? List.of(fo) : list.prepend(fo));
|
||||||
|
packageFiles.put(packageName, list);
|
||||||
|
if (!packages.contains(packageName))
|
||||||
|
packages.add(packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPackageName(String name) {
|
||||||
|
int lastDot = name.lastIndexOf(".");
|
||||||
|
return (lastDot == -1 ? "" : name.substring(0, lastDot));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSimpleName(String name) {
|
||||||
|
int lastDot = name.lastIndexOf(".");
|
||||||
|
return (lastDot == -1 ? name : name.substring(lastDot + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isIncluded(String packageName, Map<String,Boolean> includedPackages) {
|
||||||
|
Boolean b = includedPackages.get(packageName);
|
||||||
|
if (b == null) {
|
||||||
|
b = isIncluded(getPackageName(packageName), includedPackages);
|
||||||
|
includedPackages.put(packageName, b);
|
||||||
|
}
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,30 +25,23 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.zip.ZipFile;
|
import javax.tools.FileObject;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
import com.sun.tools.javac.code.Attribute;
|
import com.sun.tools.javac.code.Attribute;
|
||||||
import com.sun.tools.javac.code.Scope;
|
import com.sun.tools.javac.code.Scope;
|
||||||
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
import com.sun.tools.javac.code.Symbol.ClassSymbol;
|
||||||
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
import com.sun.tools.javac.code.Symbol.PackageSymbol;
|
||||||
import com.sun.tools.javac.comp.AttrContext;
|
|
||||||
import com.sun.tools.javac.comp.Env;
|
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
import com.sun.tools.javac.util.Name;
|
import com.sun.tools.javac.util.Name;
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a java package. Provides access to information
|
* Represents a java package. Provides access to information
|
||||||
* about the package, the package's comment and tags, and the
|
* about the package, the package's comment and tags, and the
|
||||||
|
@ -63,14 +56,10 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||||
|
|
||||||
public class PackageDocImpl extends DocImpl implements PackageDoc {
|
public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||||
|
|
||||||
private static final String PACKAGE_HTML_FILE_NAME = "package.html";
|
|
||||||
|
|
||||||
protected PackageSymbol sym;
|
protected PackageSymbol sym;
|
||||||
private JCCompilationUnit tree = null; // for source position
|
private JCCompilationUnit tree = null; // for source position
|
||||||
|
|
||||||
public String docPath = null;
|
public FileObject docPath = null;
|
||||||
public String zipDocPath = null;
|
|
||||||
public String zipDocEntry = null;
|
|
||||||
private boolean foundDoc; // found a doc comment in either
|
private boolean foundDoc; // found a doc comment in either
|
||||||
// package.html or package-info.java
|
// package.html or package-info.java
|
||||||
|
|
||||||
|
@ -108,30 +97,16 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||||
* Do lazy initialization of "documentation" string.
|
* Do lazy initialization of "documentation" string.
|
||||||
*/
|
*/
|
||||||
String documentation() {
|
String documentation() {
|
||||||
if (documentation != null) return documentation;
|
if (documentation != null)
|
||||||
if (zipDocPath != null) {
|
return documentation;
|
||||||
try {
|
|
||||||
ZipFile f = new ZipFile(zipDocPath);
|
|
||||||
ZipEntry entry = f.getEntry(zipDocEntry);
|
|
||||||
if (entry != null) {
|
|
||||||
InputStream s = f.getInputStream(entry);
|
|
||||||
return (documentation = readHTMLDocumentation(s,
|
|
||||||
zipDocPath + File.separatorChar + zipDocEntry));
|
|
||||||
}
|
|
||||||
} catch (IOException exc) {
|
|
||||||
documentation = "";
|
|
||||||
env.error(null, "javadoc.File_Read_Error",
|
|
||||||
zipDocPath + File.separatorChar + zipDocEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (docPath != null) {
|
if (docPath != null) {
|
||||||
// read from file
|
// read from file
|
||||||
try {
|
try {
|
||||||
InputStream s = new FileInputStream(docPath);
|
InputStream s = docPath.openInputStream();
|
||||||
documentation = readHTMLDocumentation(s, docPath);
|
documentation = readHTMLDocumentation(s, docPath);
|
||||||
} catch (IOException exc) {
|
} catch (IOException exc) {
|
||||||
documentation = "";
|
documentation = "";
|
||||||
env.error(null, "javadoc.File_Read_Error", docPath);
|
env.error(null, "javadoc.File_Read_Error", docPath.getName());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no doc file to be had
|
// no doc file to be had
|
||||||
|
@ -363,24 +338,12 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||||
/**
|
/**
|
||||||
* set doc path for an unzipped directory
|
* set doc path for an unzipped directory
|
||||||
*/
|
*/
|
||||||
public void setDocPath(String path) {
|
public void setDocPath(FileObject path) {
|
||||||
setDocPath = true;
|
setDocPath = true;
|
||||||
if (path == null)
|
if (path == null)
|
||||||
return;
|
return;
|
||||||
String newDocPath = path + File.separatorChar + PACKAGE_HTML_FILE_NAME;
|
if (!path.equals(docPath)) {
|
||||||
if (!newDocPath.equals(docPath)) {
|
docPath = path;
|
||||||
docPath = newDocPath;
|
|
||||||
checkDoc();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set the doc path for zipped directory
|
|
||||||
*/
|
|
||||||
public void setDocPath(String path, String entry) {
|
|
||||||
if (!path.equals(zipDocPath)) {
|
|
||||||
zipDocPath = path;
|
|
||||||
zipDocEntry = entry + PACKAGE_HTML_FILE_NAME;
|
|
||||||
checkDoc();
|
checkDoc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,7 +372,7 @@ public class PackageDocImpl extends DocImpl implements PackageDoc {
|
||||||
*/
|
*/
|
||||||
public SourcePosition position() {
|
public SourcePosition position() {
|
||||||
return (tree != null)
|
return (tree != null)
|
||||||
? SourcePositionImpl.make(tree.sourcefile + "", tree.pos, tree.lineMap)
|
? SourcePositionImpl.make(tree.sourcefile, tree.pos, tree.lineMap)
|
||||||
: SourcePositionImpl.make(docPath, Position.NOPOS, null);
|
: SourcePositionImpl.make(docPath, Position.NOPOS, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,17 +26,16 @@
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileInputStream;
|
import java.util.Locale;
|
||||||
import java.io.File;
|
import javax.tools.JavaFileObject;
|
||||||
|
import javax.tools.StandardJavaFileManager;
|
||||||
|
|
||||||
import com.sun.javadoc.*;
|
import com.sun.javadoc.*;
|
||||||
|
|
||||||
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
|
||||||
import com.sun.tools.javac.code.Symbol;
|
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class holds the information from one run of javadoc.
|
* This class holds the information from one run of javadoc.
|
||||||
|
@ -308,10 +307,13 @@ public class RootDocImpl extends DocImpl implements RootDoc {
|
||||||
* Return the path of the overview file and null if it does not exist.
|
* Return the path of the overview file and null if it does not exist.
|
||||||
* @return the path of the overview file and null if it does not exist.
|
* @return the path of the overview file and null if it does not exist.
|
||||||
*/
|
*/
|
||||||
private String getOverviewPath() {
|
private JavaFileObject getOverviewPath() {
|
||||||
for (String[] opt : options) {
|
for (String[] opt : options) {
|
||||||
if (opt[0].equals("-overview")) {
|
if (opt[0].equals("-overview")) {
|
||||||
return opt[1];
|
if (env.fileManager instanceof StandardJavaFileManager) {
|
||||||
|
StandardJavaFileManager fm = (StandardJavaFileManager) env.fileManager;
|
||||||
|
return fm.getJavaFileObjects(opt[1]).iterator().next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -323,7 +325,7 @@ public class RootDocImpl extends DocImpl implements RootDoc {
|
||||||
protected String documentation() {
|
protected String documentation() {
|
||||||
if (documentation == null) {
|
if (documentation == null) {
|
||||||
int cnt = options.length();
|
int cnt = options.length();
|
||||||
String overviewPath = getOverviewPath();
|
JavaFileObject overviewPath = getOverviewPath();
|
||||||
if (overviewPath == null) {
|
if (overviewPath == null) {
|
||||||
// no doc file to be had
|
// no doc file to be had
|
||||||
documentation = "";
|
documentation = "";
|
||||||
|
@ -331,11 +333,11 @@ public class RootDocImpl extends DocImpl implements RootDoc {
|
||||||
// read from file
|
// read from file
|
||||||
try {
|
try {
|
||||||
documentation = readHTMLDocumentation(
|
documentation = readHTMLDocumentation(
|
||||||
new FileInputStream(overviewPath),
|
overviewPath.openInputStream(),
|
||||||
overviewPath);
|
overviewPath);
|
||||||
} catch (IOException exc) {
|
} catch (IOException exc) {
|
||||||
documentation = "";
|
documentation = "";
|
||||||
env.error(null, "javadoc.File_Read_Error", overviewPath);
|
env.error(null, "javadoc.File_Read_Error", overviewPath.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,7 +349,7 @@ public class RootDocImpl extends DocImpl implements RootDoc {
|
||||||
* no position is available.
|
* no position is available.
|
||||||
*/
|
*/
|
||||||
public SourcePosition position() {
|
public SourcePosition position() {
|
||||||
String path;
|
JavaFileObject path;
|
||||||
return ((path = getOverviewPath()) == null) ?
|
return ((path = getOverviewPath()) == null) ?
|
||||||
null :
|
null :
|
||||||
SourcePositionImpl.make(path, Position.NOPOS, null);
|
SourcePositionImpl.make(path, Position.NOPOS, null);
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
|
|
||||||
package com.sun.tools.javadoc;
|
package com.sun.tools.javadoc;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import javax.tools.FileObject;
|
||||||
|
|
||||||
import com.sun.javadoc.SourcePosition;
|
import com.sun.javadoc.SourcePosition;
|
||||||
import com.sun.tools.javac.util.Position;
|
import com.sun.tools.javac.util.Position;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A source position: filename, line number, and column number.
|
* A source position: filename, line number, and column number.
|
||||||
*
|
*
|
||||||
|
@ -37,15 +38,21 @@ import java.io.File;
|
||||||
* @author Neal M Gafter
|
* @author Neal M Gafter
|
||||||
* @author Michael Van De Vanter (position representation changed to char offsets)
|
* @author Michael Van De Vanter (position representation changed to char offsets)
|
||||||
*/
|
*/
|
||||||
class SourcePositionImpl implements SourcePosition {
|
public class SourcePositionImpl implements SourcePosition {
|
||||||
String filename;
|
FileObject filename;
|
||||||
int position;
|
int position;
|
||||||
Position.LineMap lineMap;
|
Position.LineMap lineMap;
|
||||||
|
|
||||||
/** The source file. Returns null if no file information is
|
/** The source file. Returns null if no file information is
|
||||||
* available. */
|
* available. */
|
||||||
public File file() {
|
public File file() {
|
||||||
return (filename == null) ? null : new File(filename);
|
return (filename == null) ? null : new File(filename.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The source file. Returns null if no file information is
|
||||||
|
* available. */
|
||||||
|
public FileObject fileObject() {
|
||||||
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The line in the source file. The first line is numbered 1;
|
/** The line in the source file. The first line is numbered 1;
|
||||||
|
@ -71,7 +78,7 @@ class SourcePositionImpl implements SourcePosition {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SourcePositionImpl(String file, int position,
|
private SourcePositionImpl(FileObject file, int position,
|
||||||
Position.LineMap lineMap) {
|
Position.LineMap lineMap) {
|
||||||
super();
|
super();
|
||||||
this.filename = file;
|
this.filename = file;
|
||||||
|
@ -79,16 +86,27 @@ class SourcePositionImpl implements SourcePosition {
|
||||||
this.lineMap = lineMap;
|
this.lineMap = lineMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SourcePosition make(String file, int pos,
|
public static SourcePosition make(FileObject file, int pos,
|
||||||
Position.LineMap lineMap) {
|
Position.LineMap lineMap) {
|
||||||
if (file == null) return null;
|
if (file == null) return null;
|
||||||
return new SourcePositionImpl(file, pos, lineMap);
|
return new SourcePositionImpl(file, pos, lineMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
// Backwards compatibility hack. ZipFileObjects use the format
|
||||||
|
// zipfile(zipentry) but javadoc has been using zipfile/zipentry
|
||||||
|
String fn = filename.toString();
|
||||||
|
if (fn.endsWith(")")) {
|
||||||
|
int paren = fn.lastIndexOf("(");
|
||||||
|
if (paren != -1)
|
||||||
|
fn = fn.substring(0, paren)
|
||||||
|
+ File.separatorChar
|
||||||
|
+ fn.substring(paren + 1, fn.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
if (position == Position.NOPOS)
|
if (position == Position.NOPOS)
|
||||||
return filename;
|
return fn;
|
||||||
else
|
else
|
||||||
return filename + ":" + line();
|
return fn + ":" + line();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue