Skip to content

Commit 29844be

Browse files
authored
Merge pull request #8679 from mbien/standalone-file-move-fix_delivery
Fix move/copy/rename/etc for standalone java files.
2 parents 1c2ffa1 + 94497af commit 29844be

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/api/SourceLauncher.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ public static boolean isSourceLauncherFile(FileObject file) {
5555
return msrp != null && msrp.isSourceLauncher(file);
5656
}
5757

58+
/**Returns {@code true} if and only if the given file is known as a
59+
* file that is handled by a source file launcher, for which index is created.
60+
*
61+
* @param file the file to test
62+
* @return {@code true} if and only if the file is known as a file handled by the
63+
* source launcher. {@code false} otherwise.
64+
*/
65+
public static boolean isIndexedSourceLauncherFile(FileObject file) {
66+
MultiSourceRootProvider msrp = Lookup.getDefault().lookup(MultiSourceRootProvider.class);
67+
return msrp != null && msrp.isRegisteredSourceLauncher(file);
68+
}
69+
5870
public static String joinCommandLines(Iterable<? extends String> inputLines) {
5971
Map<String, String> joinedOptions = new HashMap<>();
6072

java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ public boolean isSourceLauncher(FileObject file) {
230230
return getSourceRoot(file) != null;
231231
}
232232

233+
public boolean isRegisteredSourceLauncher(FileObject file) {
234+
FileObject root = getSourceRoot(file);
235+
236+
if (root == null) {
237+
return false;
238+
}
239+
240+
synchronized (registeredRoots) {
241+
return registeredRoots.contains(root);
242+
}
243+
}
244+
233245
private ClassPath getBootPath(FileObject file) {
234246
if (isSourceLauncher(file)) {
235247
return JavaPlatformManager.getDefault()

java/refactoring.java/src/org/netbeans/modules/refactoring/java/RefactoringUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static boolean isFileInOpenProject(FileObject file) {
305305
public static boolean isOnSourceClasspath(FileObject fo) {
306306
Project pr = FileOwnerQuery.getOwner(fo);
307307
if (pr == null) {
308-
return SourceLauncher.isSourceLauncherFile(fo);
308+
return isIndexedSourceLauncherFile(fo);
309309
}
310310

311311
//workaround for 143542
@@ -321,6 +321,11 @@ public static boolean isOnSourceClasspath(FileObject fo) {
321321
//return ClassPath.getClassPath(fo, ClassPath.SOURCE)!=null;
322322
}
323323

324+
public static boolean isIndexedSourceLauncherFile(FileObject fo) {
325+
// TODO: don't call from this module
326+
return SourceLauncher.isIndexedSourceLauncherFile(fo);
327+
}
328+
324329
/**
325330
* Is given file a root of source classpath?
326331
*

java/refactoring.java/src/org/netbeans/modules/refactoring/java/ui/RefactoringActionsProvider.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.openide.util.Lookup;
5050
import org.openide.util.NbBundle;
5151
import org.openide.util.datatransfer.PasteType;
52+
5253
import static org.netbeans.modules.refactoring.java.ui.Bundle.*;
5354

5455

@@ -185,7 +186,7 @@ public boolean canCopy(Lookup lookup) {
185186
if (!fo.isFolder()) {
186187
return false;
187188
}
188-
if (!JavaRefactoringUtils.isOnSourceClasspath(fo)) {
189+
if (!JavaRefactoringUtils.isOnSourceClasspath(fo) || RefactoringUtils.isIndexedSourceLauncherFile(fo)) {
189190
return false;
190191
}
191192
}
@@ -331,7 +332,7 @@ public boolean canMove(Lookup lookup) {
331332
if (!fo.isFolder()) {
332333
return false;
333334
}
334-
if (!JavaRefactoringUtils.isOnSourceClasspath(fo)) {
335+
if (!JavaRefactoringUtils.isOnSourceClasspath(fo) || RefactoringUtils.isIndexedSourceLauncherFile(fo)) {
335336
return false;
336337
}
337338

@@ -343,7 +344,8 @@ public boolean canMove(Lookup lookup) {
343344
if (dob==null) {
344345
return false;
345346
}
346-
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile())) {
347+
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile())
348+
|| RefactoringUtils.isIndexedSourceLauncherFile(dob.getPrimaryFile())) {
347349
return false;
348350
}
349351
if (dob instanceof DataFolder) {
@@ -380,7 +382,9 @@ public boolean canMove(Lookup lookup) {
380382
return false;
381383
} else {
382384
//Ctrl-X
383-
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile()) || RefactoringUtils.isClasspathRoot(dob.getPrimaryFile())) {
385+
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile())
386+
|| RefactoringUtils.isClasspathRoot(dob.getPrimaryFile())
387+
|| RefactoringUtils.isIndexedSourceLauncherFile(dob.getPrimaryFile())) {
384388
return false;
385389
} else {
386390
LinkedList<DataFolder> folders = new LinkedList<DataFolder>();
@@ -399,7 +403,8 @@ public boolean canMove(Lookup lookup) {
399403
}
400404
}
401405
}
402-
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile())) {
406+
if (!JavaRefactoringUtils.isOnSourceClasspath(dob.getPrimaryFile())
407+
|| RefactoringUtils.isIndexedSourceLauncherFile(dob.getPrimaryFile())) {
403408
return false;
404409
}
405410
if (RefactoringUtils.isJavaFile(dob.getPrimaryFile())) {

0 commit comments

Comments
 (0)