1 11 package org.eclipse.jdt.internal.debug.eval.ast.engine; 12 13 import com.ibm.icu.text.MessageFormat; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.jdt.core.IJavaProject; 19 import org.eclipse.jdt.debug.core.IJavaClassObject; 20 import org.eclipse.jdt.debug.core.IJavaClassType; 21 import org.eclipse.jdt.debug.core.IJavaObject; 22 import org.eclipse.jdt.debug.core.IJavaType; 23 import org.eclipse.jdt.debug.core.IJavaValue; 24 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 25 import org.eclipse.jdt.internal.debug.eval.ast.instructions.InstructionsEvaluationMessages; 26 27 import com.sun.jdi.InvocationException; 28 29 35 36 public abstract class AbstractRuntimeContext implements IRuntimeContext { 37 38 41 private IJavaObject fClassLoader; 42 43 46 private IJavaClassType fJavaLangClass; 47 48 51 protected IJavaProject fProject; 52 53 public static final String CLASS= "java.lang.Class"; public static final String FOR_NAME= "forName"; public static final String FOR_NAME_SIGNATURE= "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"; 57 58 public AbstractRuntimeContext(IJavaProject project) { 59 fProject = project; 60 } 61 62 70 protected IJavaObject getClassLoaderObject() throws CoreException { 71 if (fClassLoader == null) { 72 fClassLoader = getReceivingType().getClassLoaderObject(); 73 } 74 return fClassLoader; 75 } 76 77 83 protected IJavaClassType getJavaLangClass() throws CoreException { 84 if (fJavaLangClass == null) { 85 IJavaType[] types= getVM().getJavaTypes(CLASS); 86 if (types == null || types.length != 1) { 87 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String []{CLASS}), null)); 88 } 89 fJavaLangClass = (IJavaClassType) types[0]; 90 } 91 return fJavaLangClass; 92 } 93 94 103 protected IJavaClassObject classForName(String qualifiedName, IJavaObject loader) throws CoreException { 104 IJavaValue loaderArg = loader; 105 if (loader == null) { 106 loaderArg = getVM().nullValue(); 107 } 108 IJavaValue[] args = new IJavaValue[] {getVM().newValue(qualifiedName), getVM().newValue(true), loaderArg}; 109 try { 110 return (IJavaClassObject) getJavaLangClass().sendMessage(FOR_NAME, FOR_NAME_SIGNATURE, args, getThread()); 111 } catch (CoreException e) { 112 if (e.getStatus().getException() instanceof InvocationException) { 113 if (((InvocationException)e.getStatus().getException()).exception().referenceType().name().equals("java.lang.ClassNotFoundException")) { return null; 116 } 117 } 118 throw e; 119 } 120 } 121 122 125 public IJavaClassObject classForName(String name) throws CoreException { 126 return classForName(name, getClassLoaderObject()); 127 } 128 129 132 public IJavaProject getProject() { 133 return fProject; 134 } 135 } 136 | Popular Tags |