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
.psi
.impl
.source
.tree
.injected
;
18 import com
.intellij
.psi
.LiteralTextEscaper
;
19 import com
.intellij
.psi
.impl
.source
.xml
.XmlCommentImpl
;
20 import com
.intellij
.openapi
.util
.TextRange
;
21 import com
.intellij
.openapi
.util
.ProperTextRange
;
22 import com
.intellij
.lang
.Commenter
;
23 import com
.intellij
.lang
.LanguageCommenters
;
24 import com
.intellij
.lang
.CodeDocumentationAwareCommenter
;
25 import org
.jetbrains
.annotations
.NotNull
;
30 public class XmlCommentLiteralEscaper
extends LiteralTextEscaper
<XmlCommentImpl
> {
31 public XmlCommentLiteralEscaper(@NotNull XmlCommentImpl host
) {
35 public boolean decode(@NotNull final TextRange rangeInsideHost
, @NotNull final StringBuilder outChars
) {
36 ProperTextRange
.assertProperRange(rangeInsideHost
);
37 outChars
.append(myHost
.getText(), rangeInsideHost
.getStartOffset(), rangeInsideHost
.getEndOffset());
41 public int getOffsetInHost(final int offsetInDecoded
, @NotNull final TextRange rangeInsideHost
) {
42 int offset
= offsetInDecoded
+ rangeInsideHost
.getStartOffset();
43 if (offset
< rangeInsideHost
.getStartOffset()) offset
= rangeInsideHost
.getStartOffset();
44 if (offset
> rangeInsideHost
.getEndOffset()) offset
= rangeInsideHost
.getEndOffset();
48 public boolean isOneLine() {
49 final Commenter commenter
= LanguageCommenters
.INSTANCE
.forLanguage(myHost
.getLanguage());
50 if (commenter
instanceof CodeDocumentationAwareCommenter
) {
51 return myHost
.getTokenType() == ((CodeDocumentationAwareCommenter
) commenter
).getLineCommentTokenType();