From 86b62e146bba6606fe39240faae3b7b15cd45d81 Mon Sep 17 00:00:00 2001 From: Cheryl Foil Date: Sun, 20 Jul 2008 05:20:17 +0000 Subject: [PATCH] javDocConvertor now functional for some simple commands such as author, param, returns, and b. Commands with a specific javaDoc order are sorted appropriately. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10686 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../DoxygenTranslator/DoxygenTranslator.cpp | 13 +- Source/DoxygenTranslator/JavaDocConverter.cpp | 140 +++++++++++++++--- Source/DoxygenTranslator/JavaDocConverter.h | 1 + 3 files changed, 132 insertions(+), 22 deletions(-) diff --git a/Source/DoxygenTranslator/DoxygenTranslator.cpp b/Source/DoxygenTranslator/DoxygenTranslator.cpp index d6129cda0..96fe6b2c5 100644 --- a/Source/DoxygenTranslator/DoxygenTranslator.cpp +++ b/Source/DoxygenTranslator/DoxygenTranslator.cpp @@ -69,7 +69,7 @@ "sa", "section", "see", "showinitializer", "since", "skip", "skipline", "struct", "subpage", "subsection", "subsubsection", "test", "throw", "todo", "tparam", "typedef", "union", "until", "var", "verbatim", "verbinclude", "version", "warning", "weakgroup", "xmlonly", "xrefitem", - "$", "@", "//","&", "~", "<", ">", "#", "%"}; + "$", "@", "\\","&", "~", "<", ">", "#", "%"}; string sectionIndicators[] = { "attention", "author", "brief", "bug", "cond", "date", "deprecated", "details", @@ -78,7 +78,7 @@ "version", "warning", "xrefitem" }; /* All of the doxygen commands divided up by how they are parsed */ - string simpleCommands[] = {"n", "$", "@", "//", "&", "~", "<", ">", "#", "%"}; + string simpleCommands[] = {"n", "$", "@", "\\", "&", "~", "<", ">", "#", "%"}; string ignoredSimpleCommands[] = {"nothing at the moment"}; string commandWords[] = {"a", "b", "c", "e", "em", "p", "def", "enum", "example", "package", "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"}; @@ -791,13 +791,16 @@ list convert(string doxygenBlob){ } list rootList; rootList = parse( tokList.end(), tokList); - cout << "PARSED LIST" << endl; - printTree(rootList); + if(noisy) { + cout << "PARSED LIST" << endl; + printTree(rootList); + } return rootList; } int main(int argc, char *argv[]){ - string doxygenString1 = "//! A normal member taking two arguments and returning an integer value.\n/*!\n \\param a an \\b integer argument. \\param s a constant character pointer\n\n\n\n \\return The test results\n \\sa Test(), ~Test(), testMeToo() and publicVar()\n */"; + string doxygenString1 = "//! A normal member taking two arguments and returning an integer value. This is a very long description for the simple purpose of showing off formatting. Let's make it a bit longer just to be sure. \n/*!\n \\param a an \\b integer argument.\n \\return The test results\n \\param s a constant character pointer. Let's also make this a very long description! \n \\bug this command should, for now, be totally ignored\n \\author cheryl foil\n \\sa Test(), ~Test(), testMeToo() and publicVar()\n */"; + cout << "---ORIGINAL DOXYGEN--- " << endl << doxygenString1 << endl; list rootList = convert(doxygenString1); JavaDocConverter jDC = JavaDocConverter(); jDC.convertToJavaDoc(rootList); diff --git a/Source/DoxygenTranslator/JavaDocConverter.cpp b/Source/DoxygenTranslator/JavaDocConverter.cpp index 4e6fd93e6..91f52662f 100644 --- a/Source/DoxygenTranslator/JavaDocConverter.cpp +++ b/Source/DoxygenTranslator/JavaDocConverter.cpp @@ -3,8 +3,10 @@ #include #include #include - -int printTree = 1; +#define APPROX_LINE_LENGTH 64//characters per line allowed +#define TAB_SIZE 8//characters per line allowed +int printSortedTree2 = 0; +//TODO {@link} {@linkplain} {@docRoot}, and other useful doxy commands that are not a javadoc tag JavaDocConverter::JavaDocConverter() { } @@ -40,7 +42,7 @@ bool compare_DoxygenEntities(DoxygenEntity first, DoxygenEntity second){ if(second.typeOfEntity.compare("since")== 0)return true; if(second.typeOfEntity.compare("deprecated")== 0)return true; return false; - + } if(first.typeOfEntity.compare("exception")== 0){ if(second.typeOfEntity.compare("exception")== 0) return true; @@ -66,8 +68,9 @@ bool compare_DoxygenEntities(DoxygenEntity first, DoxygenEntity second){ if(second.typeOfEntity.compare("deprecated")== 0)return true; return false; } - if(first.typeOfEntity.compare("see")== 0){ + if(first.typeOfEntity.compare("see")== 0 || first.typeOfEntity.compare("sa")== 0){ if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("sa")== 0)return true; if(second.typeOfEntity.compare("since")== 0)return true; if(second.typeOfEntity.compare("deprecated")== 0)return true; return false; @@ -84,21 +87,124 @@ bool compare_DoxygenEntities(DoxygenEntity first, DoxygenEntity second){ return true; } -string JavaDocConverter:: convertToJavaDoc(list entityList){ - - list::iterator entityIterator = entityList.begin(); - entityList.sort(compare_DoxygenEntities); +void JavaDocConverter::printSortedTree(list &entityList){ + list::iterator p = entityList.begin(); + while (p != entityList.end()){ + (*p).printEntity(0); + p++; + } +} +string formatCommand(string unformattedLine, int indent){ + string formattedLines = "\n * "; + int lastPosition = 0; + int i = 0; + int isFirstLine = 1; + while (i != -1 && i < unformattedLine.length()){ + lastPosition = i; + if (isFirstLine){ + i+=APPROX_LINE_LENGTH; + } + else i+=APPROX_LINE_LENGTH - indent*TAB_SIZE; + i = unformattedLine.find(" ", i); - cout << "---RESORTED LIST---" << endl; - if (printTree ){ - list::iterator p = entityList.begin(); - while (p != entityList.end()){ - (*p).printEntity(0); + if (i > 0 && i + 1 < unformattedLine.length()){ + if (!isFirstLine) for (int j = 0; j < indent; j++) { + formattedLines.append("\t"); + } + else { + isFirstLine = 0; + } + formattedLines.append(unformattedLine.substr(lastPosition, i - lastPosition + 1)); + formattedLines.append("\n *"); + + } + } + if (lastPosition < unformattedLine.length()){ + if (!isFirstLine) {for (int j = 0; j < indent; j++) {formattedLines.append("\t");}} + formattedLines.append(unformattedLine.substr(lastPosition, unformattedLine.length() - lastPosition)); + } + + return formattedLines; +} + +/* Contains the conversions for tags + * could probably be much more efficient... + */ +string javaDocFormat(DoxygenEntity &doxygenEntity){ + if (doxygenEntity.typeOfEntity.compare("plainstring") == 0){ + return doxygenEntity.data; + } + else if (doxygenEntity.typeOfEntity.compare("brief") == 0){ + return doxygenEntity.data; + } + if (doxygenEntity.typeOfEntity.compare("detailed") == 0){ + return doxygenEntity.data; + } + else if (doxygenEntity.typeOfEntity.compare("b") == 0){ + return "" + doxygenEntity.data + ""; + } + else if (doxygenEntity.typeOfEntity.compare("c") == 0){ + return "" + doxygenEntity.data + ""; + } + return ""; +} + + +string translateSubtree( DoxygenEntity &doxygenEntity){ + string returnedString; + if (doxygenEntity.isLeaf){ return javaDocFormat(doxygenEntity) + " ";} + else { + returnedString += javaDocFormat(doxygenEntity); + list::iterator p = doxygenEntity.entityList.begin(); + while (p != doxygenEntity.entityList.end()){ + returnedString+= translateSubtree(*p); p++; } } - string javaDocString = "/**\n"; - - javaDocString += "*/\n"; - return javaDocString; + return returnedString; } + +string translateEntity(DoxygenEntity &doxyEntity){ + if(doxyEntity.typeOfEntity.compare("plainstring")== 0 || doxyEntity.typeOfEntity.compare("deprecated")== 0 || doxyEntity.typeOfEntity.compare("brief")== 0) + return formatCommand(doxyEntity.data, 0) + "\n * "; + else if(doxyEntity.typeOfEntity.compare("see") == 0){ + return formatCommand(string("@" + doxyEntity.typeOfEntity + "\t\t" + translateSubtree(doxyEntity)), 2); + } + else if(doxyEntity.typeOfEntity.compare("return")== 0 + || doxyEntity.typeOfEntity.compare("author")== 0 + || doxyEntity.typeOfEntity.compare("param")== 0 + || doxyEntity.typeOfEntity.compare("since")== 0 + || doxyEntity.typeOfEntity.compare("version")== 0 + || doxyEntity.typeOfEntity.compare("exception") == 0 + || doxyEntity.typeOfEntity.compare("deprecated") == 0){ + return formatCommand(string("@" + doxyEntity.typeOfEntity + "\t" + translateSubtree(doxyEntity)), 2); + } + else if(doxyEntity.typeOfEntity.compare("sa")== 0){ + return formatCommand(string("@see\t\t" + translateSubtree(doxyEntity)), 2); + } + + return ""; +} + +string JavaDocConverter:: convertToJavaDoc(list entityList){ + + + entityList.sort(compare_DoxygenEntities); + if(printSortedTree2){ + cout << "---RESORTED LIST---" << endl; + printSortedTree(entityList); + } + + string javaDocString = "/**"; + + list::iterator entityIterator = entityList.begin(); + while (entityIterator != entityList.end()){ + javaDocString += translateEntity(*entityIterator); + entityIterator++; + } + + javaDocString += "\n */\n"; + cout << "\n---RESULT IN JAVADOC---" << endl; + cout << javaDocString; + return javaDocString; +} \ No newline at end of file diff --git a/Source/DoxygenTranslator/JavaDocConverter.h b/Source/DoxygenTranslator/JavaDocConverter.h index b1c76ef17..81122bc5f 100644 --- a/Source/DoxygenTranslator/JavaDocConverter.h +++ b/Source/DoxygenTranslator/JavaDocConverter.h @@ -12,6 +12,7 @@ public: JavaDocConverter(); string convertToJavaDoc(list entityList); ~JavaDocConverter(); + void printSortedTree(list &entityList); }; #endif /*JAVADOCCONVERTER_H_*/