# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: D:\workspace\nb72-src\main # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: java.editor/src/org/netbeans/modules/editor/java/SelectCodeElementAction.java --- java.editor/src/org/netbeans/modules/editor/java/SelectCodeElementAction.java Base (BASE) +++ java.editor/src/org/netbeans/modules/editor/java/SelectCodeElementAction.java Locally Modified (Based On LOCAL) @@ -59,19 +59,21 @@ import javax.swing.text.Caret; import javax.swing.text.JTextComponent; import org.netbeans.api.java.source.Task; +import javax.swing.text.StyledDocument; +import org.netbeans.api.java.source.Comment; import org.netbeans.api.java.source.CompilationController; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.JavaSource.Phase; +import org.netbeans.api.java.source.TreeUtilities; import org.netbeans.api.progress.ProgressUtils; import org.netbeans.editor.BaseAction; +import org.openide.text.NbDocument; import org.openide.util.Exceptions; import org.openide.util.NbBundle; /** - * Code selection according to syntax tree. + * Code selection according to syntax tree. It also supports JavaDoc. * - * TODO: javadoc selection - * * @author Miloslav Metelka, Jan Pokorsky */ final class SelectCodeElementAction extends BaseAction { @@ -215,11 +217,35 @@ int caretPos = target.getCaretPosition(); positions.add(new SelectionInfo(caretPos, caretPos)); SourcePositions sp = ci.getTrees().getSourcePositions(); - TreePath tp = ci.getTreeUtilities().pathFor(caretPos); + final TreeUtilities treeUtilities = ci.getTreeUtilities(); + TreePath tp = treeUtilities.pathFor(caretPos); for (Tree tree: tp) { int startPos = (int)sp.getStartPosition(tp.getCompilationUnit(), tree); int endPos = (int)sp.getEndPosition(tp.getCompilationUnit(), tree); positions.add(new SelectionInfo(startPos, endPos)); + + //Support selection of JavaDoc + int docBegin = Integer.MAX_VALUE; + { + List comments = treeUtilities.getComments(tree, true); + for (Comment comment : comments) { + docBegin = Math.min(comment.pos(), docBegin); + } + } + int docEnd = Integer.MIN_VALUE; + { + List comments = treeUtilities.getComments(tree, false); + for (Comment comment : comments) { + docEnd = Math.max(comment.endPos(), docEnd); + } + } + if (docBegin != Integer.MAX_VALUE && docEnd != Integer.MIN_VALUE) { + positions.add(new SelectionInfo(docBegin, docEnd)); + } else if (docBegin == Integer.MAX_VALUE && docEnd != Integer.MIN_VALUE) { + positions.add(new SelectionInfo(startPos, docEnd)); + } else if (docBegin != Integer.MAX_VALUE && docEnd == Integer.MIN_VALUE) { + positions.add(new SelectionInfo(docBegin, endPos)); + } } return positions.toArray(new SelectionInfo[positions.size()]); }