001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.debug.core.model;
011:
012: import com.ibm.icu.text.MessageFormat;
013: import java.util.ArrayList;
014: import java.util.Iterator;
015: import java.util.List;
016:
017: import org.eclipse.debug.core.DebugException;
018: import org.eclipse.jdt.debug.core.IJavaClassType;
019: import org.eclipse.jdt.debug.core.IJavaInterfaceType;
020:
021: import com.sun.jdi.ClassType;
022: import com.sun.jdi.InterfaceType;
023:
024: /**
025: * The interface of an object in a debug target.
026: */
027: public class JDIInterfaceType extends JDIReferenceType implements
028: IJavaInterfaceType {
029:
030: /**
031: * Cosntructs a new interface type on the given target referencing
032: * the specified interface type.
033: */
034: public JDIInterfaceType(JDIDebugTarget target, InterfaceType type) {
035: super (target, type);
036: }
037:
038: /* (non-Javadoc)
039: * @see org.eclipse.jdt.debug.core.IJavaInterfaceType#getImplementors()
040: */
041: public IJavaClassType[] getImplementors() throws DebugException {
042: try {
043: List implementorList = ((InterfaceType) getUnderlyingType())
044: .implementors();
045: List javaClassTypeList = new ArrayList(implementorList
046: .size());
047: Iterator iterator = implementorList.iterator();
048: while (iterator.hasNext()) {
049: ClassType classType = (ClassType) iterator.next();
050: if (classType != null) {
051: javaClassTypeList.add(JDIType.createType(
052: getJavaDebugTarget(), classType));
053: }
054: }
055: IJavaClassType[] javaClassTypeArray = new IJavaClassType[javaClassTypeList
056: .size()];
057: javaClassTypeArray = (IJavaClassType[]) javaClassTypeList
058: .toArray(javaClassTypeArray);
059: return javaClassTypeArray;
060: } catch (RuntimeException re) {
061: targetRequestFailed(
062: MessageFormat
063: .format(
064: JDIDebugModelMessages.JDIClassType_exception_while_retrieving_super class,
065: new String[] { re.toString() }), re);
066: }
067: return new IJavaClassType[0];
068: }
069:
070: /* (non-Javadoc)
071: * @see org.eclipse.jdt.debug.core.IJavaInterfaceType#getSubInterfaces()
072: */
073: public IJavaInterfaceType[] getSubInterfaces()
074: throws DebugException {
075: try {
076: List subList = ((InterfaceType) getUnderlyingType())
077: .subinterfaces();
078: List javaInterfaceTypeList = new ArrayList(subList.size());
079: Iterator iterator = subList.iterator();
080: while (iterator.hasNext()) {
081: InterfaceType interfaceType = (InterfaceType) iterator
082: .next();
083: if (interfaceType != null) {
084: javaInterfaceTypeList.add(JDIType.createType(
085: getJavaDebugTarget(), interfaceType));
086: }
087: }
088: IJavaInterfaceType[] javaInterfaceTypeArray = new IJavaInterfaceType[javaInterfaceTypeList
089: .size()];
090: javaInterfaceTypeArray = (IJavaInterfaceType[]) javaInterfaceTypeList
091: .toArray(javaInterfaceTypeArray);
092: return javaInterfaceTypeArray;
093: } catch (RuntimeException re) {
094: targetRequestFailed(
095: MessageFormat
096: .format(
097: JDIDebugModelMessages.JDIClassType_exception_while_retrieving_super class,
098: new String[] { re.toString() }), re);
099: }
100: return new IJavaInterfaceType[0];
101: }
102:
103: /* (non-Javadoc)
104: * @see org.eclipse.jdt.debug.core.IJavaInterfaceType#getSuperInterfaces()
105: */
106: public IJavaInterfaceType[] getSuperInterfaces()
107: throws DebugException {
108: try {
109: List super List = ((InterfaceType) getUnderlyingType())
110: .super interfaces();
111: List javaInterfaceTypeList = new ArrayList(super List.size());
112: Iterator iterator = super List.iterator();
113: while (iterator.hasNext()) {
114: InterfaceType interfaceType = (InterfaceType) iterator
115: .next();
116: if (interfaceType != null) {
117: javaInterfaceTypeList.add(JDIType.createType(
118: getJavaDebugTarget(), interfaceType));
119: }
120: }
121: IJavaInterfaceType[] javaInterfaceTypeArray = new IJavaInterfaceType[javaInterfaceTypeList
122: .size()];
123: javaInterfaceTypeArray = (IJavaInterfaceType[]) javaInterfaceTypeList
124: .toArray(javaInterfaceTypeArray);
125: return javaInterfaceTypeArray;
126: } catch (RuntimeException re) {
127: targetRequestFailed(
128: MessageFormat
129: .format(
130: JDIDebugModelMessages.JDIClassType_exception_while_retrieving_super class,
131: new String[] { re.toString() }), re);
132: }
133: return new IJavaInterfaceType[0];
134: }
135:
136: }
|