List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:December 4 2007 11:39pm
Subject:Rev 327: Added java option to swig to support suppressing of warnings for typesafe enums. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connector...
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 327
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Tue 2007-12-04 15:39:01 -0800
message:
  Added java option to swig to support suppressing of warnings for typesafe enums.
modified:
  java/Makefile.am               makefile.am-20070415032352-9dpe6aurqcnuwcrd-1
  swig/SWIG/Lib/java/enumtypesafe.swg enumtypesafe.swg-20071104211339-fod7yzi8t7xd3g0w-911
  swig/SWIG/Source/Modules/java.cxx java.cxx-20071104211339-fod7yzi8t7xd3g0w-1275
=== modified file 'java/Makefile.am'
--- a/java/Makefile.am	2007-12-04 18:31:33 +0000
+++ b/java/Makefile.am	2007-12-04 23:39:01 +0000
@@ -331,7 +331,7 @@
 
 .i.cxx:  
 	@mkdir -p ${package_builddir}/$(*F)
-	$(SWIG) -java -outdir ${builddir}/${package_namespace}/$(*F) -package `echo
${package_namespace}/$(*F) | sed 's,/,.,g'` -I$(SWIG_DIR) -I${srcdir}/swig
$(MYSQL_INCLUDES) $(DEFAULT_INCLUDES) -o $@ $<
+	$(SWIG) -java -usejava5 -outdir ${builddir}/${package_namespace}/$(*F) -package `echo
${package_namespace}/$(*F) | sed 's,/,.,g'` -I$(SWIG_DIR) -I${srcdir}/swig
$(MYSQL_INCLUDES) $(DEFAULT_INCLUDES) -o $@ $<
 
 # $(NDBAPI_JAVA_CLASSES) $(MGMAPI_JAVA_CLASSES)
 mgmj.jar: libmgmj.la $(MGMAPI_JAVA_SRC) $(MGMAPI_BUILT_J)

=== modified file 'swig/SWIG/Lib/java/enumtypesafe.swg'
--- a/swig/SWIG/Lib/java/enumtypesafe.swg	2007-11-04 21:32:20 +0000
+++ b/swig/SWIG/Lib/java/enumtypesafe.swg	2007-12-04 23:39:01 +0000
@@ -94,17 +94,20 @@
     throw new IllegalArgumentException("No enum " + $javaclassname.class + " with value "
+ swigValue);
   }
 
+  $supresswarnings
   private $javaclassname(String swigName) {
     this.swigName = swigName;
     this.swigValue = swigNext++;
   }
 
+  $supresswarnings
   private $javaclassname(String swigName, int swigValue) {
     this.swigName = swigName;
     this.swigValue = swigValue;
     swigNext = swigValue+1;
   }
 
+  $supresswarnings
   private $javaclassname(String swigName, $javaclassname swigEnum) {
     this.swigName = swigName;
     this.swigValue = swigEnum.swigValue;

=== modified file 'swig/SWIG/Source/Modules/java.cxx'
--- a/swig/SWIG/Source/Modules/java.cxx	2007-11-04 21:32:20 +0000
+++ b/swig/SWIG/Source/Modules/java.cxx	2007-12-04 23:39:01 +0000
@@ -42,6 +42,7 @@
   bool wrapping_member_flag;	// Flag for when wrapping a member variable/enum/const
   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 use_java5;		// Flag to use newer Java5 features
   bool member_func_flag;	// flag set when wrapping a member function
 
   String *imclass_name;		// intermediary class name
@@ -115,6 +116,7 @@
       wrapping_member_flag(false),
       global_variable_flag(false),
       old_variable_names(false),
+      use_java5(false),
       member_func_flag(false),
       imclass_name(NULL),
       module_class_name(NULL),
@@ -230,6 +232,9 @@
 	} else if (strcmp(argv[i], "-oldvarnames") == 0) {
 	  Swig_mark_arg(i);
 	  old_variable_names = true;
+	} else if (strcmp(argv[i], "-usejava5") == 0) { 
+	  Swig_mark_arg(i);
+	  use_java5 = true;
 	} else if (strcmp(argv[i], "-jnic") == 0) {
 	  Swig_mark_arg(i);
 	  Printf(stderr, "Deprecated command line option: -jnic. C JNI calling convention now
used when -c++ not specified.\n");
@@ -247,6 +252,7 @@
 
     // Add a symbol to the parser for conditional compilation
     Preprocessor_define("SWIGJAVA 1", 0);
+    Preprocessor_define("USEJAVA5 1", 0);
 
     // Add typemap definitions
     SWIG_typemap_lang("java");
@@ -1194,6 +1200,11 @@
 	       typemapLookup("javacode", typemap_lookup_type, WARN_NONE),	// extra Java code
 	       "}", NIL);
 
+        if (use_java5) { 
+	  Replaceall(enum_code, "$supresswarnings", "@SuppressWarnings(\"unused\")"); 
+        } else { 
+          Replaceall(enum_code, "$supresswarnings", "");
+        }
 	Replaceall(enum_code, "$javaclassname", symname);
 
 	// Substitute $enumvalues - intended usage is for typesafe enums
@@ -1680,6 +1691,15 @@
 	   "\n", NIL);
 
     // Substitute various strings into the above template
+
+    if (use_java5) {
+      Replaceall(proxy_class_code, "$supresswarnings", "@SuppressWarnings(\"unused\")");
+      Replaceall(proxy_class_def, "$supresswarnings", "@SuppressWarnings(\"unused\")");
+    } else {
+      Replaceall(proxy_class_code, "$supresswarnings", "");
+      Replaceall(proxy_class_def, "$supresswarnings", "");
+    }
+
     Replaceall(proxy_class_code, "$javaclassname", proxy_class_name);
     Replaceall(proxy_class_def, "$javaclassname", proxy_class_name);
 
@@ -2820,6 +2840,11 @@
 	   typemapLookup("javacode", type, WARN_NONE),	// extra Java code
 	   "}\n", "\n", NIL);
 
+        if (use_java5) { 
+	  Replaceall(swigtype, "$supresswarnings", "@SuppressWarnings(\"unused\")"); 
+        } else { 
+          Replaceall(swigtype, "$supresswarnings", "");
+        }
     Replaceall(swigtype, "$javaclassname", classname);
     Replaceall(swigtype, "$module", module_class_name);
     Replaceall(swigtype, "$imclassname", imclass_name);
@@ -4108,5 +4133,6 @@
      -noproxy        - Generate the low-level functional interface instead\n\
                        of proxy classes\n\
      -oldvarnames    - old intermediary method names for variable wrappers\n\
+     -usejava5          - Enable use of newer Java5 constructs\n\
      -package <name> - set name of the Java package to <name>\n\
 \n";

Thread
Rev 327: Added java option to swig to support suppressing of warnings for typesafe enums. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connector...Monty Taylor5 Dec