String selectedText= null; if (selection.y != 0) { try { selectedText= document.get(selection.x, selection.y); } catch (BadLocationException e) {} }
	public void complete(ITextViewer viewer, int completionPosition, ICompilationUnit compilationUnit)		throws JavaModelException	{	    IDocument document= viewer.getDocument();	    		// prohibit recursion		if (LinkedPositionManager.hasActiveManager(document))			return;		if (!(fContextType instanceof CompilationUnitContextType))			return;		Point selection= viewer.getSelectedRange();				((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y, compilationUnit);		CompilationUnitContext context= (CompilationUnitContext) fContextType.createContext();		int start= context.getStart();		int end= context.getEnd();		IRegion region= new Region(start, end - start);		Template[] templates= Templates.getInstance().getTemplates();		if (selection.y == 0) {				for (int i= 0; i != templates.length; i++)				if (context.canEvaluate(templates[i]))					fProposals.add(new TemplateProposal(templates[i], context, region, viewer, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)));		} else {			final String CURSOR= "${" + JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor") + '}'; //$NON-NLS-1$ //$NON-NLS-2$						context.setForceEvaluation(true);			for (int i= 0; i != templates.length; i++) {				Template template= templates[i];								if (context.canEvaluate(template) && template.getPattern().indexOf(CURSOR) != -1)					fProposals.add(new TemplateProposal(templates[i], context, region, viewer, JavaPluginImages.get(JavaPluginImages.IMG_OBJS_TEMPLATE)));						}		}	}