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
This commit is contained in:
parent
cc6db6eab6
commit
86b62e146b
3 changed files with 132 additions and 22 deletions
|
|
@ -69,7 +69,7 @@
|
||||||
"sa", "section", "see", "showinitializer", "since", "skip", "skipline", "struct", "subpage",
|
"sa", "section", "see", "showinitializer", "since", "skip", "skipline", "struct", "subpage",
|
||||||
"subsection", "subsubsection", "test", "throw", "todo", "tparam", "typedef", "union", "until",
|
"subsection", "subsubsection", "test", "throw", "todo", "tparam", "typedef", "union", "until",
|
||||||
"var", "verbatim", "verbinclude", "version", "warning", "weakgroup", "xmlonly", "xrefitem",
|
"var", "verbatim", "verbinclude", "version", "warning", "weakgroup", "xmlonly", "xrefitem",
|
||||||
"$", "@", "//","&", "~", "<", ">", "#", "%"};
|
"$", "@", "\\","&", "~", "<", ">", "#", "%"};
|
||||||
|
|
||||||
|
|
||||||
string sectionIndicators[] = { "attention", "author", "brief", "bug", "cond", "date", "deprecated", "details",
|
string sectionIndicators[] = { "attention", "author", "brief", "bug", "cond", "date", "deprecated", "details",
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
"version", "warning", "xrefitem" };
|
"version", "warning", "xrefitem" };
|
||||||
|
|
||||||
/* All of the doxygen commands divided up by how they are parsed */
|
/* 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 ignoredSimpleCommands[] = {"nothing at the moment"};
|
||||||
string commandWords[] = {"a", "b", "c", "e", "em", "p", "def", "enum", "example", "package",
|
string commandWords[] = {"a", "b", "c", "e", "em", "p", "def", "enum", "example", "package",
|
||||||
"relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"};
|
"relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"};
|
||||||
|
|
@ -791,13 +791,16 @@ list<DoxygenEntity> convert(string doxygenBlob){
|
||||||
}
|
}
|
||||||
list <DoxygenEntity> rootList;
|
list <DoxygenEntity> rootList;
|
||||||
rootList = parse( tokList.end(), tokList);
|
rootList = parse( tokList.end(), tokList);
|
||||||
cout << "PARSED LIST" << endl;
|
if(noisy) {
|
||||||
printTree(rootList);
|
cout << "PARSED LIST" << endl;
|
||||||
|
printTree(rootList);
|
||||||
|
}
|
||||||
return rootList;
|
return rootList;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
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 <DoxygenEntity> rootList = convert(doxygenString1);
|
list <DoxygenEntity> rootList = convert(doxygenString1);
|
||||||
JavaDocConverter jDC = JavaDocConverter();
|
JavaDocConverter jDC = JavaDocConverter();
|
||||||
jDC.convertToJavaDoc(rootList);
|
jDC.convertToJavaDoc(rootList);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#define APPROX_LINE_LENGTH 64//characters per line allowed
|
||||||
int printTree = 1;
|
#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()
|
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("since")== 0)return true;
|
||||||
if(second.typeOfEntity.compare("deprecated")== 0)return true;
|
if(second.typeOfEntity.compare("deprecated")== 0)return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
if(first.typeOfEntity.compare("exception")== 0){
|
if(first.typeOfEntity.compare("exception")== 0){
|
||||||
if(second.typeOfEntity.compare("exception")== 0) return true;
|
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;
|
if(second.typeOfEntity.compare("deprecated")== 0)return true;
|
||||||
return false;
|
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("see")== 0)return true;
|
||||||
|
if(second.typeOfEntity.compare("sa")== 0)return true;
|
||||||
if(second.typeOfEntity.compare("since")== 0)return true;
|
if(second.typeOfEntity.compare("since")== 0)return true;
|
||||||
if(second.typeOfEntity.compare("deprecated")== 0)return true;
|
if(second.typeOfEntity.compare("deprecated")== 0)return true;
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -84,21 +87,124 @@ bool compare_DoxygenEntities(DoxygenEntity first, DoxygenEntity second){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string JavaDocConverter:: convertToJavaDoc(list <DoxygenEntity> entityList){
|
void JavaDocConverter::printSortedTree(list <DoxygenEntity> &entityList){
|
||||||
|
list<DoxygenEntity>::iterator p = entityList.begin();
|
||||||
list<DoxygenEntity>::iterator entityIterator = entityList.begin();
|
while (p != entityList.end()){
|
||||||
entityList.sort(compare_DoxygenEntities);
|
(*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 (i > 0 && i + 1 < unformattedLine.length()){
|
||||||
if (printTree ){
|
if (!isFirstLine) for (int j = 0; j < indent; j++) {
|
||||||
list<DoxygenEntity>::iterator p = entityList.begin();
|
formattedLines.append("\t");
|
||||||
while (p != entityList.end()){
|
}
|
||||||
(*p).printEntity(0);
|
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 "<b>" + doxygenEntity.data + "</b>";
|
||||||
|
}
|
||||||
|
else if (doxygenEntity.typeOfEntity.compare("c") == 0){
|
||||||
|
return "<tt>" + doxygenEntity.data + "</tt>";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string translateSubtree( DoxygenEntity &doxygenEntity){
|
||||||
|
string returnedString;
|
||||||
|
if (doxygenEntity.isLeaf){ return javaDocFormat(doxygenEntity) + " ";}
|
||||||
|
else {
|
||||||
|
returnedString += javaDocFormat(doxygenEntity);
|
||||||
|
list<DoxygenEntity>::iterator p = doxygenEntity.entityList.begin();
|
||||||
|
while (p != doxygenEntity.entityList.end()){
|
||||||
|
returnedString+= translateSubtree(*p);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string javaDocString = "/**\n";
|
return returnedString;
|
||||||
|
|
||||||
javaDocString += "*/\n";
|
|
||||||
return javaDocString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 <DoxygenEntity> entityList){
|
||||||
|
|
||||||
|
|
||||||
|
entityList.sort(compare_DoxygenEntities);
|
||||||
|
if(printSortedTree2){
|
||||||
|
cout << "---RESORTED LIST---" << endl;
|
||||||
|
printSortedTree(entityList);
|
||||||
|
}
|
||||||
|
|
||||||
|
string javaDocString = "/**";
|
||||||
|
|
||||||
|
list<DoxygenEntity>::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;
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ public:
|
||||||
JavaDocConverter();
|
JavaDocConverter();
|
||||||
string convertToJavaDoc(list <DoxygenEntity> entityList);
|
string convertToJavaDoc(list <DoxygenEntity> entityList);
|
||||||
~JavaDocConverter();
|
~JavaDocConverter();
|
||||||
|
void printSortedTree(list <DoxygenEntity> &entityList);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*JAVADOCCONVERTER_H_*/
|
#endif /*JAVADOCCONVERTER_H_*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue