emul/mini/src/main/java/java/lang/reflect/Constructor.java
branchemul
changeset 604 3fcc279c921b
parent 601 5198affdb915
     1.1 --- a/emul/mini/src/main/java/java/lang/reflect/Constructor.java	Mon Jan 28 18:12:47 2013 +0100
     1.2 +++ b/emul/mini/src/main/java/java/lang/reflect/Constructor.java	Mon Jan 28 18:15:21 2013 +0100
     1.3 @@ -25,17 +25,8 @@
     1.4  
     1.5  package java.lang.reflect;
     1.6  
     1.7 -import sun.reflect.ConstructorAccessor;
     1.8 -import sun.reflect.Reflection;
     1.9 -import sun.reflect.generics.repository.ConstructorRepository;
    1.10 -import sun.reflect.generics.factory.CoreReflectionFactory;
    1.11 -import sun.reflect.generics.factory.GenericsFactory;
    1.12 -import sun.reflect.generics.scope.ConstructorScope;
    1.13  import java.lang.annotation.Annotation;
    1.14 -import java.util.Map;
    1.15 -import sun.reflect.annotation.AnnotationParser;
    1.16 -import java.lang.annotation.AnnotationFormatError;
    1.17 -import java.lang.reflect.Modifier;
    1.18 +import org.apidesign.bck2brwsr.emul.reflect.TypeProvider;
    1.19  
    1.20  /**
    1.21   * {@code Constructor} provides information about, and access to, a single
    1.22 @@ -69,31 +60,10 @@
    1.23      private int                 modifiers;
    1.24      // Generics and annotations support
    1.25      private transient String    signature;
    1.26 -    // generic info repository; lazily initialized
    1.27 -    private transient ConstructorRepository genericInfo;
    1.28      private byte[]              annotations;
    1.29      private byte[]              parameterAnnotations;
    1.30  
    1.31 -    // Generics infrastructure
    1.32 -    // Accessor for factory
    1.33 -    private GenericsFactory getFactory() {
    1.34 -        // create scope and factory
    1.35 -        return CoreReflectionFactory.make(this, ConstructorScope.make(this));
    1.36 -    }
    1.37  
    1.38 -    // Accessor for generic info repository
    1.39 -    private ConstructorRepository getGenericInfo() {
    1.40 -        // lazily initialize repository if necessary
    1.41 -        if (genericInfo == null) {
    1.42 -            // create and cache generic info repository
    1.43 -            genericInfo =
    1.44 -                ConstructorRepository.make(getSignature(),
    1.45 -                                           getFactory());
    1.46 -        }
    1.47 -        return genericInfo; //return cached repository
    1.48 -    }
    1.49 -
    1.50 -    private volatile ConstructorAccessor constructorAccessor;
    1.51      // For sharing of ConstructorAccessors. This branching structure
    1.52      // is currently only two levels deep (i.e., one root Constructor
    1.53      // and potentially many Constructor objects pointing to it.)
    1.54 @@ -129,23 +99,7 @@
    1.55       * "root" field points to this Constructor.
    1.56       */
    1.57      Constructor<T> copy() {
    1.58 -        // This routine enables sharing of ConstructorAccessor objects
    1.59 -        // among Constructor objects which refer to the same underlying
    1.60 -        // method in the VM. (All of this contortion is only necessary
    1.61 -        // because of the "accessibility" bit in AccessibleObject,
    1.62 -        // which implicitly requires that new java.lang.reflect
    1.63 -        // objects be fabricated for each reflective call on Class
    1.64 -        // objects.)
    1.65 -        Constructor<T> res = new Constructor<>(clazz,
    1.66 -                                                parameterTypes,
    1.67 -                                                exceptionTypes, modifiers, slot,
    1.68 -                                                signature,
    1.69 -                                                annotations,
    1.70 -                                                parameterAnnotations);
    1.71 -        res.root = this;
    1.72 -        // Might as well eagerly propagate this if already present
    1.73 -        res.constructorAccessor = constructorAccessor;
    1.74 -        return res;
    1.75 +        return this;
    1.76      }
    1.77  
    1.78      /**
    1.79 @@ -191,10 +145,7 @@
    1.80       * @since 1.5
    1.81       */
    1.82      public TypeVariable<Constructor<T>>[] getTypeParameters() {
    1.83 -      if (getSignature() != null) {
    1.84 -        return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
    1.85 -      } else
    1.86 -          return (TypeVariable<Constructor<T>>[])new TypeVariable[0];
    1.87 +        return TypeProvider.getDefault().getTypeParameters(this);
    1.88      }
    1.89  
    1.90  
    1.91 @@ -240,10 +191,7 @@
    1.92       * @since 1.5
    1.93       */
    1.94      public Type[] getGenericParameterTypes() {
    1.95 -        if (getSignature() != null)
    1.96 -            return getGenericInfo().getParameterTypes();
    1.97 -        else
    1.98 -            return getParameterTypes();
    1.99 +        return TypeProvider.getDefault().getGenericParameterTypes(this);
   1.100      }
   1.101  
   1.102  
   1.103 @@ -284,12 +232,7 @@
   1.104       * @since 1.5
   1.105       */
   1.106        public Type[] getGenericExceptionTypes() {
   1.107 -          Type[] result;
   1.108 -          if (getSignature() != null &&
   1.109 -              ( (result = getGenericInfo().getExceptionTypes()).length > 0  ))
   1.110 -              return result;
   1.111 -          else
   1.112 -              return getExceptionTypes();
   1.113 +          return TypeProvider.getDefault().getGenericExceptionTypes(this);
   1.114        }
   1.115  
   1.116      /**
   1.117 @@ -509,20 +452,7 @@
   1.118          throws InstantiationException, IllegalAccessException,
   1.119                 IllegalArgumentException, InvocationTargetException
   1.120      {
   1.121 -        if (!override) {
   1.122 -            if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
   1.123 -                Class<?> caller = Reflection.getCallerClass(2);
   1.124 -
   1.125 -                checkAccess(caller, clazz, null, modifiers);
   1.126 -            }
   1.127 -        }
   1.128 -        if ((clazz.getModifiers() & Modifier.ENUM) != 0)
   1.129 -            throw new IllegalArgumentException("Cannot reflectively create enum objects");
   1.130 -        ConstructorAccessor ca = constructorAccessor;   // read volatile
   1.131 -        if (ca == null) {
   1.132 -            ca = acquireConstructorAccessor();
   1.133 -        }
   1.134 -        return (T) ca.newInstance(initargs);
   1.135 +        throw new SecurityException();
   1.136      }
   1.137  
   1.138      /**
   1.139 @@ -551,43 +481,6 @@
   1.140          return Modifier.isSynthetic(getModifiers());
   1.141      }
   1.142  
   1.143 -    // NOTE that there is no synchronization used here. It is correct
   1.144 -    // (though not efficient) to generate more than one
   1.145 -    // ConstructorAccessor for a given Constructor. However, avoiding
   1.146 -    // synchronization will probably make the implementation more
   1.147 -    // scalable.
   1.148 -    private ConstructorAccessor acquireConstructorAccessor() {
   1.149 -        // First check to see if one has been created yet, and take it
   1.150 -        // if so.
   1.151 -        ConstructorAccessor tmp = null;
   1.152 -        if (root != null) tmp = root.getConstructorAccessor();
   1.153 -        if (tmp != null) {
   1.154 -            constructorAccessor = tmp;
   1.155 -        } else {
   1.156 -            // Otherwise fabricate one and propagate it up to the root
   1.157 -            tmp = reflectionFactory.newConstructorAccessor(this);
   1.158 -            setConstructorAccessor(tmp);
   1.159 -        }
   1.160 -
   1.161 -        return tmp;
   1.162 -    }
   1.163 -
   1.164 -    // Returns ConstructorAccessor for this Constructor object, not
   1.165 -    // looking up the chain to the root
   1.166 -    ConstructorAccessor getConstructorAccessor() {
   1.167 -        return constructorAccessor;
   1.168 -    }
   1.169 -
   1.170 -    // Sets the ConstructorAccessor for this Constructor object and
   1.171 -    // (recursively) its root
   1.172 -    void setConstructorAccessor(ConstructorAccessor accessor) {
   1.173 -        constructorAccessor = accessor;
   1.174 -        // Propagate up
   1.175 -        if (root != null) {
   1.176 -            root.setConstructorAccessor(accessor);
   1.177 -        }
   1.178 -    }
   1.179 -
   1.180      int getSlot() {
   1.181          return slot;
   1.182      }
   1.183 @@ -612,26 +505,14 @@
   1.184          if (annotationClass == null)
   1.185              throw new NullPointerException();
   1.186  
   1.187 -        return (T) declaredAnnotations().get(annotationClass);
   1.188 +        return null; // XXX (T) declaredAnnotations().get(annotationClass);
   1.189      }
   1.190  
   1.191      /**
   1.192       * @since 1.5
   1.193       */
   1.194      public Annotation[] getDeclaredAnnotations()  {
   1.195 -        return AnnotationParser.toArray(declaredAnnotations());
   1.196 -    }
   1.197 -
   1.198 -    private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
   1.199 -
   1.200 -    private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
   1.201 -        if (declaredAnnotations == null) {
   1.202 -            declaredAnnotations = AnnotationParser.parseAnnotations(
   1.203 -                annotations, sun.misc.SharedSecrets.getJavaLangAccess().
   1.204 -                getConstantPool(getDeclaringClass()),
   1.205 -                getDeclaringClass());
   1.206 -        }
   1.207 -        return declaredAnnotations;
   1.208 +        return new Annotation[0]; // XXX AnnotationParser.toArray(declaredAnnotations());
   1.209      }
   1.210  
   1.211      /**
   1.212 @@ -654,7 +535,9 @@
   1.213          int numParameters = parameterTypes.length;
   1.214          if (parameterAnnotations == null)
   1.215              return new Annotation[numParameters][0];
   1.216 -
   1.217 +        
   1.218 +        return new Annotation[numParameters][0]; // XXX
   1.219 +/*
   1.220          Annotation[][] result = AnnotationParser.parseParameterAnnotations(
   1.221              parameterAnnotations,
   1.222              sun.misc.SharedSecrets.getJavaLangAccess().
   1.223 @@ -679,5 +562,6 @@
   1.224              }
   1.225          }
   1.226          return result;
   1.227 +        */
   1.228      }
   1.229  }