KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > callhierarchy > JavaImplementorFinder


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  * Jesper Kamstrup Linnet (eclipse@kamstrup-linnet.dk) - initial API and implementation
10  * (report 36180: Callers/Callees view)
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.corext.callhierarchy;
13
14 import java.util.Arrays JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.HashSet JavaDoc;
17
18 import org.eclipse.core.runtime.IProgressMonitor;
19
20 import org.eclipse.jdt.core.IType;
21 import org.eclipse.jdt.core.ITypeHierarchy;
22 import org.eclipse.jdt.core.JavaModelException;
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24
25 public class JavaImplementorFinder implements IImplementorFinder {
26     /* (non-Javadoc)
27      * @see org.eclipse.jdt.internal.corext.callhierarchy.IImplementorFinder#findImplementingTypes(org.eclipse.jdt.core.IType, org.eclipse.core.runtime.IProgressMonitor)
28      */

29     public Collection JavaDoc findImplementingTypes(IType type, IProgressMonitor progressMonitor) {
30         ITypeHierarchy typeHierarchy;
31
32         try {
33             typeHierarchy = type.newTypeHierarchy(progressMonitor);
34
35             IType[] implementingTypes = typeHierarchy.getAllClasses();
36             HashSet JavaDoc result = new HashSet JavaDoc(Arrays.asList(implementingTypes));
37
38             return result;
39         } catch (JavaModelException e) {
40             JavaPlugin.log(e);
41         }
42
43         return null;
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.jdt.internal.corext.callhierarchy.IImplementorFinder#findInterfaces(org.eclipse.jdt.core.IType, org.eclipse.core.runtime.IProgressMonitor)
48      */

49     public Collection JavaDoc findInterfaces(IType type, IProgressMonitor progressMonitor) {
50         ITypeHierarchy typeHierarchy;
51
52         try {
53             typeHierarchy = type.newSupertypeHierarchy(progressMonitor);
54
55             IType[] interfaces = typeHierarchy.getAllSuperInterfaces(type);
56             HashSet JavaDoc result = new HashSet JavaDoc(Arrays.asList(interfaces));
57
58             return result;
59         } catch (JavaModelException e) {
60             JavaPlugin.log(e);
61         }
62
63         return null;
64     }
65 }
66
Popular Tags