Bug 52361 [templates] linked mode not exited / annotations not redrawn when inserting anonymous completion
M7 0. Auto-closed parenthesis on 1. Insert this code: import java.lang.Runnable; void m() { method(<caret> } -> closing parenthesis gets inserted -> linked mode entered 2. type "new Runnable(" -> nested linked mode is entered for second parenthesis, also autoclosed 3. use code completion to complete the anonymous type -> you end up with this code: void m() { method(new Runnable() { public void run() { } }) } -> Linked mode is still drawn 4. Press <Tab> or <Enter> -> linked mode is not exited -> annotations keep being drawn The only way to get away with the annotations is to open a new parenthesis somewhere outside the initial code.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/link/LinkedPositionAnnotations.java
List toRemove= new ArrayList(fGroupAnnotations.values());
		Map toAdd= new HashMap();
		if (positions != null) {
			for (Iterator iter= positions.iterator(); iter.hasNext();) {
				Position p= (Position) iter.next();
				if (fGroupAnnotations.containsKey(p)) {
					toRemove.remove(fGroupAnnotations.get(p));
				} else {
					Annotation a= new Annotation(SLAVE_ANNOTATION_TYPE, false, ""); 
					toAdd.put(a, p);
					fGroupAnnotations.put(p, a);
				}
			}
		}
		fGroupAnnotations.values().removeAll(toRemove);
		replaceAnnotations((Annotation[]) toRemove.toArray(new Annotation[0]), toAdd, false);
	}
	
	/**
	 * Sets the positions that should be highlighted as the target positions, i.e. 
	 * as the positions that can be jumped to in a linked set up.
	 * 
	 * @param positions the new target positions, or <code>null</code> if no target positions are to be set
	 */
	private void setTargetPositions(List positions) throws BadLocationException {
		if (!markTargets)
			return;