Closed
Bug 513369
Opened 16 years ago
Closed 16 years ago
Provide annotation based mechanism to implement host objects with ScriptableObject.defineClass()
Categories
(Rhino Graveyard :: Core, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: hannesw, Assigned: hannesw)
Details
Attachments
(1 file)
|
20.30 KB,
patch
|
Details | Diff | Splinter Review |
ScriptableObject.defineProperties() defines a naming convention for mapping java classes and methods to JS host objects.
http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/ScriptableObject.html#defineClass%28org.mozilla.javascript.Scriptable,%20java.lang.Class%29
Rhino should allow using annotations (introduced in Java 1.5) to map java methods to host class methods.
http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html
| Assignee | ||
Comment 1•16 years ago
|
||
This patch allows to write annotation based host objects. It defines the following annotations in the org.mozilla.javascript.annotations package:
* JSConstructor
* JSFunction
* JSGetter
* JSSetter
* JSStaticFunction
All annotations take except JSConstructor take an optional String value to specify the name of the JS property the method defines. For example, the following defines a property called "foo" in the host object:
@JSGetter("foo")
public String getMyFoo() {...}
while the following results in a static function called "bar"
@JSStaticFunction("bar")
public void someBAR() {...}
In absense of an explicit value, the property name equals the Java method name for JSFunction and JSStaticFunction, and the bean property name for JSGetter and JSSetter. For example,
@JSGetter
public Object getFoo() {...}
results in a property called "foo", while
JSFunction
public void bar() {...}
results in a function called "bar".
Assignee: nobody → hannes
| Assignee | ||
Comment 2•16 years ago
|
||
I committed the patch.
Checking in src/org/mozilla/javascript/ScriptableObject.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/ScriptableObject.java,v <-- ScriptableObject.java
new revision: 1.158; previous revision: 1.157
done
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSConstructor.java,v
done
Checking in src/org/mozilla/javascript/annotations/JSConstructor.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSConstructor.java,v <-- JSConstructor.java
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSFunction.java,v
done
Checking in src/org/mozilla/javascript/annotations/JSFunction.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSFunction.java,v <-- JSFunction.java
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSGetter.java,v
done
Checking in src/org/mozilla/javascript/annotations/JSGetter.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSGetter.java,v <-- JSGetter.java
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSSetter.java,v
done
Checking in src/org/mozilla/javascript/annotations/JSSetter.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSSetter.java,v <-- JSSetter.java
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSStaticFunction.java,v
done
Checking in src/org/mozilla/javascript/annotations/JSStaticFunction.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/annotations/JSStaticFunction.java,v <-- JSStaticFunction.java
initial revision: 1.1
done
RCS file: /cvsroot/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DefineClassTest.java,v
done
Checking in testsrc/org/mozilla/javascript/tests/DefineClassTest.java;
/cvsroot/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/DefineClassTest.java,v <-- DefineClassTest.java
initial revision: 1.1
done
Status: NEW → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•