Class.h (Class::desiredAssertionStatus): Declare.

* java/lang/Class.h (Class::desiredAssertionStatus): Declare.
	(Class::getPackagePortion): Likewise.
	* java/lang/Class.java (desiredAssertionStatus): New method from
	Classpath.
	(getPackagePortion): Likewise.
	* java/lang/VMClassLoader.java (defaultAssertionStatus,
	packageAssertionStatus, classAssertionStatus): New methods from
	Classpath.
	* java/lang/ClassLoader.java (defaultAssertionStatus,
	systemPackageAssertionStatus, packageAssertionStatus,
	systemClassAssertionStatus, classAssertionStatus): New fields from
	Classpath.
	(setDefaultAssertionStatus, setPackageAssertionStatus,
	setClassAssertionStatus, clearAssertionStatus): New methods from
	Classpath.
	* Makefile.in: Rebuilt.
	* Makefile.am (core_java_source_files): Added AssertionError.java.
	* java/lang/AssertionError.java: New from Classpath.

From-SVN: r54517
This commit is contained in:
Tom Tromey 2002-06-11 17:33:22 +00:00 committed by Tom Tromey
parent c6226a7e2a
commit 419831367f
10 changed files with 428 additions and 12 deletions

View file

@ -1,6 +1,6 @@
// Class.java - Representation of a Java class.
/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
/* Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation
This file is part of libgcj.
@ -217,6 +217,75 @@ public final class Class implements Serializable
return (isInterface () ? "interface " : "class ") + getName ();
}
/**
* Returns the desired assertion status of this class, if it were to be
* initialized at this moment. The class assertion status, if set, is
* returned; the backup is the default package status; then if there is
* a class loader, that default is returned; and finally the system default
* is returned. This method seldom needs calling in user code, but exists
* for compilers to implement the assert statement. Note that there is no
* guarantee that the result of this method matches the class's actual
* assertion status.
*
* @return the desired assertion status
* @see ClassLoader#setClassAssertionStatus(String, boolean)
* @see ClassLoader#setPackageAssertionStatus(String, boolean)
* @see ClassLoader#setDefaultAssertionStatus(boolean)
* @since 1.4
*/
public boolean desiredAssertionStatus()
{
ClassLoader c = getClassLoader();
Object status;
if (c == null)
return VMClassLoader.defaultAssertionStatus();
if (c.classAssertionStatus != null)
synchronized (c)
{
status = c.classAssertionStatus.get(getName());
if (status != null)
return status.equals(Boolean.TRUE);
}
else
{
status = ClassLoader.systemClassAssertionStatus.get(getName());
if (status != null)
return status.equals(Boolean.TRUE);
}
if (c.packageAssertionStatus != null)
synchronized (c)
{
String name = getPackagePortion(getName());
if ("".equals(name))
status = c.packageAssertionStatus.get(null);
else
do
{
status = c.packageAssertionStatus.get(name);
name = getPackagePortion(name);
}
while (! "".equals(name) && status == null);
if (status != null)
return status.equals(Boolean.TRUE);
}
else
{
String name = getPackagePortion(getName());
if ("".equals(name))
status = ClassLoader.systemPackageAssertionStatus.get(null);
else
do
{
status = ClassLoader.systemPackageAssertionStatus.get(name);
name = getPackagePortion(name);
}
while (! "".equals(name) && status == null);
if (status != null)
return status.equals(Boolean.TRUE);
}
return c.defaultAssertionStatus;
}
// Don't allow new classes to be made.
private Class ()
{
@ -235,4 +304,18 @@ public final class Class implements Serializable
// finalization
protected native void finalize ();
/**
* Strip the last portion of the name (after the last dot).
*
* @param name the name to get package of
* @return the package name, or "" if no package
*/
private static String getPackagePortion(String name)
{
int lastInd = name.lastIndexOf('.');
if (lastInd == -1)
return "";
return name.substring(0, lastInd);
}
}