1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.ui;
15 
16 import org.eclipse.core.resources.IResource;
17 
18 import org.eclipse.jdt.core.IJavaElement;
19 import org.eclipse.jdt.core.JavaModelException;
20 
21 /**
22  * This class locates different resources
23  * which are related to an object
24  */
25 public class ResourceLocator implements IResourceLocator {
26 
27 	@Override
getUnderlyingResource(Object element)28 	public IResource getUnderlyingResource(Object element) throws JavaModelException {
29 		if (element instanceof IJavaElement)
30 			return ((IJavaElement) element).getUnderlyingResource();
31 		else
32 			return null;
33 	}
34 
35 	@Override
getCorrespondingResource(Object element)36 	public IResource getCorrespondingResource(Object element) throws JavaModelException {
37 		if (element instanceof IJavaElement)
38 			return ((IJavaElement) element).getCorrespondingResource();
39 		else
40 			return null;
41 	}
42 
43 	@Override
getContainingResource(Object element)44 	public IResource getContainingResource(Object element) throws JavaModelException {
45 		IResource resource= null;
46 		if (element instanceof IResource)
47 			resource= (IResource) element;
48 		if (element instanceof IJavaElement) {
49 			resource= ((IJavaElement) element).getResource();
50 			if (resource == null)
51 				resource= ((IJavaElement) element).getJavaProject().getProject();
52 		}
53 		return resource;
54 	}
55 }
56