KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > MarkerManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.resources;
12
13 import java.io.*;
14 import java.util.*;
15 import org.eclipse.core.internal.localstore.SafeChunkyInputStream;
16 import org.eclipse.core.internal.localstore.SafeFileInputStream;
17 import org.eclipse.core.internal.utils.Messages;
18 import org.eclipse.core.internal.utils.Policy;
19 import org.eclipse.core.internal.watson.*;
20 import org.eclipse.core.resources.*;
21 import org.eclipse.core.runtime.*;
22 import org.eclipse.osgi.util.NLS;
23
24 /**
25  * A marker manager stores and retrieves markers on resources in the workspace.
26  */

27 public class MarkerManager implements IManager {
28
29     //singletons
30
private static final MarkerInfo[] NO_MARKER_INFO = new MarkerInfo[0];
31     private static final IMarker[] NO_MARKERS = new IMarker[0];
32     protected MarkerTypeDefinitionCache cache = new MarkerTypeDefinitionCache();
33     private long changeId = 0;
34     protected Map currentDeltas = null;
35     protected final MarkerDeltaManager deltaManager = new MarkerDeltaManager();
36
37     protected Workspace workspace;
38     protected MarkerWriter writer = new MarkerWriter(this);
39
40     /**
41      * Creates a new marker manager
42      */

43     public MarkerManager(Workspace workspace) {
44         this.workspace = workspace;
45     }
46
47     /* (non-Javadoc)
48      * Adds the given markers to the given resource.
49      *
50      * @see IResource#createMarker(String)
51      */

52     public void add(IResource resource, MarkerInfo newMarker) throws CoreException {
53         Resource target = (Resource) resource;
54         ResourceInfo info = workspace.getResourceInfo(target.getFullPath(), false, false);
55         target.checkExists(target.getFlags(info), false);
56         info = workspace.getResourceInfo(resource.getFullPath(), false, true);
57         //resource may have been deleted concurrently -- just bail out if this happens
58
if (info == null)
59             return;
60         // set the M_MARKERS_SNAP_DIRTY flag to indicate that this
61
// resource's markers have changed since the last snapshot
62
if (isPersistent(newMarker))
63             info.set(ICoreConstants.M_MARKERS_SNAP_DIRTY);
64         //Concurrency: copy the marker set on modify
65
MarkerSet markers = info.getMarkers(true);
66         if (markers == null)
67             markers = new MarkerSet(1);
68         basicAdd(resource, markers, newMarker);
69         if (!markers.isEmpty())
70             info.setMarkers(markers);
71     }
72
73     /**
74      * Adds the new markers to the given set of markers. If added, the markers
75      * are associated with the specified resource.IMarkerDeltas for Added markers
76      * are generated.
77      */

78     private void basicAdd(IResource resource, MarkerSet markers, MarkerInfo newMarker) throws CoreException {
79         // should always be a new marker.
80
if (newMarker.getId() != MarkerInfo.UNDEFINED_ID) {
81             String JavaDoc message = Messages.resources_changeInAdd;
82             throw new ResourceException(new ResourceStatus(IResourceStatus.INTERNAL_ERROR, resource.getFullPath(), message));
83         }
84         newMarker.setId(workspace.nextMarkerId());
85         markers.add(newMarker);
86         IMarkerSetElement[] changes = new IMarkerSetElement[1];
87         changes[0] = new MarkerDelta(IResourceDelta.ADDED, resource, newMarker);
88         changedMarkers(resource, changes);
89     }
90
91     /**
92      * Returns the markers in the given set of markers which match the given type.
93      */

94     protected MarkerInfo[] basicFindMatching(MarkerSet markers, String JavaDoc type, boolean includeSubtypes) {
95         int size = markers.size();
96         if (size <= 0)
97             return NO_MARKER_INFO;
98         List result = new ArrayList(size);
99         IMarkerSetElement[] elements = markers.elements();
100         for (int i = 0; i < elements.length; i++) {
101             MarkerInfo marker = (MarkerInfo) elements[i];
102             // if the type is null then we are looking for all types of markers
103
if (type == null)
104                 result.add(marker);
105             else {
106                 if (includeSubtypes) {
107                     if (cache.isSubtype(marker.getType(), type))
108                         result.add(marker);
109                 } else {
110                     if (marker.getType().equals(type))
111                         result.add(marker);
112                 }
113             }
114         }
115         size = result.size();
116         if (size <= 0)
117             return NO_MARKER_INFO;
118         return (MarkerInfo[]) result.toArray(new MarkerInfo[size]);
119     }
120
121     protected int basicFindMaxSeverity(MarkerSet markers, String JavaDoc type, boolean includeSubtypes) {
122         int max = -1;
123         int size = markers.size();
124         if (size <= 0)
125             return max;
126         IMarkerSetElement[] elements = markers.elements();
127         for (int i = 0; i < elements.length; i++) {
128             MarkerInfo marker = (MarkerInfo) elements[i];
129             // if the type is null then we are looking for all types of markers
130
if (type == null)
131                 max = Math.max(max, getSeverity(marker));
132             else {
133                 if (includeSubtypes) {
134                     if (cache.isSubtype(marker.getType(), type))
135                         max = Math.max(max, getSeverity(marker));
136                 } else {
137                     if (marker.getType().equals(type))
138                         max = Math.max(max, getSeverity(marker));
139                 }
140             }
141             if (max >= IMarker.SEVERITY_ERROR) {
142                 break;
143             }
144         }
145         return max;
146     }
147
148     private int getSeverity(MarkerInfo marker) {
149         Object JavaDoc o = marker.getAttribute(IMarker.SEVERITY);
150         if (o instanceof Integer JavaDoc) {
151             Integer JavaDoc i = (Integer JavaDoc) o;
152             return i.intValue();
153         }
154         return -1;
155     }
156
157     /**
158      * Removes markers of the specified type from the given resource.
159      * Note: this method is protected to avoid creation of a synthetic accessor (it
160      * is called from an anonymous inner class).
161      */

162     protected void basicRemoveMarkers(ResourceInfo info, IPathRequestor requestor, String JavaDoc type, boolean includeSubtypes) {
163         MarkerSet markers = info.getMarkers(false);
164         if (markers == null)
165             return;
166         IMarkerSetElement[] matching;
167         IPath path;
168         if (type == null) {
169             // if the type is null, all markers are to be removed.
170
//now we need to crack open the tree
171
path = requestor.requestPath();
172             info = workspace.getResourceInfo(path, false, true);
173             info.setMarkers(null);
174             matching = markers.elements();
175         } else {
176             matching = basicFindMatching(markers, type, includeSubtypes);
177             // if none match, there is nothing to remove
178
if (matching.length == 0)
179                 return;
180             //now we need to crack open the tree
181
path = requestor.requestPath();
182             info = workspace.getResourceInfo(path, false, true);
183             //Concurrency: copy the marker set on modify
184
markers = info.getMarkers(true);
185             // remove all the matching markers and also the whole
186
// set if there are no remaining markers
187
markers.removeAll(matching);
188             info.setMarkers(markers.size() == 0 ? null : markers);
189         }
190         info.set(ICoreConstants.M_MARKERS_SNAP_DIRTY);
191         IMarkerSetElement[] changes = new IMarkerSetElement[matching.length];
192         IResource resource = workspace.getRoot().findMember(path);
193         for (int i = 0; i < matching.length; i++)
194             changes[i] = new MarkerDelta(IResourceDelta.REMOVED, resource, (MarkerInfo) matching[i]);
195         changedMarkers(resource, changes);
196         return;
197     }
198
199     /**
200      * Adds the markers on the given target which match the specified type to the list.
201      */

202     protected void buildMarkers(IMarkerSetElement[] markers, IPath path, int type, ArrayList list) {
203         if (markers.length == 0)
204             return;
205         IResource resource = workspace.newResource(path, type);
206         list.ensureCapacity(list.size() + markers.length);
207         for (int i = 0; i < markers.length; i++) {
208             list.add(new Marker(resource, ((MarkerInfo) markers[i]).getId()));
209         }
210     }
211
212     /**
213      * Markers have changed on the given resource. Remember the changes for subsequent notification.
214      */

215     protected void changedMarkers(IResource resource, IMarkerSetElement[] changes) {
216         if (changes == null || changes.length == 0)
217             return;
218         changeId++;
219         if (currentDeltas == null)
220             currentDeltas = deltaManager.newGeneration(changeId);
221         IPath path = resource.getFullPath();
222         MarkerSet previousChanges = (MarkerSet) currentDeltas.get(path);
223         MarkerSet result = MarkerDelta.merge(previousChanges, changes);
224         if (result.size() == 0)
225             currentDeltas.remove(path);
226         else
227             currentDeltas.put(path, result);
228         ResourceInfo info = workspace.getResourceInfo(path, false, true);
229         if (info != null)
230             info.incrementMarkerGenerationCount();
231     }
232
233     /**
234      * Returns the marker with the given id or <code>null</code> if none is found.
235      */

236     public IMarker findMarker(IResource resource, long id) {
237         MarkerInfo info = findMarkerInfo(resource, id);
238         return info == null ? null : new Marker(resource, info.getId());
239     }
240
241     /**
242      * Returns the marker with the given id or <code>null</code> if none is found.
243      */

244     public MarkerInfo findMarkerInfo(IResource resource, long id) {
245         ResourceInfo info = workspace.getResourceInfo(resource.getFullPath(), false, false);
246         if (info == null)
247             return null;
248         MarkerSet markers = info.getMarkers(false);
249         if (markers == null)
250             return null;
251         return (MarkerInfo) markers.get(id);
252     }
253
254     /**
255      * Returns all markers of the specified type on the given target, with option
256      * to search the target's children.
257      * Passing <code>null</code> for the type specifies a match
258      * for all types (i.e., <code>null</code> is a wildcard.
259      */

260     public IMarker[] findMarkers(IResource target, final String JavaDoc type, final boolean includeSubtypes, int depth) {
261         ArrayList result = new ArrayList();
262         doFindMarkers(target, result, type, includeSubtypes, depth);
263         if (result.size() == 0)
264             return NO_MARKERS;
265         return (IMarker[]) result.toArray(new IMarker[result.size()]);
266     }
267
268     /**
269      * Fills the provided list with all markers of the specified type on the given target,
270      * with option to search the target's children.
271      * Passing <code>null</code> for the type specifies a match
272      * for all types (i.e., <code>null</code> is a wildcard.
273      */

274     public void doFindMarkers(IResource target, ArrayList result, final String JavaDoc type, final boolean includeSubtypes, int depth) {
275         //optimize the deep searches with an element tree visitor
276
if (depth == IResource.DEPTH_INFINITE && target.getType() != IResource.FILE)
277             visitorFindMarkers(target.getFullPath(), result, type, includeSubtypes);
278         else
279             recursiveFindMarkers(target.getFullPath(), result, type, includeSubtypes, depth);
280     }
281
282     /**
283      * Finds the max severity across all problem markers on the given target,
284      * with option to search the target's children.
285      */

286     public int findMaxProblemSeverity(IResource target, String JavaDoc type, boolean includeSubtypes, int depth) {
287         //optimize the deep searches with an element tree visitor
288
if (depth == IResource.DEPTH_INFINITE && target.getType() != IResource.FILE)
289             return visitorFindMaxSeverity(target.getFullPath(), type, includeSubtypes);
290         return recursiveFindMaxSeverity(target.getFullPath(), type, includeSubtypes, depth);
291     }
292
293     public long getChangeId() {
294         return changeId;
295     }
296
297     /**
298      * Returns the map of all marker deltas since the given change Id.
299      */

300     public Map getMarkerDeltas(long startChangeId) {
301         return deltaManager.assembleDeltas(startChangeId);
302     }
303
304     /**
305      * Returns true if this manager has a marker delta record
306      * for the given marker id, and false otherwise.
307      */

308     boolean hasDelta(IPath path, long id) {
309         if (currentDeltas == null)
310             return false;
311         MarkerSet set = (MarkerSet) currentDeltas.get(path);
312         if (set == null)
313             return false;
314         return set.get(id) != null;
315     }
316
317     /**
318      * Returns true if the given marker is persistent, and false
319      * otherwise.
320      */

321     public boolean isPersistent(MarkerInfo info) {
322         if (!cache.isPersistent(info.getType()))
323             return false;
324         Object JavaDoc isTransient = info.getAttribute(IMarker.TRANSIENT);
325         return isTransient == null || !(isTransient instanceof Boolean JavaDoc) || !((Boolean JavaDoc) isTransient).booleanValue();
326     }
327
328     /**
329      * Returns true if <code>type</code> is a sub type of <code>superType</code>.
330      */

331     public boolean isSubtype(String JavaDoc type, String JavaDoc superType) {
332         return cache.isSubtype(type, superType);
333     }
334
335     public void moved(final IResource source, final IResource destination, int depth) throws CoreException {
336         final int count = destination.getFullPath().segmentCount();
337
338         // we removed from the source and added to the destination
339
IResourceVisitor visitor = new IResourceVisitor() {
340             public boolean visit(IResource resource) {
341                 Resource r = (Resource) resource;
342                 ResourceInfo info = r.getResourceInfo(false, true);
343                 MarkerSet markers = info.getMarkers(false);
344                 if (markers == null)
345                     return true;
346                 info.set(ICoreConstants.M_MARKERS_SNAP_DIRTY);
347                 IMarkerSetElement[] removed = new IMarkerSetElement[markers.size()];
348                 IMarkerSetElement[] added = new IMarkerSetElement[markers.size()];
349                 IPath path = resource.getFullPath().removeFirstSegments(count);
350                 path = source.getFullPath().append(path);
351                 IResource sourceChild = workspace.newResource(path, resource.getType());
352                 IMarkerSetElement[] elements = markers.elements();
353                 for (int i = 0; i < elements.length; i++) {
354                     // calculate the ADDED delta
355
MarkerInfo markerInfo = (MarkerInfo) elements[i];
356                     MarkerDelta delta = new MarkerDelta(IResourceDelta.ADDED, resource, markerInfo);
357                     added[i] = delta;
358                     // calculate the REMOVED delta
359
delta = new MarkerDelta(IResourceDelta.REMOVED, sourceChild, markerInfo);
360                     removed[i] = delta;
361                 }
362                 changedMarkers(resource, added);
363                 changedMarkers(sourceChild, removed);
364                 return true;
365             }
366         };
367         destination.accept(visitor, depth, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
368     }
369
370     /**
371      * Adds the markers for a subtree of resources to the list.
372      */

373     private void recursiveFindMarkers(IPath path, ArrayList list, String JavaDoc type, boolean includeSubtypes, int depth) {
374         ResourceInfo info = workspace.getResourceInfo(path, false, false);
375         if (info == null)
376             return;
377         MarkerSet markers = info.getMarkers(false);
378
379         //add the matching markers for this resource
380
if (markers != null) {
381             IMarkerSetElement[] matching;
382             if (type == null)
383                 matching = markers.elements();
384             else
385                 matching = basicFindMatching(markers, type, includeSubtypes);
386             buildMarkers(matching, path, info.getType(), list);
387         }
388
389         //recurse
390
if (depth == IResource.DEPTH_ZERO || info.getType() == IResource.FILE)
391             return;
392         if (depth == IResource.DEPTH_ONE)
393             depth = IResource.DEPTH_ZERO;
394         IPath[] children = workspace.getElementTree().getChildren(path);
395         for (int i = 0; i < children.length; i++) {
396             recursiveFindMarkers(children[i], list, type, includeSubtypes, depth);
397         }
398     }
399
400     /**
401      * Finds the max severity across problem markers for a subtree of resources.
402      */

403     private int recursiveFindMaxSeverity(IPath path, String JavaDoc type, boolean includeSubtypes, int depth) {
404         ResourceInfo info = workspace.getResourceInfo(path, false, false);
405         if (info == null)
406             return -1;
407         MarkerSet markers = info.getMarkers(false);
408
409         //add the matching markers for this resource
410
int max = -1;
411         if (markers != null) {
412             max = basicFindMaxSeverity(markers, type, includeSubtypes);
413             if (max >= IMarker.SEVERITY_ERROR) {
414                 return max;
415             }
416         }
417
418         //recurse
419
if (depth == IResource.DEPTH_ZERO || info.getType() == IResource.FILE)
420             return max;
421         if (depth == IResource.DEPTH_ONE)
422             depth = IResource.DEPTH_ZERO;
423         IPath[] children = workspace.getElementTree().getChildren(path);
424         for (int i = 0; i < children.length; i++) {
425             max = Math.max(max, recursiveFindMaxSeverity(children[i], type, includeSubtypes, depth));
426             if (max >= IMarker.SEVERITY_ERROR) {
427                 break;
428             }
429         }
430         return max;
431     }
432
433     /**
434      * Adds the markers for a subtree of resources to the list.
435      */

436     private void recursiveRemoveMarkers(final IPath path, String JavaDoc type, boolean includeSubtypes, int depth) {
437         ResourceInfo info = workspace.getResourceInfo(path, false, false);
438         if (info == null)//phantoms don't have markers
439
return;
440         IPathRequestor requestor = new IPathRequestor() {
441             public String JavaDoc requestName() {
442                 return path.lastSegment();
443             }
444
445             public IPath requestPath() {
446                 return path;
447             }
448         };
449         basicRemoveMarkers(info, requestor, type, includeSubtypes);
450         //recurse
451
if (depth == IResource.DEPTH_ZERO || info.getType() == IResource.FILE)
452             return;
453         if (depth == IResource.DEPTH_ONE)
454             depth = IResource.DEPTH_ZERO;
455         IPath[] children = workspace.getElementTree().getChildren(path);
456         for (int i = 0; i < children.length; i++) {
457             recursiveRemoveMarkers(children[i], type, includeSubtypes, depth);
458         }
459     }
460
461     /**
462      * Removes the specified marker
463      */

464     public void removeMarker(IResource resource, long id) {
465         MarkerInfo markerInfo = findMarkerInfo(resource, id);
466         if (markerInfo == null)
467             return;
468         ResourceInfo info = ((Workspace) resource.getWorkspace()).getResourceInfo(resource.getFullPath(), false, true);
469         //Concurrency: copy the marker set on modify
470
MarkerSet markers = info.getMarkers(true);
471         int size = markers.size();
472         markers.remove(markerInfo);
473         // if that was the last marker remove the set to save space.
474
info.setMarkers(markers.size() == 0 ? null : markers);
475         // if we actually did remove a marker, post a delta for the change.
476
if (markers.size() != size) {
477             if (isPersistent(markerInfo))
478                 info.set(ICoreConstants.M_MARKERS_SNAP_DIRTY);
479             IMarkerSetElement[] change = new IMarkerSetElement[] {new MarkerDelta(IResourceDelta.REMOVED, resource, markerInfo)};
480             changedMarkers(resource, change);
481         }
482     }
483
484     /**
485      * Remove all markers for the given resource to the specified depth.
486      */

487     public void removeMarkers(IResource resource, int depth) {
488         removeMarkers(resource, null, false, depth);
489     }
490
491     /**
492      * Remove all markers with the given type from the node at the given path.
493      * Passing <code>null</code> for the type specifies a match
494      * for all types (i.e., <code>null</code> is a wildcard.
495      */

496     public void removeMarkers(IResource target, final String JavaDoc type, final boolean includeSubtypes, int depth) {
497         if (depth == IResource.DEPTH_INFINITE && target.getType() != IResource.FILE)
498             visitorRemoveMarkers(target.getFullPath(), type, includeSubtypes);
499         else
500             recursiveRemoveMarkers(target.getFullPath(), type, includeSubtypes, depth);
501     }
502
503     /**
504      * Reset the marker deltas up to but not including the given start Id.
505      */

506     public void resetMarkerDeltas(long startId) {
507         currentDeltas = null;
508         deltaManager.resetDeltas(startId);
509     }
510
511     public void restore(IResource resource, boolean generateDeltas, IProgressMonitor monitor) throws CoreException {
512         // first try and load the last saved file, then apply the snapshots
513
restoreFromSave(resource, generateDeltas);
514         restoreFromSnap(resource);
515     }
516
517     protected void restoreFromSave(IResource resource, boolean generateDeltas) throws CoreException {
518         IPath sourceLocation = workspace.getMetaArea().getMarkersLocationFor(resource);
519         IPath tempLocation = workspace.getMetaArea().getBackupLocationFor(sourceLocation);
520         java.io.File JavaDoc sourceFile = new java.io.File JavaDoc(sourceLocation.toOSString());
521         java.io.File JavaDoc tempFile = new java.io.File JavaDoc(tempLocation.toOSString());
522         if (!sourceFile.exists() && !tempFile.exists())
523             return;
524         try {
525             DataInputStream input = new DataInputStream(new SafeFileInputStream(sourceLocation.toOSString(), tempLocation.toOSString()));
526             try {
527                 MarkerReader reader = new MarkerReader(workspace);
528                 reader.read(input, generateDeltas);
529             } finally {
530                 input.close();
531             }
532         } catch (Exception JavaDoc e) {
533             //don't let runtime exceptions such as ArrayIndexOutOfBounds prevent startup
534
String JavaDoc msg = NLS.bind(Messages.resources_readMeta, sourceLocation);
535             throw new ResourceException(IResourceStatus.FAILED_READ_METADATA, sourceLocation, msg, e);
536         }
537     }
538
539     protected void restoreFromSnap(IResource resource) {
540         IPath sourceLocation = workspace.getMetaArea().getMarkersSnapshotLocationFor(resource);
541         if (!sourceLocation.toFile().exists())
542             return;
543         try {
544             DataInputStream input = new DataInputStream(new SafeChunkyInputStream(sourceLocation.toFile()));
545             try {
546                 MarkerSnapshotReader reader = new MarkerSnapshotReader(workspace);
547                 while (true)
548                     reader.read(input);
549             } catch (EOFException eof) {
550                 // ignore end of file
551
} finally {
552                 input.close();
553             }
554         } catch (Exception JavaDoc e) {
555             // only log the exception, we should not fail restoring the snapshot
556
String JavaDoc msg = NLS.bind(Messages.resources_readMeta, sourceLocation);
557             Policy.log(new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, sourceLocation, msg, e));
558         }
559     }
560
561     public void save(ResourceInfo info, IPathRequestor requestor, DataOutputStream output, List list) throws IOException {
562         writer.save(info, requestor, output, list);
563     }
564
565     /* (non-Javadoc)
566      * @see IManager#shutdown(IProgressMonitor)
567      */

568     public void shutdown(IProgressMonitor monitor) {
569         // do nothing
570
}
571
572     public void snap(ResourceInfo info, IPathRequestor requestor, DataOutputStream output) throws IOException {
573         writer.snap(info, requestor, output);
574     }
575
576     /* (non-Javadoc)
577      * @see IManager#startup(IProgressMonitor)
578      */

579     public void startup(IProgressMonitor monitor) {
580         // do nothing
581
}
582
583     /**
584      * Adds the markers for a subtree of resources to the list.
585      */

586     private void visitorFindMarkers(IPath path, final ArrayList list, final String JavaDoc type, final boolean includeSubtypes) {
587         IElementContentVisitor visitor = new IElementContentVisitor() {
588             public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object JavaDoc elementContents) {
589                 ResourceInfo info = (ResourceInfo) elementContents;
590                 if (info == null)
591                     return false;
592                 MarkerSet markers = info.getMarkers(false);
593
594                 //add the matching markers for this resource
595
if (markers != null) {
596                     IMarkerSetElement[] matching;
597                     if (type == null)
598                         matching = markers.elements();
599                     else
600                         matching = basicFindMatching(markers, type, includeSubtypes);
601                     buildMarkers(matching, requestor.requestPath(), info.getType(), list);
602                 }
603                 return true;
604             }
605         };
606         new ElementTreeIterator(workspace.getElementTree(), path).iterate(visitor);
607     }
608
609     /**
610      * Finds the max severity across problem markers for a subtree of resources.
611      */

612     private int visitorFindMaxSeverity(IPath path, final String JavaDoc type, final boolean includeSubtypes) {
613         class MaxSeverityVisitor implements IElementContentVisitor {
614             int max = -1;
615
616             public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object JavaDoc elementContents) {
617                 // bail if an earlier sibling already hit the max
618
if (max >= IMarker.SEVERITY_ERROR) {
619                     return false;
620                 }
621                 ResourceInfo info = (ResourceInfo) elementContents;
622                 if (info == null)
623                     return false;
624                 MarkerSet markers = info.getMarkers(false);
625
626                 //add the matching markers for this resource
627
if (markers != null) {
628                     max = Math.max(max, basicFindMaxSeverity(markers, type, includeSubtypes));
629                 }
630                 return max < IMarker.SEVERITY_ERROR;
631             }
632         }
633         MaxSeverityVisitor visitor = new MaxSeverityVisitor();
634         new ElementTreeIterator(workspace.getElementTree(), path).iterate(visitor);
635         return visitor.max;
636     }
637
638     /**
639      * Adds the markers for a subtree of resources to the list.
640      */

641     private void visitorRemoveMarkers(IPath path, final String JavaDoc type, final boolean includeSubtypes) {
642         IElementContentVisitor visitor = new IElementContentVisitor() {
643             public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object JavaDoc elementContents) {
644                 ResourceInfo info = (ResourceInfo) elementContents;
645                 if (info == null)
646                     return false;
647                 basicRemoveMarkers(info, requestor, type, includeSubtypes);
648                 return true;
649             }
650         };
651         new ElementTreeIterator(workspace.getElementTree(), path).iterate(visitor);
652     }
653 }
654
Popular Tags