1 11 package org.eclipse.jdt.internal.corext.refactoring.util; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IResource; 18 19 import org.eclipse.jdt.core.ICompilationUnit; 20 import org.eclipse.jdt.core.IJavaElement; 21 import org.eclipse.jdt.core.IOpenable; 22 23 24 public class ResourceUtil { 25 26 private ResourceUtil(){ 27 } 28 29 public static IFile[] getFiles(ICompilationUnit[] cus) { 30 List files= new ArrayList (cus.length); 31 for (int i= 0; i < cus.length; i++) { 32 IResource resource= cus[i].getResource(); 33 if (resource != null && resource.getType() == IResource.FILE) 34 files.add(resource); 35 } 36 return (IFile[]) files.toArray(new IFile[files.size()]); 37 } 38 39 public static IFile getFile(ICompilationUnit cu) { 40 IResource resource= cu.getResource(); 41 if (resource != null && resource.getType() == IResource.FILE) 42 return (IFile)resource; 43 else 44 return null; 45 } 46 47 49 public static IResource getResource(Object o){ 50 if (o instanceof IResource) 51 return (IResource)o; 52 if (o instanceof IJavaElement) 53 return getResource((IJavaElement)o); 54 return null; 55 } 56 57 private static IResource getResource(IJavaElement element){ 58 if (element.getElementType() == IJavaElement.COMPILATION_UNIT) 59 return ((ICompilationUnit) element).getResource(); 60 else if (element instanceof IOpenable) 61 return element.getResource(); 62 else 63 return null; 64 } 65 } 66 | Popular Tags |