KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > changes > CreateCompilationUnitChange


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc source, String JavaDoc encoding) {
26         super(unit.getResource().getFullPath(), source, encoding, "java"); //$NON-NLS-1$
27
fUnit= unit;
28     }
29
30     public String JavaDoc getName() {
31         return Messages.format(RefactoringCoreMessages.CompilationUnitChange_label, new String JavaDoc[] { fUnit.getElementName(), getPath(fUnit.getResource()) });
32     }
33
34     private String JavaDoc getPath(IResource resource) {
35         final StringBuffer JavaDoc buffer= new StringBuffer JavaDoc(resource.getProject().getName());
36         final String JavaDoc 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