* @exception DebugException
* if creation fails
*/
protected IJavaObject newInstance(String className) throws DebugException {
IJavaObject object = null;
IJavaClassType clazz = null;
IJavaType[] types = getDebugTarget().getJavaTypes(className);
if (types != null && types.length > 0) {
clazz = (IJavaClassType) types[0];
}
if (clazz == null) {
// The class is not loaded on the target VM.
// Force the load of the class.
types = getDebugTarget().getJavaTypes("java.lang.Class"); //$NON-NLS-1$
IJavaClassType classClass = null;
if (types != null && types.length > 0) {
classClass = (IJavaClassType) types[0];
}
if (classClass == null) {
// unable to load the class
throw new DebugException(
new Status(
IStatus.ERROR,
JDIDebugModel.getPluginIdentifier(),
DebugException.REQUEST_FAILED,
EvaluationMessages.LocalEvaluationEngine_Evaluation_failed___unable_to_instantiate_code_snippet_class__11,
null));
}
IJavaValue[] args = new IJavaValue[] { getDebugTarget().newValue(
className) };
IJavaObject classObject = (IJavaObject) classClass
.sendMessage(
"forName", "(Ljava/lang/String;)Ljava/lang/Class;", args, getThread()); //$NON-NLS-2$ //$NON-NLS-1$
object = (IJavaObject) classObject
.sendMessage(
"newInstance", "()Ljava/lang/Object;", null, getThread(), false); //$NON-NLS-2$ //$NON-NLS-1$