[Kde-java] QtJava api via Dynamic Proxies progress - part 1
Eric Blake
ebb9 at byu.net
Tue Aug 26 07:31:15 CEST 2003
I haven't had a good chance to look at this lately, but your change to compute
the class name in Proxy as a String is probably ok. However, I am almost
positive that inner classes will need more work - we are not setting the
InnerClasses attribute as required when one (or more) of the superinterfaces
of the Proxy is an inner class.
Tom Tromey wrote:
>>>>>>"Tom" == Tom Tromey <tromey at redhat.com> writes:
>
>
> Tom> The simplest fix may be to change Proxy to compute the package name
> Tom> itself, from the class name, rather than to go through the Package.
> Tom> This won't fix the appended, but there's no guarantee that
> Tom> getPackage() will return a non-null result.
>
> I looked into this some more. Fixing libgcj to set the Package on a
> compiled class is pretty complicated, as it gets into problems with
> the ordering of class initialization at startup.
>
> So I gave up on that approach and put a note in bugzilla.
>
> I wrote the appended, but I'm not really certain it is correct.
> Perhaps we really do need to use the Package and not just the
> package's name.
>
> I've CCd Eric Blake, who wrote Proxy, and can hopefully advise.
>
> Tom
>
> Index: ChangeLog
> from Tom Tromey <tromey at redhat.com>
>
> * java/lang/reflect/Proxy.java (ProxyData): `pack' now a String.
> (ProxyData.getPackage): New method.
> (ProxyData.getProxyData): Use package name, not Package.
> (ClassFactory.ClassFactory): Updated.
>
> Index: java/lang/reflect/Proxy.java
> ===================================================================
> RCS file: /cvs/gcc/gcc/libjava/java/lang/reflect/Proxy.java,v
> retrieving revision 1.3
> diff -u -r1.3 Proxy.java
> --- java/lang/reflect/Proxy.java 29 Mar 2003 01:34:23 -0000 1.3
> +++ java/lang/reflect/Proxy.java 21 Aug 2003 18:33:35 -0000
> @@ -1,5 +1,5 @@
> /* Proxy.java -- build a proxy class that implements reflected interfaces
> - Copyright (C) 2001, 2002 Free Software Foundation, Inc.
> + Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
>
> This file is part of GNU Classpath.
>
> @@ -733,7 +733,7 @@
> * The package this class is in. Possibly null, meaning the unnamed
> * package.
> */
> - Package pack;
> + String pack;
>
> /**
> * The interfaces this class implements. Non-null, but possibly empty.
> @@ -777,6 +777,21 @@
> }
>
> /**
> + * Return the name of a package given the name of a class.
> + * Returns null if no package. We use this in preference to
> + * using Class.getPackage() to avoid problems with ClassLoaders
> + * that don't set the package.
> + */
> + static String getPackage(Class k)
> + {
> + String name = k.getName();
> + int idx = name.lastIndexOf('.');
> + if (idx >= 0)
> + return name.substring(0, idx);
> + return null;
> + }
> +
> + /**
> * Verifies that the arguments are legal, and sets up remaining data
> * This should only be called when a class must be generated, as
> * it is expensive.
> @@ -818,8 +833,8 @@
> if (! Modifier.isPublic(inter.getModifiers()))
> if (in_package)
> {
> - Package p = inter.getPackage();
> - if (data.pack != inter.getPackage())
> + String p = getPackage(inter);
> + if (! data.pack.equals(p))
> throw new IllegalArgumentException("non-public interfaces "
> + "from different "
> + "packages");
> @@ -827,7 +842,7 @@
> else
> {
> in_package = true;
> - data.pack = inter.getPackage();
> + data.pack = getPackage(inter);
> }
> for (int j = i-1; j >= 0; j--)
> if (data.interfaces[j] == inter)
> @@ -954,7 +969,7 @@
> // access_flags
> putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC);
> // this_class
> - qualName = ((data.pack == null ? "" : data.pack.getName() + '.')
> + qualName = ((data.pack == null ? "" : data.pack + '.')
> + "$Proxy" + data.id);
> putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false)));
> // super_class
>
--
Someday, I might put a cute statement here.
Eric Blake ebb9 at byu.net
More information about the Kde-java
mailing list