This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: importing java packages


> My mileage varies quite a bit in this case.

To each his own.  I'm just saying what works for me!

> define-namespace is only useful when you're invoking methods.  You
> can't use it in any of the other places you use type tags.  You still
> need type tags for calling field and static-field, declaring function
> argument and return types, and declaring types on local variables.

That's not precisely true.  There are patches floating around (I wrote
some of them) that change this behavior.  For example, you can use
(JFrame:class) and (JFrame:instance? x) if you load in the right
patches.  Some things certainly still don't work (like accessing
fields), but I'd call that a missing feature or a bug.

My point is, really, that if we're adding features then let's add them
to the namespace logic.

> Kawa's type-guesser doesn't always guess correctly, and my app is always
> giving me warnings about no applicable methods for java.lang.Object.
> You can't just drop the :: <Container> from the example above.

(Since I've started wandering down this path, I might as well finish.)

I care about those warnings too and there are two ways to fix them in
when using the namespace style.  One is to use (container:class)
instead of <Container> and the other is to use (container:cast root)
when calling (container:add ...).  There is sample code below, if you
are interested.

> Unfortunately you still have to write a *bunch* of these if you're
> doing any significant SWT or Swing code.  

The define-package-namespaces is an attempt to help with that, but
with namespaces instead of aliases for Classes.

Regards,
Chris Dean




(module-name <Foo>)
(module-static #t)

(define-namespace jframe <javax.swing.JFrame>)
(define-namespace container <java.awt.Container>)
(define-namespace border-layout <java.awt.BorderLayout>)
(define-namespace jlabel <javax.swing.JLabel>)


(define (foo)
  (let* ((f (jframe:new))
         (root (jframe:getContentPane f)))
    (container:setLayout root (border-layout:new))
    (container:add (container:cast root)
                   (jlabel:new "hello")
                   (static-field (border-layout:class) 'CENTER))))



==>
    
    public static void foo() {
        Object f = new JFrame();
        Object object = f;
        JFrame jframe;
        try {
            jframe = (JFrame) object;
        } catch (ClassCastException classcastexception) {
            throw WrongType.make(classcastexception,
                                 "javax.swing.JFrame.getContentPane()", 1);
        }
        Object root = jframe.getContentPane();
        Object object_0_ = root;
        Container container;
        try {
            container = (Container) object_0_;
        } catch (ClassCastException classcastexception) {
            throw WrongType.make
                      (classcastexception,
                       "java.awt.Container.setLayout(java.awt.LayoutManager)",
                       1);
        }
        container.setLayout(new BorderLayout());
        ((Container) root).add(new JLabel("hello"), BorderLayout.CENTER);
    }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]