1 11 package org.eclipse.jdt.internal.corext.refactoring.util; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.NullProgressMonitor; 17 18 import org.eclipse.core.resources.IResource; 19 20 import org.eclipse.core.filebuffers.FileBuffers; 21 import org.eclipse.core.filebuffers.ITextFileBuffer; 22 import org.eclipse.core.filebuffers.LocationKind; 23 24 import org.eclipse.jdt.core.ICompilationUnit; 25 26 27 30 public final class RefactoringFileBuffers { 31 32 43 public static ITextFileBuffer acquire(final ICompilationUnit unit) throws CoreException { 44 Assert.isNotNull(unit); 45 final IResource resource= unit.getResource(); 46 if (resource != null && resource.getType() == IResource.FILE) { 47 final IPath path= resource.getFullPath(); 48 FileBuffers.getTextFileBufferManager().connect(path, LocationKind.IFILE, new NullProgressMonitor()); 49 return FileBuffers.getTextFileBufferManager().getTextFileBuffer(path, LocationKind.IFILE); 50 } 51 return null; 52 } 53 54 60 public static ITextFileBuffer getTextFileBuffer(final ICompilationUnit unit) { 61 Assert.isNotNull(unit); 62 final IResource resource= unit.getResource(); 63 if (resource == null || resource.getType() != IResource.FILE) 64 return null; 65 return FileBuffers.getTextFileBufferManager().getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE); 66 } 67 68 74 public static void release(final ICompilationUnit unit) throws CoreException { 75 Assert.isNotNull(unit); 76 final IResource resource= unit.getResource(); 77 if (resource != null && resource.getType() == IResource.FILE) 78 FileBuffers.getTextFileBufferManager().disconnect(resource.getFullPath(), LocationKind.IFILE, new NullProgressMonitor()); 79 } 80 81 private RefactoringFileBuffers() { 82 } 84 } 85 | Popular Tags |