01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.debug.eval.ast.instructions;
11:
12: import com.ibm.icu.text.MessageFormat;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.core.runtime.IStatus;
16: import org.eclipse.core.runtime.Status;
17: import org.eclipse.jdt.debug.core.IJavaClassType;
18: import org.eclipse.jdt.debug.core.IJavaType;
19: import org.eclipse.jdt.debug.core.IJavaValue;
20: import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin;
21:
22: /**
23: * Sends a message. The arguments are on the
24: * stack in reverse order, followed by the receiver.
25: * Pushes the result, if any, onto the stack
26: */
27: public class SendStaticMessage extends CompoundInstruction {
28:
29: private int fArgCount;
30: private String fSelector;
31: private String fSignature;
32: private String fTypeName;
33:
34: public SendStaticMessage(String typeName, String selector,
35: String signature, int argCount, int start) {
36: super (start);
37: fArgCount = argCount;
38: fSelector = selector;
39: fSignature = signature;
40: fTypeName = typeName;
41: }
42:
43: public void execute() throws CoreException {
44: IJavaValue[] args = new IJavaValue[fArgCount];
45: // args are in reverse order
46: for (int i = fArgCount - 1; i >= 0; i--) {
47: args[i] = popValue();
48: }
49:
50: IJavaType receiver = getType(fTypeName);
51: IJavaValue result;
52: if (receiver instanceof IJavaClassType) {
53: result = ((IJavaClassType) receiver).sendMessage(fSelector,
54: fSignature, args, getContext().getThread());
55: } else {
56: throw new CoreException(
57: new Status(
58: IStatus.ERROR,
59: JDIDebugPlugin.getUniqueIdentifier(),
60: IStatus.OK,
61: InstructionsEvaluationMessages.SendStaticMessage_Cannot_send_a_static_message_to_a_non_class_type_object_1,
62: null));
63: }
64: setLastValue(result);
65: if (!fSignature.endsWith(")V")) { //$NON-NLS-1$
66: // only push the result if not a void method
67: push(result);
68: }
69: }
70:
71: public String toString() {
72: return MessageFormat
73: .format(
74: InstructionsEvaluationMessages.SendStaticMessage_send_static_message__0___1__2,
75: new String[] { fSelector, fSignature });
76: }
77: }
|