Block (@NotNull ASTNode child, @NotNull CommonCodeStyleSettings settings, @NotNull JavaCodeStyleSettings javaSettings, @Nullable Indent indent, Wrap wrap, @NotNull AlignmentStrategy alignmentStrategy, int startOffset, @NotNull FormattingMode formattingMode) { Indent actualIndent = indent == null ? getDefaultSubtreeIndent(child, settings) : indent; IElementType elementType = child.getElementType(); Alignment alignment = alignmentStrategy.getAlignment(elementType); PsiElement childPsi = child.getPsi(); if (childPsi instanceof PsiWhiteSpace) { String text = child.getText(); int start = CharArrayUtil.shiftForward(text, 0, " \t\n"); int end = CharArrayUtil.shiftBackward(text, text.length() - 1, " \t\n") + 1; LOG.assertTrue(start < end); TextRange range = new TextRange(start + child.getStartOffset(), end + child.getStartOffset()); return new PartialWhitespaceBlock(child, range, wrap, alignment, actualIndent, settings, javaSettings, myFormattingMode); } if (childPsi instanceof PsiUnnamedClass) { return new SimpleJavaBlock(child, wrap, alignmentStrategy, Indent.getNoneIndent(), settings, javaSettings, formattingMode); } if (childPsi instanceof PsiClass || childPsi instanceof PsiJavaModule) { return new CodeBlockBlock(child, wrap, alignment, actualIndent, settings, javaSettings, formattingMode); } if (child.getElementType() == JavaElementType.METHOD) { return new BlockContainingJavaBlock(child, actualIndent, alignmentStrategy, mySettings, myJavaSettings, formattingMode); } if (isBlockType(elementType)) { return new BlockContainingJavaBlock(child, wrap, alignment, actualIndent, settings, javaSettings, formattingMode); } if (isStatement(child, child.getTreeParent())) { return new CodeBlockBlock(child, wrap, alignment, actualIndent, settings, javaSettings, myFormattingMode); } if (!isBuildIndentsOnly() && child instanceof PsiComment && child instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)child)) { return new CommentWithInjectionBlock(child, wrap, alignment, indent, settings, javaSettings, formattingMode); } if (child instanceof LeafElement || childPsi instanceof PsiJavaModuleReferenceElement) { if (child.getElementType() == JavaTokenType.C_STYLE_COMMENT) { return new CStyleCommentBlock(child, actualIndent); } LeafBlock block = new LeafBlock(child, wrap, alignment, actualIndent); block.setStartOffset(startOffset); return block; } if (isLikeExtendsList(elementType)) { return new ExtendsListBlock(child, wrap, alignmentStrategy, settings, javaSettings, formattingMode); } if (elementType == JavaElementType.CODE_BLOCK) { return new CodeBlockBlock(child, wrap, alignment, actualIndent, settings, javaSettings, formattingMode); } if (elementType == JavaElementType.LABELED_STATEMENT) { return new LabeledJavaBlock(child, wrap, alignment, actualIndent, settings, javaSettings, formattingMode); } if (elementType == JavaDocElementType.DOC_COMMENT) { return new DocCommentBlock(child, wrap, alignment, actualIndent, settings, javaSettings, formattingMode); } if (isTextBlock(childPsi)) { return new TextBlockBlock(child, wrap, alignmentStrategy, actualIndent, settings, javaSettings, formattingMode); } SimpleJavaBlock simpleJavaBlock = new SimpleJavaBlock(child, wrap, alignmentStrategy, actualIndent, settings, javaSettings, myFormattingMode); simpleJavaBlock.setStartOffset(startOffset); return simpleJavaBlock; }