if (fValueSuggestion != null && fSelectedRegion != null) { document.replace(fSelectedRegion.getOffset(), fSelectedRegion.getLength(), fValueSuggestion); fSelectedRegion= new Region(fSelectedRegion.getOffset(), fValueSuggestion.length()); }
	public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {		try {			// get full ast			CompilationUnit root= JavaPlugin.getDefault().getASTProvider().getAST(fCompilationUnit, ASTProvider.WAIT_YES, null);			ASTNode nameNode= NodeFinder.perform(root, fNode.getStartPosition(), fNode.getLength());			final int pos= fNode.getStartPosition();						ASTNode[] sameNodes;			if (nameNode instanceof SimpleName) {				sameNodes= LinkedNodeFinder.findByNode(root, (SimpleName) nameNode);			} else {				sameNodes= new ASTNode[] { nameNode };			}			// sort for iteration order, starting with the node @ offset			Arrays.sort(sameNodes, new Comparator() {								public int compare(Object o1, Object o2) {					return rank((ASTNode) o1) - rank((ASTNode) o2);				}				/**				 * Returns the absolute rank of an <code>ASTNode</code>. Nodes 				 * preceding <code>offset</code> are ranked last.				 * 				 * @param node the node to compute the rank for				 * @return the rank of the node with respect to the invocation offset				 */				private int rank(ASTNode node) {					int relativeRank= node.getStartPosition() + node.getLength() - pos;					if (relativeRank < 0)						return Integer.MAX_VALUE + relativeRank;					else						return relativeRank;				}							});						IDocument document= viewer.getDocument();			LinkedPositionGroup group= new LinkedPositionGroup();			for (int i= 0; i < sameNodes.length; i++) {				ASTNode elem= sameNodes[i];				group.addPosition(new LinkedPosition(document, elem.getStartPosition(), elem.getLength(), i));			}						LinkedModeModel model= new LinkedModeModel();			model.addGroup(group);			model.forceInstall();			JavaEditor editor= getJavaEditor();			if (editor != null) {				model.addLinkingListener(new EditorHighlightingSynchronizer(editor));			}						LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);//			ui.setInitialOffset(offset);			ui.setExitPosition(viewer, offset, 0, LinkedPositionGroup.NO_STOP);			ui.enter();						fSelectedRegion= ui.getSelectedRegion();		} catch (BadLocationException e) {			JavaPlugin.log(e);		}	}	