< prev index next >

src/java.base/share/classes/java/lang/reflect/Constructor.java

Print this page

108     private Constructor<T>      root;
109 
110     @Override
111     Constructor<T> getRoot() {
112         return root;
113     }
114 
115     /**
116      * Package-private constructor used by ReflectAccess to enable
117      * instantiation of these objects in Java code from the java.lang
118      * package via jdk.internal.access.JavaLangReflectAccess.
119      */
120     Constructor(Class<T> declaringClass,
121                 Class<?>[] parameterTypes,
122                 Class<?>[] checkedExceptions,
123                 int modifiers,
124                 int slot,
125                 String signature,
126                 byte[] annotations,
127                 byte[] parameterAnnotations) {

128         this.clazz = declaringClass;
129         this.parameterTypes = parameterTypes;
130         this.exceptionTypes = checkedExceptions;
131         this.modifiers = modifiers;
132         this.slot = slot;
133         this.signature = signature;
134         this.annotations = annotations;
135         this.parameterAnnotations = parameterAnnotations;
136     }
137 
138     /**
139      * Package-private routine (exposed to java.lang.Class via
140      * ReflectAccess) which returns a copy of this Constructor. The copy's
141      * "root" field points to this Constructor.
142      */
143     Constructor<T> copy() {
144         // This routine enables sharing of ConstructorAccessor objects
145         // among Constructor objects which refer to the same underlying
146         // method in the VM. (All of this contortion is only necessary
147         // because of the "accessibility" bit in AccessibleObject,

346      * thrown exception types.
347      *
348      * <p>The only possible modifiers for constructors are the access
349      * modifiers {@code public}, {@code protected} or
350      * {@code private}.  Only one of these may appear, or none if the
351      * constructor has default (package) access.
352      *
353      * @return a string describing this {@code Constructor}
354      * @jls 8.8.3 Constructor Modifiers
355      * @jls 8.9.2 Enum Body Declarations
356      */
357     public String toString() {
358         return sharedToString(Modifier.constructorModifiers(),
359                               false,
360                               parameterTypes,
361                               exceptionTypes);
362     }
363 
364     @Override
365     void specificToStringHeader(StringBuilder sb) {
366         sb.append(getDeclaringClass().getTypeName());
367     }
368 
369     @Override
370     String toShortString() {
371         StringBuilder sb = new StringBuilder("constructor ");
372         sb.append(getDeclaringClass().getTypeName());
373         sb.append('(');
374         StringJoiner sj = new StringJoiner(",");
375         for (Class<?> parameterType : getParameterTypes()) {
376             sj.add(parameterType.getTypeName());
377         }
378         sb.append(sj);
379         sb.append(')');
380         return sb.toString();
381     }
382 
383     /**
384      * Returns a string describing this {@code Constructor},
385      * including type parameters.  The string is formatted as the
386      * constructor access modifiers, if any, followed by an
387      * angle-bracketed comma separated list of the constructor's type
388      * parameters, if any, including  informative bounds of the
389      * type parameters, if any, followed by the fully-qualified name of the
390      * declaring class, followed by a parenthesized, comma-separated
391      * list of the constructor's generic formal parameter types.
392      *

108     private Constructor<T>      root;
109 
110     @Override
111     Constructor<T> getRoot() {
112         return root;
113     }
114 
115     /**
116      * Package-private constructor used by ReflectAccess to enable
117      * instantiation of these objects in Java code from the java.lang
118      * package via jdk.internal.access.JavaLangReflectAccess.
119      */
120     Constructor(Class<T> declaringClass,
121                 Class<?>[] parameterTypes,
122                 Class<?>[] checkedExceptions,
123                 int modifiers,
124                 int slot,
125                 String signature,
126                 byte[] annotations,
127                 byte[] parameterAnnotations) {
128         assert declaringClass.isPrimaryType();
129         this.clazz = declaringClass;
130         this.parameterTypes = parameterTypes;
131         this.exceptionTypes = checkedExceptions;
132         this.modifiers = modifiers;
133         this.slot = slot;
134         this.signature = signature;
135         this.annotations = annotations;
136         this.parameterAnnotations = parameterAnnotations;
137     }
138 
139     /**
140      * Package-private routine (exposed to java.lang.Class via
141      * ReflectAccess) which returns a copy of this Constructor. The copy's
142      * "root" field points to this Constructor.
143      */
144     Constructor<T> copy() {
145         // This routine enables sharing of ConstructorAccessor objects
146         // among Constructor objects which refer to the same underlying
147         // method in the VM. (All of this contortion is only necessary
148         // because of the "accessibility" bit in AccessibleObject,

347      * thrown exception types.
348      *
349      * <p>The only possible modifiers for constructors are the access
350      * modifiers {@code public}, {@code protected} or
351      * {@code private}.  Only one of these may appear, or none if the
352      * constructor has default (package) access.
353      *
354      * @return a string describing this {@code Constructor}
355      * @jls 8.8.3 Constructor Modifiers
356      * @jls 8.9.2 Enum Body Declarations
357      */
358     public String toString() {
359         return sharedToString(Modifier.constructorModifiers(),
360                               false,
361                               parameterTypes,
362                               exceptionTypes);
363     }
364 
365     @Override
366     void specificToStringHeader(StringBuilder sb) {
367         sb.append(getDeclaringClassTypeName());
368     }
369 
370     @Override
371     String toShortString() {
372         StringBuilder sb = new StringBuilder("constructor ");
373         sb.append(getDeclaringClassTypeName());
374         sb.append('(');
375         StringJoiner sj = new StringJoiner(",");
376         for (Class<?> parameterType : getParameterTypes()) {
377             sj.add(parameterType.getTypeName());
378         }
379         sb.append(sj);
380         sb.append(')');
381         return sb.toString();
382     }
383 
384     /**
385      * Returns a string describing this {@code Constructor},
386      * including type parameters.  The string is formatted as the
387      * constructor access modifiers, if any, followed by an
388      * angle-bracketed comma separated list of the constructor's type
389      * parameters, if any, including  informative bounds of the
390      * type parameters, if any, followed by the fully-qualified name of the
391      * declaring class, followed by a parenthesized, comma-separated
392      * list of the constructor's generic formal parameter types.
393      *
< prev index next >