KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import com.ibm.icu.text.MessageFormat;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.jdt.debug.core.IJavaClassType;
20 import org.eclipse.jdt.debug.core.IJavaType;
21 import org.eclipse.jdt.debug.core.IJavaValue;
22 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
23  
24 /**
25  * Sends a message. The arguments are on the
26  * stack in reverse order, followed by the receiver.
27  * Pushes the result, if any, onto the stack
28  */

29 public class SendStaticMessage extends CompoundInstruction {
30     
31     private int fArgCount;
32     private String JavaDoc fSelector;
33     private String JavaDoc fSignature;
34     private String JavaDoc fTypeName;
35     
36     public SendStaticMessage(String JavaDoc typeName, String JavaDoc selector, String JavaDoc signature, int argCount, int start) {
37         super(start);
38         fArgCount= argCount;
39         fSelector= selector;
40         fSignature= signature;
41         fTypeName= typeName;
42     }
43     
44     public void execute() throws CoreException {
45         IJavaValue[] args = new IJavaValue[fArgCount];
46         // args are in reverse order
47
for (int i= fArgCount - 1; i >= 0; i--) {
48             args[i] = popValue();
49         }
50         
51         IJavaType receiver= getType(fTypeName);
52         IJavaValue result;
53         if (receiver instanceof IJavaClassType) {
54             result= ((IJavaClassType)receiver).sendMessage(fSelector, fSignature, args, getContext().getThread());
55         } else {
56             throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, InstructionsEvaluationMessages.SendStaticMessage_Cannot_send_a_static_message_to_a_non_class_type_object_1, null));
57         }
58         setLastValue(result);
59         if (!fSignature.endsWith(")V")) { //$NON-NLS-1$
60
// only push the result if not a void method
61
push(result);
62         }
63     }
64     
65     public String JavaDoc toString() {
66         return MessageFormat.format(InstructionsEvaluationMessages.SendStaticMessage_send_static_message__0___1__2, new String JavaDoc[]{fSelector, fSignature});
67     }
68 }
69
70
Popular Tags