163 SharedSecrets.getJavaLangAccess(). 164 getConstantPool(getDeclaringRecord()), 165 this, 166 getDeclaringRecord(), 167 getGenericType(), 168 TypeAnnotation.TypeAnnotationTarget.FIELD); 169 } 170 171 /** 172 * Returns a {@code Method} that represents the accessor for this record 173 * component. 174 * 175 * @return a {@code Method} that represents the accessor for this record 176 * component 177 */ 178 public Method getAccessor() { 179 return accessor; 180 } 181 182 /** 183 * @throws NullPointerException {@inheritDoc} 184 */ 185 @Override 186 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 187 Objects.requireNonNull(annotationClass); 188 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 189 } 190 191 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 192 193 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 194 Map<Class<? extends Annotation>, Annotation> declAnnos; 195 if ((declAnnos = declaredAnnotations) == null) { 196 synchronized (this) { 197 if ((declAnnos = declaredAnnotations) == null) { 198 @SuppressWarnings("preview") 199 RecordComponent root = this.root; 200 if (root != null) { 201 declAnnos = root.declaredAnnotations(); 202 } else { 203 declAnnos = AnnotationParser.parseAnnotations( 204 annotations, 205 SharedSecrets.getJavaLangAccess() 206 .getConstantPool(getDeclaringRecord()), 207 getDeclaringRecord()); 208 } 209 declaredAnnotations = declAnnos; 210 } 211 } 212 } 213 return declAnnos; 214 } 215 216 /** 217 * {@inheritDoc} 218 */ 219 @Override 220 public Annotation[] getAnnotations() { 221 return getDeclaredAnnotations(); 222 } 223 224 /** 225 * {@inheritDoc} 226 */ 227 @Override 228 public Annotation[] getDeclaredAnnotations() { return AnnotationParser.toArray(declaredAnnotations()); } 229 230 /** 231 * Returns a string describing this record component. The format is 232 * the record component type, followed by a space, followed by the name 233 * of the record component. 234 * For example: 235 * <pre> 236 * java.lang.String name 237 * int age 238 * </pre> 239 * 240 * @return a string describing this record component 241 */ 242 public String toString() { 243 return (getType().getTypeName() + " " + getName()); 244 } 245 | 163 SharedSecrets.getJavaLangAccess(). 164 getConstantPool(getDeclaringRecord()), 165 this, 166 getDeclaringRecord(), 167 getGenericType(), 168 TypeAnnotation.TypeAnnotationTarget.FIELD); 169 } 170 171 /** 172 * Returns a {@code Method} that represents the accessor for this record 173 * component. 174 * 175 * @return a {@code Method} that represents the accessor for this record 176 * component 177 */ 178 public Method getAccessor() { 179 return accessor; 180 } 181 182 /** 183 * {@inheritDoc} 184 * <p>Note that any annotation returned by this method is a 185 * declaration annotation. 186 * @throws NullPointerException {@inheritDoc} 187 */ 188 @Override 189 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 190 Objects.requireNonNull(annotationClass); 191 return annotationClass.cast(declaredAnnotations().get(annotationClass)); 192 } 193 194 private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations; 195 196 private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() { 197 Map<Class<? extends Annotation>, Annotation> declAnnos; 198 if ((declAnnos = declaredAnnotations) == null) { 199 synchronized (this) { 200 if ((declAnnos = declaredAnnotations) == null) { 201 @SuppressWarnings("preview") 202 RecordComponent root = this.root; 203 if (root != null) { 204 declAnnos = root.declaredAnnotations(); 205 } else { 206 declAnnos = AnnotationParser.parseAnnotations( 207 annotations, 208 SharedSecrets.getJavaLangAccess() 209 .getConstantPool(getDeclaringRecord()), 210 getDeclaringRecord()); 211 } 212 declaredAnnotations = declAnnos; 213 } 214 } 215 } 216 return declAnnos; 217 } 218 219 /** 220 * {@inheritDoc} 221 * <p>Note that any annotations returned by this method are 222 * declaration annotations. 223 */ 224 @Override 225 public Annotation[] getAnnotations() { 226 return getDeclaredAnnotations(); 227 } 228 229 /** 230 * {@inheritDoc} 231 * <p>Note that any annotations returned by this method are 232 * declaration annotations. 233 */ 234 @Override 235 public Annotation[] getDeclaredAnnotations() { return AnnotationParser.toArray(declaredAnnotations()); } 236 237 /** 238 * Returns a string describing this record component. The format is 239 * the record component type, followed by a space, followed by the name 240 * of the record component. 241 * For example: 242 * <pre> 243 * java.lang.String name 244 * int age 245 * </pre> 246 * 247 * @return a string describing this record component 248 */ 249 public String toString() { 250 return (getType().getTypeName() + " " + getName()); 251 } 252 |