Closed
Bug 245882
Opened 21 years ago
Closed 21 years ago
JavaImporter constructor
Categories
(Rhino Graveyard :: Core, enhancement)
Rhino Graveyard
Core
Tracking
(Not tracked)
RESOLVED
FIXED
1.6R1
People
(Reporter: igor, Assigned: igor)
Details
Attachments
(3 files)
15.49 KB,
patch
|
Details | Diff | Splinter Review | |
2.27 KB,
patch
|
Details | Diff | Splinter Review | |
1.20 KB,
patch
|
Details | Diff | Splinter Review |
Currently in Rhino importPackage and importCass are available when
ImporterTopLevel is a scope object. I suggest to add JavaImporter constructor to
Rhino that would construct explicit ImporterTopLevel objects. The constructor
should be initialized during Context.initStandardObjects call to allow in all
scripts a usage like:
var Swing = new JavaImporter();
Swing.importPackage(Packages.java.awt.event);
Swing.importPackage(Packages.javax.swing);
Swing.importClass(Packages.java.awt.EventQueue);
and later:
var btn = new Swing.JButton()
etc.
In this way it would be possible to create ready-to-use aliases to package
groups in application without danger of namespace pollution.
The constructor should also allow to pass a list of packages/classes to import
to simplify usage:
var Swing = new JavaImporter(Packages.java.awt.event,
Packages.javax.swing,
Packages.java.awt.EventQueue);
The extension should be orthogonal to the current usage of ImporterTopLevel as
top scope object.
Assignee | ||
Comment 1•21 years ago
|
||
Simultaneous usage of ImporterTopLevel as top scope and prototype object makes
the patch bigger then necessary. For example, it alters IdScriptable to avoid
setting parent scope to self causing infinite loops.
Assignee | ||
Comment 2•21 years ago
|
||
The previous patch made JavaImporter a full-fetured host object constructor
that defines among others JavaImporter.prototype.constructor property.
This is problematic for ImporterTopLevel usage as top scope object as it makes
top-level constructor property to point to JavaImporter.prototype.constructor
and not to Object.prototype.constructor.
This additional fix resolves the regression.
Assignee | ||
Comment 3•21 years ago
|
||
Fixed: I committed both patches.
With the patch applied and "with" operator one can almost achive affect of
global importPackage without adding package classes to the scope permanently:
with (new JavaImporter(Packages.java.awt.event)) {
var btn = new JButton();
...
}
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Assignee | ||
Comment 4•21 years ago
|
||
Fixed: I committed both patches.
With the patch applied and "with" operator one can almost achive effect of
global importPackage without adding package classes to the scope permanently:
with (new JavaImporter(Packages.java.awt.event)) {
var btn = new JButton();
...
}
Assignee | ||
Comment 5•21 years ago
|
||
The example in comment 4 is wrong. A better way to demonstrate usability of
JavaImporter is this code:
var SwingGui = JavaImporter(Packages.javax.swing,
Packages.javax.swing.event,
Packages.javax.swing.border,
java.awt.event,
java.awt.Point,
java.awt.Rectangle,
java.awt.Dimension);
...
with (SwingGui) {
var mybutton = new JButton(test);
var mypoint = new Point(10, 10);
var myframe = new JFrame();
...
}
Assignee | ||
Comment 7•21 years ago
|
||
The patch (which I already committed) fixes regression reported by Merten
Schumman:
The new implementation of importPackage/importClass assumed that thisObj should
always be ImporterTopLevel. But this is wrong when ImporterTopLevel is used as
top scope object to provide global import* functions since such scope can be a
part of prototype chain.
Comment 8•21 years ago
|
||
JavaImporter is an absolutely useful extension to Rhino IMHO, nice feature!
Merten
You need to log in
before you can comment on or make changes to this bug.
Description
•