eliad007 / as3-commons

Automatically exported from code.google.com/p/as3-commons
0 stars 0 forks source link

ByteCodeType.clazz null for private/helper class #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Using: as3commons-bytecode-0.9.7.swc,
       as3commons-reflect-1.3.4.swc

Is it expected that ByteCodeType.clazz will contain null for 
private/helper classes, as shown in the following example?  Or,
is this a bug?

The code below clearly already has access to the Helper class
directly when it calls ByteCodeType.forClass().  However, in my
real code, I have a generic function which takes an Object
instance and need to determine its class.  The  instance might
be an instance of an internal/private class.

-----------

// Test.as

package
{
    import org.as3commons.bytecode.reflect.ByteCodeType;

    import flash.display.Sprite;

    public class Test extends Sprite
    {
        public function Test()
        {
            ByteCodeType.fromLoader(loaderInfo);
            var t1:ByteCodeType = ByteCodeType.forClass(Test);
            var t2:ByteCodeType = ByteCodeType.forClass(Helper);
            trace(t1.clazz); // "[class Test]"
            trace(t2.clazz); // "null"  
        }
    }
}

class Helper { }

Original issue reported on code.google.com by idontneedthisacct@gmail.com on 1 Feb 2011 at 12:45

GoogleCodeExporter commented 9 years ago
hey there, no, the clazz property shouldn't be null, unless maybe if the Class 
is an internal one. I will need to experiment a bit.

As for the other issue you've added, I won't have time to get into this until 
next week, I'm sorry for this, but my dayjob is rather busy at the moment. I'll 
definitely follow-up though, bear with me :)

Original comment by rol...@stackandheap.com on 3 Feb 2011 at 12:26

GoogleCodeExporter commented 9 years ago
Thanks for your help.

So you say, "unless maybe if the Class is an internal one".  Well, that's the 
situation in my example code above, so that is probably the issue. :(  I know 
that the native flash.utils.getDefinitionByName() does not return internal 
classes.  I thought ByteCodeType might have some magic. :)

However, if you notice in my above example, it requests the internal class 
using ByteCodeType.forClass().  But, this *still* does not fill in the clazz of 
the returned ByteCodeType instance (even though the library has just been 
"given" a reference to that very Class).  Perhaps it should be filled in for 
this case?  Although it might be of marginal overall usefulness, it would allow 
client code to at least treat ByteCodeType instances for internal and external 
classes the same in cases similar to my example.

Original comment by idontneedthisacct@gmail.com on 3 Feb 2011 at 7:14

GoogleCodeExporter commented 9 years ago
I'm actually now checking to see if the clazz property is null in the 
ByteCodeType.forClass() method, if its null I assign the Class instance that 
was passed to the method as its value. This should solve your problem with 
ByteCodeType.forClass().

Original comment by ihatelivelyids on 26 Mar 2011 at 10:51