patch to jde-wiz.el (to allow inner-class names)
"Jeff Peck" <[email protected]>
| Newsgroups | gmane.emacs.jdee.devel |
|---|---|
| Message-ID | <A7F29094FAD5456EBA2227ED10D4629B@blue> |
I generalized this solution and applied it to other parts of jde-wiz. attached is patch against: --- jde-wiz.el (revision 154) ----- Original Message ----- From: Jeff Peck To: [email protected] Sent: Tuesday, October 13, 2009 2:48 PM Subject: jde-wiz-implement-interface and getQualifiedNames 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: ------------------------------------------------------------------------------ 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, 4.2 KB)
:jdee/branches/2.4.0/jde/lisp>svn diff jde-wiz.el
Index: jde-wiz.el
===================================================================
--- jde-wiz.el (revision 154)
+++ jde-wiz.el (working copy)
@@ -124,19 +124,40 @@
(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-jeval-classname (fmt interface-name &optional eval-return)
+ "Try jde-jeval on the command derived from (format FMT INTERFACE-NAME),
+if that fails (as it will when INTERFACE-NAME is an inner-class name),
+then try after replacing INTERFACE-NAME with (jde-dollar-name INTERFACE-NAME).
+
+If EVAL-RETURN is t, then return (jde-jeval ... t), else return (read (jde-jeval ...))"
+ (flet ((jeval (name) (if eval-return
+ (jde-jeval (format fmt name) t)
+ (read (jde-jeval (format fmt name))))))
+ (let ((code (jeval interface-name)))
+ (if (and code (eq (car code) 'error))
+ (jeval (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-jeval-classname
+ "jde.wizards.InterfaceFactory.makeInterfaceExpression(\"%s\",true);"
+ 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)))))
@@ -211,12 +232,9 @@
to store the listeners too."
(condition-case err
(let* ((pos (point))
- (code
- (read
- (jde-jeval
- (concat
- "jde.wizards.EventSourceFactory.makeEventSourceSupportExpression(\""
- event-listener-interface-name "\", true);")))))
+ (code (jde-jeval-classname
+ "jde.wizards.EventSourceFactory.makeEventSourceSupportExpression(\"%s\", true);"
+ event-listener-interface-name)))
(if code
(let ((required-imports
(jde-jeval-r
@@ -365,11 +383,10 @@
(setq pos (string-match "(" method-name))
(if qualified-super-class
- (let ((signatures
- (jde-jeval
- (concat
- "jde.wizards.MethodOverrideFactory.getCandidateSignatures(\""
- qualified-class-name "\",\"" (substring method-name 0 pos) "\");") t)))
+ (let* ((fmt (concat
+ "jde.wizards.MethodOverrideFactory.getCandidateSignatures"
+ "(\"%s\",\"" (substring method-name 0 pos) "\");"))
+ (signatures (jde-jeval-classname fmt qualified-class-name t)))
(jde-wiz-override-method-internal method-name
signatures))
(error "Cannot find parent class %s" super-class)))
@@ -510,12 +527,9 @@
(car (jde-parse-declared-type-of delegee)) t)
(read-string (concat "Enter fully qualified class name of "
delegee ": "))))
- (code
- (read
- (jde-jeval
- (concat
- "jde.wizards.DelegateFactory.makeDelegatorMethods(\""
- delegee "\", \"" class-name "\", true);")))))
+ (fmt (concat "jde.wizards.DelegateFactory.makeDelegatorMethods(\""
+ delegee "\", \"%s\", true);"))
+ (code (jde-jeval-classname fmt class-name)))
(if code
(let ((required-imports
(jde-jeval-r
@@ -539,12 +553,9 @@
(defun jde-wiz-generate-abstract-class (class-name)
"*Generate a skeleton implementation of a specified abstract class."
(condition-case err
- (let* ((code
- (read
- (jde-jeval
- (concat
- "jde.wizards.AbstractClassFactory.makeAbstractClassExpression(\""
- class-name "\", true);")))))
+ (let* ((code (jde-jeval-classname
+ "jde.wizards.AbstractClassFactory.makeAbstractClassExpression(\"%s\", true);"
+ class-name)))
(if code
(let ((required-imports
(jde-jeval-r