KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > ResourceLocator


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.ui;
12
13 import org.eclipse.core.resources.IResource;
14
15 import org.eclipse.jdt.core.IJavaElement;
16 import org.eclipse.jdt.core.JavaModelException;
17
18 /**
19  * This class locates different resources
20  * which are related to an object
21  */

22 public class ResourceLocator implements IResourceLocator {
23     
24     public IResource getUnderlyingResource(Object JavaDoc element) throws JavaModelException {
25         if (element instanceof IJavaElement)
26             return ((IJavaElement) element).getUnderlyingResource();
27         else
28             return null;
29     }
30
31     public IResource getCorrespondingResource(Object JavaDoc element) throws JavaModelException {
32         if (element instanceof IJavaElement)
33             return ((IJavaElement) element).getCorrespondingResource();
34         else
35             return null;
36     }
37
38     public IResource getContainingResource(Object JavaDoc element) throws JavaModelException {
39         IResource resource= null;
40         if (element instanceof IResource)
41             resource= (IResource) element;
42         if (element instanceof IJavaElement) {
43             resource= ((IJavaElement) element).getResource();
44             if (resource == null)
45                 resource= ((IJavaElement) element).getJavaProject().getProject();
46         }
47         return resource;
48     }
49 }
50
Popular Tags