On Sat, 3 Apr 2010, Bill Janssen wrote:

Andi Vajda <va...@apache.org> wrote:

On Apr 3, 2010, at 11:38, Bill Janssen <jans...@parc.com> wrote:

Does JCC support templated types yet?

Yes, Lucene Java moved to Java 5 and makes extensive use of generics
in the 3.x release series.
I added support for that in JCC 2.5.

In particular, I'd like to be able to say,

     --sequence List<com.parc.goodstuff.Stuff>
                'size:()I'
                'get:(I)Lcom/parc.goodstuff.Stuff;'

The first arg to --sequence is that of an existing class, and the
following, the actual signatures of existing methods on it.

Let's see if I understand this.  I'm not sure I know what the "existing
classes" are.  In this case, the type is
java.util.List<com.parc.goodstuff.Stuff>.  java.util.List is an
interface rather than a class.  On the other hand,
java.util.List<com.parc.goodstuff.Stuff> is a parameterized type of some
sort.  A parameterized interface?  I see no .class file for it.

There is a .class file for java.util.List so that's what I mean by 'existing'. The parameterizations of it are a runtime feature, not a compile time feature as in C++.

So I'm guessing I can't do what I want to do.

Yes, you could, were it not for the bug that, currently, --sequence code does not heed parameterization. I'm fixing this next.

So, assuming this bug were fixed, using:

   --sequence java.util.AbstractList 'size:()I' 'get:(I)Ljava/lang/Object;'

Note: you can't use List since, in Python, ArrayList doesn't inherit from List because a Python C type can have only one base and that's AbstractList <- AbstractCollection <- Object. Hence, use AbstractList instead.

Then, in your code:

   >>> list = ArrayList().of_(Stuff)
   >>> list.add(Stuff())
   >>> list[0]
   <Stuff ...>

If you define a class foo parameterized on type T and that type is the
return type of a method, that type is used, at runtime, as the wrapper
for the return value.

I'm sorry, but I don't think I understand what you're saying here.
Which type is the return type of a method, "foo" or "T"?

say you have:

  class Foo<T> {
    T get(int i)
    {
       return something;
    }
}

then when you do elsewhere in java:

  Foo<Stuff> foo = new Foo(...);
  Stuff fromFoo = foo.get(0);  //get returns T, bound to Stuff in Foo<Stuff>

In Python, by way of JCC, that T bound to Stuff is visible in the foo instances's parameters_ and is set via calls compiled to return it or manually via the new of_() method.

 >>> foo = Foo(...).of_(Stuff)
 >>> fromFoo = foo.get(0)
 <Stuff ...>

JCC does not generate code for all known expansions of a generic class
- that would lead to serious code explosion.

I assume this also includes generic interface types.

How about generating code for expansions that are specifically called
out in the args to JCC, as in the example above?

That is not necessary. It's all the same code, even in Java.

Andi..

Reply via email to