* within the AST subtree identified by <code>scope</code>.
* @throws JavaModelException
*/
public static IASTFragment createFragmentForSourceRange(SourceRange range,
ASTNode scope, IDocument document) throws Exception {
SelectionAnalyzer sa = new SelectionAnalyzer(
Selection.createFromStartLength(range.getOffset(),
range.getLength()), false);
scope.accept(sa);
if (isSingleNodeSelected(sa, range, document, scope))
return ASTFragmentFactory.createFragmentForFullSubtree(
sa.getFirstSelectedNode(), null);
if (isEmptySelectionCoveredByANode(range, sa))
return ASTFragmentFactory.createFragmentForFullSubtree(
sa.getLastCoveringNode(), null);
return ASTFragmentFactory.createFragmentForSubPartBySourceRange(
sa.getLastCoveringNode(), range, scope, document);
}