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.
17 package com
.intellij
.formatting
;
19 import com
.intellij
.openapi
.util
.TextRange
;
21 import java
.util
.List
;
23 public class CompositeBlockWrapper
extends AbstractBlockWrapper
{
24 private List
<AbstractBlockWrapper
> myChildren
;
25 //private static final CodeStyleSettings.IndentOptions DEF_OPTIONS = new CodeStyleSettings.IndentOptions();
27 public CompositeBlockWrapper(final Block block
, final WhiteSpace whiteSpace
, final CompositeBlockWrapper parent
, TextRange textRange
) {
28 super(block
, whiteSpace
, parent
, textRange
);
31 public List
<AbstractBlockWrapper
> getChildren() {
35 public void setChildren(final List
<AbstractBlockWrapper
> children
) {
36 myChildren
= children
;
42 if (myChildren
!= null) {
43 for(AbstractBlockWrapper wrapper
:myChildren
) wrapper
.reset();
47 protected boolean indentAlreadyUsedBefore(final AbstractBlockWrapper child
) {
48 for (AbstractBlockWrapper childBefore
: myChildren
) {
49 if (childBefore
== child
) return false;
50 if (childBefore
.getWhiteSpace().containsLineFeeds()) return true;
55 public void dispose() {
60 public AbstractBlockWrapper
getPrevIndentedSibling(final AbstractBlockWrapper current
) {
61 AbstractBlockWrapper candidate
= null;
62 for (AbstractBlockWrapper child
: myChildren
) {
63 if (child
.getStartOffset() >= current
.getStartOffset()) return candidate
;
64 if (child
.getWhiteSpace().containsLineFeeds()) candidate
= child
;
72 public String toString() {
73 StringBuilder result = new StringBuilder();
74 for (AbstractBlockWrapper child : myChildren) {
75 result.append(child.getWhiteSpace().generateWhiteSpace(DEF_OPTIONS)).append(child.toString());
77 return result.toString();