Lines 59-77
Link Here
|
59 |
import javax.swing.text.Caret; |
59 |
import javax.swing.text.Caret; |
60 |
import javax.swing.text.JTextComponent; |
60 |
import javax.swing.text.JTextComponent; |
61 |
import org.netbeans.api.java.source.Task; |
61 |
import org.netbeans.api.java.source.Task; |
|
|
62 |
import javax.swing.text.StyledDocument; |
63 |
import org.netbeans.api.java.source.Comment; |
62 |
import org.netbeans.api.java.source.CompilationController; |
64 |
import org.netbeans.api.java.source.CompilationController; |
63 |
import org.netbeans.api.java.source.JavaSource; |
65 |
import org.netbeans.api.java.source.JavaSource; |
64 |
import org.netbeans.api.java.source.JavaSource.Phase; |
66 |
import org.netbeans.api.java.source.JavaSource.Phase; |
|
|
67 |
import org.netbeans.api.java.source.TreeUtilities; |
65 |
import org.netbeans.api.progress.ProgressUtils; |
68 |
import org.netbeans.api.progress.ProgressUtils; |
66 |
import org.netbeans.editor.BaseAction; |
69 |
import org.netbeans.editor.BaseAction; |
|
|
70 |
import org.openide.text.NbDocument; |
67 |
import org.openide.util.Exceptions; |
71 |
import org.openide.util.Exceptions; |
68 |
import org.openide.util.NbBundle; |
72 |
import org.openide.util.NbBundle; |
69 |
|
73 |
|
70 |
/** |
74 |
/** |
71 |
* Code selection according to syntax tree. |
75 |
* Code selection according to syntax tree. It also supports JavaDoc. |
72 |
* |
76 |
* |
73 |
* TODO: javadoc selection |
|
|
74 |
* |
75 |
* @author Miloslav Metelka, Jan Pokorsky |
77 |
* @author Miloslav Metelka, Jan Pokorsky |
76 |
*/ |
78 |
*/ |
77 |
final class SelectCodeElementAction extends BaseAction { |
79 |
final class SelectCodeElementAction extends BaseAction { |
Lines 215-225
Link Here
|
215 |
int caretPos = target.getCaretPosition(); |
217 |
int caretPos = target.getCaretPosition(); |
216 |
positions.add(new SelectionInfo(caretPos, caretPos)); |
218 |
positions.add(new SelectionInfo(caretPos, caretPos)); |
217 |
SourcePositions sp = ci.getTrees().getSourcePositions(); |
219 |
SourcePositions sp = ci.getTrees().getSourcePositions(); |
218 |
TreePath tp = ci.getTreeUtilities().pathFor(caretPos); |
220 |
final TreeUtilities treeUtilities = ci.getTreeUtilities(); |
|
|
221 |
TreePath tp = treeUtilities.pathFor(caretPos); |
219 |
for (Tree tree: tp) { |
222 |
for (Tree tree: tp) { |
220 |
int startPos = (int)sp.getStartPosition(tp.getCompilationUnit(), tree); |
223 |
int startPos = (int)sp.getStartPosition(tp.getCompilationUnit(), tree); |
221 |
int endPos = (int)sp.getEndPosition(tp.getCompilationUnit(), tree); |
224 |
int endPos = (int)sp.getEndPosition(tp.getCompilationUnit(), tree); |
222 |
positions.add(new SelectionInfo(startPos, endPos)); |
225 |
positions.add(new SelectionInfo(startPos, endPos)); |
|
|
226 |
|
227 |
//Support selection of JavaDoc |
228 |
int docBegin = Integer.MAX_VALUE; |
229 |
{ |
230 |
List<Comment> comments = treeUtilities.getComments(tree, true); |
231 |
for (Comment comment : comments) { |
232 |
docBegin = Math.min(comment.pos(), docBegin); |
233 |
} |
234 |
} |
235 |
int docEnd = Integer.MIN_VALUE; |
236 |
{ |
237 |
List<Comment> comments = treeUtilities.getComments(tree, false); |
238 |
for (Comment comment : comments) { |
239 |
docEnd = Math.max(comment.endPos(), docEnd); |
240 |
} |
241 |
} |
242 |
if (docBegin != Integer.MAX_VALUE && docEnd != Integer.MIN_VALUE) { |
243 |
positions.add(new SelectionInfo(docBegin, docEnd)); |
244 |
} else if (docBegin == Integer.MAX_VALUE && docEnd != Integer.MIN_VALUE) { |
245 |
positions.add(new SelectionInfo(startPos, docEnd)); |
246 |
} else if (docBegin != Integer.MAX_VALUE && docEnd == Integer.MIN_VALUE) { |
247 |
positions.add(new SelectionInfo(docBegin, endPos)); |
248 |
} |
223 |
} |
249 |
} |
224 |
return positions.toArray(new SelectionInfo[positions.size()]); |
250 |
return positions.toArray(new SelectionInfo[positions.size()]); |
225 |
} |
251 |
} |