KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > eval > ast > instructions > InstanceOfOperator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.eval.ast.instructions;
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.debug.core.IJavaObject;
19 import org.eclipse.jdt.debug.core.IJavaType;
20 import org.eclipse.jdt.debug.core.IJavaValue;
21 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
22 import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
23
24 public class InstanceOfOperator extends CompoundInstruction {
25     public static final String JavaDoc IS_INSTANCE= "isInstance"; //$NON-NLS-1$
26
public static final String JavaDoc IS_INSTANCE_SIGNATURE= "(Ljava/lang/Object;)Z"; //$NON-NLS-1$
27

28     public InstanceOfOperator(int start) {
29         super(start);
30     }
31     
32     /*
33      * @see Instruction#execute()
34      */

35     public void execute() throws CoreException {
36         IJavaType type= (IJavaType)pop();
37         IJavaValue value= popValue();
38         if (value instanceof JDINullValue) {
39             pushNewValue(false);
40             return;
41         }
42         IJavaObject object= (IJavaObject)value;
43
44         IJavaObject classObject= getClassObject(type);
45         if (classObject == null) {
46             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.InstanceOfOperator_No_class_object, new String JavaDoc[]{type.getName()}), null));
47         }
48         push(classObject.sendMessage(IS_INSTANCE, IS_INSTANCE_SIGNATURE, new IJavaValue[] {object}, getContext().getThread(), false));
49     }
50     
51     public String JavaDoc toString() {
52         return InstructionsEvaluationMessages.InstanceOfOperator__instanceof___operator_3;
53     }
54
55 }
56
Popular Tags