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
.codeInsight
.editorActions
.ExtendWordSelectionHandler
;
19 import com
.intellij
.lang
.Language
;
20 import com
.intellij
.lang
.StdLanguages
;
21 import com
.intellij
.openapi
.editor
.Editor
;
22 import com
.intellij
.openapi
.util
.TextRange
;
23 import com
.intellij
.psi
.PsiComment
;
24 import com
.intellij
.psi
.PsiElement
;
25 import com
.intellij
.psi
.util
.PsiTreeUtil
;
27 import java
.util
.Arrays
;
28 import java
.util
.Collections
;
29 import java
.util
.List
;
31 public class AntLikePropertySelectionHandler
implements ExtendWordSelectionHandler
{
32 public boolean canSelect(PsiElement e
) {
33 Language l
= e
.getLanguage();
34 if (!(l
.equals(StdLanguages
.JAVA
)
35 || l
.equals(StdLanguages
.XML
)
36 || l
.equals(StdLanguages
.ANT
))) {
40 return PsiTreeUtil
.getParentOfType(e
, PsiComment
.class) == null;
43 public List
<TextRange
> select(PsiElement e
, CharSequence editorText
, int cursorOffset
, Editor editor
) {
44 TextRange range
= e
.getTextRange();
45 char prevLeftChar
= ' ';
46 for (int left
= cursorOffset
; left
>= range
.getStartOffset(); left
--) {
47 char leftChar
= editorText
.charAt(left
);
48 if (leftChar
== '}') return Collections
.emptyList();
49 if (leftChar
== '$' && prevLeftChar
== '{') {
50 for (int right
= cursorOffset
; right
< range
.getEndOffset(); right
++) {
51 char rightChar
= editorText
.charAt(right
);
52 if (rightChar
== '{') return Collections
.emptyList();
53 if (rightChar
== '}') {
54 return Arrays
.asList(new TextRange(left
+ 2, right
), new TextRange(left
, right
+ 1));
58 prevLeftChar
= leftChar
;
60 return Collections
.emptyList();