001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.jdi.internal;
011:
012: import java.io.DataInputStream;
013: import java.io.IOException;
014: import java.util.ArrayList;
015: import java.util.Iterator;
016: import java.util.List;
017:
018: import org.eclipse.jdi.internal.jdwp.JdwpClassObjectID;
019: import org.eclipse.jdi.internal.jdwp.JdwpID;
020: import org.eclipse.jdi.internal.jdwp.JdwpInterfaceID;
021:
022: import com.sun.jdi.ClassNotPreparedException;
023: import com.sun.jdi.InterfaceType;
024: import com.sun.jdi.Value;
025:
026: /**
027: * this class implements the corresponding interfaces
028: * declared by the JDI specification. See the com.sun.jdi package
029: * for more information.
030: *
031: */
032: public class InterfaceTypeImpl extends ReferenceTypeImpl implements
033: InterfaceType {
034: /** JDWP Tag. */
035: public static final byte typeTag = JdwpID.TYPE_TAG_INTERFACE;
036:
037: /**
038: * Creates new InterfaceTypeImpl.
039: */
040: public InterfaceTypeImpl(VirtualMachineImpl vmImpl,
041: JdwpInterfaceID interfaceID) {
042: super ("InterfaceType", vmImpl, interfaceID); //$NON-NLS-1$
043: }
044:
045: /**
046: * Creates new InterfaceTypeImpl.
047: */
048: public InterfaceTypeImpl(VirtualMachineImpl vmImpl,
049: JdwpInterfaceID interfaceID, String signature,
050: String genericSignature) {
051: super (
052: "InterfaceType", vmImpl, interfaceID, signature, genericSignature); //$NON-NLS-1$
053: }
054:
055: /**
056: * @return Create a null value instance of the type.
057: */
058: public Value createNullValue() {
059: return new ClassObjectReferenceImpl(virtualMachineImpl(),
060: new JdwpClassObjectID(virtualMachineImpl()));
061: }
062:
063: /**
064: * @return Returns type tag.
065: */
066: public byte typeTag() {
067: return typeTag;
068: }
069:
070: /**
071: * Flushes all stored Jdwp results.
072: */
073: public void flushStoredJdwpResults() {
074: super .flushStoredJdwpResults();
075:
076: // For all reftypes that have this interface cached, this cache must be undone.
077: Iterator itr = virtualMachineImpl().allCachedRefTypes();
078: while (itr.hasNext()) {
079: ReferenceTypeImpl refType = (ReferenceTypeImpl) itr.next();
080: if (refType.fInterfaces != null
081: && refType.fInterfaces.contains(this )) {
082: refType.flushStoredJdwpResults();
083: }
084: }
085:
086: }
087:
088: /**
089: * @return Returns the currently prepared classes which directly implement this interface.
090: */
091: public List implementors() {
092: // Note that this information should not be cached.
093: List implementors = new ArrayList();
094: Iterator itr = virtualMachineImpl().allRefTypes();
095: while (itr.hasNext()) {
096: ReferenceTypeImpl refType = (ReferenceTypeImpl) itr.next();
097: if (refType instanceof ClassTypeImpl) {
098: try {
099: ClassTypeImpl classType = (ClassTypeImpl) refType;
100: List interfaces = classType.interfaces();
101: if (interfaces.contains(this )) {
102: implementors.add(classType);
103: }
104: } catch (ClassNotPreparedException e) {
105: continue;
106: }
107: }
108: }
109: return implementors;
110: }
111:
112: /**
113: * @return Returns the currently prepared interfaces which directly extend this interface.
114: */
115: public List subinterfaces() {
116: // Note that this information should not be cached.
117: List implementors = new ArrayList();
118: Iterator itr = virtualMachineImpl().allRefTypes();
119: while (itr.hasNext()) {
120: try {
121: ReferenceTypeImpl refType = (ReferenceTypeImpl) itr
122: .next();
123: if (refType instanceof InterfaceTypeImpl) {
124: InterfaceTypeImpl interFaceType = (InterfaceTypeImpl) refType;
125: List interfaces = interFaceType.super interfaces();
126: if (interfaces.contains(this )) {
127: implementors.add(interFaceType);
128: }
129: }
130: } catch (ClassNotPreparedException e) {
131: continue;
132: }
133: }
134: return implementors;
135: }
136:
137: /**
138: * @return Returns the interfaces directly extended by this interface.
139: */
140: public List super interfaces() {
141: return interfaces();
142: }
143:
144: /**
145: * @return Returns true if this type has been initialized.
146: */
147: public boolean isInitialized() {
148: return isPrepared();
149: }
150:
151: /**
152: * @return Reads ID and returns known ReferenceTypeImpl with that ID, or if ID is unknown a newly created ReferenceTypeImpl.
153: */
154: public static InterfaceTypeImpl read(MirrorImpl target,
155: DataInputStream in) throws IOException {
156: VirtualMachineImpl vmImpl = target.virtualMachineImpl();
157: JdwpInterfaceID ID = new JdwpInterfaceID(vmImpl);
158: ID.read(in);
159: if (target.fVerboseWriter != null) {
160: target.fVerboseWriter.println("interfaceType", ID.value()); //$NON-NLS-1$
161: }
162:
163: if (ID.isNull()) {
164: return null;
165: }
166:
167: InterfaceTypeImpl mirror = (InterfaceTypeImpl) vmImpl
168: .getCachedMirror(ID);
169: if (mirror == null) {
170: mirror = new InterfaceTypeImpl(vmImpl, ID);
171: vmImpl.addCachedMirror(mirror);
172: }
173: return mirror;
174: }
175:
176: /**
177: * @return Reads ID and returns known ReferenceTypeImpl with that ID, or if ID is unknown a newly created ReferenceTypeImpl.
178: */
179: public static InterfaceTypeImpl readWithSignature(
180: MirrorImpl target, boolean withGenericSignature,
181: DataInputStream in) throws IOException {
182: VirtualMachineImpl vmImpl = target.virtualMachineImpl();
183: JdwpInterfaceID ID = new JdwpInterfaceID(vmImpl);
184: ID.read(in);
185: if (target.fVerboseWriter != null) {
186: target.fVerboseWriter.println("interfaceType", ID.value()); //$NON-NLS-1$
187: }
188:
189: String signature = target.readString("signature", in); //$NON-NLS-1$
190: String genericSignature = null;
191: if (withGenericSignature) {
192: genericSignature = target.readString(
193: "generic signature", in); //$NON-NLS-1$
194: }
195: if (ID.isNull()) {
196: return null;
197: }
198:
199: InterfaceTypeImpl mirror = (InterfaceTypeImpl) vmImpl
200: .getCachedMirror(ID);
201: if (mirror == null) {
202: mirror = new InterfaceTypeImpl(vmImpl, ID);
203: vmImpl.addCachedMirror(mirror);
204: }
205: mirror.setSignature(signature);
206: mirror.setGenericSignature(genericSignature);
207: return mirror;
208: }
209: }
|