summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/lang/Package.java
diff options
context:
space:
mode:
authormark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
committermark <mark@138bc75d-0d04-0410-961f-82ee72b054a4>2006-05-18 17:29:21 +0000
commit64089cc9f030d8ef7972adb5d117e0b23f47d62b (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/java/lang/Package.java
parent96034e28360d660d7a7708807fcbc4b519574d8e (diff)
downloadgcc-64089cc9f030d8ef7972adb5d117e0b23f47d62b.tar.gz
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java/lang/Package.java')
-rw-r--r--libjava/classpath/java/lang/Package.java106
1 files changed, 102 insertions, 4 deletions
diff --git a/libjava/classpath/java/lang/Package.java b/libjava/classpath/java/lang/Package.java
index 4cded0af304..38bb3240de4 100644
--- a/libjava/classpath/java/lang/Package.java
+++ b/libjava/classpath/java/lang/Package.java
@@ -1,5 +1,6 @@
/* Package.java -- information about a package
- Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006
+ Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,6 +40,8 @@ package java.lang;
import gnu.classpath.VMStackWalker;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
@@ -70,9 +73,10 @@ import java.util.StringTokenizer;
* @see ClassLoader#definePackage(String, String, String, String, String,
* String, String, URL)
* @since 1.2
- * @status updated to 1.4
+ * @status updated to 1.5
*/
public class Package
+ implements AnnotatedElement
{
/** The name of the Package */
private final String name;
@@ -98,6 +102,20 @@ public class Package
/** If sealed the origin of the package classes, otherwise null */
private final URL sealed;
+ /** The class loader that defined this package */
+ private ClassLoader loader;
+
+ /** @deprecated Please use the other constructor that takes the class loader
+ * that defines the Package.
+ */
+ Package(String name,
+ String specTitle, String specVendor, String specVersion,
+ String implTitle, String implVendor, String implVersion, URL sealed)
+ {
+ this(name, specTitle, specVendor, specVersion, implTitle, implVendor,
+ implVersion, sealed, null);
+ }
+
/**
* A package local constructor for the Package class. All parameters except
* the <code>name</code> of the package may be <code>null</code>.
@@ -115,7 +133,8 @@ public class Package
*/
Package(String name,
String specTitle, String specVendor, String specVersion,
- String implTitle, String implVendor, String implVersion, URL sealed)
+ String implTitle, String implVendor, String implVersion, URL sealed,
+ ClassLoader loader)
{
if (name == null)
throw new IllegalArgumentException("null Package name");
@@ -128,6 +147,7 @@ public class Package
this.specVendor = specVendor;
this.specVersion = specVersion;
this.sealed = sealed;
+ this.loader = loader;
}
/**
@@ -233,7 +253,7 @@ public class Package
*
* @return true if the version is compatible, false otherwise
*
- * @Throws NumberFormatException if either version string is invalid
+ * @throws NumberFormatException if either version string is invalid
* @throws NullPointerException if either version string is null
*/
public boolean isCompatibleWith(String version)
@@ -315,4 +335,82 @@ public class Package
return ("package " + name + (specTitle == null ? "" : ", " + specTitle)
+ (specVersion == null ? "" : ", version " + specVersion));
}
+
+ /**
+ * Returns this package's annotation for the specified annotation type,
+ * or <code>null</code> if no such annotation exists.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return this package's annotation for the specified type, or
+ * <code>null</code> if no such annotation exists.
+ * @since 1.5
+ */
+ /* FIXME[GENERICS]: <T extends Annotation> T getAnnotation(Class <T>) */
+ public Annotation getAnnotation(Class annotationClass)
+ {
+ Annotation foundAnnotation = null;
+ Annotation[] annotations = getAnnotations();
+ for (int i = 0; i < annotations.length; i++)
+ if (annotations[i].annotationType() == annotationClass)
+ foundAnnotation = annotations[i];
+ return foundAnnotation;
+ }
+
+ /**
+ * Returns all annotations associated with this package. If there are
+ * no annotations associated with this package, then a zero-length array
+ * will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * package, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return this package' annotations.
+ * @since 1.5
+ */
+ public Annotation[] getAnnotations()
+ {
+ /** All a package's annotations are declared within it. */
+ return getDeclaredAnnotations();
+ }
+
+ /**
+ * Returns all annotations directly defined by this package. If there are
+ * no annotations associated with this package, then a zero-length array
+ * will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * package, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @return the annotations directly defined by this package.
+ * @since 1.5
+ */
+ public Annotation[] getDeclaredAnnotations()
+ {
+ try
+ {
+ Class pkgInfo = Class.forName(name + ".package-info", false, loader);
+ return pkgInfo.getDeclaredAnnotations();
+ }
+ catch (ClassNotFoundException _)
+ {
+ return new Annotation[0];
+ }
+ }
+
+ /**
+ * Returns true if an annotation for the specified type is associated
+ * with this package. This is primarily a short-hand for using marker
+ * annotations.
+ *
+ * @param annotationClass the type of annotation to look for.
+ * @return true if an annotation exists for the specified type.
+ * @since 1.5
+ */
+ /* FIXME[GENERICS]: Signature is Class<? extends Annotation> */
+ public boolean isAnnotationPresent(Class
+ annotationClass)
+ {
+ return getAnnotation(annotationClass) != null;
+ }
+
} // class Package