1 /*
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
366
367 private Class<?> getPackageInfo() {
368 if (packageInfo == null) {
369 try {
370 packageInfo = Class.forName(pkgName + ".package-info", false, loader);
371 } catch (ClassNotFoundException ex) {
372 // store a proxy for the package info that has no annotations
373 class PackageInfoProxy {}
374 packageInfo = PackageInfoProxy.class;
375 }
376 }
377 return packageInfo;
378 }
379
380 /**
381 * @throws NullPointerException {@inheritDoc}
382 * @since 1.5
383 */
384 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
385 return getPackageInfo().getAnnotation(annotationClass);
386 }
387
388 /**
389 * @throws NullPointerException {@inheritDoc}
390 * @since 1.5
391 */
392 public boolean isAnnotationPresent(
393 Class<? extends Annotation> annotationClass) {
394 return getPackageInfo().isAnnotationPresent(annotationClass);
395 }
396
397 /**
398 * @throws NullPointerException {@inheritDoc}
399 * @since 1.8
400 */
401 public <A extends Annotation> A[] getAnnotations(Class<A> annotationClass) {
402 return getPackageInfo().getAnnotations(annotationClass);
403 }
404
405 /**
406 * @since 1.5
407 */
408 public Annotation[] getAnnotations() {
409 return getPackageInfo().getAnnotations();
410 }
411
412 /**
413 * @throws NullPointerException {@inheritDoc}
414 * @since 1.8
|
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
366
367 private Class<?> getPackageInfo() {
368 if (packageInfo == null) {
369 try {
370 packageInfo = Class.forName(pkgName + ".package-info", false, loader);
371 } catch (ClassNotFoundException ex) {
372 // store a proxy for the package info that has no annotations
373 class PackageInfoProxy {}
374 packageInfo = PackageInfoProxy.class;
375 }
376 }
377 return packageInfo;
378 }
379
380 /**
381 * @throws NullPointerException {@inheritDoc}
382 * @since 1.5
383 */
384 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
385 return getPackageInfo().getAnnotation(annotationClass);
386 }
387
388 /**
389 * @throws NullPointerException {@inheritDoc}
390 * @since 1.8
391 */
392 public <A extends Annotation> A[] getAnnotations(Class<A> annotationClass) {
393 return getPackageInfo().getAnnotations(annotationClass);
394 }
395
396 /**
397 * @since 1.5
398 */
399 public Annotation[] getAnnotations() {
400 return getPackageInfo().getAnnotations();
401 }
402
403 /**
404 * @throws NullPointerException {@inheritDoc}
405 * @since 1.8
|