KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > model > JDIArrayType


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.core.model;
12
13
14 import com.ibm.icu.text.MessageFormat;
15
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.jdt.debug.core.IJavaArray;
18 import org.eclipse.jdt.debug.core.IJavaArrayType;
19 import org.eclipse.jdt.debug.core.IJavaType;
20
21 import com.sun.jdi.ArrayReference;
22 import com.sun.jdi.ArrayType;
23 import com.sun.jdi.ClassNotLoadedException;
24 import com.sun.jdi.Type;
25
26 /**
27  * The type of an array
28  */

29 public class JDIArrayType extends JDIReferenceType implements IJavaArrayType {
30
31     /**
32      * Cosntructs a new array type on the given target referencing
33      * the specified array type.
34      */

35     public JDIArrayType(JDIDebugTarget target, ArrayType type) {
36         super(target, type);
37     }
38     /**
39      * @see IJavaArrayType#newInstance(int)
40      */

41     public IJavaArray newInstance(int size) throws DebugException {
42         try {
43             ArrayReference ar = ((ArrayType)getUnderlyingType()).newInstance(size);
44             return (IJavaArray)JDIValue.createValue(getJavaDebugTarget(), ar);
45         } catch (RuntimeException JavaDoc e) {
46             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayType_exception_while_creating_new_instance_of_array, new String JavaDoc[] {e.toString()}), e);
47         }
48         // execution will not reach this line as
49
// an exception will be thrown
50
return null;
51     }
52
53     /**
54      * @see IJavaArray#getComponentType()
55      */

56     public IJavaType getComponentType() throws DebugException {
57         try {
58             Type type = ((ArrayType)getUnderlyingType()).componentType();
59             return JDIType.createType(getJavaDebugTarget(), type);
60         } catch (ClassNotLoadedException e) {
61             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayType_exception_while_retrieving_component_type_of_array, new String JavaDoc[] {e.toString()}), e);
62         } catch (RuntimeException JavaDoc e) {
63             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIArrayType_exception_while_retrieving_component_type_of_array, new String JavaDoc[] {e.toString()}), e);
64         }
65         // execution will not reach this line as
66
// an exception will be thrown
67
return null;
68     }
69
70 }
71
72
Popular Tags