Fixed enum comments generation, added testcases

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13184 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-06-18 19:13:23 +00:00
parent 72b23954fb
commit b88de2aa89
14 changed files with 470 additions and 45 deletions

View File

@ -55,15 +55,6 @@ public:
}
};
/** Test enumeration */
enum E_TEST
{
/** the first item */
E_TEST_ONE,
E_TEST_TWO = 2, /**< the second */
E_TEST_THREE = 2+1
};
/**
* Comment for template class
*/

View File

@ -0,0 +1,15 @@
%module doxygen_parsing_enums
%inline %{
/** Test enumeration */
enum E_TEST
{
/** the first item */
E_TEST_ONE,
E_TEST_TWO = 2, /**< the second */
E_TEST_THREE = 2+1
};
%}

View File

@ -0,0 +1,7 @@
%module "doxygen_parsing_enums_proper"
// Test enum commenting using the proper enums in the target language
%include "enums.swg"
%include "doxygen_parsing_enums.i"

View File

@ -0,0 +1,6 @@
%module "doxygen_parsing_enums_simple"
// Test enum commenting using simple constants (SWIG-1.3.21 and earlier default enum wrapping for C# and Java)
%include "enumsimple.swg"
%include "doxygen_parsing_enums.i"

View File

@ -0,0 +1,8 @@
%module "doxygen_parsing_enums_typesafe"
// Test enum commenting using the typesafe enum pattern in the target language
%include "enumtypesafe.swg"
#define SWIG_TEST_NOCSCONST // For C# typesafe enums
%include "doxygen_parsing_enums.i"

View File

@ -0,0 +1,6 @@
%module "doxygen_parsing_enums_typeunsafe"
// Test enum commenting using a type unsafe enum pattern (constant integers in a class for the enum type)
%include "enumtypeunsafe.swg"
%include "doxygen_parsing_enums.i"

View File

@ -16,6 +16,10 @@ C_TEST_CASES = \
java_lib_various
CPP_TEST_CASES = \
doxygen_parsing_enums_simple \
doxygen_parsing_enums_proper \
doxygen_parsing_enums_typesafe \
doxygen_parsing_enums_typeunsafe \
enum_thorough_proper \
enum_thorough_simple \
enum_thorough_typeunsafe \

View File

@ -0,0 +1,93 @@
import doxygen_parsing_enums_proper.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_proper_runme {
static {
try {
System.loadLibrary("doxygen_parsing_enums_proper");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_proper runtime test",
"doxygen_parsing_enums_proper_runme", new String[]{"-quiet", "doxygen_parsing_enums_proper"});
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
}
}

View File

@ -0,0 +1,93 @@
import doxygen_parsing_enums_simple.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_simple_runme {
static {
try {
System.loadLibrary("doxygen_parsing_enums_simple");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_simple runtime test",
"doxygen_parsing_enums_simple_runme", new String[]{"-quiet", "doxygen_parsing_enums_simple"});
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
}
}

View File

@ -0,0 +1,93 @@
import doxygen_parsing_enums_typesafe.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_typesafe_runme {
static {
try {
System.loadLibrary("doxygen_parsing_enums_typesafe");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typesafe runtime test",
"doxygen_parsing_enums_typesafe_runme", new String[]{"-quiet", "doxygen_parsing_enums_typesafe"});
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
}
}

View File

@ -0,0 +1,93 @@
import doxygen_parsing_enums_typeunsafe.*;
import com.sun.javadoc.*;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Iterator;
public class doxygen_parsing_enums_typeunsafe_runme {
static {
try {
System.loadLibrary("doxygen_parsing_enums_typeunsafe");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
System.exit(1);
}
}
static HashMap<String, String> parsedComments = new HashMap<String, String>();
static HashMap<String, String> wantedComments = new HashMap<String, String>();
public static boolean start(RootDoc root) {
/*
This method is called by 'javadoc' and gets the whole parsed
java file, we get comments and store them
*/
ClassDoc[] classes = root.classes();
for (int i = 0; i < classes.length; i++) {
if (classes[i].getRawCommentText().length() > 0)
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
parsedComments.put(m.name(), m.getRawCommentText());
}
}
return true;
}
public static void main(String argv[])
{
/*
Here we are using internal javadoc tool, it accepts the name of the class as paramterer,
and calls the start() method of that class with parsed information.
*/
com.sun.tools.javadoc.Main.execute("doxygen_parsing_enums_typeunsafe runtime test",
"doxygen_parsing_enums_typeunsafe_runme", new String[]{"-quiet", "doxygen_parsing_enums_typeunsafe"});
wantedComments.put("E_TEST", " Test enumeration \n");
wantedComments.put("E_TEST_ONE", " the first item \n");
wantedComments.put("E_TEST_TWO", " the second \n");
int errorCount=0;
Iterator< Entry<String, String> > it = parsedComments.entrySet().iterator();
while (it.hasNext())
{
Entry<String, String> e = (Entry<String, String>) it.next();
if (!e.getValue().equals(wantedComments.get(e.getKey()))) {
System.out.println("Documentation comments for " + e.getKey() + " does not match: ");
System.out.println("\texpected:"+wantedComments.get(e.getKey()));
System.out.println("\tgot:\t"+e.getValue());
errorCount++;
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
}
}

View File

@ -33,6 +33,19 @@ public class doxygen_parsing_runme {
parsedComments.put(classes[i].name(), classes[i].getRawCommentText());
MethodDoc[] methods = classes[i].methods();
FieldDoc[] fields = classes[i].fields();
FieldDoc[] constants = classes[i].enumConstants();
for (int j = 0; j < constants.length; j++) {
FieldDoc f = constants[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < fields.length; j++) {
FieldDoc f = fields[j];
if (f.getRawCommentText().length() > 0)
parsedComments.put(f.name(), f.getRawCommentText());
}
for (int j = 0; j < methods.length; j++) {
MethodDoc m = methods[j];
if (m.getRawCommentText().length() > 0)
@ -84,6 +97,11 @@ public class doxygen_parsing_runme {
}
}
if (parsedComments.size() != wantedComments.size()) {
System.out.println("Found " + (wantedComments.size()-parsedComments.size()) + " missed comment(s)!");
errorCount++;
}
System.exit(errorCount);
}
}

View File

@ -13,7 +13,7 @@
#include "DoxygenParser.h"
#include <iostream>
#define APPROX_LINE_LENGTH 64 //characters per line allowed
#define TAB_SIZE 8 //characters per line allowed
#define TAB_SIZE 8 //current tab size in spaces
int printSortedTree2 = 0;
//TODO {@link} {@linkplain} {@docRoot}, and other useful doxy commands that are not a javadoc tag

View File

@ -49,7 +49,7 @@ class JAVA:public Language {
bool global_variable_flag; // Flag for when wrapping a global variable
bool old_variable_names; // Flag for old style variable names in the intermediary class
bool member_func_flag; // flag set when wrapping a member function
bool doxygen_javadoc_flag; //flag for converting found doxygen to javadoc
bool doxygen; //flag for converting found doxygen to javadoc
bool comment_creation_chatter; //flag for getting information about where comments were created in java.cxx
String *imclass_name; // intermediary class name
@ -123,7 +123,7 @@ public:
global_variable_flag(false),
old_variable_names(false),
member_func_flag(false),
doxygen_javadoc_flag(true),
doxygen(true),
comment_creation_chatter(false),
imclass_name(NULL),
module_class_name(NULL),
@ -255,6 +255,14 @@ public:
Printf(stderr, "Deprecated command line option: %s. Proxy classes are now generated by default.\n", argv[i]);
Swig_mark_arg(i);
proxy_flag = true;
} else if ((strcmp(argv[i], "-doxygen") == 0)) {
Swig_mark_arg(i);
doxygen = true;
scan_doxygen_comments = true;
} else if ((strcmp(argv[i], "-nodoxygen") == 0)) {
Swig_mark_arg(i);
doxygen = false;
scan_doxygen_comments = false;
} else if ((strcmp(argv[i], "-noproxy") == 0)) {
Swig_mark_arg(i);
proxy_flag = false;
@ -528,7 +536,7 @@ public:
// Start writing out the module class file
emitBanner(f_module);
//Add any structural comments to the top
if(doxygen_javadoc_flag && structuralComments){
if(doxygen && structuralComments){
Printf(f_module, "%s", structuralComments);
}
if (package)
@ -537,7 +545,7 @@ public:
if (module_imports)
Printf(f_module, "%s\n", module_imports);
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc,doxygen_comments)){
if(comment_creation_chatter)
@ -1292,17 +1300,6 @@ public:
// Add extra indentation
Replaceall(enum_code, "\n", "\n ");
Replaceall(enum_code, " \n", "\n");
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc,doxygen_comments)){
if(comment_creation_chatter)
Printf(proxy_class_constants_code, "/* This was generated from enumvalueDeclaration() */");
Printf(proxy_class_constants_code, Char(doxygen_comments));
Delete(doxygen_comments);
}
}
Printv(proxy_class_constants_code, " ", enum_code, "\n\n", NIL);
} else {
@ -1418,30 +1415,29 @@ public:
}
if (!addSymbol(name, n, scope))
return SWIG_ERROR;
//translate and write javadoc comment if flagged
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
Printf(enum_code, "/* This was generated from enumvalueDeclaration() */");
Printf(enum_code, Char(doxygen_comments));
Delete(doxygen_comments);
}
}
if ((enum_feature == ProperEnum) && parent_name && !unnamedinstance) {
// Wrap (non-anonymous) C/C++ enum with a proper Java enum
// Emit the enum item.
if (!GetFlag(n, "firstenumitem"))
Printf(enum_code, ",\n");
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc,doxygen_comments)){
if(comment_creation_chatter)
Printf(enum_code, "/* This was generated from enumvalueDeclaration() */");
Printf(enum_code, Char(doxygen_comments));
Delete(doxygen_comments);
}
}
Printf(enum_code, " %s", symname);
if (Getattr(n, "enumvalue")) {
String *value = enumValue(n);
Printf(enum_code, "(%s)", value);
Delete(value);
}
Printf(enum_code, ",\n");
} else {
// Wrap C/C++ enums with constant integers or use the typesafe enum pattern
SwigType *typemap_lookup_type = parent_name ? parent_name : NewString("enum ");
@ -1493,7 +1489,7 @@ public:
* file
* ------------------------------------------------------------------------ */
virtual int doxygenComment(Node *n){
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
@ -1527,7 +1523,7 @@ public:
Swig_save("constantWrapper", n, "value", NIL);
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
@ -1825,7 +1821,7 @@ public:
const String *pure_interfaces = typemapLookup(n, "javainterfaces", typemap_lookup_type, WARN_NONE);
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
@ -2231,7 +2227,7 @@ public:
}
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
@ -2464,7 +2460,7 @@ public:
Printf(im_return_type, "%s", tm);
//translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)){
if(comment_creation_chatter)
@ -2736,7 +2732,7 @@ public:
String *post_code = NewString("");
// translate and write javadoc comment if flagged
if (doxygen_javadoc_flag){
if (doxygen){
String *doxygen_comments;
if(DoxygenTranslator::getDocumentation(n, JavaDoc, doxygen_comments)) {
if(comment_creation_chatter)
@ -4523,6 +4519,8 @@ extern "C" Language *swig_java(void) {
const char *JAVA::usage = (char *) "\
Java Options (available with -java)\n\
-doxygen - Convert C++ doxygen comments to JavaDoc comments in proxy classes (default)\n\
-nodoxygen - Don't convert C++ doxygen comments to JavaDoc comments in proxy classes\n\
-nopgcpp - Suppress premature garbage collection prevention parameter\n\
-noproxy - Generate the low-level functional interface instead\n\
of proxy classes\n\