KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > plugins > RenameRefactoringPlugin


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.refactoring.java.plugins;
20
21 import com.sun.source.tree.CompilationUnitTree;
22 import com.sun.source.util.TreePath;
23 import java.io.IOException JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.*;
26 import javax.lang.model.element.*;
27 import javax.lang.model.util.Elements;
28 import javax.lang.model.util.Types;
29 import org.netbeans.api.java.classpath.ClassPath;
30 import org.netbeans.api.java.source.*;
31 import org.netbeans.api.java.source.ModificationResult.Difference;
32 import org.netbeans.modules.refactoring.java.plugins.RetoucheCommit;
33 import org.netbeans.modules.refactoring.spi.Transaction;
34 import org.netbeans.modules.refactoring.java.DiffElement;
35 import org.netbeans.modules.refactoring.api.*;
36 import org.netbeans.modules.refactoring.java.RetoucheUtils;
37 import org.netbeans.modules.refactoring.java.classpath.RefactoringClassPathImplementation;
38 import org.netbeans.modules.refactoring.java.plugins.JavaRefactoringPlugin;
39 import org.netbeans.modules.refactoring.java.ui.tree.ElementGripFactory;
40 import org.netbeans.modules.refactoring.spi.BackupFacility;
41 import org.openide.filesystems.FileObject;
42 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
43 import org.openide.ErrorManager;
44 import org.openide.filesystems.FileUtil;
45 import org.openide.util.NbBundle;
46 import org.openide.util.Utilities;
47
48 /**
49  *
50  * @author Jan Becicka, Martin Matula, Pavel Flaska, Daniel Prusa
51  */

52 public class RenameRefactoringPlugin extends JavaRefactoringPlugin {
53     
54     private TreePathHandle treePathHandle = null;
55     private Collection overriddenByMethods = null; // methods that override the method to be renamed
56
private Collection overridesMethods = null; // methods that are overridden by the method to be renamed
57
private boolean doCheckName = true;
58     private FileObject originalFolder = null;
59     private Set varNames;
60     
61     private RenameRefactoring refactoring;
62     
63     /** Creates a new instance of RenameRefactoring */
64     public RenameRefactoringPlugin(RenameRefactoring rename) {
65         this.refactoring = rename;
66         TreePathHandle tph = rename.getRefactoringSource().lookup(TreePathHandle.class);
67         if (tph!=null) {
68             treePathHandle = tph;
69         } else {
70             JavaSource source = JavaSource.forFileObject(rename.getRefactoringSource().lookup(FileObject.class));
71             try {
72                 source.runUserActionTask(new CancellableTask<CompilationController>() {
73                     public void cancel() {
74                     }
75                     
76                     public void run(CompilationController co) throws Exception JavaDoc {
77                         co.toPhase(JavaSource.Phase.RESOLVED);
78                         CompilationUnitTree cut = co.getCompilationUnit();
79                         treePathHandle = TreePathHandle.create(TreePath.getPath(cut, cut.getTypeDecls().get(0)), co);
80                         refactoring.getContext().add(co);
81                     }
82                 }, false);
83             } catch (IllegalArgumentException JavaDoc ex) {
84                 ex.printStackTrace();
85             } catch (IOException JavaDoc ex) {
86                 ex.printStackTrace();
87             }
88         }
89     }
90     
91     public Problem preCheck() {
92         CompilationInfo info = refactoring.getContext().lookup(CompilationInfo.class);
93         Element el = treePathHandle.resolveElement(info);
94         
95         fireProgressListenerStart(refactoring.PRE_CHECK, 4);
96         try {
97             Problem result = isElementAvail(treePathHandle, info);
98             if (result != null) {
99                 return result;
100             }
101             FileObject file = SourceUtils.getFile(el, info.getClasspathInfo());
102             if (FileUtil.getArchiveFile(file)!= null) { //NOI18N
103
return createProblem(result, true, getCannotRename(file));
104             }
105             
106             if (!RetoucheUtils.isElementInOpenProject(file)) {
107                 return new Problem(true, NbBundle.getMessage(JavaRefactoringPlugin.class, "ERR_ProjectNotOpened"));
108             }
109             
110             switch(el.getKind()) {
111                 case METHOD:
112                     fireProgressListenerStep();
113                     fireProgressListenerStep();
114                     overriddenByMethods = RetoucheUtils.getOverridingMethods((ExecutableElement)el, info);
115                     fireProgressListenerStep();
116                     if (!overriddenByMethods.isEmpty()) {
117                         String JavaDoc msg = new MessageFormat JavaDoc(getString("ERR_IsOverridden")).format(
118                                 new Object JavaDoc[] {SourceUtils.getEnclosingTypeElement(el).getSimpleName().toString()});
119                         result = createProblem(result, false, msg);
120                     }
121                     overridesMethods = RetoucheUtils.getOverridingMethods((ExecutableElement) treePathHandle.resolveElement(info), info);
122                     fireProgressListenerStep();
123                     if (!overridesMethods.isEmpty()) {
124                         boolean fatal = false;
125                         for (Iterator iter = overridesMethods.iterator();iter.hasNext();) {
126                             ExecutableElement method = (ExecutableElement) iter.next();
127                             if (RetoucheUtils.isFromLibrary(method, info.getClasspathInfo())) {
128                                 fatal = true;
129                                 break;
130                             }
131                         }
132                         String JavaDoc msg = fatal?getString("ERR_Overrides_Fatal"):getString("ERR_Overrides");
133                         result = createProblem(result, fatal, msg);
134                     }
135                     break;
136                 case FIELD:
137                 case ENUM_CONSTANT:
138                     fireProgressListenerStep();
139                     fireProgressListenerStep();
140                     Element hiddenField = hides(el, el.getSimpleName().toString(), info);
141                     fireProgressListenerStep();
142                     fireProgressListenerStep();
143                     if (hiddenField != null) {
144                         String JavaDoc msg = new MessageFormat JavaDoc(getString("ERR_Hides")).format(
145                                 new Object JavaDoc[] {SourceUtils.getEnclosingTypeElement(el)}
146                         );
147                         result = createProblem(result, false, msg);
148                     }
149                     break;
150                 case PACKAGE:
151                     //TODO: any prechecks?
152
break;
153                 case LOCAL_VARIABLE:
154                     //TODO: any prechecks for formal parametr or local variable?
155
break;
156                 case CLASS:
157                 case INTERFACE:
158                 case ANNOTATION_TYPE:
159                 case ENUM:
160                     //TODO: any prechecks for JavaClass?
161
break;
162                 default:
163                     // if (!((jmiObject instanceof Resource) && ((Resource)jmiObject).getClassifiers().isEmpty()))
164
// result = createProblem(result, true, NbBundle.getMessage(RenameRefactoring.class, "ERR_RenameWrongType"));
165
}
166             
167             return result;
168         } finally {
169             fireProgressListenerStop();
170         }
171     }
172     
173     private static final String JavaDoc getCannotRename(FileObject r) {
174         return new MessageFormat JavaDoc(NbBundle.getMessage(RenameRefactoringPlugin.class, "ERR_CannotRenameFile")).format(new Object JavaDoc[] {r.getNameExt()});
175     }
176     
177     public Problem fastCheckParameters() {
178         CompilationInfo info = refactoring.getContext().lookup(CompilationInfo.class);
179         Element el = treePathHandle.resolveElement(info);
180         ElementKind kind = el.getKind();
181         
182         String JavaDoc newName = refactoring.getNewName();
183         Problem result = null;
184         String JavaDoc oldName = el.getSimpleName().toString();
185         
186         if (oldName.equals(newName)) {
187             boolean nameNotChanged = true;
188             if (el.getKind().isClass()) {
189                 // Object comp = jmiObject.refImmediateComposite();
190
// if (comp instanceof Resource && isResourceClass((Resource)comp, jmiObject)) {
191
// String dobjName = JavaMetamodel.getManager().getDataObject((Resource)comp).getName();
192
// nameNotChanged = dobjName.equals(newName);
193
// }
194
}
195             if (nameNotChanged)
196                 return createProblem(result, true, getString("ERR_NameNotChanged"));
197         }
198         
199         if (!Utilities.isJavaIdentifier(newName)) {
200             String JavaDoc s = kind == ElementKind.PACKAGE? getString("ERR_InvalidPackage"):getString("ERR_InvalidIdentifier"); //NOI18N
201
String JavaDoc msg = new MessageFormat JavaDoc(s).format(
202                     new Object JavaDoc[] {newName}
203             );
204             result = createProblem(result, true, msg);
205             return result;
206         }
207         
208         if (kind.isClass()) {
209             if (doCheckName) {
210                 TypeElement type = (TypeElement) el;
211                 String JavaDoc oldfqn = type.getQualifiedName().toString();
212                 String JavaDoc newFqn = oldfqn.substring(0, oldfqn.lastIndexOf(type.getSimpleName().toString()));
213                 
214                 String JavaDoc pkgname = type.getQualifiedName().toString();
215                 int i = pkgname.indexOf('.');
216                 if (i>=0)
217                     pkgname = pkgname.substring(0,i);
218                 else
219                     pkgname = "";
220                 
221                 String JavaDoc fqn = "".equals(pkgname) ? newName : pkgname + '.' + newName;
222                 FileObject fo = treePathHandle.getFileObject();
223                 ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
224                 if (info.getElements().getTypeElement(newFqn)!=null) {
225                     String JavaDoc msg = new MessageFormat JavaDoc(getString("ERR_ClassClash")).format(
226                             new Object JavaDoc[] {newName, pkgname}
227                     );
228                     return createProblem(result, true, msg);
229                 }
230             }
231             FileObject primFile = treePathHandle.getFileObject();
232             FileObject folder = primFile.getParent();
233             FileObject[] children = folder.getChildren();
234             for (int x = 0; x < children.length; x++) {
235                 if (children[x] != primFile && !children[x].isVirtual() && children[x].getName().equals(newName) && "java".equals(children[x].getExt())) { //NOI18N
236
String JavaDoc msg = new MessageFormat JavaDoc(getString("ERR_ClassClash")).format(
237                             new Object JavaDoc[] {newName, folder.getPath()}
238                     );
239                     result = createProblem(result, true, msg);
240                     break;
241                 }
242             } // for
243

244             if (kind == ElementKind.LOCAL_VARIABLE || kind == ElementKind.PARAMETER) {
245                 // String msg = variableClashes(newName,JavaModelUtil.getDeclaringFeature((Variable) jmiObject));
246
// if (msg != null) {
247
// result = createProblem(result, true, msg);
248
// return result;
249
// }
250
}
251             if (kind.isField() || kind == kind.METHOD) {
252                 // String msg = clashes((Feature) jmiObject, newName);
253
// if (msg != null) {
254
// result = createProblem(result, true, msg);
255
// return result;
256
// }
257
}
258         }
259         return result;
260     }
261     
262     public Problem checkParameters() {
263         int steps = 0;
264         if (overriddenByMethods != null)
265             steps += overriddenByMethods.size();
266         if (overridesMethods != null)
267             steps += overridesMethods.size();
268         
269         CompilationInfo info = refactoring.getContext().lookup(CompilationInfo.class);
270         Element element = treePathHandle.resolveElement(info);
271         
272         Problem result = null;
273         fireProgressListenerStart(refactoring.PARAMETERS_CHECK, 8 + 3*steps);
274         
275         try {
276             fireProgressListenerStep();
277             fireProgressListenerStep();
278             String JavaDoc msg;
279             if (element.getKind() == ElementKind.METHOD) {
280                 // result = checkMethodForOverriding(m, newName, result);
281
// for (Iterator iter = overridesMethods.iterator(); iter.hasNext();) {
282
// m = (Method) iter.next();
283
// msg = clashes(m, newName);
284
// if (msg != null) {
285
// result = createProblem(result, true, msg);
286
// }
287
// result = checkMethodForOverriding(m, newName, result);
288
// }
289
// for (Iterator iter = overriddenByMethods.iterator(); iter.hasNext();) {
290
// m = (Method) iter.next();
291
// msg = clashes(m, newName);
292
// if (msg != null) {
293
// result = createProblem(result, true, msg);
294
// }
295
// result = checkMethodForOverriding(m, newName, result);
296
// }
297
fireProgressListenerStep();
298                 fireProgressListenerStep();
299             } else if (element.getKind().isField()) {
300                 fireProgressListenerStep();
301                 fireProgressListenerStep();
302                 Element hiddenField = hides(element, refactoring.getNewName(), info);
303                 fireProgressListenerStep();
304                 fireProgressListenerStep();
305                 fireProgressListenerStep();
306                 if (hiddenField != null) {
307                     msg = new MessageFormat JavaDoc(getString("ERR_WillHide")).format(
308                             new Object JavaDoc[] {SourceUtils.getEnclosingTypeElement(element).toString()}
309                     );
310                     result = createProblem(result, false, msg);
311                 }
312             }
313             
314             return result;
315         } finally {
316             fireProgressListenerStop();
317         }
318     }
319     
320     // private Problem checkMethodForOverriding(ExecutableElement m, String newName, Problem problem) {
321
// List argTypes = getParamTypes(m);
322
// fireProgressListenerStep();
323
// problem = willBeOverridden(m, newName, argTypes, problem);
324
// fireProgressListenerStep();
325
// problem = willOverride(m, newName, argTypes, problem);
326
// fireProgressListenerStep();
327
// return problem;
328
// }
329

330     private Set<FileObject> getRelevantFiles(CompilationInfo info, Element el) {
331         ClasspathInfo cpInfo = refactoring.getContext().lookup(ClasspathInfo.class);
332         ClassIndex idx = cpInfo.getClassIndex();
333         Set<FileObject> set = new HashSet<FileObject>();
334         set.add(SourceUtils.getFile(el, cpInfo));
335         if (el.getKind().isField()) {
336             set.addAll(idx.getResources(ElementHandle.create((TypeElement)el.getEnclosingElement()), EnumSet.of(ClassIndex.SearchKind.FIELD_REFERENCES), EnumSet.of(ClassIndex.SearchScope.SOURCE)));
337         } else if (el instanceof TypeElement) {
338             set.addAll(idx.getResources(ElementHandle.create((TypeElement) el), EnumSet.of(ClassIndex.SearchKind.TYPE_REFERENCES, ClassIndex.SearchKind.IMPLEMENTORS),EnumSet.of(ClassIndex.SearchScope.SOURCE)));
339         } else if (el.getKind() == ElementKind.METHOD) {
340             //XXX: IMPLEMENTORS_RECURSIVE was removed
341
Set<ElementHandle<TypeElement>> s = idx.getElements(ElementHandle.create((TypeElement) el.getEnclosingElement()), EnumSet.of(ClassIndex.SearchKind.IMPLEMENTORS),EnumSet.of(ClassIndex.SearchScope.SOURCE));
342             for (ElementHandle<TypeElement> eh:s) {
343                 TypeElement te = eh.resolve(info);
344                 if (te==null) {
345                     continue;
346                 }
347                 for (Element e:te.getEnclosedElements()) {
348                     if (e instanceof ExecutableElement) {
349                         if (info.getElements().overrides((ExecutableElement)e, (ExecutableElement)el, te)) {
350                             set.addAll(idx.getResources(ElementHandle.create(te), EnumSet.of(ClassIndex.SearchKind.METHOD_REFERENCES),EnumSet.of(ClassIndex.SearchScope.SOURCE)));
351                         }
352                     }
353                 }
354             }
355             set.addAll(idx.getResources(ElementHandle.create((TypeElement) el.getEnclosingElement()), EnumSet.of(ClassIndex.SearchKind.METHOD_REFERENCES),EnumSet.of(ClassIndex.SearchScope.SOURCE))); //?????
356
}
357         return set;
358     }
359     
360     private ClasspathInfo getClasspathInfo(CompilationInfo info) {
361         ClassPath boot = info.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT);
362         FileObject fo = treePathHandle.getFileObject();
363         ClassPath rcp = RefactoringClassPathImplementation.getCustom(Collections.singleton(fo));
364         ClasspathInfo cpi = ClasspathInfo.create(boot, rcp, rcp);
365         return cpi;
366     }
367     
368     public Problem prepare(RefactoringElementsBag elements) {
369         ClasspathInfo cpInfo = refactoring.getContext().lookup(ClasspathInfo.class);
370         final CompilationInfo mainInfo = refactoring.getContext().lookup(CompilationInfo.class);
371         final Element element = treePathHandle.resolveElement(mainInfo);
372         
373         if (cpInfo==null) {
374             cpInfo = getClasspathInfo(mainInfo);
375             refactoring.getContext().add(cpInfo);
376         }
377         
378         Set<FileObject> a = getRelevantFiles(mainInfo, element);
379         fireProgressListenerStart(ProgressEvent.START, a.size());
380         if (!a.isEmpty()) {
381             final Collection<ModificationResult> results = processFiles(a, new FindTask(elements, element));
382             elements.registerTransaction(new RetoucheCommit(results));
383             for (ModificationResult result:results) {
384                 for (FileObject jfo : result.getModifiedFileObjects()) {
385                     for (Difference dif: result.getDifferences(jfo)) {
386                         String JavaDoc old = dif.getOldText();
387                         if (old!=null) {
388                             //TODO: workaround
389
//generator issue?
390
elements.add(refactoring,DiffElement.create(dif, jfo, result));
391                         }
392                     }
393                 }
394             }
395         }
396         fireProgressListenerStop();
397         return null;
398         // varNames = null;
399
// CommentRenameFinder docFinder=null;
400
//
401
// if (newName == null) {
402
// return new Problem(true, getString("ERR_NameNotSet"));
403
// }
404
//
405
// int steps = 9;
406
// if (overriddenByMethods != null)
407
// steps += overriddenByMethods.size();
408
// if (overridesMethods != null)
409
// steps += overridesMethods.size();
410
//
411
// JavaMetamodel.getManager().getProgressSupport().addProgressListener(this);
412
//
413
//
414
// //fireProgressListenerStart(rename.PREPARE, steps);
415
//
416
// try {
417
// if (refactoring.isSearchInComments()) {
418
// docFinder=new CommentRenameFinder((Element)jmiObject,newName);
419
// elements.addAll(refactoring, docFinder.searchCommentsInResource(((Element)jmiObject).getResource()));
420
// }
421
// if (jmiObject instanceof JavaPackage) {
422
// //fireProgressListenerStep();
423
//
424
// referencesIterator = ((NamedElement) jmiObject).getReferences().iterator();
425
// while (referencesIterator.hasNext()) {
426
// Element element = (Element) referencesIterator.next();
427
//
428
// if (cancelRequest) {
429
// return null;
430
// }
431
// if (refactoring.isSearchInComments()) {
432
// elements.addAll(refactoring, docFinder.searchCommentsInResource(element.getResource()));
433
// }
434
// elements.add(refactoring, new RenamePackageElement(jmiObject, element, newName));
435
// }
436
// DataFolder folder = originalFolder!=null ? DataFolder.findFolder(originalFolder) : getFolder(((JavaPackage)jmiObject).getName());
437
// if (folder != null) {
438
// elements.add(refactoring, new RenameDataFolder(folder, newName));
439
// }
440
// return null;
441
// } else {
442
// //fireProgressListenerStep();
443
// addElementsForJmiObject(elements, jmiObject, docFinder);
444
//
445
//
446
// if (overridesMethods != null) {
447
// for (Iterator iter = overridesMethods.iterator(); iter.hasNext();) {
448
// if (cancelRequest) {
449
// return null;
450
// }
451
// //fireProgressListenerStep();
452
// Method m = (Method) iter.next();
453
// if (m.getResource().getName().endsWith(".class")) {
454
// return resourceNotAvailable(m);
455
// }
456
// elements.add(refactoring, new RenameDOElement(m));
457
// //addElementsForJmiObject(elements, (RefObject) iter.next());
458
// }
459
// }
460
// if (overriddenByMethods != null) {
461
// for (Iterator iter = overriddenByMethods.iterator(); iter.hasNext();) {
462
// if (cancelRequest) {
463
// return null;
464
// }
465
// Method m = (Method) iter.next();
466
// if (m.getResource().getName().endsWith(".class")) {
467
// return resourceNotAvailable(m);
468
// }
469
// //fireProgressListenerStep();
470
// elements.add(refactoring, new RenameDOElement(m));
471
// //addElementsForJmiObject(elements, (RefObject) iter.next());
472
// }
473
// }
474
// return null;
475
// }
476
// } finally {
477
// referencesIterator = null;
478
// JavaMetamodel.getManager().getProgressSupport().removeProgressListener(this);
479
// }
480
}
481     
482     // private static Problem resourceNotAvailable(Method m) {
483
// String resourceName = Utilities.replaceString(m.getResource().getName(), ".class", ".java"); //NOI18N
484
// return new Problem(true, new MessageFormat(getString("ERR_ResourceUnavailable")).format (new Object[] {m.getName(), resourceName}));
485
// }
486
//
487
// private void addElementsForJmiObject(RefactoringElementsBag elements, RefObject refObject, CommentRenameFinder docFinder) {
488
// elements.add(refactoring, new RenameDOElement(refObject));
489
// if (refObject instanceof Method) {
490
// referencesIterator = ((MethodImpl) refObject).findDependencies(true, true, false).iterator();
491
// } else {
492
// referencesIterator = ((NamedElement) refObject).getReferences().iterator();
493
// }
494
// while (referencesIterator.hasNext()) {
495
// Element element = (Element) referencesIterator.next();
496
//
497
// if (cancelRequest) {
498
// return;
499
// }
500
// if (refactoring.isSearchInComments()) {
501
// elements.addAll(refactoring, docFinder.searchCommentsInResource(element.getResource()));
502
// }
503
// String name = newName;
504
// if (jmiObject instanceof Field) {
505
// Feature f = JavaModelUtil.getDeclaringFeature(element);
506
// if (((VariableAccess)element).getParentClass()==null && variableClashes(newName,f)!=null) {
507
// ClassDefinition decl = ((Field)jmiObject).getDeclaringClass() ;
508
// if (f.getDeclaringClass().equals(decl)) {
509
// name = "this." + newName; //NOI18N
510
// } else {
511
// if (decl instanceof NamedElement)
512
// name = ((NamedElement) decl).getName() + ".this." + newName; //NOI18N
513
// }
514
// }
515
// }
516
// elements.add(refactoring, new RenameUsageElement(refObject, element, name));
517
// }
518
// }
519
//
520
// private DataFolder getFolder(String name) {
521
// FileObject fo = RefactoringClassPathImplementation.getDefault().findResource(name.replace('.','/'));
522
// if (fo == null)
523
// return null;
524
// return DataFolder.findFolder(fo);
525
// }
526
//
527
// private Collection overriddenBy(Method method, String name, List argTypes) {
528
// if (!CheckUtils.isVirtual(method))
529
// return Collections.EMPTY_LIST;
530
//
531
// return ((MethodImpl) method).findDependencies(false, false, true);
532
// }
533
//
534
// private Collection overrides(Method method, String name, List argTypes, ClassDefinition[] cls_par) {
535
// if (!CheckUtils.isVirtual(method))
536
// return Collections.EMPTY_LIST;
537
//
538
// ClassDefinition javaClass = method.getDeclaringClass ();
539
// LinkedList supertypes = new LinkedList ();
540
// Collection result = new HashSet();
541
// Method last = null;
542
//
543
// supertypes.addAll (javaClass.getInterfaces());
544
// ClassDefinition jc = javaClass.getSuperClass ();
545
// if (jc != null)
546
// supertypes.add (jc);
547
// while (supertypes.size () > 0) {
548
// jc = (ClassDefinition) supertypes.removeFirst ();
549
// if (jc instanceof UnresolvedClass) {
550
// continue;
551
// }
552
// Method m = jc.getMethod (name, argTypes, false);
553
// if ((m != null) && CheckUtils.isVirtual(m)) {
554
// result.add(m);
555
// last = m;
556
// }
557
// supertypes.addAll (jc.getInterfaces ());
558
// jc = jc.getSuperClass ();
559
// if (jc != null) {
560
// supertypes.add (jc);
561
// }
562
// }
563
//
564
// if (last != null) {
565
// ClassDefinition cd = last.getDeclaringClass();
566
// ClassDefinition implementor = findDifferentSubtype((JavaClass) cd, name, argTypes, javaClass);
567
// if (implementor != null) {
568
// cls_par[0] = cd;
569
// cls_par[1] = implementor;
570
// }
571
// }
572
// return result;
573
// }
574
//
575
// private ClassDefinition findDifferentSubtype(JavaClass baseClass, String name, List argTypes, ClassDefinition subtype) {
576
// Set supertypes = new HashSet();
577
// LinkedList subtypes = new LinkedList();
578
// ClassDefinition jc = baseClass;
579
//
580
// collectSupertypes(supertypes, subtype);
581
// addSubtypes(jc, subtypes);
582
// while (subtypes.size() > 0) {
583
// jc = (ClassDefinition) subtypes.removeFirst();
584
// if (jc instanceof UnresolvedClass) {
585
// continue;
586
// }
587
// if (supertypes.contains(jc)) {
588
// continue;
589
// } else if (jc.getMethod(name, argTypes, false) != null) {
590
// return jc;
591
// }
592
// addSubtypes(jc, subtypes);
593
// }
594
// return null;
595
// }
596
//
597
// private void collectSupertypes(Set supertypes, ClassDefinition jc) {
598
// if (jc == null)
599
// return;
600
// supertypes.add(jc);
601
// collectSupertypes(supertypes, jc.getSuperClass());
602
// for (Iterator iter = jc.getInterfaces().iterator(); iter.hasNext();) {
603
// collectSupertypes(supertypes, (ClassDefinition)iter.next());
604
// }
605
// }
606
//
607
// private boolean isStatic(Feature feature) {
608
// return (feature.getModifiers () & Modifier.STATIC) > 0;
609
// }
610
//
611
// private int getAccessLevel(Feature f) {
612
// int mod = f.getModifiers();
613
// if ((mod & Modifier.PUBLIC) > 0)
614
// return 3;
615
// if ((mod & Modifier.PROTECTED) > 0)
616
// return 2;
617
// if ((mod & Modifier.PRIVATE) > 0)
618
// return 0;
619
// return 1;
620
// }
621
//
622
// private Method isOverridden(Method method, String name, List argTypes) {
623
// if (!CheckUtils.isVirtual(method))
624
// return null;
625
//
626
// ClassDefinition jc = method.getDeclaringClass();
627
// LinkedList subtypes = new LinkedList();
628
// addSubtypes(jc, subtypes);
629
// while (subtypes.size() > 0) {
630
// jc = (ClassDefinition) subtypes.removeFirst();
631
// if (jc instanceof UnresolvedClass) {
632
// continue;
633
// }
634
// Method m = jc.getMethod(name, argTypes, false);
635
// if ((m != null) && CheckUtils.isVirtual(m))
636
// return m;
637
// addSubtypes(jc, subtypes);
638
// }
639
// return null;
640
// }
641
//
642
// private Problem willBeOverridden(Method method, String name, List argTypes, Problem problem) {
643
// int accessLevel = getAccessLevel(method);
644
// if (accessLevel == 0)
645
// return null;
646
//
647
// boolean isStatic = isStatic(method);
648
// boolean isFinal = (method.getModifiers() & Modifier.FINAL) > 0;
649
// Method temp = null;
650
// ClassDefinition jc = method.getDeclaringClass();
651
// LinkedList subtypes = new LinkedList();
652
// addSubtypes(jc, subtypes);
653
// while (subtypes.size() > 0) {
654
// jc = (ClassDefinition) subtypes.removeFirst();
655
// if (jc instanceof UnresolvedClass) {
656
// continue;
657
// }
658
// Method m = jc.getMethod(name, argTypes, false);
659
// if (m != null) {
660
// if (temp == null)
661
// temp = m;
662
// if (isFinal) {
663
// String msg = new MessageFormat(getString("ERR_WillBeOverridden_final")).format(
664
// new Object[] {
665
// method.getName(),
666
// getDefClassName(method.getDeclaringClass()),
667
// m.getName(),
668
// getDefClassName(m.getDeclaringClass())
669
// }
670
// );
671
// return createProblem(problem, true, msg);
672
// }
673
// if (getAccessLevel(m) < accessLevel) {
674
// String msg = new MessageFormat(getString("ERR_WillBeOverridden_access")).format(
675
// new Object[] {
676
// method.getName(),
677
// getDefClassName(method.getDeclaringClass()),
678
// m.getName(),
679
// getDefClassName(m.getDeclaringClass())
680
// }
681
// );
682
// return createProblem(problem, true, msg);
683
// }
684
// if (isStatic != isStatic(m)) {
685
// String msg = new MessageFormat(getString("ERR_WillBeOverridden_static")).format(
686
// new Object[] {
687
// isStatic ? getString("LBL_static") : getString("LBL_instance"),
688
// method.getName(),
689
// getDefClassName(method.getDeclaringClass()),
690
// isStatic(m) ? getString("LBL_static") : getString("LBL_instance"),
691
// m.getName(),
692
// getDefClassName(m.getDeclaringClass())
693
// }
694
// );
695
// return createProblem(problem, true, msg);
696
// }
697
// } else {
698
// addSubtypes(jc, subtypes);
699
// }
700
// }
701
// if (temp != null) {
702
// String msg = new MessageFormat(getString("ERR_WillBeOverridden")).format(
703
// new Object[] {
704
// method.getName(),
705
// getDefClassName(method.getDeclaringClass()),
706
// temp.getName(),
707
// getDefClassName(temp.getDeclaringClass())
708
// }
709
// );
710
// return createProblem(problem, false, msg);
711
// } else {
712
// return problem;
713
// }
714
// }
715
//
716
// private Problem willOverride(Method method, String name, List argTypes, Problem problem) {
717
// int accessLevel = getAccessLevel(method);
718
// boolean isStatic = isStatic(method);
719
// Method temp = null;
720
// ClassDefinition jc = method.getDeclaringClass ();
721
// LinkedList supertypes = new LinkedList ();
722
//
723
// supertypes.addAll (jc.getInterfaces());
724
// jc = jc.getSuperClass ();
725
// if (jc != null)
726
// supertypes.add (jc);
727
// while (supertypes.size () > 0) {
728
// jc = (ClassDefinition) supertypes.removeFirst ();
729
// if (jc instanceof UnresolvedClass) {
730
// continue;
731
// }
732
// Method m = jc.getMethod (name, argTypes, false);
733
// if (m != null) {
734
// if (temp == null)
735
// temp = m;
736
// if ((m.getModifiers() & Modifier.FINAL) > 0) {
737
// String msg = new MessageFormat(getString("ERR_WillOverride_final")).format(
738
// new Object[] {
739
// method.getName(),
740
// getDefClassName(method.getDeclaringClass()),
741
// m.getName(),
742
// getDefClassName(m.getDeclaringClass())
743
// }
744
// );
745
// return createProblem(problem, true, msg);
746
// }
747
// if (getAccessLevel(m) > accessLevel) {
748
// String msg = new MessageFormat(getString("ERR_WillOverride_access")).format(
749
// new Object[] {
750
// method.getName(),
751
// getDefClassName(method.getDeclaringClass()),
752
// m.getName(),
753
// getDefClassName(m.getDeclaringClass())
754
// }
755
// );
756
// return createProblem(problem, true, msg);
757
// }
758
// if (isStatic != isStatic(m)) {
759
// String msg = new MessageFormat(getString("ERR_WillOverride_static")).format(
760
// new Object[] {
761
// isStatic ? getString("LBL_static") : getString("LBL_instance"),
762
// method.getName(),
763
// getDefClassName(method.getDeclaringClass()),
764
// isStatic(m) ? getString("LBL_static") : getString("LBL_instance"),
765
// m.getName(),
766
// getDefClassName(m.getDeclaringClass())
767
// }
768
// );
769
// return createProblem(problem, true, msg);
770
// }
771
// } else {
772
// supertypes.addAll (jc.getInterfaces ());
773
// jc = jc.getSuperClass ();
774
// if (jc != null)
775
// supertypes.add (jc);
776
// }
777
// } // while
778
// if (temp != null) {
779
// String msg = new MessageFormat(getString("ERR_WillOverride")).format(
780
// new Object[] {
781
// method.getName(),
782
// getDefClassName(method.getDeclaringClass()),
783
// temp.getName(),
784
// getDefClassName(temp.getDeclaringClass())
785
// }
786
// );
787
// return createProblem(problem, false, msg);
788
// } else {
789
// return problem;
790
// }
791
// }
792
//
793
// private Method overrides(Method method, String name, List argTypes, boolean findFinal) {
794
// Method res = null;
795
// if (!CheckUtils.isVirtual(method))
796
// return null;
797
//
798
// ClassDefinition jc = method.getDeclaringClass ();
799
// LinkedList supertypes = new LinkedList ();
800
//
801
// supertypes.addAll (jc.getInterfaces());
802
// jc = jc.getSuperClass ();
803
// if (jc != null)
804
// supertypes.add (jc);
805
// while (supertypes.size () > 0) {
806
// jc = (ClassDefinition) supertypes.removeFirst ();
807
// if (jc instanceof UnresolvedClass) {
808
// continue;
809
// }
810
// Method m = jc.getMethod (name, argTypes, false);
811
// if ((m != null) && CheckUtils.isVirtual(m)) {
812
// if ((m.getModifiers () & Modifier.FINAL) > 0) {
813
// res = m;
814
// break;
815
// } else if (res == null) {
816
// res = m;
817
// if (!findFinal)
818
// break;
819
// }
820
// }
821
// supertypes.addAll (jc.getInterfaces ());
822
// jc = jc.getSuperClass ();
823
// if (jc != null)
824
// supertypes.add (jc);
825
// }
826
// return res;
827
// }
828
//
829
private Element hides(Element field, String JavaDoc name, CompilationInfo info) {
830         TypeElement jc = SourceUtils.getEnclosingTypeElement(field);
831         Types types = info.getTypes();
832         Elements elements = info.getElements();
833         jc =(TypeElement) types.asElement(jc.getSuperclass());
834         while (jc != null) {
835             for (Element el : info.getElements().getAllMembers(jc)) {
836                 if (elements.hides(el, field)) {
837                     return el;
838                 }
839             }
840             jc =(TypeElement) types.asElement(jc.getSuperclass());
841         }
842         return null;
843     }
844     
845     // private String variableClashes(String newName, Feature scope) {
846
// if (varNames==null)
847
// varNames=CheckUtils.getAllVariableNames(scope);
848
// if (varNames.contains(newName)) {
849
// return new MessageFormat (getString ("ERR_LocVariableClash")).format (
850
// new Object[] {newName}
851
// );
852
// }
853
// return null;
854
// }
855
//
856
// private String clashes(Feature feature, String newName) {
857
// ClassDefinition dc = feature.getDeclaringClass ();
858
// if (feature instanceof TypeParameter) {
859
// // TODO: any check?
860
// } else if (feature instanceof JavaClass) {
861
// if (dc != null) {
862
// String result = checkInnersForClash(newName, dc);
863
// if (result != null)
864
// return result;
865
// } else {
866
// Element composite = (Element) feature.refImmediateComposite();
867
// if (composite instanceof Resource) {
868
// Resource resource = (Resource)composite;
869
// DataObject dobj = JavaMetamodel.getManager().getDataObject(resource);
870
// FileObject primFile = dobj.getPrimaryFile();
871
// FileObject folder = primFile.getParent();
872
// FileObject[] children = folder.getChildren();
873
// for (int x = 0; x < children.length; x++) {
874
// if (children[x] != primFile && !children[x].isVirtual() && children[x].getName().equals(newName) && "java".equals(children[x].getExt())) { //NOI18N
875
// return new MessageFormat(getString("ERR_ClassClash")).format(
876
// new Object[] {newName, resource.getPackageName()}
877
// );
878
// }
879
// }
880
// }
881
// }
882
// } else if (feature instanceof Method) {
883
// List params = getParamTypes ((Method) feature);
884
// if (dc.getMethod(newName, params, false) != null) {
885
// return new MessageFormat (getString ("ERR_MethodClash")).format (
886
// new Object[] {newName, getDefClassName(dc)}
887
// );
888
// } // if
889
// } else if (feature instanceof Field) {
890
// if (dc.getField(newName, false) != null) {
891
// return new MessageFormat (getString ("ERR_FieldClash")).format (
892
// new Object[] {newName, getDefClassName(dc)}
893
// );
894
// } // if
895
// }
896
// return null;
897
// }
898
//
899
// private String checkInnersForClash(final String newName, final ClassDefinition dc) {
900
// Iterator iter = dc.getFeatures ().iterator ();
901
// while (iter.hasNext ()) {
902
// Object obj = iter.next();
903
// if (!(obj instanceof JavaClass))
904
// continue;
905
// JavaClass nestedClass = (JavaClass) obj;
906
// if (nestedClass.getSimpleName ().equals (newName)) {
907
// return new MessageFormat (getString ("ERR_InnerClassClash")).format (
908
// new Object[] {newName, getDefClassName(dc)}
909
// );
910
// }
911
// } // while
912
// return null;
913
// }
914
//
915
// String getElementName(NamedElement elem) {
916
// if (elem instanceof JavaClass) {
917
// return ((JavaClass) elem).getSimpleName();
918
// } else {
919
// return elem.getName();
920
// }
921
// }
922
//
923
// String getDefClassName(ClassDefinition cd) {
924
// if (cd instanceof JavaClass) {
925
// return ((JavaClass) cd).getName();
926
// } else {
927
// return "";
928
// }
929
// }
930
//
931
// private List getParamTypes(Method method) {
932
// List types = new LinkedList ();
933
// Iterator iter = method.getParameters ().iterator ();
934
// while (iter.hasNext ())
935
// types.add (getRealType(((Parameter) iter.next ()).getType ()));
936
// return types;
937
// }
938
//
939
// private static Type getRealType(Type type) {
940
// if (type instanceof ParameterizedType) {
941
// return ((ParameterizedType) type).getDefinition();
942
// }
943
// return type;
944
// }
945
//
946
// /**
947
// * Tests, if the renamed object should cause resource rename. Checks
948
// * if the object is java class. Then it checks for resource. If the
949
// * resource exists and resource name is the same as the name of class
950
// * is the same as the name of resource, it returns true. In all other
951
// * cases it returns false.
952
// *
953
// * @return true, if the renamed object should cause resource rename
954
// */
955
// static boolean isResourceClass(Resource res, RefObject refObject) { //todo (#pf): try to find out better name for this method.
956
// if (res == null || !(refObject instanceof JavaClass))
957
// return false;
958
// int classCount = 0;
959
// for (Iterator iter = res.getClassifiers().iterator(); iter.hasNext(); ) {
960
// if (iter.next() instanceof JavaClass) {
961
// classCount++;
962
// }
963
// }
964
// if (classCount == 1) {
965
// return true;
966
// }
967
// String relativeResName = res.getName();
968
// String javaClassName = ((JavaClass) refObject).getSimpleName();
969
// int begin = relativeResName.lastIndexOf('/') + 1;
970
// if (begin < 0) begin = 0;
971
// int end = relativeResName.lastIndexOf('.');
972
// if (javaClassName.equals(relativeResName.substring(begin, end)))
973
// return true;
974
// else
975
// return false;
976
// }
977
//
978
// private void addSubtypes(ClassDefinition cd, List list) {
979
// if (!(cd instanceof JavaClass)) {
980
// return;
981
// }
982
// JavaClass jc = (JavaClass) cd;
983
// Collection subtypes = null;
984
// if (jc.isInterface()) {
985
// subtypes = jc.getImplementors();
986
// } else {
987
// subtypes = jc.getSubClasses();
988
// }
989
// list.addAll(subtypes);
990
// }
991
//
992
private static final String JavaDoc getString(String JavaDoc key) {
993         return NbBundle.getMessage(RenameRefactoringPlugin.class, key);
994     }
995     
996     // public void start(org.netbeans.modules.javacore.internalapi.ProgressEvent event) {
997
// fireProgressListenerStart(event.getOperationType(), event.getCount());
998
// }
999
//
1000
// public void step(org.netbeans.modules.javacore.internalapi.ProgressEvent event) {
1001
// fireProgressListenerStep();
1002
// }
1003
//
1004
// public void stop(org.netbeans.modules.javacore.internalapi.ProgressEvent event) {
1005
// fireProgressListenerStop();
1006
// }
1007

1008    // public void setClassPath() {
1009
// if (NbAbstractRefactoring.isElementAvail((Element) jmiObject) == null && (jmiObject instanceof Method)) {
1010
// Collection c = ((MethodImpl) jmiObject).getOverridenMethods();
1011
// if (!c.isEmpty()) {
1012
// setClassPath(c);
1013
// return;
1014
// }
1015
// }
1016
// setClassPath((Element) jmiObject);
1017
// }
1018

1019    // RenameDOElement ..........................................................
1020
// private class RenameDOElement extends SimpleRefactoringElementImpl implements ExternalChange {
1021
// private final String text;
1022
// private PositionBounds bounds = null;
1023
// private String oldName = null;
1024
// private Resource res = null;
1025
// private RefObject refObject;
1026
//
1027
// public RenameDOElement(RefObject refObject) {
1028
// this.refObject = refObject;
1029
// Object o;
1030
// if (refObject instanceof Resource) {
1031
// o = refObject;
1032
// } else {
1033
// o = refObject.refImmediateComposite();
1034
// }
1035
// if (o instanceof Resource) res = (Resource) o;
1036
// String bundleName = null;
1037
// if (refObject instanceof Resource) {
1038
// bundleName = "LBL_RenameClassDO"; //NOI18N
1039
// } else if (refObject instanceof JavaEnum) {
1040
// bundleName = "LBL_RenameEnum"; // NOI18N
1041
// } else if (refObject instanceof AnnotationType) {
1042
// bundleName = "LBL_RenameAnnotationType"; // NOI18N
1043
// } else if (refObject instanceof TypeParameter) {
1044
// bundleName = "LBL_RenameTypeParameter"; // NOI18N
1045
// } else if (refObject instanceof JavaClass) {
1046
// bundleName = isResourceClass() ? "LBL_RenameClassDO" : "LBL_RenameClass"; //NOI18N
1047
// } else if (refObject instanceof Method) {
1048
// bundleName = "LBL_RenameMethod"; //NOI18N
1049
// } else if (refObject instanceof Field) {
1050
// bundleName ="LBL_RenameField"; //NOI18N
1051
// } else if (refObject instanceof Parameter) {
1052
// bundleName = "LBL_RenameParameter"; // NOI18N
1053
// } else if (refObject instanceof LocalVariable) {
1054
// bundleName = "LBL_RenameLocVariable"; // NOI18N
1055
// } else if (refObject instanceof Attribute) {
1056
// bundleName = "LBL_RenameAttribute"; // NOI18N
1057
// } else {
1058
// assert false:"Invalid type "+refObject.getClass(); // NOI18N
1059
// }
1060
// text = MessageFormat.format(NbBundle.getMessage(RenameRefactoring.class, bundleName), new Object[] {newName});
1061
// }
1062
//
1063
// private boolean isResourceClass() {
1064
// return RenameRefactoringPlugin.isResourceClass(res, refObject);
1065
// }
1066
//
1067
// public String getDisplayText() {
1068
// return text;
1069
// }
1070
//
1071
// public Element getJavaElement() {
1072
// return (Element) refObject;
1073
// }
1074
//
1075
// public PositionBounds getPosition() {
1076
// if (bounds == null) {
1077
// if (!(refObject instanceof Resource)) {
1078
// bounds = JavaMetamodel.getManager().getElementPosition((Element)refObject);
1079
// }
1080
// }
1081
// return bounds;
1082
// }
1083
//
1084
// public String getText() {
1085
// return getDisplayText();
1086
// }
1087
//
1088
// public void performChange() {
1089
// if (refObject instanceof Resource) {
1090
// JavaMetamodel.getManager().registerExtChange(this);
1091
// } else {
1092
// NamedElement obj = (NamedElement) refObject;
1093
// if (obj instanceof JavaClass) {
1094
// oldName = ((JavaClass) obj).getSimpleName();
1095
// if (isResourceClass()) {
1096
// JavaMetamodel.getManager().registerExtChange(this);
1097
// }
1098
// ((JavaClass) obj).setSimpleName(newName);
1099
// } else {
1100
// oldName = obj.getName();
1101
// obj.setName(newName);
1102
// }
1103
// }
1104
// }
1105
//
1106
// private void doRename() {
1107
// try {
1108
// DataObject dobj = JavaMetamodel.getManager().getDataObject(res);
1109
// oldName = dobj.getName();
1110
// dobj.rename(newName);
1111
// } catch (DataObjectNotFoundException e) {
1112
// throw (RuntimeException) new RuntimeException().initCause(e);
1113
// } catch (IOException e) {
1114
// throw (RuntimeException) new RuntimeException().initCause(e);
1115
// }
1116
// }
1117
//
1118
// public void performExternalChange () {
1119
// doRename();
1120
// }
1121
//
1122
// public void undoExternalChange() {
1123
// if (oldName == null) return;
1124
// String temp = newName;
1125
// newName = oldName;
1126
// oldName = temp;
1127
// doRename();
1128
// newName = temp;
1129
// }
1130
//
1131
// public FileObject getParentFile() {
1132
// return null;
1133
// }
1134
// } // RenameDOElement
1135
//
1136
// // RenamePackageElement ..........................................................
1137
// private class RenamePackageElement extends RenameUsageElement {
1138
// private String oldName = null;
1139
//
1140
// public RenamePackageElement(RefObject jmiObject, Element feature, String newName) {
1141
// super(jmiObject, feature, newName);
1142
// }
1143
//
1144
// public void performChange() {
1145
// MultipartId mpi = (MultipartId) feature;
1146
// oldName = mpi.getName();
1147
// mpi.setName(newName);
1148
// }
1149
//
1150
// } // RenamePackageElement
1151
//
1152
// // RenameDataFolder ..........................................................
1153
// private class RenameDataFolder extends SimpleRefactoringElementImpl implements RefactoringElementImplementation, ExternalChange {
1154
// private final String text;
1155
// private PositionBounds bounds;
1156
// private String oldName, newName;
1157
// private DataFolder folder;
1158
//
1159
// public RenameDataFolder(DataFolder folder, String name) {
1160
// newName = name;
1161
// this.folder = folder;
1162
// text = MessageFormat.format(NbBundle.getMessage(RenameRefactoring.class, "LBL_RenameFolder"), new Object[] {folder.getName(), newName});
1163
// }
1164
//
1165
// public String getDisplayText() {
1166
// return text;
1167
// }
1168
//
1169
// public Element getJavaElement() {
1170
// return (Element) jmiObject;
1171
// }
1172
//
1173
// public PositionBounds getPosition() {
1174
// if (bounds == null) {
1175
// bounds = JavaMetamodel.getManager().getElementPosition((Element)jmiObject);
1176
// }
1177
// return bounds;
1178
// }
1179
//
1180
//
1181
// public String getText() {
1182
// return getDisplayText();
1183
// }
1184
//
1185
// public void performChange() {
1186
// JavaMetamodel.getManager().registerExtChange(this);
1187
// }
1188
//
1189
// private void doRename() {
1190
// oldName = folder.getName();
1191
// try {
1192
// folder.rename(newName);
1193
// } catch (java.io.IOException e) {
1194
// throw (RuntimeException) new RuntimeException().initCause(e);
1195
// }
1196
// }
1197
//
1198
// public void performExternalChange () {
1199
// doRename();
1200
// }
1201
//
1202
// public void undoExternalChange() {
1203
// if (oldName == null) return;
1204
// String temp = newName;
1205
// newName = oldName;
1206
// oldName = temp;
1207
// doRename();
1208
// newName = temp;
1209
// }
1210
//
1211
// public FileObject getParentFile() {
1212
// return null;
1213
// }
1214
//
1215
// } // RenameDataFolder
1216

1217    private class FindTask implements CancellableTask<WorkingCopy> {
1218        
1219        private RefactoringElementsBag elements;
1220        private Element element;
1221        
1222        public FindTask(RefactoringElementsBag elements, Element element) {
1223            super();
1224            this.elements = elements;
1225            this.element = element;
1226        }
1227        
1228        public void cancel() {
1229        }
1230        
1231        public void run(WorkingCopy compiler) throws IOException JavaDoc {
1232            compiler.toPhase(JavaSource.Phase.RESOLVED);
1233            CompilationUnitTree cu = compiler.getCompilationUnit();
1234            if (cu == null) {
1235                ErrorManager.getDefault().log(ErrorManager.ERROR, "compiler.getCompilationUnit() is null " + compiler);
1236                return;
1237            }
1238            Element el = treePathHandle.resolveElement(compiler);
1239            assert el != null;
1240            
1241            RenameTransformer findVisitor = new RenameTransformer(refactoring.getNewName(), compiler);
1242            findVisitor.scan(compiler.getCompilationUnit(), el);
1243            
1244            for (TreePath tree : findVisitor.getUsages()) {
1245                ElementGripFactory.getDefault().put(compiler.getFileObject(), tree, compiler);
1246            }
1247            fireProgressListenerStep();
1248        }
1249    }
1250}
1251
Popular Tags