Skip to content

Commit 9272c55

Browse files
committed
Using sharp(er) classpath when rename refactoring.
1 parent b4c38d8 commit 9272c55

2 files changed

Lines changed: 8 additions & 27 deletions

File tree

java/refactoring.java/src/org/netbeans/modules/refactoring/java/plugins/RenameRefactoringPlugin.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,8 @@ protected JavaSource getJavaSource(Phase p) {
367367
if (treePathHandle == null && docTreePathHandle == null) {
368368
return null;
369369
}
370-
switch (p) {
371-
case PRECHECK:
372-
case FASTCHECKPARAMETERS:
373-
return JavaSource.forFileObject(docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
374-
: treePathHandle.getFileObject());
375-
case PREPARE:
376-
case CHECKPARAMETERS:
377-
if(treePathHandle != null && treePathHandle.getKind() == Tree.Kind.LABELED_STATEMENT) {
378-
return JavaSource.forFileObject(treePathHandle.getFileObject());
379-
}
380-
ClasspathInfo cpInfo = getClasspathInfo(refactoring);
381-
JavaSource source = JavaSource.create(cpInfo, docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
382-
: treePathHandle.getFileObject());
383-
return source;
384-
385-
}
386-
throw new IllegalStateException();
370+
return JavaSource.forFileObject(docTreePathHandle != null? docTreePathHandle.getTreePathHandle().getFileObject()
371+
: treePathHandle.getFileObject());
387372
}
388373

389374
@Override
@@ -408,16 +393,10 @@ private Set<FileObject> getRelevantFiles() {
408393
JavaSource source = getJavaSource(Phase.PREPARE);
409394

410395
try {
411-
source.runUserActionTask(new CancellableTask<CompilationController>() {
412-
413-
@Override
414-
public void cancel() {
415-
throw new UnsupportedOperationException("Not supported yet."); // NOI18N
416-
}
417-
396+
source.runUserActionTask(new Task<CompilationController>() {
418397
@Override
419398
public void run(CompilationController info) throws Exception {
420-
final ClassIndex idx = info.getClasspathInfo().getClassIndex();
399+
final ClassIndex idx = getClasspathInfo(refactoring).getClassIndex();
421400
info.toPhase(JavaSource.Phase.RESOLVED);
422401
Element el = docTreePathHandle != null? ((DocTrees)info.getTrees()).getElement(docTreePathHandle.resolve(info))
423402
: treePathHandle.resolveElement(info);
@@ -631,7 +610,7 @@ public Problem prepare(RefactoringElementsBag elements) {
631610
Set<FileObject> a = getRelevantFiles();
632611
fireProgressListenerStart(AbstractRefactoring.PREPARE, a.size());
633612
TransformTask transform = new TransformTask(new RenameTransformer(treePathHandle, docTreePathHandle, refactoring, allMethods, recordLinkedDeclarations, refactoring.isSearchInComments()), treePathHandle != null && treePathHandle.getKind() == Tree.Kind.LABELED_STATEMENT ? null : treePathHandle);
634-
Problem problem = createAndAddElements(a, transform, elements, refactoring,getClasspathInfo(refactoring));
613+
Problem problem = createAndAddElements(a, transform, elements, null);
635614
fireProgressListenerStop();
636615
return problem;
637616
}

java/refactoring.java/src/org/netbeans/modules/refactoring/java/spi/JavaRefactoringPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,15 @@ private Collection<ModificationResult> processFiles(Set<FileObject> sourceFiles,
268268
return results;
269269
}
270270

271-
private void processFiles(Map<FileObject, List<FileObject>> work, ClasspathInfo info, boolean modification, Collection<ModificationResult> results, CancellableTask<? extends CompilationController> task) throws IOException, IllegalArgumentException {
271+
//the meaning of overrideInfo (used to be info) is very unclear, and is suspicious. Possibly, it should be eliminated:
272+
private void processFiles(Map<FileObject, List<FileObject>> work, ClasspathInfo overrideInfo, boolean modification, Collection<ModificationResult> results, CancellableTask<? extends CompilationController> task) throws IOException, IllegalArgumentException {
272273
for (Map.Entry<FileObject, List<FileObject>> entry : work.entrySet()) {
273274
if (cancelRequested.get()) {
274275
results.clear();
275276
return;
276277
}
277278
final FileObject root = entry.getKey();
279+
ClasspathInfo info = overrideInfo;
278280
if (info == null) {
279281
ClassPath bootPath = ClassPath.getClassPath(root, ClassPath.BOOT);
280282
if (bootPath == null) {

0 commit comments

Comments
 (0)