update copyright
[fedora-idea.git] / xml / impl / src / com / intellij / codeInsight / editorActions / XmlCDATAContentSelectioner.java
blobfe440e00a0d4df9b7877204c4f7f4d8b7d6b5eec
1 /*
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;
18 import com.intellij.psi.PsiElement;
19 import com.intellij.psi.xml.XmlElementType;
20 import com.intellij.psi.xml.XmlToken;
21 import com.intellij.psi.xml.XmlTokenType;
22 import com.intellij.psi.impl.source.tree.CompositePsiElement;
23 import com.intellij.openapi.util.TextRange;
24 import com.intellij.openapi.editor.Editor;
26 import java.util.List;
28 public class XmlCDATAContentSelectioner extends ExtendWordSelectionHandlerBase {
29 public boolean canSelect(PsiElement e) {
30 return e instanceof CompositePsiElement &&
31 ((CompositePsiElement)e).getElementType() == XmlElementType.XML_CDATA;
34 public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
35 List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
36 PsiElement[] children = e.getChildren();
38 PsiElement first = null;
39 PsiElement last = null;
40 for (PsiElement child : children) {
41 if (child instanceof XmlToken) {
42 XmlToken token = (XmlToken)child;
43 if (token.getTokenType() == XmlTokenType.XML_CDATA_START) {
44 first = token.getNextSibling();
46 if (token.getTokenType() == XmlTokenType.XML_CDATA_END) {
47 last = token.getPrevSibling();
48 break;
53 if (first != null && last != null) {
54 result.addAll(expandToWholeLine(editorText,
55 new TextRange(first.getTextRange().getStartOffset(),
56 last.getTextRange().getEndOffset()),
57 false));
60 return result;