KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jdt.debug.core.IJavaClassType;
16 import org.eclipse.jdt.debug.core.IJavaValue;
17
18 /**
19  * Invokes a constructor. The arguments are on the
20  * stack in reverse order, followed by the type.
21  * Pushes the result onto the stack
22  */

23 public class Constructor extends CompoundInstruction {
24     
25     private int fArgCount;
26     private String JavaDoc fSignature;
27     
28     public Constructor(String JavaDoc signature, int argCount, int start) {
29         super(start);
30         fArgCount = argCount;
31         fSignature = signature;
32     }
33     
34     public void execute() throws CoreException {
35         IJavaValue[] args = new IJavaValue[fArgCount];
36         // args are in reverse order
37
for (int i= fArgCount - 1; i >= 0; i--) {
38             args[i] = popValue();
39         }
40         IJavaClassType clazz = (IJavaClassType)pop();
41         IJavaValue result = clazz.newInstance(fSignature, args, getContext().getThread());
42         push(result);
43     }
44     
45     public String JavaDoc toString() {
46         return InstructionsEvaluationMessages.Constructor_constructor__1 + fSignature;
47     }
48
49 }
50
51
Popular Tags