jde-wiz-implement-interface and getQualifiedNames

"Jeff Peck" <[email protected]>
Newsgroups gmane.emacs.jdee.devel
Message-ID <2E0ABF3E6AEC4C23A81A8EDA3084FCF7@blue>
I frequently use nested interface and class definitions,
and therefore frequently trip on Java's dual naming convention:
 Within Java code, the names are typically: pkg.Outer.Inner  (for import, extends, implements)
 But for filesystem and reflection, one needs: pkg.Outer$Inner  (for Class.forName())

jde-wiz-implement-interface calls JdeUtilities.getQualifiedName(),
which amazingly finds the correct nested class name, and returns it as "pkg.Outer.Inner"
Sadly, this fails when passed to jde-generate-interface: makeInterfaceExpression, 
          which needs it as "pkg.Outer$Inner"
(and then back to pkg.Inner.Outer for update-implements-clause)

Has this been addressed in any of the upcoming releases?

I was thinking to just catch/condition-case the error, replace the final "." with "$" and try again...
[trys to hack this...]
But the error is not thrown until the later (eval code)
So instead test for (and (code (eq (car code 'error))) and retry based on that.

I don't know how pervasive the problem is, (where else this hack is needed)
but this solves my immediate problem:

:jde>svn diff lisp/jde-wiz.el
Index: lisp/jde-wiz.el
===================================================================
--- lisp/jde-wiz.el (revision 154)
+++ lisp/jde-wiz.el (working copy)
@@ -124,19 +124,38 @@
        (forward-char))
      (insert (concat " " keyword " " interface " "))))))))
 
+(defun jde-dollar-name (name) 
+  "Convert pkg.Outer.Inner to pkg.Outer$Inner"
+  (let* ((ndx (string-match "^\\(.*\\)\\.\\([^.]*\\)$" name ))
+  (pkg (substring name (match-beginning 1) (match-end 1)))
+  (cls (substring name (match-beginning 2) (match-end 2))))
+    (concat pkg "$" cls))
+  )
+
+(defun jde-read-interface-expression (interface-name) 
+  "Try makeInterfaceExpression using interface-name,
+if that fails (as it will for an inner-class name),
+then try (jde-dollar-name interface-name)"
+  (flet ((jde-ife (name)
+   (read (jde-jeval
+   (format
+    "jde.wizards.InterfaceFactory.makeInterfaceExpression(\"%s\",true);"
+    name)))))
+    (let ((code (jde-ife interface-name)))
+      (if (and code (eq (car code) 'error))
+   (jde-ife (jde-dollar-name interface-name)); try again if there was an error:
+ code)
+      )))
+
 (defun jde-wiz-generate-interface (interface-name)
   "*Generate a skeleton implementation of a specified interface."
   (let* ((code
-   (read
-    (jde-jeval
-     (concat
-      "jde.wizards.InterfaceFactory.makeInterfaceExpression(\""
-      interface-name "\", true);")))))
-    (if  code
+   (jde-read-interface-expression interface-name)))
+    (if code
       (let ((required-imports
       (jde-jeval-r
   "jde.wizards.InterfaceFactory.getImportedClasses();")))
-   (eval code)
+   (eval code)   ;error may be thrown if bad intf name
    (if required-imports
        (jde-import-insert-imports-into-buffer required-imports t))
    (jde-wiz-update-implements-clause interface-name)))))

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference

_______________________________________________
jdee-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jdee-devel
jde-wiz.patch (application/octet-stream, 1.8 KB)
:jde>svn diff lisp/jde-wiz.el
Index: lisp/jde-wiz.el
===================================================================
--- lisp/jde-wiz.el	(revision 154)
+++ lisp/jde-wiz.el	(working copy)
@@ -124,19 +124,38 @@
 	      (forward-char))
 	    (insert (concat " " keyword " " interface " "))))))))
 
+(defun jde-dollar-name (name) 
+  "Convert pkg.Outer.Inner to pkg.Outer$Inner"
+  (let* ((ndx (string-match "^\\(.*\\)\\.\\([^.]*\\)$" name ))
+	 (pkg (substring name (match-beginning 1) (match-end 1)))
+	 (cls (substring name (match-beginning 2) (match-end 2))))
+    (concat pkg "$" cls))
+  )
+
+(defun jde-read-interface-expression (interface-name) 
+  "Try makeInterfaceExpression using interface-name,
+if that fails (as it will for an inner-class name),
+then try (jde-dollar-name interface-name)"
+  (flet ((jde-ife (name)
+	  (read (jde-jeval
+		 (format
+		  "jde.wizards.InterfaceFactory.makeInterfaceExpression(\"%s\",true);"
+		  name)))))
+    (let ((code (jde-ife interface-name)))
+      (if (and code (eq (car code) 'error))
+	  (jde-ife (jde-dollar-name interface-name)); try again if there was an error:
+	code)
+      )))
+
 (defun jde-wiz-generate-interface (interface-name)
   "*Generate a skeleton implementation of a specified interface."
   (let* ((code
-	  (read
-	   (jde-jeval
-	    (concat
-	     "jde.wizards.InterfaceFactory.makeInterfaceExpression(\""
-	     interface-name "\", true);")))))
-    (if  code
+	  (jde-read-interface-expression interface-name)))
+    (if code
       (let ((required-imports
 	     (jde-jeval-r
 		"jde.wizards.InterfaceFactory.getImportedClasses();")))
-	  (eval code)
+	  (eval code)			;error may be thrown if bad intf name
 	  (if required-imports
 	      (jde-import-insert-imports-into-buffer required-imports t))
 	  (jde-wiz-update-implements-clause interface-name)))))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.