[JBoss-user] [Javassist user questions] - Re: Array Class Literals

2005-03-30 Thread hlovatt
First two appologies: I don't seem to be able to watch this thread so I missed 
your post and secondly my test class is a little long :( . Take a look at lines 
75 to 90 which demonstrate the problem I am having with array class literals 
and also with testing for null on primitive arrays (see seperate post to this 
forum for null problems).


  | package examples.javassisttests.poolget;
  | 
  | import javassist.*;
  | import pec.compile.*;
  | import java.io.*;
  | import java.lang.reflect.*;
  | 
  | public class Test {
  | static class Y {}
  | static class X extends Y {}
  | public static void main( final String[] notUsed ) throws Exception {
  | // Test of assignment compatability
  | final X[] xs = new X[ 1 ];
  | final Y[] ys = xs;
  | ys[ 0 ] = new X(); // OK
  | // ys[ 0 ] = new Y(); // ArrayStoreException
  | final ClassPool pool = ClassPool.getDefault();
  | final CtClass intClass = pool.get( "int" );
  | final CtClass longClass = pool.get( "long" );
  | System.out.println( "Class: " + long.class.isAssignableFrom( 
int.class ) );
  | System.out.println( "CtClass: " + longClass.subtypeOf( intClass ) );
  | 
  | // get classes
  | System.out.println( "int = " +  intClass );
  | final CtClass intArrayClass = pool.get( "int[]" );
  | System.out.println( "int[] = " +  intArrayClass );
  | final CtClass objectArrayClass = pool.get( "java.lang.Object[]" );
  | System.out.println( "Object[] = " +  objectArrayClass );
  | 
  | // class definition (AbstractTest)
  | final CtClass clazz = pool.makeClass( 
"examples.javassisttests.poolget.AbstractTest" );
  | clazz.setModifiers( javassist.Modifier.ABSTRACT );
  | clazz.setModifiers( javassist.Modifier.PUBLIC );
  | 
  | // protected constructor definition
  | final CtConstructor constructor = 
CtNewConstructor.defaultConstructor( 
  |   clazz );
  | constructor.setModifiers( javassist.Modifier.PROTECTED );
  | clazz.addConstructor( constructor );
  | 
  | // abstract method definition
  | final CtClass[] arguments = new CtClass[] { intClass, 
intArrayClass, objectArrayClass };
  | final CtMethod method = CtNewMethod.abstractMethod( 
  | intClass, 
  | "f", 
  | arguments, 
  | null, 
  | clazz );
  | clazz.addMethod( method );
  | 
  | // write the abstract class
  | clazz.writeFile( "C:\\Personal\\Java" );
  | 
  | // print the abstract class
  | final Class classOfClazz = Class.forName( 
"examples.javassisttests.poolget.AbstractTest" );
  | System.out.println();
  | Utilities.printSignature( classOfClazz, null );
  | 
  | // class definition (DerivedTest)
  | final CtClass derivedClass = pool.makeClass( 
  |  
"examples.javassisttests.poolget.DerivedTest", clazz );
  | derivedClass.setModifiers( javassist.Modifier.PUBLIC );
  | 
  | // public constructor definition
  | final CtConstructor derivedConstructor = 
CtNewConstructor.defaultConstructor( 
  |   derivedClass );
  | derivedClass.addConstructor( derivedConstructor );
  | 
  | // method definition
  | final CtMethod derivedMethod = CtNewMethod.make( 
  | intClass, 
  | "f", 
  | arguments, 
  | null, 
  | /*"{\n" +
  | "if ( $2 != null )\n" +
  | "return $2.length;\n" +
  | "if ( $3 instanceof 
Object[].class )\n" +
  | "return $3.length;\n" +
  | "return $1;\n" +
  | "}",*/
  | "{\n" +
  | "if ( System.identityHashCode( 
$2 ) != 0 )\n" +
  | "return $2.length;\n" +
  | "Class array = 
java.lang.reflect.Array.newInstance( Object.class, 0 ).getClass();\n" +
  | "if ( array.isInstance( $3 ) 
)\n" +
  | "return $3.length;\n" +
  | "return 

[JBoss-user] [Javassist user questions] - Re: Array Class Literals

2005-03-16 Thread chiba
Really?
Can you post a complete test case?
Thanks!


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3870411#3870411

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3870411


---
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user


[JBoss-user] [Javassist user questions] - Re: Array Class Literals

2005-03-13 Thread hlovatt
3 couldn't when I tried the above example.

Howard.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3869965#3869965

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3869965


---
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user


[JBoss-user] [Javassist user questions] - Re: Array Class Literals

2005-03-01 Thread chiba
Let me make sure.
Javassist 3 can compile Object[].class.

Chiba


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3868436#3868436

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3868436


---
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user


[JBoss-user] [Javassist user questions] - Re: Array Class Literals

2005-02-27 Thread hlovatt
Ignore - I forgot to watch the topic :)

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3868135#3868135

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3868135


---
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
___
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user