incubator-kato-spec mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stuart Monteith <stuk...@stoo.me.uk>
Subject Inner classes, Enums
Date Tue, 13 Oct 2009 20:41:44 GMT
Hi,
    I've noticed that we don't really have support for inner classes or 
enums in the API or any query languages that have been suggested.

For enums we'd want to do comparisons where a field is compared against 
an enum type. An enum just now will appear as a class subclassing 
java.lang.Enum with a modifier including "0x4000" - this, incidentally, 
doesn't appear in "java.lang.reflect.Modifier", which the API depends on.

For example,
    "SELECT x FROM instances WHERE x.class=com.example.diy.Paint AND 
x.colour = RED"

Where
    public com.example.diy.Paint {
       Colour colour;
    }


    public enum Colour {
       RED, GREEN, FUSCHIA, MAGNOLIA, WHITE
    }


In the Java application API, it might be worth having:

    public interface JavaEnum extends JavaClass {
        EnumConstant[] getConstants();       
       EnumConstant getConstant(String name);
    }

    public interface EnumConstant extends JavaObject {
       public String getName();
       public int getOrdinal();
       public JavaEnum getType();
    }

These would correspond with Enums and their types, extending JavaClass 
and JavaObject, and would still allow more sophisticated, non-standard 
enums to be queried like other classes and objects.
So you could do:

    EnumType terry=xxxx;
    if ( ((JavaObject)character).equals(terry.getConstant("June")) )
       // Do something interesting.
    }

Now, inner classes..

The relationship between classes and their inner classes isn't exposed 
by the API. I'm not sure how to judge how important that is, but it 
might be important for field value retrieval and querying.

java.lang.Class provides the following methods:
    Class getDeclaringClass()
    Class getEnclosingClass()
    Class getEnclosingMethod()
    boolean isAnonymousClass()
    boolean isLocalClass()
    boolean isMemberClass()

Which could be conceivably be duplicated within JavaClass.

For querying, say:

public class A {
    int aNumber = 2;

    public class B {
       int anotherNumber = 5;

       public class C {
          String inDepth = 18;
       }
    }
}

Given an instance of A$B$C, should we allow querying to allow:
    WHERE x.anotherNumber = 5
when x is A$B$C ?


Regards,
    Stuart

   


Regards,
    Stuart

-- 
Stuart Monteith
http://blog.stoo.me.uk/


Mime
View raw message