1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2022 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2024 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
38
38
import java .util .Comparator ;
39
39
import java .util .HashMap ;
40
40
import java .util .HashSet ;
41
- import java .util .Iterator ;
42
41
import java .util .List ;
43
42
import java .util .Map ;
44
43
import java .util .Map .Entry ;
@@ -307,79 +306,6 @@ public void run() throws Exception {
307
306
}
308
307
}
309
308
310
- /**
311
- * Visitor for handling a resource begin deleted, and the need to check mapped configurations
312
- * for auto-deletion
313
- * @since 3.4
314
- */
315
- class MappedResourceVisitor implements IResourceDeltaVisitor {
316
-
317
- @ Override
318
- public boolean visit (IResourceDelta delta ) throws CoreException {
319
- if (0 != (delta .getFlags () & IResourceDelta .OPEN )) {
320
- return false ;
321
- }
322
- if (delta .getKind () == IResourceDelta .REMOVED && delta .getFlags () != IResourceDelta .MOVED_TO ) {
323
- ArrayList <ILaunchConfiguration > configs = collectAssociatedLaunches (delta .getResource ());
324
- for (ILaunchConfiguration config : configs ) {
325
- try {
326
- config .delete ();
327
- } catch (CoreException e ) {
328
- DebugPlugin .log (e .getStatus ());
329
- }
330
- }
331
- return false ;
332
- }
333
- return true ;
334
- }
335
- }
336
-
337
- /**
338
- * Visitor for handling resource deltas.
339
- */
340
- class LaunchManagerVisitor implements IResourceDeltaVisitor {
341
-
342
- @ Override
343
- public boolean visit (IResourceDelta delta ) {
344
- if (delta == null ) {
345
- return false ;
346
- }
347
- if (0 != (delta .getFlags () & IResourceDelta .OPEN )) {
348
- if (delta .getResource () instanceof IProject ) {
349
- IProject project = (IProject )delta .getResource ();
350
- if (project .isOpen ()) {
351
- LaunchManager .this .projectOpened (project );
352
- } else {
353
- LaunchManager .this .projectClosed (project );
354
- }
355
- }
356
- return false ;
357
- }
358
- IResource resource = delta .getResource ();
359
- if (resource instanceof IFile ) {
360
- IFile file = (IFile )resource ;
361
- if (ILaunchConfiguration .LAUNCH_CONFIGURATION_FILE_EXTENSION .equals (file .getFileExtension ()) || ILaunchConfiguration .LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION .equals (file .getFileExtension ())) {
362
- ILaunchConfiguration handle = new LaunchConfiguration (file );
363
- switch (delta .getKind ()) {
364
- case IResourceDelta .ADDED :
365
- LaunchManager .this .launchConfigurationAdded (handle );
366
- break ;
367
- case IResourceDelta .REMOVED :
368
- LaunchManager .this .launchConfigurationDeleted (handle );
369
- break ;
370
- case IResourceDelta .CHANGED :
371
- LaunchManager .this .launchConfigurationChanged (handle );
372
- break ;
373
- default :
374
- break ;
375
- }
376
- }
377
- return false ;
378
- }
379
- return true ;
380
- }
381
- }
382
-
383
309
/**
384
310
* Notifies a launch listener (single launch) in a safe runnable to handle
385
311
* exceptions.
@@ -631,7 +557,42 @@ public static String serializeDocument(Document doc, String lineDelimiter) throw
631
557
* Visitor used to process resource deltas,
632
558
* to update launch configuration index.
633
559
*/
634
- private LaunchManagerVisitor fgVisitor ;
560
+ private final IResourceDeltaVisitor fgVisitor = delta -> {
561
+ if (delta == null ) {
562
+ return false ;
563
+ }
564
+ if (0 != (delta .getFlags () & IResourceDelta .OPEN )) {
565
+ if (delta .getFullPath ().segmentCount () == 1 && delta .getResource () instanceof IProject project ) {
566
+ if (project .isOpen ()) {
567
+ LaunchManager .this .projectOpened (project );
568
+ } else {
569
+ LaunchManager .this .projectClosed (project );
570
+ }
571
+ }
572
+ return false ;
573
+ }
574
+ String fileExtension = delta .getFullPath ().getFileExtension ();
575
+ if (ILaunchConfiguration .LAUNCH_CONFIGURATION_FILE_EXTENSION .equals (fileExtension ) || ILaunchConfiguration .LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION .equals (fileExtension )) {
576
+ if (delta .getResource () instanceof IFile file ) {
577
+ ILaunchConfiguration handle = new LaunchConfiguration (file );
578
+ switch (delta .getKind ()) {
579
+ case IResourceDelta .ADDED :
580
+ LaunchManager .this .launchConfigurationAdded (handle );
581
+ break ;
582
+ case IResourceDelta .REMOVED :
583
+ LaunchManager .this .launchConfigurationDeleted (handle );
584
+ break ;
585
+ case IResourceDelta .CHANGED :
586
+ LaunchManager .this .launchConfigurationChanged (handle );
587
+ break ;
588
+ default :
589
+ break ;
590
+ }
591
+ }
592
+ return false ;
593
+ }
594
+ return true ;
595
+ };
635
596
636
597
/**
637
598
* Visitor used to process a deleted resource,
@@ -640,7 +601,23 @@ public static String serializeDocument(Document doc, String lineDelimiter) throw
640
601
*
641
602
* @since 3.4
642
603
*/
643
- private MappedResourceVisitor fgMRVisitor ;
604
+ private final IResourceDeltaVisitor fgMRVisitor = delta -> {
605
+ if (0 != (delta .getFlags () & IResourceDelta .OPEN )) {
606
+ return false ;
607
+ }
608
+ if (delta .getKind () == IResourceDelta .REMOVED && delta .getFlags () != IResourceDelta .MOVED_TO ) {
609
+ List <ILaunchConfiguration > configs = collectAssociatedLaunches (delta .getResource ());
610
+ for (ILaunchConfiguration config : configs ) {
611
+ try {
612
+ config .delete ();
613
+ } catch (CoreException e ) {
614
+ DebugPlugin .log (e .getStatus ());
615
+ }
616
+ }
617
+ return false ;
618
+ }
619
+ return true ;
620
+ };
644
621
645
622
/**
646
623
* Whether this manager is listening for resource change events
@@ -1129,31 +1106,6 @@ public IDebugTarget[] getDebugTargets() {
1129
1106
}
1130
1107
}
1131
1108
1132
- /**
1133
- * Returns the resource delta visitor for the launch manager.
1134
- *
1135
- * @return the resource delta visitor for the launch manager
1136
- */
1137
- private LaunchManagerVisitor getDeltaVisitor () {
1138
- if (fgVisitor == null ) {
1139
- fgVisitor = new LaunchManagerVisitor ();
1140
- }
1141
- return fgVisitor ;
1142
- }
1143
-
1144
- /**
1145
- * Returns the resource delta visitor for auto-removal of mapped launch configurations
1146
- * @return the resource delta visitor for auto-removal of mapped launch configurations
1147
- *
1148
- * @since 3.4
1149
- */
1150
- private MappedResourceVisitor getMappedResourceVisitor () {
1151
- if (fgMRVisitor == null ) {
1152
- fgMRVisitor = new MappedResourceVisitor ();
1153
- }
1154
- return fgMRVisitor ;
1155
- }
1156
-
1157
1109
@ Override
1158
1110
public String [] getEnvironment (ILaunchConfiguration configuration ) throws CoreException {
1159
1111
Map <String , String > configEnv = configuration .getAttribute (ATTR_ENVIRONMENT_VARIABLES , (Map <String , String >) null );
@@ -1314,9 +1266,7 @@ public ILaunchConfiguration[] getLaunchConfigurations(int kinds) {
1314
1266
return allConfigs .toArray (new ILaunchConfiguration [allConfigs .size ()]);
1315
1267
} else {
1316
1268
List <ILaunchConfiguration > select = new ArrayList <>(allConfigs .size ());
1317
- Iterator <ILaunchConfiguration > iterator = allConfigs .iterator ();
1318
- while (iterator .hasNext ()) {
1319
- ILaunchConfiguration config = iterator .next ();
1269
+ for (ILaunchConfiguration config : allConfigs ) {
1320
1270
try {
1321
1271
if ((config .getKind () & kinds ) > 0 ) {
1322
1272
select .add (config );
@@ -2126,15 +2076,11 @@ public void removeLaunchListener(ILaunchListener listener) {
2126
2076
public void resourceChanged (IResourceChangeEvent event ) {
2127
2077
IResourceDelta delta = event .getDelta ();
2128
2078
if (delta != null ) {
2129
- LaunchManagerVisitor visitor = getDeltaVisitor ();
2130
- MappedResourceVisitor v = null ;
2131
- if (isDeleteConfigurations ()) {
2132
- v = getMappedResourceVisitor ();
2133
- }
2134
2079
try {
2135
- delta .accept (visitor );
2136
- if (v != null ) {
2137
- delta .accept (v );
2080
+ boolean deleteConfigurations = isDeleteConfigurations ();
2081
+ delta .accept (fgVisitor );
2082
+ if (deleteConfigurations ) {
2083
+ delta .accept (fgMRVisitor );
2138
2084
}
2139
2085
} catch (CoreException e ) {
2140
2086
DebugPlugin .log (e .getStatus ());
@@ -2150,14 +2096,13 @@ public void resourceChanged(IResourceChangeEvent event) {
2150
2096
* @param resource the resource to collect launch configurations for
2151
2097
* @return the list of associated launch configurations
2152
2098
*/
2153
- private ArrayList <ILaunchConfiguration > collectAssociatedLaunches (IResource resource ) {
2154
- ArrayList <ILaunchConfiguration > list = new ArrayList <>();
2099
+ private static List <ILaunchConfiguration > collectAssociatedLaunches (IResource resource ) {
2100
+ List <ILaunchConfiguration > list = new ArrayList <>();
2155
2101
try {
2156
2102
ILaunchConfiguration [] configs = DebugPlugin .getDefault ().getLaunchManager ().getLaunchConfigurations ();
2157
- IResource [] resources = null ;
2158
2103
for (ILaunchConfiguration config : configs ) {
2159
2104
if (config .isLocal ()) {
2160
- resources = config .getMappedResources ();
2105
+ IResource [] resources = config .getMappedResources ();
2161
2106
if (resources != null ) {
2162
2107
for (IResource res : resources ) {
2163
2108
if (resource .equals (res ) ||
0 commit comments