01: package core;
02:
03: import org.eclipse.jdt.core.IJavaElement;
04: import org.eclipse.jdt.core.dom.CompilationUnit;
05: import org.eclipse.jdt.core.dom.FieldDeclaration;
06: import org.eclipse.jdt.internal.core.SourceField;
07:
08: /**
09: * This class is responsible for execute the type
10: * refactoring in the source.
11: *
12: * @author sh
13: */
14: public class RenameFieldDeclaration extends AbstractAST implements
15: ICodeRefactoring {
16:
17: // the Info Object containing all nesessary refactor info
18: private RefactorInfo info = null;
19:
20: /**
21: * performs the source modifications.
22: * The compilation unit of the info object
23: * will be investigated and modified by the fild visitor.
24: *
25: * @param modelElement the field to refactor
26: */
27: public void updateSource(IJavaElement modelElement) {
28: // investigate the cu by the visitor
29: FieldDeclarationVisitor fieldVisitor = new FieldDeclarationVisitor();
30: CompilationUnit u = parse(info.getUnit());
31: fieldVisitor.process(u, info);
32:
33: // write changes
34: ManipulateHelper.saveDirectlyModifiedUnit(u);
35: }
36:
37: @Override
38: public void process(ModelInfo info) {
39: }
40:
41: /**
42: * Start the refactoring process.
43: *
44: * @param info the info object
45: */
46: public void process(RefactorInfo info) {
47: //if (info.getElement() instanceof SourceField == false) return;
48: if (info.getElement() instanceof SourceField
49: || info.getElement() instanceof FieldDeclaration) {
50: this.info = info;
51:
52: updateSource(null);
53: }
54: }
55: }
|