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
.formatter
.xml
;
18 import com
.intellij
.formatting
.Block
;
19 import com
.intellij
.formatting
.ChildAttributes
;
20 import com
.intellij
.formatting
.Indent
;
21 import com
.intellij
.formatting
.Spacing
;
22 import com
.intellij
.lang
.ASTNode
;
23 import com
.intellij
.openapi
.util
.TextRange
;
24 import org
.jetbrains
.annotations
.NotNull
;
25 import org
.jetbrains
.annotations
.Nullable
;
27 import java
.util
.List
;
29 public class AnotherLanguageBlockWrapper
extends AbstractXmlBlock
{
30 private final Block myOriginal
;
31 private final Indent myIndent
;
32 private final int myOffset
;
33 @Nullable private final TextRange myRange
;
35 public AnotherLanguageBlockWrapper(final ASTNode node
,
36 final XmlFormattingPolicy policy
,
37 final Block original
, final Indent indent
,
39 @Nullable TextRange range
) {
40 super(node
, original
.getWrap(), original
.getAlignment(), policy
);
41 myOriginal
= original
;
47 public Indent
getIndent() {
51 public boolean insertLineBreakBeforeTag() {
55 public boolean removeLineBreakBeforeTag() {
59 public boolean isTextElement() {
63 protected List
<Block
> buildChildren() {
64 if (myOffset
== 0 && myRange
== null) return myOriginal
.getSubBlocks();
66 return InjectedLanguageBlockWrapper
.buildBlocks(myOriginal
, myOffset
, myRange
);
70 public TextRange
getTextRange() {
71 final TextRange range
= super.getTextRange();
72 if (myOffset
== 0) return range
;
75 myOffset
+ range
.getStartOffset(),
76 myOffset
+ (myRange
!= null ? myRange
.getLength() : range
.getLength())
80 @Nullable public Spacing
getSpacing(Block child1
, Block child2
) {
81 if (child1
instanceof InjectedLanguageBlockWrapper
) child1
= ((InjectedLanguageBlockWrapper
)child1
).myOriginal
;
82 if (child2
instanceof InjectedLanguageBlockWrapper
) child2
= ((InjectedLanguageBlockWrapper
)child2
).myOriginal
;
83 return myOriginal
.getSpacing(child1
, child2
);
87 public ChildAttributes
getChildAttributes(final int newChildIndex
) {
88 return myOriginal
.getChildAttributes(newChildIndex
);