1 11 package org.eclipse.jdt.internal.corext.refactoring.changes; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.IResource; 15 16 import org.eclipse.ltk.core.refactoring.MultiStateTextFileChange; 17 18 import org.eclipse.jdt.core.ICompilationUnit; 19 20 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 21 import org.eclipse.jdt.internal.corext.util.Messages; 22 23 28 public final class MultiStateCompilationUnitChange extends MultiStateTextFileChange { 29 30 31 private final ICompilationUnit fUnit; 32 33 41 public MultiStateCompilationUnitChange(final String name, final ICompilationUnit unit) { 42 super(name, (IFile) unit.getResource()); 43 44 fUnit= unit; 45 46 setTextType("java"); } 48 49 52 public final Object getAdapter(final Class adapter) { 53 54 if (ICompilationUnit.class.equals(adapter)) 55 return fUnit; 56 57 return super.getAdapter(adapter); 58 } 59 60 65 public final ICompilationUnit getCompilationUnit() { 66 return fUnit; 67 } 68 69 72 public String getName() { 73 return Messages.format(RefactoringCoreMessages.MultiStateCompilationUnitChange_name_pattern, new String [] { fUnit.getElementName(), getPath(fUnit.getResource()) }); 74 } 75 76 83 private String getPath(IResource resource) { 84 final StringBuffer buffer= new StringBuffer (resource.getProject().getName()); 85 final String path= resource.getParent().getProjectRelativePath().toString(); 86 if (path.length() > 0) { 87 buffer.append('/'); 88 buffer.append(path); 89 } 90 return buffer.toString(); 91 } 92 } 93 | Popular Tags |