package org.aspectj.tools.ajdoc;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.BufferedWriter;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.StringReader;
-import java.io.FilenameFilter;
-
+import java.io.*;
import java.util.*;
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
+
/**
* This is an old implementation of ajdoc that does not use an OO style. However, it
* does the job, and should serve to evolve a lightweight ajdoc implementation until
if ( !(new File( Config.WORKING_DIR ).isDirectory()) ) {
File dir = new File( Config.WORKING_DIR );
dir.mkdir();
- dir.deleteOnExit();
+// dir.deleteOnExit();
}
for (int i = 0; i < filenames.size(); i++) {
javadocargs[options.size() + k] = signatureFiles[k].getCanonicalPath();
}
}
+
Phase2.callJavadoc(javadocargs);
-
//for ( int o = 0; o < inputFiles.length; o++ ) {
// System.out.println( "file: " + inputFiles[o] );
//}
* into multiple .html files to handle inner classes or local classes. The html
* file decorator picks that up.
*/
- System.out.println( "> Decorating html files..." );
- Phase3.decorateHTMLFromInputFiles(declIDTable,
- rootDir,
- symbolManager,
- inputFiles,
- docModifier);
- removeDeclIDsFromFile("index-all.html");
- removeDeclIDsFromFile("serialized-form.html");
- for (int p = 0; p < packageList.size(); p++) {
- removeDeclIDsFromFile(((String)packageList.elementAt(p)).replace('.','/') +
- Config.DIR_SEP_CHAR +
- "package-summary.html" );
- }
+// System.out.println( "> Decorating html files..." );
+// Phase3.decorateHTMLFromInputFiles(declIDTable,
+// rootDir,
+// symbolManager,
+// inputFiles,
+// docModifier);
+// removeDeclIDsFromFile("index-all.html");
+// removeDeclIDsFromFile("serialized-form.html");
+// for (int p = 0; p < packageList.size(); p++) {
+// removeDeclIDsFromFile(((String)packageList.elementAt(p)).replace('.','/') +
+// Config.DIR_SEP_CHAR +
+// "package-summary.html" );
+// }
} catch (Throwable e) {
handleInternalError(e);
exit(-2);
}
static File createSignatureFile(File inputFile) throws IOException {
- Declaration[] decls = symbolManager.getDeclarations(inputFile.getAbsolutePath());
- Declaration decl = null;
- String packageName = null;
- if ( decls != null && decls[0] != null ) {
- decl = decls[0];
- packageName = decl.getPackageName();
- }
+ String packageName = StructureUtil.getPackageDeclarationFromFile(inputFile);
+
+// System.err.println(">>> package: " + packageName);
String filename = "";
if ( packageName != null ) {
- //System.err.println(">> creating: " + packageName);
String pathName = Config.WORKING_DIR + '/' + packageName.replace('.', '/');
- //System.err.println(">> pathName: " + pathName);
File packageDir = new File(pathName);
if ( !packageDir.exists() ) {
packageDir.mkdirs();
File packageDir = new File( filePath );
if ( !packageDir.exists() ) {
packageDir.mkdir();
- packageDir.deleteOnExit();
+// packageDir.deleteOnExit();
}
if ( remainingPkg != "" ) {
verifyPackageDirExists( remainingPkg, currPkgDir );
File packageDir = new File( filePath );
if ( !packageDir.exists() ) {
packageDir.mkdir();
- packageDir.deleteOnExit();
+// packageDir.deleteOnExit();
}
}
}
package org.aspectj.tools.ajdoc;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.BufferedWriter;
-import java.io.PrintWriter;
-import java.io.IOException;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.StringReader;
-import java.util.StringTokenizer;
-
-import java.util.*;
+import java.io.*;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
class Phase1 {
File[] signatureFiles) {
declIDTable = table;
for (int i = 0; i < inputFiles.length; i++) {
- doFile(symbolManager, inputFiles[i], signatureFiles[i]);
+ processFile(symbolManager, inputFiles[i], signatureFiles[i]);
}
}
- static void doFile(SymbolManager symbolManager, File inputFile, File signatureFile) {
+ static void processFile(SymbolManager symbolManager, File inputFile, File signatureFile) {
try {
-
- Declaration[] decls = symbolManager.getDeclarations(inputFile.getCanonicalPath());
+ // Declaration[] decls = symbolManager.getDeclarations(inputFile.getCanonicalPath());
PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(signatureFile.getCanonicalPath())));
-
- // write the package info
- if ( decls != null && decls[0] != null && decls[0].getPackageName() != null ) {
- writer.println( "package " + decls[0].getPackageName() + ";" );
+
+ String packageName = StructureUtil.getPackageDeclarationFromFile(inputFile);
+
+ if (packageName != null ) {
+ writer.println( "package " + packageName + ";" );
}
- if (decls != null) {
- doDecls(decls, writer, false);
- }
- writer.close(); //this isn't in a finally, because if we got an
- //error we don't really want the contents anyways
- }
- catch (IOException e) {
+ IProgramElement fileNode = (IProgramElement)AsmManager.getDefault().getHierarchy().findElementForSourceFile(inputFile.getAbsolutePath());
+ for (Iterator it = fileNode.getChildren().iterator(); it.hasNext(); ) {
+ IProgramElement node = (IProgramElement)it.next();
+ if (!node.getKind().equals(IProgramElement.Kind.IMPORT_REFERENCE)) {
+ processTypeDeclaration(node, writer);
+ }
+ }
+
+ // if we got an error we don't want the contents of the file
+ writer.close();
+ } catch (IOException e) {
System.err.println(e.getMessage());
e.printStackTrace();
- }
+ }
}
- static void doDecls (Declaration[] decls,
- PrintWriter writer,
- boolean declaringDeclIsInterface) throws IOException {
- for (int i = 0; i < decls.length; i++) {
- Declaration decl = decls[i];
- //System.out.println( ">> sig: " + decl.getSignature() );
- doDecl(decl, writer, declaringDeclIsInterface);
- }
- }
-
- static void doDecl(Declaration decl,
- PrintWriter writer,
- boolean declaringDeclIsInterface) throws IOException {
- String formalComment = decl.getFormalComment();
- String fullSignature = decl.getFullSignature();
- System.err.println("> full: " + fullSignature);
- Declaration[] ptbs = decl.getPointedToBy();
- Declaration[] subs = decl.getDeclarations();
- if (decl.hasSignature()) {
- formalComment = addDeclID(decl, formalComment);
-
- writer.println(formalComment);
-
- // HACK: this should be in Declaration
- int implementsClauseIndex = fullSignature.indexOf(" implements");
- if (implementsClauseIndex != -1) {
- String newSignature = "";
- StringTokenizer st = new StringTokenizer(fullSignature.substring(implementsClauseIndex, fullSignature.length()));
- for (String element = (String)st.nextElement(); st.hasMoreElements(); element = (String)st.nextElement()) {
- if (element.indexOf("$MightHaveAspect") != -1
- && element.indexOf("implements") != -1) {
- newSignature += element;
- }
- }
- if (!newSignature.equals("")) {
- writer.print(fullSignature.substring(0, implementsClauseIndex)
- + " implements " + newSignature + " " );
- } else {
- writer.print(fullSignature.substring(0, implementsClauseIndex) + " " );
- }
- } else {
- writer.print(fullSignature + " " );
- }
+// static void processClassDeclarations(IProgramElement fileNode,
+// PrintWriter writer,
+// boolean declaringDeclIsInterface) throws IOException {
+// for (Iterator it = fileNode.getChildren().iterator(); it.hasNext(); ) {
+// IProgramElement node = (IProgramElement)it.next();
+// proc
+// }
+// for (int i = 0; i < decls.length; i++) {
+// Declaration decl = decls[i];
+//
+// //System.out.println( ">> sig: " + decl.getSignature() );
+// doDecl(decl, writer, declaringDeclIsInterface);
+// }
+// }
- if ((!decl.hasBody() && !decl.getKind().equals( "interface" ) ||
- (decl.getKind().equals( "method" ) && declaringDeclIsInterface)) && // !!! bug in Jim's API?
- !(decl.getKind().equals("initializer") && decl.getModifiers().indexOf("static") != -1 ) ) {
-
- System.err.println(">>>> kind: " + decl.getKind());
-
- if (decl.getModifiers().indexOf("static final") != -1) {
- String fullSig = decl.getFullSignature().trim();
- String stripped = fullSig.substring(0, fullSig.lastIndexOf(' '));
- //System.err.println(">>> " + fullSig);
- String type = stripped.substring(stripped.lastIndexOf(' '), stripped.length());
- //System.err.println("> type: " + type);
-
- if (type.equals("boolean")) {
- writer.println(" = false");
- } else if (type.equals("char")) {
- writer.println(" = '0'");
- } else if (type.equals("byte")) {
- writer.println(" = 0");
- } else if (type.equals("short")) {
- writer.println(" = 0");
- } else if (type.equals("int")) {
- writer.println(" = 0");
- } else if (type.equals("long")) {
- writer.println(" = 0");
- } else if (type.equals("float")) {
- writer.println(" = 0");
- } else if (type.equals("double")) {
- writer.println(" = 0");
- } else if (type.equals("String")) {
- writer.println(" = \"\"");
- } else {
- writer.println(" = null");
- }
- }
- writer.println(";");
-// } else if ((!decl.hasBody() && !decl.getKind().equals( "interface" ) ||
+ private static void processTypeDeclaration(IProgramElement classNode, PrintWriter writer) throws IOException {
+
+// String formalComment = classNode.getFormalComment();
+// String fullSignature = classNode.getFullSignature();
+// Declaration[] ptbs = classNode.getPointedToBy();
+// Declaration[] subs = classNode.getDeclarations();
+
+ String formalComment = addDeclID(classNode, classNode.getFormalComment());
+ writer.println(formalComment);
+
+ String signature = StructureUtil.genSignature(classNode);
+ writer.println(signature + " {" );
+ processMembers(classNode.getChildren(), writer, classNode.getKind().equals(IProgramElement.Kind.INTERFACE));
+ writer.println();
+ writer.println("}");
+ }
+
+ private static void processMembers(List/*IProgramElement*/ members, PrintWriter writer, boolean declaringTypeIsInterface) throws IOException {
+ for (Iterator it = members.iterator(); it.hasNext();) {
+ IProgramElement member = (IProgramElement) it.next();
+
+ if (member.getKind().isTypeKind()) {
+ processTypeDeclaration(member, writer);
+ } else {
+
+ String formalComment = addDeclID(member, member.getFormalComment());
+ writer.println(formalComment);
+ String signature = StructureUtil.genSignature(member);
+ writer.print(signature);
+
+ if (member.getKind().equals(IProgramElement.Kind.METHOD)) {
+ writer.println(" { }");
+
+ } else if (member.getKind().equals(IProgramElement.Kind.FIELD)) {
+ writer.println(";");
+ }
+ }
+ }
+ }
+
+//
+// if (decl.hasSignature()) {
+// formalComment = addDeclID(decl, formalComment);
+//
+// writer.println(formalComment);
+//
+// // HACK: this should be in Declaration
+// int implementsClauseIndex = fullSignature.indexOf(" implements");
+// if (implementsClauseIndex != -1) {
+// String newSignature = "";
+// StringTokenizer st = new StringTokenizer(fullSignature.substring(implementsClauseIndex, fullSignature.length()));
+// for (String element = (String)st.nextElement(); st.hasMoreElements(); element = (String)st.nextElement()) {
+// if (element.indexOf("$MightHaveAspect") != -1
+// && element.indexOf("implements") != -1) {
+// newSignature += element;
+// }
+// }
+// if (!newSignature.equals("")) {
+// writer.print(fullSignature.substring(0, implementsClauseIndex)
+// + " implements " + newSignature + " " );
+// } else {
+// writer.print(fullSignature.substring(0, implementsClauseIndex) + " " );
+// }
+// } else {
+// writer.print(fullSignature + " " );
+// }
+//
+//
+// if ((!decl.hasBody() && !decl.getKind().equals( "interface" ) ||
// (decl.getKind().equals( "method" ) && declaringDeclIsInterface)) && // !!! bug in Jim's API?
// !(decl.getKind().equals("initializer") && decl.getModifiers().indexOf("static") != -1 ) ) {
//
+// if (decl.getModifiers().indexOf("static final") != -1) {
+// String fullSig = decl.getFullSignature().trim();
+// String stripped = fullSig.substring(0, fullSig.lastIndexOf(' '));
+// String type = stripped.substring(stripped.lastIndexOf(' '), stripped.length());
+//
+// if (type.equals("boolean")) {
+// writer.println(" = false");
+// } else if (type.equals("char")) {
+// writer.println(" = '0'");
+// } else if (type.equals("byte")) {
+// writer.println(" = 0");
+// } else if (type.equals("short")) {
+// writer.println(" = 0");
+// } else if (type.equals("int")) {
+// writer.println(" = 0");
+// } else if (type.equals("long")) {
+// writer.println(" = 0");
+// } else if (type.equals("float")) {
+// writer.println(" = 0");
+// } else if (type.equals("double")) {
+// writer.println(" = 0");
+// } else if (type.equals("String")) {
+// writer.println(" = \"\"");
+// } else {
+// writer.println(" = null");
+// }
+// }
// writer.println(";");
-
- } else {
- if (subs != null) {
- if ( decl.getKind().equals( "interface" ) ) {
- declaringDeclIsInterface = true;
- }
- writer.println("{");
- doDecls(subs, writer, declaringDeclIsInterface);
- writer.println("}");
- }
- }
- writer.println();
- }
- }
+//// } else if ((!decl.hasBody() && !decl.getKind().equals( "interface" ) ||
+//// (decl.getKind().equals( "method" ) && declaringDeclIsInterface)) && // !!! bug in Jim's API?
+//// !(decl.getKind().equals("initializer") && decl.getModifiers().indexOf("static") != -1 ) ) {
+////
+//// writer.println(";");
+//
+// } else {
+// if (subs != null) {
+// if ( decl.getKind().equals( "interface" ) ) {
+// declaringDeclIsInterface = true;
+// }
+// writer.println("{");
+// processDeclarations(subs, writer, declaringDeclIsInterface);
+// writer.println("}");
+// }
+// }
+// writer.println();
+// }
static int nextDeclID = 0;
- static String addDeclID(Declaration decl, String formalComment) {
+ static String addDeclID(IProgramElement decl, String formalComment) {
String declID = "" + ++nextDeclID;
declIDTable.put(declID, decl);
return addToFormal(formalComment, Config.DECL_ID_STRING + declID + Config.DECL_ID_TERMINATOR);
* TODO: only works for one class
*/
public Declaration[] getDeclarations(String filename) {
+
IProgramElement file = (IProgramElement)AsmManager.getDefault().getHierarchy().findElementForSourceFile(filename);
IProgramElement node = (IProgramElement)file.getChildren().get(0);
HierarchyWalker walker = new HierarchyWalker() {
public void preProcess(IProgramElement node) {
IProgramElement p = (IProgramElement)node;
- nodes.add(buildDecl(p));
+ if (accept(node)) nodes.add(buildDecl(p));
}
};
file.walk(walker);
+ System.err.println("> got: " + nodes);
+
return (Declaration[])nodes.toArray(new Declaration[nodes.size()]);
// return lookupDeclarations(filename);
}
+
+ private boolean accept(IProgramElement node) {
+ return !node.getKind().equals(IProgramElement.Kind.IMPORT_REFERENCE);
+ }
private Declaration buildDecl(IProgramElement node) {
- System.err.println("> getting decs: " + node);
-
+
+ String signature = "";
+ String accessibility = node.getAccessibility().toString();
+ if (!accessibility.equals("package")) signature = accessibility + " ";
+
String modifiers = "";
for (Iterator modIt = node.getModifiers().iterator(); modIt.hasNext(); ) {
modifiers += modIt.next() + " ";
}
-// Declaration dec = new Declaration(
-// node.getSourceLocation().getLine(),
-// node.getSourceLocation().getEndLine(),
-// node.getSourceLocation().getColumn(),
-// -1,
-// modifiers,
-// node.getName(),
-// node.getFullSignature(),
-// "",
-// node.getDeclaringType(),
-// node.getKind(),
-// node.getSourceLocation().getSourceFile().getAbsolutePath(),
-// node.getFormalComment(),
-// node.getPackageName()
-// );
-// return dec;
- return null;
+
+ if (node.getKind().equals(IProgramElement.Kind.METHOD) ||
+ node.getKind().equals(IProgramElement.Kind.FIELD)) {
+ signature += node.getCorrespondingType() + " ";
+ }
+
+ if (node.getKind().equals(IProgramElement.Kind.CLASS) ||
+ node.getKind().equals(IProgramElement.Kind.METHOD)) {
+ signature += "class ";
+ } else if (node.getKind().equals(IProgramElement.Kind.INTERFACE) ||
+ node.getKind().equals(IProgramElement.Kind.METHOD)) {
+ signature += "interface ";
+ }
+
+ signature += node.toSignatureString();
+// System.err.println(">>>> " + signature);
+
+ Declaration dec = new Declaration(
+ node.getSourceLocation().getLine(),
+ node.getSourceLocation().getEndLine(),
+ node.getSourceLocation().getColumn(),
+ -1,
+ modifiers,
+ node.getName(),
+ signature,
+ "", // crosscut designator
+ node.getDeclaringType(),
+ node.getKind().toString(),
+ node.getSourceLocation().getSourceFile().getAbsolutePath(),
+ node.getFormalComment(),
+ node.getPackageName()
+ );
+ return dec;
}
-
-
// // In the unusual case that there are multiple declarations on a single line
// // This will return a random one