Bug 99325 [syntax highlighting] semantic highlighting broken when using "convert to new for loop"
I20050610-0010 (no regression, though - just exposed by the quick fix) - In the code below, execute the "convert to new for loop" quick fix - undo -> note that the 'for' keyword is wrongly colored. -> subsequent reconciles do not correct the failure -> only doing a major change (cutting and pasting entire method, closing editor..) corrects the problem class Test{ void m() { LinkedList<Number> list = null; for (Iterator it = list.iterator(); it.hasNext();) { Number num = (Number) it.next(); System.out.println(num.intValue()); } } } Code inspection revealed that SemanticHighlightingPresenter.contain() relies on positions being disjoint, which is not true in this case: the quick fix modifies the document in a way that produces many positions at the same offset/length. A fix would change indexOf() to check all positions at a certain offset instead of the index returned. Need to talk to Christof about whether the position updater might be doing the wrong thing...
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/SemanticHighlightingPresenter.java
/**
	 * Create a text presentation in the background.
	 * <p>
	 * NOTE: Called from background thread.
	 * </p>
	 *
	 * @param addedPositions the added positions
	 * @param removedPositions the removed positions
	 * @return the text presentation or <code>null</code>, if reconciliation should be canceled
	 */
	public TextPresentation createPresentation(List addedPositions, List removedPositions) {
		JavaSourceViewer sourceViewer= fSourceViewer;
		JavaPresentationReconciler presentationReconciler= fPresentationReconciler;
		if (sourceViewer == null || presentationReconciler == null)
			return null;
		if (isCanceled())
			return null;
		IDocument document= sourceViewer.getDocument();
		if (document == null)
			return null;
		int minStart= Integer.MAX_VALUE;
		int maxEnd= Integer.MIN_VALUE;
		for (int i= 0, n= removedPositions.size(); i < n; i++) {
			Position position= (Position) removedPositions.get(i);
			int offset= position.getOffset();
			minStart= Math.min(minStart, offset);
			maxEnd= Math.max(maxEnd, offset + position.getLength());
		}
		for (int i= 0, n= addedPositions.size(); i < n; i++) {
			Position position= (Position) addedPositions.get(i);