[JBoss-dev] Re: [jboss-cvs] jbossretro/src/main/org/jboss/lang ...

2006-03-15 Thread Adrian Brock
I think you can get the enclosing stuff from the attributes in the
constant pool. See the javassist EnclosingMethodAttribute which
also serves for classes when the index is 0

On Tue, 2006-03-14 at 22:56 -0500, Scott Stark wrote:
   User: starksm 
   Date: 06/03/14 22:56:35
 
   Modified:src/main/org/jboss/lang  ClassRedirects.java
   Log:
   Add missing jdk5 Class method redirects. Several todos still exist for 
 methods.
   
   Revision  ChangesPath
   1.4   +252 -19   jbossretro/src/main/org/jboss/lang/ClassRedirects.java
   
   (In the diff below, changes in quantity of whitespace are not shown.)
   
   Index: ClassRedirects.java
   ===
   RCS file: 
 /cvsroot/jboss/jbossretro/src/main/org/jboss/lang/ClassRedirects.java,v
   retrieving revision 1.3
   retrieving revision 1.4
   diff -u -b -r1.3 -r1.4
   --- ClassRedirects.java 15 Feb 2006 22:31:11 -  1.3
   +++ ClassRedirects.java 15 Mar 2006 03:56:35 -  1.4
   @@ -22,20 +22,29 @@
package org.jboss.lang;

import java.lang.reflect.Array;
   +import java.lang.reflect.TypeVariable;
   +import java.lang.reflect.Type;
   +import java.lang.reflect.Method;
   +import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
   - * ClassRedirects.
   + * Implementations of java.lang.Class methods added in jdk5
 * 
 * @author a href=[EMAIL PROTECTED]Adrian Brock/a
   - * @version $Revision: 1.3 $
   + * @author [EMAIL PROTECTED]
   + * @version $Revision: 1.4 $
 */
public class ClassRedirects
{
   /** The enum modifier */
   // private static final int ENUM = 0x4000;
   +   /**
   +* The synthetic modifier
   +*/
   +   private static final int SYNTHETIC = 0x1000;

   /**
* Whether the class is an enum
   @@ -50,9 +59,13 @@
  //   return false;
  Class superClass = clazz.getSuperclass();
  if (superClass == null)
   +  {
 return false;
   +  }
  if (Enum.class == clazz.getSuperclass())
   +  {
 return true;
   +  }
  return superClass.getName().equals(java.lang.Enum);
   }

   @@ -60,7 +73,6 @@
* Get the enumeration constants
* 
* @param T the enum type
   -* @param the array
* @param enumType the enum type
* @return the constants
*/
   @@ -82,11 +94,34 @@
   public static T T cast(ClassT clazz, Object o)
   {
  if (o != null  clazz.isInstance(o) == false)
   +  {
 throw new ClassCastException(Expected  + clazz.getName() +  
 got  + o.getClass().getName());
   +  }
  return (T) o;
   }
   
   /**
   +* @param clazz
   +* @param thisClazz
   +* @return thisClazz object, cast to represent a subclass of
   +* the specified class object.
   +* @throws ClassCastException if thisClazz object does not
   +*  represent a subclass of the specified class (here subclass 
 includes
   +*  the class itself).
   +*/
   +   public static T Class? extends T asSubclass(ClassT clazz, Class 
 thisClazz)
   +   {
   +  if (clazz.isAssignableFrom(thisClazz))
   +  {
   + return (Class? extends T) thisClazz;
   +  }
   +  else
   +  {
   + throw new ClassCastException(Expected  + clazz.getName() +  
 got  + thisClazz.getName());
   +  }
   +   }
   +
   +   /**
* Replace a character sequence
* 
* @param string the string
   @@ -125,16 +160,214 @@
  for (char c : string.toCharArray())
  {
 if (c == '\\')
   + {
builder.append();
   + }
 else if (c == '$')
   + {
builder.append(\\$);
   + }
 else
   + {
builder.append(c);
  }
   +  }
  return builder.toString();
   }
   
   /**
   +* Implementation of the jdk5 Class.getSimpleName() method.
   +* Returns the simple name of the underlying class as given in the
   +* source code. Returns an empty string if the underlying class is
   +* anonymous.
   +* p/
   +* pThe simple name of an array is the simple name of the
   +* component type with [] appended.  In particular the simple
   +* name of an array whose component type is anonymous is [].
   +*
   +* @param clazz the Class instance
   +* @return the simple name of the underlying class
   +*/
   +   public static String getSimpleName(Class clazz)
   +   {
   +  boolean isArray = clazz.isArray();
   +  if (isArray)
   +  {
   + String arrayName = getSimpleName(clazz.getComponentType())+[];
   + return arrayName;
   +  }
   +  // Remove the package name
   +  String name = 

[JBoss-dev] RE: [jboss-cvs] jbossretro/src/main/org/jboss/lang ...

2006-03-15 Thread Scott M Stark
Ok. 

 -Original Message-
 From: Adrian Brock 
 Sent: Wednesday, March 15, 2006 3:48 AM
 To: Scott M Stark
 Cc: jboss-development@lists.sourceforge.net
 Subject: Re: [jboss-cvs] jbossretro/src/main/org/jboss/lang ...
 
 I think you can get the enclosing stuff from the attributes 
 in the constant pool. See the javassist 
 EnclosingMethodAttribute which also serves for classes when 
 the index is 0
 


---
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnkkid0944bid$1720dat1642
___
JBoss-Development mailing list
JBoss-Development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-development