import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.lang.FileASTNode;
+import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.formatter.FormatterUtil;
import com.intellij.psi.formatter.common.AbstractBlock;
import com.intellij.psi.impl.source.tree.LeafElement;
import com.intellij.psi.tree.IElementType;
-import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.javafx.lang.lexer.JavaFxTokenTypes;
*
* @author Alexey.Ivanov
*/
-public class JavaFxFormattingBlock extends AbstractBlock {
+class JavaFxFormattingBlock extends AbstractBlock {
protected final Indent myIndent;
protected final Indent myChildIndent;
+ protected final CodeStyleSettings myCodeStyleSettings;
- public JavaFxFormattingBlock(final FileASTNode node) {
- this(node, Indent.getAbsoluteNoneIndent(), Indent.getNoneIndent());
+ public JavaFxFormattingBlock(@NotNull final FileASTNode node, @NotNull final CodeStyleSettings codeStyleSettings) {
+ this(node, codeStyleSettings, Indent.getAbsoluteNoneIndent(), Indent.getNoneIndent());
}
- public JavaFxFormattingBlock(final ASTNode node, final Indent indent, final Indent childIndent) {
- this(node, null, null, indent, childIndent);
+ public JavaFxFormattingBlock(@NotNull final ASTNode node,
+ @NotNull final CodeStyleSettings codeStyleSettings,
+ final Indent indent,
+ final Indent childIndent) {
+ this(node, null, null, codeStyleSettings, indent, childIndent);
}
protected JavaFxFormattingBlock(@NotNull final ASTNode node,
@Nullable final Wrap wrap,
@Nullable final Alignment alignment,
+ @NotNull final CodeStyleSettings codeStyleSettings,
final Indent indent,
final Indent childIndent) {
super(node, wrap, alignment);
+ myCodeStyleSettings = codeStyleSettings;
myIndent = indent;
myChildIndent = childIndent;
}
if (type == JavaFxElementTypes.BLOCK_EXPRESSION ||
type == JavaFxElementTypes.OBJECT_LITERAL ||
- type == JavaFxElementTypes.SEQUENCE_LITERAL) {
- blocks.add(new JavaFxBlockFormattingBlock(node, childIndent, Indent.getNormalIndent(false)));
+ type == JavaFxElementTypes.SEQUENCE_LITERAL ||
+ type == JavaFxElementTypes.CLASS_DEFINITION) {
+ blocks.add(new JavaFxBlockFormattingBlock(node, myCodeStyleSettings, childIndent, Indent.getNormalIndent(false)));
}
else {
- blocks.add(new JavaFxFormattingBlock(node, childIndent, Indent.getNoneIndent()));
+ blocks.add(new JavaFxFormattingBlock(node, myCodeStyleSettings, childIndent, Indent.getNoneIndent()));
}
}
}
private static class JavaFxBlockFormattingBlock extends JavaFxFormattingBlock {
- private static final TokenSet BRACES =
- TokenSet.create(JavaFxTokenTypes.LBRACE, JavaFxTokenTypes.RBRACE, JavaFxTokenTypes.LBRACK, JavaFxTokenTypes.RBRACK);
private boolean myInsideBraces;
- public JavaFxBlockFormattingBlock(final ASTNode node, final Indent indent, final Indent childIndent) {
- super(node, indent, childIndent);
+ public JavaFxBlockFormattingBlock(@NotNull final ASTNode node,
+ @NotNull final CodeStyleSettings codeStyleSettings,
+ final Indent indent,
+ final Indent childIndent) {
+ super(node, codeStyleSettings, indent, childIndent);
}
@Override
protected Indent calcIndent(final ASTNode child, final IElementType childType) {
- if (isBrace(childType)) {
+ if (JavaFxFormattingUtil.isBrace(childType)) {
myInsideBraces = (childType == JavaFxTokenTypes.LBRACE || childType == JavaFxTokenTypes.LBRACK);
return Indent.getNoneIndent();
}
return myInsideBraces ? myChildIndent : Indent.getNoneIndent();
}
-
- private boolean isBrace(final IElementType childType) {
- return BRACES.contains(childType);
- }
}
}