This is the mail archive of the kawa@sourceware.org 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: annotations for Kawa


Are annotations supported on simple variables and functions yet,
or just on fields/methods of classes?

(define var (@Deprecated) ::type init-expr) is currently giving me
"no matching syntax-rule for define".

(define (foo) (@Deprecated) ::int 20) compiles without warning, but
at runtime I can't find the annotation:
#|kawa:1|# (*:get-annotations (*:get-declared-field test "foo"))
[]
#|kawa:2|# (*:get-annotations (*:get-declared-method test "foo"))
[]

On the other hand, it works fine on classes:
(define-simple-class T ()
  (v (@Deprecated) ::int)
  ((m) (@Deprecated) ::int v))

#|kawa:10|# (*:get-annotations (*:get-declared-field T "v"))
[@java.lang.Deprecated()]
#|kawa:11|# (*:get-annotations (*:get-declared-method T "m"))
[@java.lang.Deprecated()]

And slightly OT, I notice that Kawa doesn't actually warn me that
I'm calling a deprecated method when I evaluate "((T):m)". Actually,
I don't get an error from javac in that case, either -

$ cat test.scm
(define-alias Deprecated java.lang.Deprecated)
(define-simple-class T ()
  (v (@Deprecated) ::int)
  ((m) (@Deprecated) ::int v))
$ java kawa.repl -C test.scm
(compiling test.scm to test)
$ cat S.java
public class S {
  @Deprecated double d;
  @Deprecated public double m() { return d; }
}
$ javac S.java
$ cat U.java
public class U {
  public static void main(String[] args) {
    T t = new T();
    t.v = 42;
    System.out.println("the value: " + t.m());
    S s = new S();
    System.out.println("s: " + s.m());
  }
}
$ javac -Xlint:deprecation U.java
U.java:8: warning: [deprecation] m() in S has been deprecated
    System.out.println("s: " + s.m());
                                ^
1 warning
$

javac notices while compiling U.java that S.m() is a deprecated method, but it doesn't notice that T.m() is also deprecated. (And it's not re-reading S.java, because the results are the same even if I mv it aside and only have the class file present.)

Thanks,
Jamie

On Dec 28, 2010, at 2:58 AM, Per Bothner wrote:

Kawa now supports Java5-style annotations.  While not quite
as finished or polished as I'd like, still they should be usable.
I'm working on an example (a blog article) illustrating use of JAXB
annotations, and it's working pretty well.

I haven't written the documentation yet, but you can see
some examples in testsuite/annotations1.scm.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

-- Jamison Hope The PTR Group www.theptrgroup.com




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