You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-spec@incubator.apache.org by Stuart Monteith <st...@stoo.me.uk> on 2009/10/13 20:41:44 UTC

Inner classes, Enums

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/


Re: Inner classes, Enums

Posted by Stuart Monteith <st...@stoo.me.uk>.
Hi Steve,

Steve Poole wrote:
> On Tue, Oct 13, 2009 at 9:41 PM, Stuart Monteith <st...@stoo.me.uk> wrote:
>
>   
>> 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.
>>
>> True
>>     
>
>   
>> 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.
>>
>> The modifier is irrelevant for us yes?   As long as its a subclass of
>>     
> java.lang.Enum   we know what it is.
>
>   
Enum can't be explicitly subclassed, so only direct subclasses of Enum 
will be Enums, so there are two sure fire ways of recognising
Enums.My point was just that the modifiers would probably be there but 
not recognisable using java.lang.Modifier.

Now, annotations... They are similar to Enums in that they subclass 
java.lang.annotation.Annotation and has a special modifier
that marks them as annotations.Of course, there are lots of things to 
resolve, like testing for the presence of annotations against methods, 
classes, etc.
and their values, which might be present at runtime.

> For example,
>   
>>   "SELECT x FROM instances WHERE x.class=com.example.diy.Paint AND x.colour
>> = RED"
>>
>> Think you mean
>>     
>
>    "SELECT x FROM instances WHERE x.class=com.example.diy.Paint AND x.colour
> = Colour.RED"
>
>   
That would work too, however as every Enum has a name, which is stores, 
that could be used directly.
i.e. Colour.RED has a name "RED" and a value 0 (if it was the first).

> 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 ?
>>
>> anotherNumber is not  a field of  C so its not reasonable to allow
>>     
> x.anotherNumber.    What is required is that somehow you can  make the jump
> from the inner instance to the outer instance.    That would allow   x {goto
> parent instance operator} anotherNumber to work
>
>
>   
True - there is no Java syntax that resolve things the way I suggested, 
and you can always get there directly.
With nested classes it would just be important that you could get the 
enclosing instance via the API.
>   
>> Regards,
>>   Stuart
>>
>>
>>
>> Regards,
>>   Stuart
>>
>> --
>> Stuart Monteith
>> http://blog.stoo.me.uk/
>>
>>
>>     
>
>
>   

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


Re: Inner classes, Enums

Posted by Steve Poole <sp...@googlemail.com>.
On Tue, Oct 13, 2009 at 9:41 PM, Stuart Monteith <st...@stoo.me.uk> wrote:

> 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.
>
> True


> 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.
>
> The modifier is irrelevant for us yes?   As long as its a subclass of
java.lang.Enum   we know what it is.

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

   "SELECT x FROM instances WHERE x.class=com.example.diy.Paint AND x.colour
= 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 ?
>
> anotherNumber is not  a field of  C so its not reasonable to allow
x.anotherNumber.    What is required is that somehow you can  make the jump
from the inner instance to the outer instance.    That would allow   x {goto
parent instance operator} anotherNumber to work



> Regards,
>   Stuart
>
>
>
> Regards,
>   Stuart
>
> --
> Stuart Monteith
> http://blog.stoo.me.uk/
>
>


-- 
Steve