View | Details | Raw Unified | Return to bug 177384 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/resources/MarkerManager.java (+108 lines)
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) {
(-)src/org/eclipse/core/internal/resources/Resource.java (+12 lines)
Lines 856-861 Link Here
856
		return workspace.getMarkerManager().findMarkers(this, type, includeSubtypes, depth);
856
		return workspace.getMarkerManager().findMarkers(this, type, includeSubtypes, depth);
857
	}
857
	}
858
858
859
	/* (non-Javadoc)
860
	 * @see IResource#findMaxProblemSeverity(String, boolean, int)
861
	 */
862
	public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException {
863
		ResourceInfo info = getResourceInfo(false, false);
864
		checkAccessible(getFlags(info));
865
		// It might happen that from this point the resource is not accessible anymore.
866
		// But markers have the #exists method that callers can use to check if it is
867
		// still valid.
868
		return workspace.getMarkerManager().findMaxProblemSeverity(this, type, includeSubtypes, depth);
869
	}
870
859
	/**
871
	/**
860
	 * Searches for a variant of the given target in the list,
872
	 * Searches for a variant of the given target in the list,
861
	 * that differs only in case. Returns the variant from
873
	 * that differs only in case. Returns the variant from
(-)src/org/eclipse/core/resources/IResource.java (+26 lines)
Lines 1059-1064 Link Here
1059
	public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException;
1059
	public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException;
1060
1060
1061
	/**
1061
	/**
1062
	 * Returns the maximum value of the {@link IMarker#SEVERITY} attribute across markers 
1063
	 * of the specified type on this resource, and, optionally, on its children. 
1064
	 * If <code>includeSubtypes</code>is <code>false</code>, only markers whose type 
1065
	 * exactly matches the given type are considered.  
1066
	 * Returns <code>-1</code> if there are no matching markers.  
1067
	 * Returns {@link IMarker#SEVERITY_ERROR} if any of the markers has a severity 
1068
	 * greater than or equal to {@link IMarker#SEVERITY_ERROR}.
1069
	 *
1070
	 * @param type the type of marker to consider (normally {@link IMarker#PROBLEM} 
1071
	 *   or one of its subtypes), or <code>null</code> to indicate all types 
1072
	 *   
1073
	 * @param includeSubtypes whether or not to consider sub-types of the given type
1074
	 * @param depth how far to recurse (see <code>IResource.DEPTH_* </code>)
1075
	 * @return {@link IMarker#SEVERITY_INFO}, {@link IMarker#SEVERITY_WARNING}, {@link IMarker#SEVERITY_ERROR}, or -1
1076
	 * @exception CoreException if this method fails. Reasons include:
1077
	 * <ul>
1078
	 * <li> This resource does not exist.</li>
1079
	 * <li> This resource is a project that is not open.</li>
1080
	 * </ul>
1081
	 * @see IResource#DEPTH_ZERO
1082
	 * @see IResource#DEPTH_ONE
1083
	 * @see IResource#DEPTH_INFINITE
1084
	 */
1085
	public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException;
1086
	
1087
	/**
1062
	 * Returns the file extension portion of this resource's name,
1088
	 * Returns the file extension portion of this resource's name,
1063
	 * or <code>null</code> if it does not have one.
1089
	 * or <code>null</code> if it does not have one.
1064
	 * <p>
1090
	 * <p>

Return to bug 177384