1 11 package org.eclipse.jdt.internal.corext.refactoring.changes; 12 13 import org.eclipse.core.resources.IResource; 14 15 import org.eclipse.jdt.core.ICompilationUnit; 16 17 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 18 import org.eclipse.jdt.internal.corext.refactoring.nls.changes.CreateTextFileChange; 19 import org.eclipse.jdt.internal.corext.util.Messages; 20 21 public final class CreateCompilationUnitChange extends CreateTextFileChange { 22 23 private final ICompilationUnit fUnit; 24 25 public CreateCompilationUnitChange(ICompilationUnit unit, String source, String encoding) { 26 super(unit.getResource().getFullPath(), source, encoding, "java"); fUnit= unit; 28 } 29 30 public String getName() { 31 return Messages.format(RefactoringCoreMessages.CompilationUnitChange_label, new String [] { fUnit.getElementName(), getPath(fUnit.getResource()) }); 32 } 33 34 private String getPath(IResource resource) { 35 final StringBuffer buffer= new StringBuffer (resource.getProject().getName()); 36 final String path= resource.getParent().getProjectRelativePath().toString(); 37 if (path.length() > 0) { 38 buffer.append('/'); 39 buffer.append(path); 40 } 41 return buffer.toString(); 42 } 43 } 44 | Popular Tags |