22
22
23
23
import java .io .IOException ;
24
24
import java .nio .file .Path ;
25
- import java .util .*;
25
+ import java .util .ArrayList ;
26
+ import java .util .Arrays ;
27
+ import java .util .Collections ;
28
+ import java .util .Iterator ;
29
+ import java .util .LinkedList ;
30
+ import java .util .List ;
26
31
import java .util .regex .Pattern ;
27
- import org .eclipse .core .filesystem .*;
32
+ import org .eclipse .core .filesystem .EFS ;
33
+ import org .eclipse .core .filesystem .IFileInfo ;
34
+ import org .eclipse .core .filesystem .IFileStore ;
35
+ import org .eclipse .core .filesystem .IFileTree ;
28
36
import org .eclipse .core .internal .refresh .RefreshJob ;
29
- import org .eclipse .core .internal .resources .*;
37
+ import org .eclipse .core .internal .resources .ICoreConstants ;
38
+ import org .eclipse .core .internal .resources .Resource ;
39
+ import org .eclipse .core .internal .resources .ResourceInfo ;
40
+ import org .eclipse .core .internal .resources .Workspace ;
30
41
import org .eclipse .core .resources .IContainer ;
31
42
import org .eclipse .core .resources .IResource ;
32
- import org .eclipse .core .runtime .*;
43
+ import org .eclipse .core .runtime .Assert ;
44
+ import org .eclipse .core .runtime .CoreException ;
45
+ import org .eclipse .core .runtime .IPath ;
46
+ import org .eclipse .core .runtime .Platform ;
33
47
import org .eclipse .core .runtime .jobs .Job ;
34
48
35
49
/**
@@ -43,16 +57,9 @@ public class UnifiedTree {
43
57
/** special node to mark the separation of a node's children */
44
58
protected static final UnifiedTreeNode childrenMarker = new UnifiedTreeNode (null , null , null , null , false );
45
59
46
- private static final Iterator <UnifiedTreeNode > EMPTY_ITERATOR = Collections .EMPTY_LIST .iterator ();
47
-
48
60
/** special node to mark the beginning of a level in the tree */
49
61
protected static final UnifiedTreeNode levelMarker = new UnifiedTreeNode (null , null , null , null , false );
50
62
51
- private static final IFileInfo [] NO_CHILDREN = {};
52
-
53
- /** Singleton to indicate no local children */
54
- private static final IResource [] NO_RESOURCES = {};
55
-
56
63
/**
57
64
* True if the level of the children of the current node are valid according
58
65
* to the requested refresh depth, false otherwise
@@ -145,7 +152,7 @@ protected void addChildren(UnifiedTreeNode node) {
145
152
146
153
// get the list of resources in the file system
147
154
// don't ask for local children if we know it doesn't exist locally
148
- IFileInfo [] list = node .existsInFileSystem () ? getLocalList (node ) : NO_CHILDREN ;
155
+ List < IFileInfo > list = node .existsInFileSystem () ? getLocalList (node ) : List . of () ;
149
156
int localIndex = 0 ;
150
157
151
158
// See if the children of this resource have been computed before
@@ -155,21 +162,21 @@ protected void addChildren(UnifiedTreeNode node) {
155
162
156
163
// get the list of resources in the workspace
157
164
if (!unknown && (parentType == IResource .FOLDER || parentType == IResource .PROJECT ) && parent .exists (flags , true )) {
158
- IResource target = null ;
159
- UnifiedTreeNode child = null ;
160
- IResource [] members ;
165
+ List <IResource > members ;
161
166
try {
162
- members = ((IContainer ) parent ).members (IContainer .INCLUDE_TEAM_PRIVATE_MEMBERS | IContainer .INCLUDE_HIDDEN );
167
+ IContainer container = (IContainer ) parent ;
168
+ members = Arrays .asList (container .members (IContainer .INCLUDE_TEAM_PRIVATE_MEMBERS | IContainer .INCLUDE_HIDDEN ));
163
169
} catch (CoreException e ) {
164
- members = NO_RESOURCES ;
170
+ members = List . of () ;
165
171
}
166
172
int workspaceIndex = 0 ;
167
173
//iterate simultaneously over file system and workspace members
168
- while (workspaceIndex < members .length ) {
169
- target = members [ workspaceIndex ] ;
174
+ while (workspaceIndex < members .size () ) {
175
+ IResource target = members . get ( workspaceIndex ) ;
170
176
String name = target .getName ();
171
- IFileInfo localInfo = localIndex < list .length ? list [ localIndex ] : null ;
177
+ IFileInfo localInfo = localIndex < list .size () ? list . get ( localIndex ) : null ;
172
178
int comp = localInfo != null ? name .compareTo (localInfo .getName ()) : -1 ;
179
+ UnifiedTreeNode child = null ;
173
180
//special handling for linked resources
174
181
if (target .isLinked ()) {
175
182
//child will be null if location is undefined
@@ -221,11 +228,11 @@ protected void addChildren(UnifiedTreeNode node) {
221
228
addChildrenMarker ();
222
229
}
223
230
224
- protected void addChildrenFromFileSystem (UnifiedTreeNode node , IFileInfo [] childInfos , int index ) {
225
- if (childInfos == null )
231
+ protected void addChildrenFromFileSystem (UnifiedTreeNode node , List < IFileInfo > childInfos , int index ) {
232
+ if (childInfos == null ) {
226
233
return ;
227
- for ( int i = index ; i < childInfos . length ; i ++) {
228
- IFileInfo info = childInfos [ i ];
234
+ }
235
+ for ( IFileInfo info : childInfos . subList ( index , childInfos . size ())) {
229
236
//don't create a node for symbolic links that create a cycle
230
237
if (!info .getAttribute (EFS .ATTRIBUTE_SYMLINK ) || !info .isDirectory () || !isRecursiveLink (node .getStore (), info ))
231
238
addChildToTree (node , createChildNodeFromFileSystem (node , info ));
@@ -321,14 +328,14 @@ protected Iterator<UnifiedTreeNode> getChildren(UnifiedTreeNode node) {
321
328
322
329
/* if the first child is still null, the node does not have any children */
323
330
if (node .getFirstChild () == null )
324
- return EMPTY_ITERATOR ;
331
+ return Collections . emptyIterator () ;
325
332
326
333
/* get the index of the first child */
327
334
int index = queue .indexOf (node .getFirstChild ());
328
335
329
336
/* if we do not have children, just return an empty enumeration */
330
337
if (index == -1 )
331
- return EMPTY_ITERATOR ;
338
+ return Collections . emptyIterator () ;
332
339
333
340
/* create an enumeration with node's children */
334
341
List <UnifiedTreeNode > result = new ArrayList <>(10 );
@@ -350,7 +357,7 @@ protected int getLevel() {
350
357
return level ;
351
358
}
352
359
353
- protected IFileInfo [] getLocalList (UnifiedTreeNode node ) {
360
+ protected List < IFileInfo > getLocalList (UnifiedTreeNode node ) {
354
361
try {
355
362
final IFileStore store = node .getStore ();
356
363
IFileInfo [] list ;
@@ -360,15 +367,15 @@ protected IFileInfo[] getLocalList(UnifiedTreeNode node) {
360
367
list = store .childInfos (EFS .NONE , null );
361
368
362
369
if (list == null || list .length == 0 )
363
- return NO_CHILDREN ;
370
+ return List . of () ;
364
371
list = ((Resource ) node .getResource ()).filterChildren (list , false );
365
- int size = list .length ;
366
- if ( size > 1 )
367
- quickSort ( list , 0 , size - 1 );
368
- return list ;
372
+ if ( list .length > 1 ) {
373
+ Arrays . sort ( list );
374
+ }
375
+ return Arrays . asList ( list ) ;
369
376
} catch (CoreException e ) {
370
377
//treat failure to access the directory as a non-existent directory
371
- return NO_CHILDREN ;
378
+ return List . of () ;
372
379
}
373
380
}
374
381
@@ -402,11 +409,11 @@ protected boolean isLevelMarker(UnifiedTreeNode node) {
402
409
private static class PatternHolder {
403
410
//Initialize-on-demand Holder class to avoid compiling Pattern if never needed
404
411
//Pattern: A UNIX or Windows relative path that just points backward
405
- private static final String REGEX = Platform . getOS (). equals ( Platform . OS_WIN32 ) ? " \\ .[. \\ \\ ]*" : " \\ .[./]*" ; //$NON-NLS-1$ //$NON-NLS-2$
406
- public static final Pattern TRIVIAL_SYMLINK_PATTERN = Pattern . compile ( REGEX );
412
+ static final Pattern TRIVIAL_SYMLINK_PATTERN = Pattern . compile ( //
413
+ Platform . OS . isWindows () ? " \\ .[. \\ \\ ]*" : " \\ .[./]*" ); //$NON-NLS-1$//$NON-NLS-2$
407
414
408
- private static final String REGEX_BACK_REPEATING = Platform . getOS (). equals ( Platform . OS_WIN32 ) ? "( \\ . \\ . \\ \\ )+.*" : "( \\ . \\ ./)+.*" ; //$NON-NLS-1$ //$NON-NLS-2$
409
- public static final Pattern REPEATING_BACKWARDS_PATTERN = Pattern . compile ( REGEX_BACK_REPEATING );
415
+ static final Pattern REPEATING_BACKWARDS_PATTERN = Pattern . compile ( //
416
+ Platform . OS . isWindows () ? "( \\ . \\ . \\ \\ )+.*" : "( \\ . \\ ./)+.*" ); //$NON-NLS-1$//$NON-NLS-2$
410
417
}
411
418
412
419
/**
@@ -541,44 +548,12 @@ private boolean isRecursiveLink(IFileStore parentStore, IFileInfo localInfo) {
541
548
}
542
549
543
550
protected boolean isValidLevel (int currentLevel , int depth ) {
544
- switch (depth ) {
545
- case IResource .DEPTH_INFINITE :
546
- return true ;
547
- case IResource .DEPTH_ONE :
548
- return currentLevel <= 1 ;
549
- case IResource .DEPTH_ZERO :
550
- return currentLevel == 0 ;
551
- default :
552
- return currentLevel + 1000 <= depth ;
553
- }
554
- }
555
-
556
- /**
557
- * Sorts the given array of strings in place. This is
558
- * not using the sorting framework to avoid casting overhead.
559
- */
560
- protected void quickSort (IFileInfo [] infos , int left , int right ) {
561
- int originalLeft = left ;
562
- int originalRight = right ;
563
- IFileInfo mid = infos [(left + right ) / 2 ];
564
- do {
565
- while (mid .compareTo (infos [left ]) > 0 )
566
- left ++;
567
- while (infos [right ].compareTo (mid ) > 0 )
568
- right --;
569
- if (left <= right ) {
570
- IFileInfo tmp = infos [left ];
571
- infos [left ] = infos [right ];
572
- infos [right ] = tmp ;
573
- left ++;
574
- right --;
575
- }
576
- } while (left <= right );
577
- if (originalLeft < right )
578
- quickSort (infos , originalLeft , right );
579
- if (left < originalRight )
580
- quickSort (infos , left , originalRight );
581
- return ;
551
+ return switch (depth ) {
552
+ case IResource .DEPTH_INFINITE -> true ;
553
+ case IResource .DEPTH_ONE -> currentLevel <= 1 ;
554
+ case IResource .DEPTH_ZERO -> currentLevel == 0 ;
555
+ default -> currentLevel + 1000 <= depth ;
556
+ };
582
557
}
583
558
584
559
/**
0 commit comments