1 11 package org.eclipse.jdt.internal.corext.util; 12 13 import org.eclipse.core.runtime.IProgressMonitor; 14 15 import org.eclipse.jdt.core.ICompilationUnit; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IMember; 18 import org.eclipse.jdt.core.IPackageFragment; 19 import org.eclipse.jdt.core.JavaModelException; 20 import org.eclipse.jdt.core.WorkingCopyOwner; 21 22 23 public class WorkingCopyUtil { 24 25 private WorkingCopyUtil(){ 27 } 28 29 32 public static IJavaElement getWorkingCopyIfExists(IJavaElement element) { 33 return element; 34 } 35 36 39 public static ICompilationUnit getWorkingCopyIfExists(ICompilationUnit element) { 40 return element; 41 } 42 43 46 public static IMember getWorkingCopyIfExists(IMember member) { 47 return member; 48 } 49 50 public static IJavaElement getOriginal(IMember member){ 51 return JavaModelUtil.toOriginal(member); 52 } 53 54 public static ICompilationUnit getOriginal(ICompilationUnit cu){ 55 return JavaModelUtil.toOriginal(cu); 56 } 57 58 public static IMember[] getOriginals(IMember[] members){ 59 IMember[] result= new IMember[members.length]; 60 for (int i= 0; i < members.length; i++) { 61 result[i]= (IMember)WorkingCopyUtil.getOriginal(members[i]); 62 } 63 return result; 64 } 65 66 70 public static ICompilationUnit getNewWorkingCopy(ICompilationUnit cu) throws JavaModelException{ 71 74 return getOriginal(cu).getWorkingCopy(null); 75 } 76 77 81 public static ICompilationUnit getNewWorkingCopy(ICompilationUnit cu, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{ 82 85 return getOriginal(cu).getWorkingCopy(owner, null, pm); 86 } 87 88 93 public static ICompilationUnit getNewWorkingCopy(IPackageFragment pack, String cuName) throws JavaModelException{ 94 return pack.getCompilationUnit(cuName).getWorkingCopy(null); 95 } 96 97 102 public static ICompilationUnit getNewWorkingCopy(IPackageFragment pack, String cuName, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{ 103 return pack.getCompilationUnit(cuName).getWorkingCopy(owner, null, pm); 104 } 105 } 106 107 | Popular Tags |