Lines 118-123
Link Here
|
118 |
return (MarkerInfo[]) result.toArray(new MarkerInfo[size]); |
118 |
return (MarkerInfo[]) result.toArray(new MarkerInfo[size]); |
119 |
} |
119 |
} |
120 |
|
120 |
|
|
|
121 |
protected int basicFindMaxSeverity(MarkerSet markers, String 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 o = marker.getAttribute(IMarker.SEVERITY); |
150 |
if (o instanceof Integer) { |
151 |
Integer i = (Integer) o; |
152 |
return i.intValue(); |
153 |
} |
154 |
return -1; |
155 |
} |
156 |
|
121 |
/** |
157 |
/** |
122 |
* Removes markers of the specified type from the given resource. |
158 |
* Removes markers of the specified type from the given resource. |
123 |
* Note: this method is protected to avoid creation of a synthetic accessor (it |
159 |
* Note: this method is protected to avoid creation of a synthetic accessor (it |
Lines 243-248
Link Here
|
243 |
recursiveFindMarkers(target.getFullPath(), result, type, includeSubtypes, depth); |
279 |
recursiveFindMarkers(target.getFullPath(), result, type, includeSubtypes, depth); |
244 |
} |
280 |
} |
245 |
|
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 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 |
|
246 |
public long getChangeId() { |
293 |
public long getChangeId() { |
247 |
return changeId; |
294 |
return changeId; |
248 |
} |
295 |
} |
Lines 351-356
Link Here
|
351 |
} |
398 |
} |
352 |
|
399 |
|
353 |
/** |
400 |
/** |
|
|
401 |
* Finds the max severity across problem markers for a subtree of resources. |
402 |
*/ |
403 |
private int recursiveFindMaxSeverity(IPath path, String 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 |
/** |
354 |
* Adds the markers for a subtree of resources to the list. |
434 |
* Adds the markers for a subtree of resources to the list. |
355 |
*/ |
435 |
*/ |
356 |
private void recursiveRemoveMarkers(final IPath path, String type, boolean includeSubtypes, int depth) { |
436 |
private void recursiveRemoveMarkers(final IPath path, String type, boolean includeSubtypes, int depth) { |
Lines 527-532
Link Here
|
527 |
} |
607 |
} |
528 |
|
608 |
|
529 |
/** |
609 |
/** |
|
|
610 |
* Finds the max severity across problem markers for a subtree of resources. |
611 |
*/ |
612 |
private int visitorFindMaxSeverity(IPath path, final String type, final boolean includeSubtypes) { |
613 |
class MaxSeverityVisitor implements IElementContentVisitor { |
614 |
int max = -1; |
615 |
public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object elementContents) { |
616 |
// bail if an earlier sibling already hit the max |
617 |
if (max >= IMarker.SEVERITY_ERROR) { |
618 |
return false; |
619 |
} |
620 |
ResourceInfo info = (ResourceInfo) elementContents; |
621 |
if (info == null) |
622 |
return false; |
623 |
MarkerSet markers = info.getMarkers(false); |
624 |
|
625 |
//add the matching markers for this resource |
626 |
if (markers != null) { |
627 |
max = Math.max(max, basicFindMaxSeverity(markers, type, includeSubtypes)); |
628 |
} |
629 |
return max < IMarker.SEVERITY_ERROR; |
630 |
} |
631 |
} |
632 |
MaxSeverityVisitor visitor = new MaxSeverityVisitor(); |
633 |
new ElementTreeIterator(workspace.getElementTree(), path).iterate(visitor); |
634 |
return visitor.max; |
635 |
} |
636 |
|
637 |
/** |
530 |
* Adds the markers for a subtree of resources to the list. |
638 |
* Adds the markers for a subtree of resources to the list. |
531 |
*/ |
639 |
*/ |
532 |
private void visitorRemoveMarkers(IPath path, final String type, final boolean includeSubtypes) { |
640 |
private void visitorRemoveMarkers(IPath path, final String type, final boolean includeSubtypes) { |