public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* @Override notations for member functions (e.g. onCreate on Android)
@ 2014-02-23 13:18 Marius Kjeldahl
  2014-02-23 19:19 ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Marius Kjeldahl @ 2014-02-23 13:18 UTC (permalink / raw)
  To: kawa

I can't seem to get them working, like in the following example:

(define-simple-class MainActivity (android.app.Activity)
  ((onCreate (savedInstanceState :: android.os.Bundle)) (@Override)
   (invoke-special android.app.Activity (this) 'onCreate savedInstanceState)
...)

Are @Override notation supported at all, and if so, how can I use them
on member functions like onCreate?

Thanks,

Marius K.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: @Override notations for member functions (e.g. onCreate on Android)
  2014-02-23 13:18 @Override notations for member functions (e.g. onCreate on Android) Marius Kjeldahl
@ 2014-02-23 19:19 ` Per Bothner
       [not found]   ` <CAHdMyCJ0701d6o0N4uhGztJ_oPHu9TH-eFxBR3qhMWp6juprWg@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2014-02-23 19:19 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

On 02/23/2014 05:18 AM, Marius Kjeldahl wrote:
> I can't seem to get them working, like in the following example:
>
> (define-simple-class MainActivity (android.app.Activity)
>    ((onCreate (savedInstanceState :: android.os.Bundle)) (@Override)
>     (invoke-special android.app.Activity (this) 'onCreate savedInstanceState)
> ...)
>
> Are @Override notation supported at all, and if so, how can I use them
> on member functions like onCreate?

You need to either write: (@java.lang.Override) or add a:
(define-alias Override java.lang.Override)

Kawa does not automatically "import" java.lang.*.  This could
be changed of course.

Note that Kawa currently doesn't check @Override annotations,
and since it has @Retention(SOURCE) it is just ignored.

Making Kawa check @Override annotation seems a worthwhile change.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Fwd: @Override notations for member functions (e.g. onCreate on Android)
       [not found]   ` <CAHdMyCJ0701d6o0N4uhGztJ_oPHu9TH-eFxBR3qhMWp6juprWg@mail.gmail.com>
@ 2014-02-23 22:05     ` Marius Kjeldahl
  2014-02-24  1:59     ` Per Bothner
  1 sibling, 0 replies; 5+ messages in thread
From: Marius Kjeldahl @ 2014-02-23 22:05 UTC (permalink / raw)
  To: kawa

I mistankenly sent this message to Per directly; reposting to list
(where it was supposed to go anyway):

---------- Forwarded message ----------
From: Marius Kjeldahl <marius.kjeldahl@gmail.com>
Date: Sun, Feb 23, 2014 at 10:31 PM
Subject: Re: @Override notations for member functions (e.g. onCreate on Android)
To: Per Bothner <per@bothner.com>


Thanks, that works (even if it is not really supported yet as you say).

Let me share why I'm bothering you with this. I'm working on a set of
tutorials, both for myself and anybody else who wants to write Android
apps (and possibly even iOS apps, using RoboVM) using Kawa instead of
Java.

So my first test is simply to write the Android version of "hello
world" in Kawa. But instead of doing it elegantly (like Per in his
"view construction" tutorial) I am doing it more or less line-by-line
so people can understand how it translates. With the proper
understanding in place, moving on to something elegant is probably a
lot easier.

So I've created a gist here that seems to compile, but with a warning:

https://gist.github.com/mariusk/9177506

The compiler output is:

(compiling KawaActivity.scm to net.kjeldahl.kawatest)
KawaActivity.scm:15:26: warning - no accessible method 'add' in
android.widget.LinearLayout

It seems to compile fine, but is there any way to get rid of that
warning when constructing the LinearLayout? I realize it's related to
"magic" of setting properties, but from the warning I am not sure if
it actually found the right "setOrientation" or not. If it did find
it, it really should shut up, right?

Thanks,

Marius K.


On Sun, Feb 23, 2014 at 8:19 PM, Per Bothner <per@bothner.com> wrote:
> On 02/23/2014 05:18 AM, Marius Kjeldahl wrote:
>>
>> I can't seem to get them working, like in the following example:
>>
>> (define-simple-class MainActivity (android.app.Activity)
>>    ((onCreate (savedInstanceState :: android.os.Bundle)) (@Override)
>>     (invoke-special android.app.Activity (this) 'onCreate
>> savedInstanceState)
>> ...)
>>
>> Are @Override notation supported at all, and if so, how can I use them
>> on member functions like onCreate?
>
>
> You need to either write: (@java.lang.Override) or add a:
> (define-alias Override java.lang.Override)
>
> Kawa does not automatically "import" java.lang.*.  This could
> be changed of course.
>
> Note that Kawa currently doesn't check @Override annotations,
> and since it has @Retention(SOURCE) it is just ignored.
>
> Making Kawa check @Override annotation seems a worthwhile change.
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: @Override notations for member functions (e.g. onCreate on Android)
       [not found]   ` <CAHdMyCJ0701d6o0N4uhGztJ_oPHu9TH-eFxBR3qhMWp6juprWg@mail.gmail.com>
  2014-02-23 22:05     ` Fwd: " Marius Kjeldahl
@ 2014-02-24  1:59     ` Per Bothner
       [not found]       ` <CAHdMyCKyXoM+CMYSe+WH4BHgeRTmAbQCdnOHnErGaQ=tY5fwHw@mail.gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Per Bothner @ 2014-02-24  1:59 UTC (permalink / raw)
  To: Marius Kjeldahl, kawa

On 02/23/2014 01:31 PM, Marius Kjeldahl wrote:
> (compiling KawaActivity.scm to net.kjeldahl.kawatest)
> KawaActivity.scm:15:26: warning - no accessible method 'add' in
> android.widget.LinearLayout
>
> It seems to compile fine, but is there any way to get rid of that
> warning when constructing the LinearLayout? I realize it's related to
> "magic" of setting properties, but from the warning I am not sure if
> it actually found the right "setOrientation" or not. If it did find
> it, it really should shut up, right?

I'm guessing the problem is not the orientation:
but the 'tv' parameter.  That is needed to "add" children.

If you:
(require 'android-defs)
then that associates a ViewBuilder with android.view.View and so
ViewBuilder is used when compiling a build of a sub-class instance.
And ViewBuilder defines "addView" as a child-method-name, and so it
magically works.

As a hack the following will probably work:
     (LinearLayout (this)
                   orientation: LinearLayout:VERTICAL
                   view: tv)

though if you really want to show the "low-level" way of
doing it you can add an explicit addView call.

BTW, you might not realize you can replace:

  (define str (string-append "KawaActivity - "
                               ((tv:getText):toString)
                               " - "
                               ((Date):toString)))
    (tv:setText str)))

by the following (not tested ...):

    (tv:setText &{KawaActivity - &(tv:getText) - &(Date)})
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Fwd: @Override notations for member functions (e.g. onCreate on Android)
       [not found]       ` <CAHdMyCKyXoM+CMYSe+WH4BHgeRTmAbQCdnOHnErGaQ=tY5fwHw@mail.gmail.com>
@ 2014-02-24 16:38         ` Marius Kjeldahl
  0 siblings, 0 replies; 5+ messages in thread
From: Marius Kjeldahl @ 2014-02-24 16:38 UTC (permalink / raw)
  To: kawa

My gmail skills are lacking, which is why I keep replying privately
instead of to the list. Shared with list for future reference.

Thanks,

Marius K.


---------- Forwarded message ----------
From: Marius Kjeldahl <marius.kjeldahl@gmail.com>
Date: Mon, Feb 24, 2014 at 5:37 PM
Subject: Re: @Override notations for member functions (e.g. onCreate on Android)
To: Per Bothner <per@bothner.com>


As always, you're spot on. I missed the fact that android-defs also
took care of the add-view magic. Also adding "view:tv" as you
suggested seems to work just fine.

Thanks,

Marius K.

On Mon, Feb 24, 2014 at 2:58 AM, Per Bothner <per@bothner.com> wrote:
> On 02/23/2014 01:31 PM, Marius Kjeldahl wrote:
>>
>> (compiling KawaActivity.scm to net.kjeldahl.kawatest)
>> KawaActivity.scm:15:26: warning - no accessible method 'add' in
>> android.widget.LinearLayout
>>
>> It seems to compile fine, but is there any way to get rid of that
>> warning when constructing the LinearLayout? I realize it's related to
>> "magic" of setting properties, but from the warning I am not sure if
>> it actually found the right "setOrientation" or not. If it did find
>> it, it really should shut up, right?
>
>
> I'm guessing the problem is not the orientation:
> but the 'tv' parameter.  That is needed to "add" children.
>
> If you:
> (require 'android-defs)
> then that associates a ViewBuilder with android.view.View and so
> ViewBuilder is used when compiling a build of a sub-class instance.
> And ViewBuilder defines "addView" as a child-method-name, and so it
> magically works.
>
> As a hack the following will probably work:
>     (LinearLayout (this)
>                   orientation: LinearLayout:VERTICAL
>                   view: tv)
>
> though if you really want to show the "low-level" way of
> doing it you can add an explicit addView call.
>
> BTW, you might not realize you can replace:
>
>  (define str (string-append "KawaActivity - "
>                               ((tv:getText):toString)
>                               " - "
>                               ((Date):toString)))
>    (tv:setText str)))
>
> by the following (not tested ...):
>
>    (tv:setText &{KawaActivity - &(tv:getText) - &(Date)})
>
> --
>         --Per Bothner
> per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-24 16:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-23 13:18 @Override notations for member functions (e.g. onCreate on Android) Marius Kjeldahl
2014-02-23 19:19 ` Per Bothner
     [not found]   ` <CAHdMyCJ0701d6o0N4uhGztJ_oPHu9TH-eFxBR3qhMWp6juprWg@mail.gmail.com>
2014-02-23 22:05     ` Fwd: " Marius Kjeldahl
2014-02-24  1:59     ` Per Bothner
     [not found]       ` <CAHdMyCKyXoM+CMYSe+WH4BHgeRTmAbQCdnOHnErGaQ=tY5fwHw@mail.gmail.com>
2014-02-24 16:38         ` Fwd: " Marius Kjeldahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).