1 19 20 package org.netbeans.modules.refactoring.java.plugins; 21 22 import com.sun.source.tree.*; 23 import javax.lang.model.element.*; 24 import org.netbeans.api.java.source.WorkingCopy; 25 26 30 public class CopyTransformer extends SearchVisitor { 31 32 private String newName; 33 private boolean insertImport; 34 private String oldPackage; 35 36 public CopyTransformer(WorkingCopy workingCopy, String newName, boolean insertImport, String oldPackage) { 37 super(workingCopy); 38 this.newName = newName; 39 this.insertImport = insertImport; 40 this.oldPackage = oldPackage + ".*"; 41 } 42 43 @Override 44 public Tree visitCompilationUnit(CompilationUnitTree tree, Element p) { 45 if (!workingCopy.getTreeUtilities().isSynthetic(getCurrentPath())) { 46 if (insertImport) { 47 Element el = workingCopy.getTrees().getElement(getCurrentPath()); 48 Tree tree2 = make.insertCompUnitImport(tree, 0, make.Import(make.Identifier(oldPackage), false)); 49 workingCopy.rewrite(tree, tree2); 50 } 51 } 52 return super.visitCompilationUnit(tree, p); 53 } 54 55 @Override 56 public Tree visitClass(ClassTree tree, Element p) { 57 if (!workingCopy.getTreeUtilities().isSynthetic(getCurrentPath())) { 58 Tree nju = make.setLabel(tree, newName); 60 workingCopy.rewrite(tree, nju); 61 } 63 return null; 64 } 65 66 } 67 | Popular Tags |