This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Subclasses and protected methods
Hi Per Bothner,
> Adam Warner wrote:
>
>> A java.lang.NoSuchMethodException for
>> org.eclipse.jface.window.ApplicationWindow.addStatusLine() is thrown
>> because addStatusLine is a protected method. I may only access it within
>> a subclass of ApplicationWindow.
>
> Have you tried the latest version of Kawa in CVS? It should have better
> support for calling (and defining) protected methods.
Ah, perhaps I've hit a bug. I've just performed a cvs update and compiled
the latest version. This is the result if I try to access the protected
method ApplicationWindow.addStatusLine():
java.lang.NoSuchMethodException: org.eclipse.jface.window.ApplicationWindow.addStatusLine()
at java.lang.Class.getMethod(Class.java:978)
at gnu.expr.PrimProcedure.applyV(PrimProcedure.java:155)
at gnu.mapping.MethodProc.applyN(MethodProc.java:141)
at gnu.mapping.Procedure.apply(Procedure.java:115)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:289)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:191)
at kawa.Shell.run(Shell.java:233)
at kawa.standard.load.loadSource(load.java:161)
at kawa.standard.load.loadSource(load.java:131)
at kawa.standard.load.apply(load.java:307)
at kawa.standard.load.apply2(load.java:199)
at kawa.standard.load.apply1(load.java:189)
at gnu.mapping.Procedure1.applyN(Procedure1.java:49)
at gnu.mapping.Procedure.apply(Procedure.java:115)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:289)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:191)
at kawa.Shell.run(Shell.java:233)
at kawa.Shell.run(Shell.java:180)
at kawa.Shell.run(Shell.java:167)
at kawa.Shell.run(Shell.java:154)
at kawa.repl.main(repl.java:650)
In the following code:
(define-namespace jface.window.Window "class:org.eclipse.jface.window.Window")
(define-namespace jface.window.ApplicationWindow
"class:org.eclipse.jface.window.ApplicationWindow")
(define window (jface.window.ApplicationWindow:new #!null))
(jface.window.ApplicationWindow:addStatusLine window)
(jface.window.ApplicationWindow:setStatus window "The status line.")
(jface.window.Window:setBlockOnOpen window #t)
(jface.window.Window:open window)
(jface.window.Window:close window)
I can prove the method exists in my classpath by removing the window
argument from the method call:
(jface.window.ApplicationWindow:addStatusLine);; window)
gnu.mapping.WrongArguments: call to
'org.eclipse.jface.window.ApplicationWindow.addStatusLine()' has too few
arguments (0; must be 1)
at gnu.mapping.Procedure.checkArgCount(Procedure.java:85) at
gnu.mapping.MethodProc.applyN(MethodProc.java:133) at
gnu.mapping.ProcedureN.apply0(ProcedureN.java:24) at
gnu.mapping.Procedure.apply(Procedure.java:121) at
gnu.mapping.CallContext.runUntilDone(CallContext.java:289) at
gnu.expr.ModuleExp.evalModule(ModuleExp.java:191) at
kawa.Shell.run(Shell.java:233)
at kawa.standard.load.loadSource(load.java:161) at
kawa.standard.load.loadSource(load.java:131) at
kawa.standard.load.apply(load.java:307) at
kawa.standard.load.apply2(load.java:199) at
kawa.standard.load.apply1(load.java:189) at
gnu.mapping.Procedure1.applyN(Procedure1.java:49) at
gnu.mapping.Procedure.apply(Procedure.java:115) at
gnu.mapping.CallContext.runUntilDone(CallContext.java:289) at
gnu.expr.ModuleExp.evalModule(ModuleExp.java:191) at
kawa.Shell.run(Shell.java:233)
at kawa.Shell.run(Shell.java:180)
at kawa.Shell.run(Shell.java:167)
at kawa.Shell.run(Shell.java:154)
at kawa.repl.main(repl.java:650)
If you're using Linux and you need to reproduce this you can add these
jars into your CLASSPATH (assuming you extracted the Stable Build 3.0M8 of
Eclipse in the subdirectory ~/files/eclipse):
export
CLASSPATH=.:~/files/eclipse/eclipse/plugins/org.eclipse.core.runtime_3.0.0/runtime.jar:
~/files/eclipse/eclipse/plugins/org.eclipse.jface_3.0.0/jface.jar:
~/files/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/ws/gtk/swt-pi.jar:
~/files/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/ws/gtk/swt-mozilla.jar:
~/files/eclipse/eclipse/plugins/org.eclipse.swt.gtk_3.0.0/ws/gtk/swt.jar
Available from here:
<http://eclipse.org/downloads/index.php>
I hope I haven't misinterpreted your reply and I simply shouldn't be able
to call a protected method except when explicitly within a subclass.
An extract from the Eclipse Platform Pre-release 3.0 documentation:
public class ApplicationWindow
extends Window
implements IRunnableContext
An application window is a high-level "main window", with built-in support
for an optional menu bar with standard menus, an optional toolbar, and an
optional status line.
Creating an application window involves the following steps:
* creating an instance of ApplicationWindow
* assigning the window to a window manager (optional)
* opening the window by calling open
Only on the last step, when the window is told to open, are the window's
shell and widget tree created. When the window is closed, the shell and
widget tree are disposed of and are no longer referenced, and the window
is automatically removed from its window manager. Like all windows, an
application window may be reopened.
An application window is also a suitable context in which to perform
long-running operations (that is, it implements IRunnableContext).
...
addStatusLine
protected void addStatusLine()
Configures this window to have a status line. Does nothing if it
already has one. This method must be called before this window's shell
is created.
...
createStatusLine
protected void createStatusLine(Shell shell)
Create the status line if required.
Parameters:
shell -
...
setStatus
public void setStatus(String message)
Sets or clears the message displayed in this window's status line (if
it has one). This method has no effect if the window does not have a
status line.
Parameters:
message - the status message, or null to clear it
Regards,
Adam