本文整理汇总了Java中com.intellij.formatting.Block类的典型用法代码示例。如果您正苦于以下问题:Java Block类的具体用法?Java Block怎么用?Java Block使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Block类属于com.intellij.formatting包,在下文中一共展示了Block类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildChildren
import com.intellij.formatting.Block; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<>();
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
if (child.getElementType() != TokenType.WHITE_SPACE) {
Block block = new FlexibleSearchBlock(
child,
Wrap.createWrap(WrapType.NONE, false),
null,
spacingBuilder
);
blocks.add(block);
}
child = child.getTreeNext();
}
return blocks;
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:FlexibleSearchBlock.java
示例2: createModel
import com.intellij.formatting.Block; //导入依赖的package包/类
@NotNull
@Override
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
final Block impexBlock = new ImpexBlock(
element.getNode(),
null,
Alignment.createAlignment(),
createSpaceBuilder(settings)
);
return FormattingModelProvider.createFormattingModelForPsiFile(
element.getContainingFile(),
impexBlock,
settings
);
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:18,代码来源:ImpexFormattingModelBuilder.java
示例3: getSpacing
import com.intellij.formatting.Block; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
if (!formattingInfo.getCsvCodeStyleSettings().TABULARIZE || formattingInfo.getCsvCodeStyleSettings().WHITE_SPACES_OUTSIDE_QUOTES || child1 == null) {
return null;
}
int spaces = 0;
CsvBlockElement block1 = (CsvBlockElement) child1;
CsvBlockElement block2 = (CsvBlockElement) child2;
if ((block1.getElementType() == CsvTypes.QUOTE && formattingInfo.getCsvCodeStyleSettings().LEADING_WHITE_SPACES) ||
(block2.getElementType() == CsvTypes.QUOTE && !formattingInfo.getCsvCodeStyleSettings().LEADING_WHITE_SPACES)) {
spaces = getColumnInfo().getMaxLength() - getTextLength();
} else {
return formattingInfo.getSpacingBuilder().getSpacing(this, child1, child2);
}
return Spacing.createSpacing(spaces, spaces, 0, true, 0);
}
示例4: generateForBinaryExpr
import com.intellij.formatting.Block; //导入依赖的package包/类
/**
* Generates blocks for binary expressions
*
* @param node
* @return
*/
private static List<Block> generateForBinaryExpr(final ASTNode node, Wrap myWrap, CodeStyleSettings mySettings) {
final ArrayList<Block> subBlocks = new ArrayList<Block>();
Alignment alignment = mySettings.ALIGN_MULTILINE_BINARY_OPERATION ? Alignment.createAlignment() : null;
LuaBinaryExpression myExpr = (LuaBinaryExpression) node.getPsi();
ASTNode[] children = node.getChildren(null);
if (myExpr.getLeftExpression() instanceof LuaBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getLeftExpression(), subBlocks, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
}
for (ASTNode childNode : children) {
if (canBeCorrectBlock(childNode) &&
!(childNode.getPsi() instanceof LuaBinaryExpression)) {
subBlocks.add(new LuaFormattingBlock(childNode, alignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
}
}
if (myExpr.getRightExpression() instanceof LuaBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getRightExpression(), subBlocks, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
}
return subBlocks;
}
示例5: addBinaryChildrenRecursively
import com.intellij.formatting.Block; //导入依赖的package包/类
/**
* Adds all children of specified element to given list
*
* @param elem
* @param list
* @param indent
* @param alignment
*/
private static void addBinaryChildrenRecursively(PsiElement elem,
List<Block> list,
Indent indent,
Alignment alignment, Wrap myWrap, CodeStyleSettings mySettings) {
if (elem == null) return;
ASTNode[] children = elem.getNode().getChildren(null);
// For binary expressions
if ((elem instanceof LuaBinaryExpression)) {
LuaBinaryExpression myExpr = ((LuaBinaryExpression) elem);
if (myExpr.getLeftExpression() instanceof LuaBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getLeftExpression(), list, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
}
for (ASTNode childNode : children) {
if (canBeCorrectBlock(childNode) &&
!(childNode.getPsi() instanceof LuaBinaryExpression)) {
list.add(new LuaFormattingBlock(childNode, alignment, indent, myWrap, mySettings));
}
}
if (myExpr.getRightExpression() instanceof LuaBinaryExpression) {
addBinaryChildrenRecursively(myExpr.getRightExpression(), list, Indent.getContinuationWithoutFirstIndent(), alignment, myWrap, mySettings);
}
}
}
示例6: generateForNestedExpr
import com.intellij.formatting.Block; //导入依赖的package包/类
/**
* Generates blocks for nested expressions like a.b.c etc.
*
* @param node
* @return
*/
private static List<Block> generateForNestedExpr(final ASTNode node, Alignment myAlignment, Wrap myWrap, CodeStyleSettings mySettings) {
final ArrayList<Block> subBlocks = new ArrayList<Block>();
ASTNode children[] = node.getChildren(null);
if (children.length > 0 && false /* NESTED.contains(children[0].getElementType()) */) {
addNestedChildrenRecursively(children[0].getPsi(), subBlocks, myAlignment, myWrap, mySettings);
} else if (canBeCorrectBlock(children[0])) {
subBlocks.add(new LuaFormattingBlock(children[0], myAlignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
}
if (children.length > 1) {
for (ASTNode childNode : children) {
if (canBeCorrectBlock(childNode) &&
children[0] != childNode) {
subBlocks.add(new LuaFormattingBlock(childNode, myAlignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
}
}
}
return subBlocks;
}
示例7: addNestedChildrenRecursively
import com.intellij.formatting.Block; //导入依赖的package包/类
/**
* Adds nested children for paths
*
* @param elem
* @param list
* @param myAlignment
* @param mySettings
*/
private static void addNestedChildrenRecursively(PsiElement elem,
List<Block> list, Alignment myAlignment, Wrap myWrap, CodeStyleSettings mySettings) {
ASTNode[] children = elem.getNode().getChildren(null);
// For path expressions
if (children.length > 0) {
addNestedChildrenRecursively(children[0].getPsi(), list, myAlignment, myWrap, mySettings);
} else if (canBeCorrectBlock(children[0])) {
list.add(new LuaFormattingBlock(children[0], myAlignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
}
if (children.length > 1) {
for (ASTNode childNode : children) {
if (canBeCorrectBlock(childNode) &&
children[0] != childNode) {
if (elem.getNode() != null) {
list.add(new LuaFormattingBlock(childNode, myAlignment, Indent.getContinuationWithoutFirstIndent(), myWrap, mySettings));
} else {
list.add(new LuaFormattingBlock(childNode, myAlignment, Indent.getNoneIndent(), myWrap, mySettings));
}
}
}
}
}
示例8: buildChildren
import com.intellij.formatting.Block; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<>();
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child)) {
IElementType elementType = child.getElementType();
if (ProtoParserDefinition.rule(ProtoParser.RULE_proto).equals(elementType)) {
appendProtoBlocks(child, blocks);
} else {
// Comments are not part of root rule, we have to append them separately
blocks.add(new LeafBlock(child, Alignment.createAlignment(), Indent.getNoneIndent(), settings));
}
}
child = child.getTreeNext();
}
return blocks;
}
示例9: getSpacing
import com.intellij.formatting.Block; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
if (child1 == null) {
return StatementBlock.NONE;
}
if (child2 instanceof ASTBlock) {
ASTBlock block = (ASTBlock) child2;
IElementType elementType = block.getNode().getElementType();
// Do not move trailing comments to new line.
if (LINE_COMMENT.equals(elementType)
|| COMMENT.equals(elementType)) {
return SPACE_OR_NEW_LINE;
}
}
return StatementBlock.NEW_LINE;
}
示例10: getSpacing
import com.intellij.formatting.Block; //导入依赖的package包/类
@Nullable
@Override
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
if (child2 instanceof ASTBlock) {
ASTBlock block = (ASTBlock) child2;
// Do not move semicolon after '}' to new line.
IElementType elementType = block.getNode().getElementType();
if (SEMICOLON.equals(elementType)) {
return NONE;
}
// Do not move trailing comments to new line.
if (LINE_COMMENT.equals(elementType)
|| COMMENT.equals(elementType)) {
return SPACE_OR_NEW_LINE;
}
}
if (headerBlocks.contains(child1)) {
return super.getSpacing(child1, child2);
}
return NEW_LINE;
}
示例11: buildChildren
import com.intellij.formatting.Block; //导入依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<Block>();
if (myNode.getElementType() == STRUCT) {
goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, pairContainers);
} else if (myNode.getElementType() == ARRAY) {
goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, arrayContainers);
} else if (myNode.getElementType() == EXPRESSION) {
goDeep(blocks, myNode, myAlignment, Alignment.createAlignment(), false, expressionContainers);
} else {
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
if (child.getElementType() != TokenType.WHITE_SPACE) {
Block block = new IonBlock(child, Wrap.createWrap(WrapType.NORMAL, false), myAlignment, spacingBuilder, settings);
blocks.add(block);
}
child = child.getTreeNext();
}
}
return blocks;
}
示例12: buildNodeChildBlocks
import com.intellij.formatting.Block; //导入依赖的package包/类
public List<Block> buildNodeChildBlocks(ASTNode node, BlockFactory factory) {
List<Block> blocks = ContainerUtil.newArrayList();
for (ASTNode child : node.getChildren(null)) {
if (FormatterUtil.isWhitespaceOrEmpty(child) || child.getTextLength() == 0) {
continue;
}
Alignment alignment = myConfig.getAlignment(child);
IElementType type = child.getElementType();
Indent indent = myConfig.getIndent(type);
Wrap wrap = myConfig.getWrap(type);
blocks.add(factory.createBlock(child, indent, alignment, wrap));
}
return blocks;
}
示例13: create
import com.intellij.formatting.Block; //导入依赖的package包/类
@NotNull
public Block create(@NotNull final List<ASTNode> subNodes, final Wrap wrap, @Nullable final Alignment alignment) {
final ArrayList<Block> subBlocks = new ArrayList<Block>();
final ASTNode firstNode = subNodes.get(0);
if (firstNode.getElementType() == JavaTokenType.DOT) {
AlignmentStrategy strategy = AlignmentStrategy.getNullStrategy();
Block block = newJavaBlock(firstNode, mySettings, myJavaSettings, Indent.getNoneIndent(), null, strategy);
subBlocks.add(block);
subNodes.remove(0);
if (!subNodes.isEmpty()) {
subBlocks.add(create(subNodes, wrap, null));
}
return new SyntheticCodeBlock(subBlocks, alignment, mySettings, myJavaSettings, Indent.getContinuationIndent(myIndentSettings.USE_RELATIVE_INDENTS), wrap);
}
return new SyntheticCodeBlock(createJavaBlocks(subNodes), alignment, mySettings, myJavaSettings, Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS), null);
}
示例14: doTestLineToIndentMapping
import com.intellij.formatting.Block; //导入依赖的package包/类
private static void doTestLineToIndentMapping(@NotNull String text, int... spacesForLine) {
configureFromFileText("x.java", text);
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(document);
Assert.assertNotNull(builder);
FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
Block block = model.getRootBlock();
List<LineIndentInfo> list = new FormatterBasedLineIndentInfoBuilder(document, block).build();
Assert.assertEquals(list.size(), spacesForLine.length);
for (int i = 0; i < spacesForLine.length; i++) {
int indentSize = list.get(i).getIndentSize();
Assert.assertEquals("Mismatch on line " + i, spacesForLine[i], indentSize);
}
}
示例15: DocumentBasedFormattingModel
import com.intellij.formatting.Block; //导入依赖的package包/类
@Deprecated
public DocumentBasedFormattingModel(final Block rootBlock,
@NotNull final Document document,
final Project project,
final CodeStyleSettings settings,
final FileType fileType,
final PsiFile file) {
myRootBlock = rootBlock;
myDocument = document;
myProject = project;
mySettings = settings;
myFileType = fileType;
myFile = file;
myDocumentModel = new FormattingDocumentModelImpl(document,file);
myOriginalFormattingModel = null;
}