Clojure

GC Issue 2: gen-class - :exposes should expose static fields as static methods

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Reported by richhickey, Dec 14, 2008
right now it doesn't look at type of field, and always generates instance
methods

Comment 1 by richhickey, Dec 17, 2008
(No comment was entered for this change.)
Owner: ---
Comment 2 by richhickey, Dec 18, 2008
(No comment was entered for this change.)
Labels: Priority-High
Comment 3 by chouser, Mar 06, 2009
The attached patch was tested using this gen-class call:

  (ns clojure.contrib.test-clojure.gen-class
    (:gen-class
      :extends javax.swing.border.TitledBorder
      :exposes {TEXT_SPACING {:get getSpacing :set setSpacing}
                title {:get getString :set setString}}))

Then:

  (compile 'clojure.contrib.test-clojure.gen-class)
  (def x (clojure.contrib.test_clojure.gen_class. "hi"))

  (.getString x)  ==> "hi"
  (.setString x "yo")
  (.getString x)  ==> "yo"

  (.getSpacing x)
  ==> java.lang.IncompatibleClassChangeError: Expected non-static field
clojure.contrib.test_clojure.gen_class.TEXT_SPACING (NO_SOURCE_FILE:0)

With the patch applied, .getString and .setString work the same, but now:

  (clojure.contrib.test_clojure.gen_class/getSpacing)  ==> 2
  (clojure.contrib.test_clojure.gen_class/setSpacing 10)
  ==> java.lang.IllegalAccessError (NO_SOURCE_FILE:0)

This last error is because the static field is final.

--Chouser
 genclass-exposes-statics.patch
2.2 KB Download
Comment 4 by richhickey, Apr 12, 2009
Patch applied - r1345 - thanks!
Status: Fixed

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: