} else if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {  try {  final IJavaElement element= getElementAt(selection.x, true); if (element != null && element.exists()) {  ISourceRange range= null; final int kind= element.getElementType();  if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.INITIALIZER) {  final ISourceReference reference= (ISourceReference)element; range= reference.getSourceRange();
if (range != null) { viewer.setSelectedRange(range.getOffset(), range.getLength()); viewer.doOperation(ISourceViewer.FORMAT);
		public void run() {			final JavaSourceViewer viewer= (JavaSourceViewer) getSourceViewer();			if (viewer.isEditable()) {				final IDocument document= viewer.getDocument();				final Point selection= viewer.getSelectedRange();				try {					if (selection.y == 0) {						final String type= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.x);						if (type.equals(IJavaPartitions.JAVA_DOC) || type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT) || type.equals(IJavaPartitions.JAVA_SINGLE_LINE_COMMENT)) {							final ITypedRegion partition= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, selection.x);							format(viewer, partition.getOffset(), partition.getLength(), false);						} else if (type.equals(IDocument.DEFAULT_CONTENT_TYPE)) {							try {								final IJavaElement element= getElementAt(selection.x, true);								if (element != null && element.exists()) {									ISourceRange range= null;									final int kind= element.getElementType();									if (kind == IJavaElement.TYPE || kind == IJavaElement.METHOD || kind == IJavaElement.INITIALIZER) {										final ISourceReference reference= (ISourceReference)element;										range= reference.getSourceRange();									}									if (range != null)										format(viewer, range.getOffset(), range.getLength(), true);								}							} catch (JavaModelException exception) {								// Should not happen							}						}					} else						format(viewer, selection.x, selection.y, true);				} catch (BadLocationException exception) {					// Should not happen				}			}		}