public final class Assert
extends java.lang.Object
The Assert
class provides basic assertion and tracing support
when the IDE is running in debug mode. In non-debug mode, calling the methods
of this class has no effect.
The check
and precondition
methods will
throw exceptions if checking is enabled. Checking is enabled
by default in debug mode. To disable checking, use
-J-Dide.AssertCheckingDisabled=trueas a command-line option when starting JDeveloper, or add
ADDVMOPTION -Dide.AssertCheckingDisabled=trueto
$HOME/.jdeveloper/<product-version>/product.confon Unix or
%APPDATA%\JDeveloper\<product-version>\product.confon Windows.
For command line programs based on the IDE code base that write to standard output and error, the voluminous output that passes through the trace methods makes it difficult to use and test these programs. Tracing output is enabled by default in debug mode. To disable tracing output, use
-J-Dide.AssertTracingDisabled=trueas a command-line option when starting JDeveloper, or add
ADDVMOPTION -Dide.AssertTracingDisabled=trueto
$HOME/.jdeveloper/<product-version>/product.confon Unix or
%APPDATA%\JDeveloper\<product-version>\product.confon Windows.
Modifier and Type | Method and Description |
---|---|
static void |
check(boolean condition)
This method only works in debug mode!
Check a condition within a method body.
|
static void |
check(boolean condition,
java.lang.String description)
This method only works in debug mode!
Check a condition within a method body.
|
static void |
checkAWTThread()
This method only works in debug mode!
Checks that the current thread is the AWT event dispatcher.
|
static void |
checkTracking(java.lang.String key,
java.lang.Object object)
This method only works in debug mode!
Call this method immediately after the potential object performed
the time consuming operation.
|
static void |
endTiming(java.lang.String key,
java.lang.String msg,
java.lang.String indent,
boolean quietStart)
This method only works in debug mode!
Ends timing of an event and prints the elapsed time between
the time stored with
startTiming() and
endTiming() using Assert. |
static void |
endTiming(java.lang.String key,
java.lang.String msg,
java.lang.String indent,
boolean quietStart,
boolean prefixThread)
This method only works in debug mode!
Ends timing of an event and prints the elapsed time between
the time stored with
startTiming() and
endTiming() using Assert. |
static void |
endTiming(java.lang.String key,
java.lang.String msg,
java.lang.String indent,
boolean quietStart,
boolean prefixThread,
long timeThreshold)
This method only works in debug mode!
Ends timing of an event and prints the elapsed time between
the time stored with
startTiming() and
endTiming() using Assert. |
static void |
endTiming(java.lang.String key,
java.lang.String msg,
java.lang.String indent,
boolean quietStart,
long timeThreshold)
This method only works in debug mode!
Ends timing of an event and prints the elapsed time between
the time stored with
startTiming() and
endTiming() using Assert. |
static void |
endTracking(java.lang.String key)
This method only works in debug mode!
Report the result of the tracking.
|
static void |
endTracking(java.lang.String key,
java.lang.String msg)
This method only works in debug mode!
Report the result of the tracking.
|
static void |
execute(java.lang.Runnable runnable)
This method only works in debug mode!
Execute a runnable.
|
static void |
exit(int code)
This method only works in debug mode!
Exit the IDE with an error code.
|
static void |
fail()
This method only works in debug mode!
Shorthand for causing a check exception if the code reaches an
unexpected location.
|
static void |
fail(java.lang.Exception exception)
This method only works in debug mode!
Shorthand for causing a check exception if the code reaches an
unexpected location.
|
static void |
fail(java.lang.String description)
This method only works in debug mode!
Shorthand for causing a check exception if the code reaches an
unexpected location.
|
static void |
markTracking(java.lang.String key)
This method only works in debug mode!
Call this method just before a potentional object is about to
perform a lengthy operation.
|
static void |
precondition(boolean condition)
This method only works in debug mode!
Assert a precondition before a method body run.
|
static void |
precondition(boolean condition,
java.lang.String description)
This method only works in debug mode!
Assert a precondition before a method body run.
|
static void |
print(boolean condition,
java.lang.String s)
This method only works in debug mode!
Print a string to standard error if a condition is true.
|
static void |
print(boolean condition,
java.lang.String trueString,
java.lang.String falseString)
This method only works in debug mode!
Print a string to standard error based on the evaluation of a condition.
|
static void |
print(java.lang.String s)
This method only works in debug mode!
Print a string to standard error.
|
static void |
printHeader(java.lang.String msg)
This method only works in debug mode!
Print a header of the form: [--]
msg ... |
static void |
println(boolean condition,
java.lang.String s)
This method only works in debug mode!
Print a string and a newline to standard error if a condition is true
|
static void |
println(boolean condition,
java.lang.String trueString,
java.lang.String falseString)
This method only works in debug mode!
Print a string and a newline to standard error based on the evaluation
of a condition.
|
static void |
println(java.lang.String s)
This method only works in debug mode!
Print a string and a newline to standard error.
|
static void |
println(java.lang.String pattern,
java.lang.Object param)
This method only works in debug mode!
Print a one parameter formatted message string and a newline to
standard error.
|
static void |
println(java.lang.String pattern,
java.lang.Object[] params)
This method only works in debug mode!
Print a multiple parameter formatted message string and a newline to
standard error.
|
static void |
println(java.lang.String pattern,
java.lang.Object param1,
java.lang.Object param2)
This method only works in debug mode!
Print a two parameter formatted message string and a newline to
standard error.
|
static void |
println(java.lang.String pattern,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3)
This method only works in debug mode!
Print a three parameter formatted message string and a newline to
standard error.
|
static void |
printStackTrace()
This method only works in debug mode!
Print a diagnostic stack trace of the current thread.
|
static void |
printStackTrace(boolean condition,
java.lang.String s)
This method only works in debug mode!
Print a diagnostic stack trace if the specified condition is true.
|
static void |
printStackTrace(java.lang.String message)
This method only works in debug mode!
Print a diagnostic stack trace of the current thread.
|
static void |
printStackTrace(java.lang.Throwable ex)
This method only works in debug mode!
Print the stack trace of a Throwable.
|
static void |
printTiming(long time,
java.lang.String msg,
java.lang.String indent)
This method only works in debug mode!
This method takes the time and the message and indent strings
and formats them, then it prints them.
|
static void |
printTiming(long time,
java.lang.String msg,
java.lang.String indent,
long threshold)
This method only works in debug mode!
This method takes the time and the message and indent strings
and formats them, then it prints them.
|
static int |
printTimingThreshold()
Get the default timing threshold; times are not printed out
unless the time is larger than this threshold.
|
static void |
startTiming(java.lang.String key,
java.lang.String msg,
boolean quietStart)
This method only works in debug mode!
Starts timing of an event which will be reported using
Assert.endTiming()
The name of the currently executing thread is prefixed to the
name of the key passed in. |
static void |
startTiming(java.lang.String key,
java.lang.String msg,
boolean quietStart,
boolean prefixThread)
This method only works in debug mode!
Starts timing of an event which will be reported using Assert
|
static void |
startTracking(java.lang.String key)
This method only works in debug mode!
Get ready to track the time taken by a list of tasks.
|
public static void precondition(boolean condition, java.lang.String description) throws java.lang.IllegalStateException
condition
- The condition being asserted.description
- The description of the failed assertionjava.lang.IllegalStateException
- when the IDE is in debug mode and
condition is falsepublic static void precondition(boolean condition) throws java.lang.IllegalStateException
condition
- The condition being asserted.java.lang.IllegalStateException
- when the IDE is in debug mode and the
condition is falsepublic static void check(boolean condition, java.lang.String description) throws java.lang.IllegalStateException
condition
- The condition being asserted.description
- The description of the failed assertionjava.lang.IllegalStateException
- when the IDE is in debug mode and
condition is falsepublic static void check(boolean condition) throws java.lang.IllegalStateException
condition
- The condition being asserted.java.lang.IllegalStateException
- when the IDE is in debug mode and
condition is falsepublic static void checkAWTThread() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- when the IDE is in debug mode and
the check failspublic static void fail(java.lang.String description) throws java.lang.IllegalStateException
description
- The description of the failurejava.lang.IllegalStateException
- when the IDE is in debug modepublic static void fail() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- when the IDE is in debug modepublic static void fail(java.lang.Exception exception) throws java.lang.IllegalStateException
exception
- An exception encapsulating the failurejava.lang.IllegalStateException
- when the IDE is in debug modepublic static void exit(int code)
code
- the Exit code.public static void printStackTrace()
public static void printStackTrace(java.lang.String message)
public static void printStackTrace(java.lang.Throwable ex)
ex
- The Throwable with the stack trace info.public static void printStackTrace(boolean condition, java.lang.String s)
condition
- the condition that determines whether to print the
stack trace.s
- the string to print before the stack trace.public static void print(java.lang.String s)
s
- the string to print.public static void print(boolean condition, java.lang.String s)
condition
- the condition to evaluates
- the string to print.public static void print(boolean condition, java.lang.String trueString, java.lang.String falseString)
condition
- the condition to evaluatetrueString
- the string to print if condition
is
true.falseString
- the string to print if condition
is
false.public static void println(java.lang.String s)
s
- the string to printpublic static void println(boolean condition, java.lang.String s)
condition
- the condition to evaluates
- the string to print.public static void println(boolean condition, java.lang.String trueString, java.lang.String falseString)
condition
- the condition to evaluatetrueString
- the string to print if condition
is
true.falseString
- the string to print if condition
is
false.public static void println(java.lang.String pattern, java.lang.Object param)
println(String,Object[])
.pattern
- the format pattern for the message.param
- an object to be formatted and substituted into
the result string.public static void println(java.lang.String pattern, java.lang.Object param1, java.lang.Object param2)
println(String,Object[])
.pattern
- the format pattern for the message.param1
- an object to be formatted and substituted into
the result string.param2
- an object to be formatted and substituted into
the result string.public static void println(java.lang.String pattern, java.lang.Object param1, java.lang.Object param2, java.lang.Object param3)
println(String,Object[])
.pattern
- the format pattern for the message.param1
- an object to be formatted and substituted into
the result string.param2
- an object to be formatted and substituted into
the result string.param3
- an object to be formatted and substituted into
the result string.public static void println(java.lang.String pattern, java.lang.Object[] params)
pattern
- the format pattern for the message.params
- an array of objects to be formatted and substituted into
the result string.MessageFormat.format(String,Object[])
public static void execute(java.lang.Runnable runnable)
runnable
- The runnable to executepublic static void startTiming(java.lang.String key, java.lang.String msg, boolean quietStart)
Assert.endTiming()
The name of the currently executing thread is prefixed to the
name of the key passed in.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- An optional message to print. If null nothing
will be printed, only the start time will be storedquietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.public static void startTiming(java.lang.String key, java.lang.String msg, boolean quietStart, boolean prefixThread)
key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- An optional message to print. If null nothing
will be printed, only the start time will be storedquietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.prefixThread
- true if the key should be prefixed by the name of
the currently executing thread; false otherwisepublic static void endTiming(java.lang.String key, java.lang.String msg, java.lang.String indent, boolean quietStart)
startTiming()
and
endTiming()
using Assert.
The name of the currently executing thread is prefixed to the
name of the key passed in.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- the message to printindent
- A string of spaces to be used for indenting the
message. Null is allowed and will mean no indentation.quietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.public static void endTiming(java.lang.String key, java.lang.String msg, java.lang.String indent, boolean quietStart, long timeThreshold)
startTiming()
and
endTiming()
using Assert.
The name of the currently executing thread is prefixed to the
name of the key passed in.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- the message to printindent
- A string of spaces to be used for indenting the
message. Null is allowed and will mean no indentation.quietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.timeThreshold
- minimum number of elapsed milliseconds by the
operation being timed to have the message being displayed, any operation
that takes less than timeThreshold will not have their time displayedpublic static void endTiming(java.lang.String key, java.lang.String msg, java.lang.String indent, boolean quietStart, boolean prefixThread)
startTiming()
and
endTiming()
using Assert.
The name of the currently executing thread is prefixed to the
name of the key passed in.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- the message to printindent
- A string of spaces to be used for indenting the
message. Null is allowed and will mean no indentation.quietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.prefixThread
- true if the key should be prefixed by the name of
the currently executing thread; false otherwisepublic static void endTiming(java.lang.String key, java.lang.String msg, java.lang.String indent, boolean quietStart, boolean prefixThread, long timeThreshold)
startTiming()
and
endTiming()
using Assert.
The name of the currently executing thread is prefixed to the
name of the key passed in.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- the message to printindent
- A string of spaces to be used for indenting the
message. Null is allowed and will mean no indentation.quietStart
- true if you want to store timing information
and print it using endTiming(); false otherwise.prefixThread
- true if the key should be prefixed by the name of
the currently executing thread; false otherwisetimeThreshold
- minimum number of elapsed milliseconds by the
operation being timed to have the message being displayed, any operation
that takes less than timeThreshold will not have their time displayedpublic static void printTiming(long time, java.lang.String msg, java.lang.String indent)
time
- The time to printmsg
- The message to printindent
- The indent to usepublic static void printTiming(long time, java.lang.String msg, java.lang.String indent, long threshold)
time
- The time to printmsg
- The message to printindent
- The indent to usethreshold
- The threshold, time needs to be >= than this
threshold and larger than the default threshold for printing
to occurpublic static void printHeader(java.lang.String msg)
msg
...msg
- The message to printpublic static int printTimingThreshold()
public static void startTracking(java.lang.String key)
endTracking(String)
or
endTracking(String, String)
is called.key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent"). Key
is prefixed with the name of the currently executing thread.public static void markTracking(java.lang.String key)
key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent"). Key
is prefixed with the name of the currently executing thread.public static void checkTracking(java.lang.String key, java.lang.Object object)
key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")object
- the object performing the operation or task.public static void endTracking(java.lang.String key)
key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")public static void endTracking(java.lang.String key, java.lang.String msg)
key
- typically the fully-qualified class name with the
method name at the end (eg, "oracle.ide.Ide.fireEvent")msg
- An optional message to indicate that the total time taken
by all the tasks should be reported. If null is specified, only the
slowest task time will be reported. Key is prefixed with the name of
the currently executing thread.