use of com.sun.javadoc.ClassDoc in project jdk8u_jdk by JetBrains.
the class RemoteClass method computeInterfaceHash.
/**
* Computes the "interface hash" of the stub/skeleton pair for
* this remote implementation class. This is the 64-bit value
* used to enforce compatibility between a stub class and a
* skeleton class in the JDK 1.1 version of the JRMP stub/skeleton
* protocol.
*
* It is calculated using the first 64 bits of an SHA digest. The
* digest is of a stream consisting of the following data:
* (int) stub version number, always 1
* for each remote method, in order of operation number:
* (UTF-8) method name
* (UTF-8) method descriptor
* for each declared exception, in alphabetical name order:
* (UTF-8) name of exception class
* (where "UTF-8" includes a 16-bit length prefix as written by
* java.io.DataOutput.writeUTF).
**/
private long computeInterfaceHash() {
long hash = 0;
ByteArrayOutputStream sink = new ByteArrayOutputStream(512);
try {
MessageDigest md = MessageDigest.getInstance("SHA");
DataOutputStream out = new DataOutputStream(new DigestOutputStream(sink, md));
out.writeInt(INTERFACE_HASH_STUB_VERSION);
for (Method method : remoteMethods) {
MethodDoc methodDoc = method.methodDoc();
out.writeUTF(methodDoc.name());
out.writeUTF(Util.methodDescriptorOf(methodDoc));
// descriptors already use binary names
ClassDoc[] exceptions = methodDoc.thrownExceptions();
Arrays.sort(exceptions, new ClassDocComparator());
for (ClassDoc ex : exceptions) {
out.writeUTF(Util.binaryNameOf(ex));
}
}
out.flush();
// use only the first 64 bits of the digest for the hash
byte[] hashArray = md.digest();
for (int i = 0; i < Math.min(8, hashArray.length); i++) {
hash += ((long) (hashArray[i] & 0xFF)) << (i * 8);
}
} catch (IOException e) {
throw new AssertionError(e);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
return hash;
}
use of com.sun.javadoc.ClassDoc in project jdk8u_jdk by JetBrains.
the class Main method start.
/**
* Doclet class entry point.
**/
public static boolean start(RootDoc rootDoc) {
/*
* Find batch ID among javadoc options, and retrieve
* corresponding batch data from global table.
*/
long batchID = -1;
for (String[] option : rootDoc.options()) {
if (option[0].equals("-batchID")) {
try {
batchID = Long.parseLong(option[1]);
} catch (NumberFormatException e) {
throw new AssertionError(e);
}
}
}
Batch batch = batchTable.get(batchID);
assert batch != null;
/*
* Construct batch environment using class agreed upon by
* generator implementations.
*/
BatchEnvironment env;
try {
Constructor<? extends BatchEnvironment> cons = batch.envClass.getConstructor(new Class<?>[] { RootDoc.class });
env = cons.newInstance(rootDoc);
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
} catch (IllegalAccessException e) {
throw new AssertionError(e);
} catch (InstantiationException e) {
throw new AssertionError(e);
} catch (InvocationTargetException e) {
throw new AssertionError(e);
}
env.setVerbose(batch.verbose);
/*
* Determine the destination directory (the top of the package
* hierarchy) for the output of this batch; if no destination
* directory was specified on the command line, then the
* default is the current working directory.
*/
File destDir = batch.destDir;
if (destDir == null) {
destDir = new File(System.getProperty("user.dir"));
}
/*
* Run each input class through each generator.
*/
for (String inputClassName : batch.classes) {
ClassDoc inputClass = rootDoc.classNamed(inputClassName);
try {
for (Generator gen : batch.generators) {
gen.generate(env, inputClass, destDir);
}
} catch (NullPointerException e) {
/*
* We assume that this means that some class that was
* needed (perhaps even a bootstrap class) was not
* found, and that javadoc has already reported this
* as an error. There is nothing for us to do here
* but try to continue with the next input class.
*
* REMIND: More explicit error checking throughout
* would be preferable, however.
*/
}
}
/*
* Compile any generated source files, if configured to do so.
*/
boolean status = true;
List<File> generatedFiles = env.generatedFiles();
if (!batch.noCompile && !batch.noWrite && !generatedFiles.isEmpty()) {
status = batch.enclosingMain().invokeJavac(batch, generatedFiles);
}
/*
* Delete any generated source files, if configured to do so.
*/
if (!batch.keepGenerated) {
for (File file : generatedFiles) {
file.delete();
}
}
return status;
}
use of com.sun.javadoc.ClassDoc in project jdk8u_jdk by JetBrains.
the class GenDocletBeanInfo method start.
/** @beaninfo
* bound:true
* constrained:false
* expert:true
* hidden:true
* preferred:false
* description: the description of this method can
* do all sorts of funky things. if it \n
* is indented like this, we have to remove
* all char spaces greater than 2 and also any hard-coded \n
* newline characters and all newlines
* displayname: theString
* propertyeditorclass: foo.bar.MyPropertyEditorClass
* customizerclass: foo.bar.MyCustomizerClass
* attribute:key1 value1
* attribute: key2 value2
*
*/
public static boolean start(RootDoc doc) {
readOptions(doc.options());
if (templateDir.length() == 0) {
System.err.println("-t option not specified");
return false;
}
if (fileDir.length() == 0) {
System.err.println("-d option not specified");
return false;
}
GenSwingBeanInfo generator = new GenSwingBeanInfo(fileDir, templateDir, DEBUG);
Hashtable dochash = new Hashtable();
DocBeanInfo dbi;
/* "javadoc Foo.java Bar.java" will return:
* "Foo Foo.I1 Foo.I2 Bar Bar.I1 Bar.I2"
* i.e., with all the innerclasses of classes specified in the command
* line. We don't want to generate BeanInfo for any of these inner
* classes, so we ignore these by remembering what the last outer
* class was. A hack, I admit, but makes the build faster.
*/
String previousClass = null;
ClassDoc[] classes = doc.classes();
for (int cnt = 0; cnt < classes.length; cnt++) {
String className = classes[cnt].qualifiedName();
if (previousClass != null && className.startsWith(previousClass) && className.charAt(previousClass.length()) == '.') {
continue;
}
previousClass = className;
// XXX - debug
System.out.println("\n>>> Generating beaninfo for " + className + "...");
// Examine the javadoc tags and look for the the @beaninfo tag
// This first block looks at the javadoc for the class
Tag[] tags = classes[cnt].tags();
for (int i = 0; i < tags.length; i++) {
if (tags[i].kind().equalsIgnoreCase("@beaninfo")) {
if (DEBUG)
System.out.println("GenDocletBeanInfo: found @beaninfo tagged Class: " + tags[i].text());
dbi = genDocletInfo(tags[i].text(), classes[cnt].name());
dochash.put(dbi.name, dbi);
break;
}
}
// This block looks at the javadoc for the class methods.
int startPos = -1;
MethodDoc[] methods = classes[cnt].methods();
for (int j = 0; j < methods.length; j++) {
// actually don't "introspect" - look for all
// methods with a @beaninfo tag
tags = methods[j].tags();
for (int x = 0; x < tags.length; x++) {
if (tags[x].kind().equalsIgnoreCase("@beaninfo")) {
if ((methods[j].name().startsWith("get")) || (methods[j].name().startsWith("set")))
startPos = 3;
else if (methods[j].name().startsWith("is"))
startPos = 2;
else
startPos = 0;
String propDesc = Introspector.decapitalize((methods[j].name()).substring(startPos));
if (DEBUG)
System.out.println("GenDocletBeanInfo: found @beaninfo tagged Method: " + tags[x].text());
dbi = genDocletInfo(tags[x].text(), propDesc);
dochash.put(dbi.name, dbi);
break;
}
}
}
if (DEBUG) {
// dump our classes doc beaninfo
System.out.println(">>>>DocletBeanInfo for class: " + classes[cnt].name());
Enumeration e = dochash.elements();
while (e.hasMoreElements()) {
DocBeanInfo db = (DocBeanInfo) e.nextElement();
System.out.println(db.toString());
}
}
// Use the generator to create the beaninfo code for the class.
generator.genBeanInfo(classes[cnt].containingPackage().name(), classes[cnt].name(), dochash);
// reset the values!
dochash.clear();
}
// end for loop
return true;
}
Aggregations