2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.codeInsight
.editorActions
.wordSelection
;
18 import com
.intellij
.openapi
.editor
.Editor
;
19 import com
.intellij
.openapi
.util
.TextRange
;
20 import com
.intellij
.psi
.JavaDocTokenType
;
21 import com
.intellij
.psi
.PsiElement
;
22 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
23 import com
.intellij
.psi
.javadoc
.PsiDocToken
;
24 import com
.intellij
.util
.text
.CharArrayUtil
;
26 import java
.util
.List
;
28 public class DocCommentSelectioner
extends LineCommentSelectioner
{
29 public boolean canSelect(PsiElement e
) {
30 return e
instanceof PsiDocComment
;
33 public List
<TextRange
> select(PsiElement e
, CharSequence editorText
, int cursorOffset
, Editor editor
) {
34 List
<TextRange
> result
= super.select(e
, editorText
, cursorOffset
, editor
);
36 PsiElement
[] children
= e
.getChildren();
38 int startOffset
= e
.getTextRange().getStartOffset();
39 int endOffset
= e
.getTextRange().getEndOffset();
41 for (PsiElement child
: children
) {
42 if (child
instanceof PsiDocToken
) {
43 PsiDocToken token
= (PsiDocToken
)child
;
45 if (token
.getTokenType() == JavaDocTokenType
.DOC_COMMENT_DATA
) {
46 char[] chars
= token
.getText().toCharArray();
48 if (CharArrayUtil
.shiftForward(chars
, 0, " *\n\t\r") != chars
.length
) {
54 startOffset
= child
.getTextRange().getEndOffset();
57 for (PsiElement child
: children
) {
58 if (child
instanceof PsiDocToken
) {
59 PsiDocToken token
= (PsiDocToken
)child
;
61 if (token
.getTokenType() == JavaDocTokenType
.DOC_COMMENT_DATA
) {
62 char[] chars
= token
.getText().toCharArray();
64 if (CharArrayUtil
.shiftForward(chars
, 0, " *\n\t\r") != chars
.length
) {
65 endOffset
= child
.getTextRange().getEndOffset();
71 startOffset
= CharArrayUtil
.shiftBackward(editorText
, startOffset
- 1, "* \t") + 1;
73 result
.add(new TextRange(startOffset
, endOffset
));