本文整理汇总了Java中com.intellij.psi.formatter.FormatterUtil类的典型用法代码示例。如果您正苦于以下问题:Java FormatterUtil类的具体用法?Java FormatterUtil怎么用?Java FormatterUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FormatterUtil类属于com.intellij.psi.formatter包,在下文中一共展示了FormatterUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildChildren
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的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;
}
示例2: combineWithErrorElementIfPossible
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
/**
* Checks if previous non-white space leaf of the given node is error element and combines formatting range relevant for it
* with the range of the given node.
*
* @param node target node
* @return given node range if there is no error-element before it; combined range otherwise
*/
@Nullable
private static TextRange combineWithErrorElementIfPossible(@NotNull ASTNode node) {
if (node.getElementType() == TokenType.ERROR_ELEMENT) {
return node.getTextRange();
}
final ASTNode prevLeaf = FormatterUtil.getPreviousLeaf(node, TokenType.WHITE_SPACE);
if (prevLeaf == null || prevLeaf.getElementType() != TokenType.ERROR_ELEMENT) {
return node.getTextRange();
}
final TextRange range = doGetRangeAffectingIndent(prevLeaf);
if (range == null) {
return node.getTextRange();
}
else {
return new TextRange(range.getStartOffset(), node.getTextRange().getEndOffset());
}
}
示例3: buildChildren
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
final ArrayList<Block> result = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
Indent currentIndent = getLabelIndent();
Wrap currentWrap = null;
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0){
result.add(createJavaBlock(child, mySettings, myJavaSettings, currentIndent, currentWrap, AlignmentStrategy.getNullStrategy()));
if (child.getElementType() == JavaTokenType.COLON) {
currentIndent = Indent.getNoneIndent();
currentWrap =Wrap.createWrap(WrapType.ALWAYS, true);
}
}
child = child.getTreeNext();
}
return result;
}
示例4: processHeadCommentsAndWhiteSpaces
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
private void processHeadCommentsAndWhiteSpaces(@NotNull List<Block> result) {
while (myCurrentChild != null) {
if (StdTokenSets.COMMENT_BIT_SET.contains(myCurrentChild.getElementType()) || myCurrentChild.getElementType() == JavaDocElementType.DOC_COMMENT) {
Block commentBlock = createJavaBlock(
myCurrentChild,
mySettings, myJavaSettings,
Indent.getNoneIndent(), null, AlignmentStrategy.getNullStrategy()
);
result.add(commentBlock);
myCurrentIndent = Indent.getNoneIndent();
}
else if (!FormatterUtil.containsWhiteSpacesOnly(myCurrentChild)) {
break;
}
myCurrentOffset += myCurrentChild.getTextLength();
myCurrentChild = myCurrentChild.getTreeNext();
}
}
示例5: processField
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
private ASTNode processField(@NotNull final List<Block> result,
ASTNode child,
@NotNull final AlignmentStrategy alignmentStrategy,
final Wrap defaultWrap,
final Indent childIndent) {
ASTNode lastFieldInGroup = findLastFieldInGroup(child);
if (lastFieldInGroup == child) {
result.add(createJavaBlock(child, getSettings(), myJavaSettings, childIndent, arrangeChildWrap(child, defaultWrap), alignmentStrategy));
return child;
}
else {
final ArrayList<Block> localResult = new ArrayList<Block>();
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child)) {
localResult.add(createJavaBlock(
child, getSettings(), myJavaSettings,
Indent.getContinuationWithoutFirstIndent(myIndentSettings.USE_RELATIVE_INDENTS),
arrangeChildWrap(child, defaultWrap),
alignmentStrategy
)
);
}
if (child == lastFieldInGroup) break;
child = child.getTreeNext();
}
if (!localResult.isEmpty()) {
result.add(new SyntheticCodeBlock(localResult, null, getSettings(), myJavaSettings, childIndent, null));
}
return lastFieldInGroup;
}
}
示例6: collectNodes
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
private static void collectNodes(@NotNull List<ASTNode> nodes, @NotNull ASTNode node) {
ASTNode child = node.getFirstChildNode();
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child)) {
IElementType type = child.getElementType();
if (type == JavaElementType.METHOD_CALL_EXPRESSION ||
type == JavaElementType.REFERENCE_EXPRESSION) {
collectNodes(nodes, child);
}
else {
nodes.add(child);
}
}
child = child.getTreeNext();
}
}
示例7: shouldAlignFieldInColumns
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
/**
* Encapsulates alignment retrieval logic for variable declaration use-case assuming that given node is a child node
* of basic variable declaration node.
*
* @param child variable declaration child node which alignment is to be defined
* @return alignment to use for the given node
* @see CodeStyleSettings#ALIGN_GROUP_FIELD_DECLARATIONS
*/
@Nullable
private boolean shouldAlignFieldInColumns(@NotNull ASTNode child) {
// The whole idea of variable declarations alignment is that complete declaration blocks which children are to be aligned hold
// reference to the same AlignmentStrategy object, hence, reuse the same Alignment objects. So, there is no point in checking
// if it's necessary to align sub-blocks if shared strategy is not defined.
if (!mySettings.ALIGN_GROUP_FIELD_DECLARATIONS) {
return false;
}
IElementType childType = child.getElementType();
// We don't want to align subsequent identifiers in single-line declarations like 'int i1, i2, i3'. I.e. only 'i1'
// should be aligned then.
ASTNode previousNode = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if (childType == JavaTokenType.IDENTIFIER && (previousNode == null || previousNode.getElementType() == JavaTokenType.COMMA)) {
return false;
}
return true;
}
示例8: processEnumBlock
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Nullable
private ASTNode processEnumBlock(@NotNull List<Block> result,
@Nullable ASTNode child,
ASTNode last)
{
final WrappingStrategy wrappingStrategy = WrappingStrategy.createDoNotWrapCommaStrategy(Wrap
.createWrap(getWrapType(mySettings.ENUM_CONSTANTS_WRAP), true));
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
result.add(createJavaBlock(child, mySettings, myJavaSettings, Indent.getNormalIndent(),
wrappingStrategy.getWrap(child.getElementType()), AlignmentStrategy.getNullStrategy()));
if (child == last) return child;
}
child = child.getTreeNext();
}
return null;
}
示例9: buildChildren
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
final ArrayList<Block> result = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
while (child != null) {
if (child.getElementType() == JavaDocTokenType.DOC_COMMENT_START) {
result.add(createJavaBlock(child, mySettings, myJavaSettings, Indent.getNoneIndent(), null, AlignmentStrategy.getNullStrategy()));
} else if (!FormatterUtil.containsWhiteSpacesOnly(child) && !child.getText().trim().isEmpty()){
result.add(createJavaBlock(child, mySettings, myJavaSettings, Indent.getSpaceIndent(1), null, AlignmentStrategy.getNullStrategy()));
}
child = child.getTreeNext();
}
return result;
}
示例10: getAlignmentStrategy
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
/**
* There is a possible case that 'implements' section is incomplete (e.g. ends with comma). We may want to align lbrace
* to the comma then.
*
* @param alignment block alignment
* @param baseNode base AST node
* @return alignment strategy to use for the given node
*/
private static AlignmentStrategy getAlignmentStrategy(Alignment alignment, ASTNode baseNode, @NotNull CommonCodeStyleSettings settings) {
if (baseNode.getElementType() != JavaElementType.CLASS || !settings.ALIGN_MULTILINE_EXTENDS_LIST) {
return AlignmentStrategy.wrap(alignment);
}
for (ASTNode node = baseNode.getLastChildNode(); node != null; node = FormatterUtil.getPreviousNonWhitespaceSibling(node)) {
if (node.getElementType() != JavaElementType.IMPLEMENTS_LIST) {
continue;
}
ASTNode lastChildNode = node.getLastChildNode();
if (lastChildNode != null && lastChildNode.getElementType() == TokenType.ERROR_ELEMENT) {
Alignment alignmentToUse = alignment;
if (alignment == null) {
alignmentToUse = Alignment.createAlignment();
}
return AlignmentStrategy.wrap(
alignmentToUse, false, JavaTokenType.LBRACE, JavaElementType.JAVA_CODE_REFERENCE, node.getElementType()
);
}
break;
}
return AlignmentStrategy.wrap(alignment);
}
示例11: buildNodeChildBlocks
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的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;
}
示例12: runCheckinHandlers
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Override
public void runCheckinHandlers(@NotNull final Runnable finishAction) {
final VcsConfiguration configuration = VcsConfiguration.getInstance(myProject);
final Collection<VirtualFile> files = myPanel.getVirtualFiles();
final Runnable performCheckoutAction = new Runnable() {
@Override
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
finishAction.run();
}
};
if (reformat(configuration, true)) {
new ReformatCodeProcessor(
myProject, CheckinHandlerUtil.getPsiFiles(myProject, files), FormatterUtil.REFORMAT_BEFORE_COMMIT_COMMAND_NAME, performCheckoutAction, true
).run();
}
else {
performCheckoutAction.run();
}
}
示例13: buildChildren
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
myChildrenBuilt = true;
if (isLeaf()) {
return EMPTY;
}
final ArrayList<TemplateLanguageBlock> tlChildren = new ArrayList<TemplateLanguageBlock>(5);
for (ASTNode childNode = getNode().getFirstChildNode(); childNode != null; childNode = childNode.getTreeNext()) {
if (FormatterUtil.containsWhiteSpacesOnly(childNode)) continue;
if (shouldBuildBlockFor(childNode)) {
final TemplateLanguageBlock childBlock = myBlockFactory
.createTemplateLanguageBlock(childNode, createChildWrap(childNode), createChildAlignment(childNode), null, mySettings);
childBlock.setParent(this);
tlChildren.add(childBlock);
}
}
final List<Block> children = (List<Block>)(myForeignChildren == null ? tlChildren : BlockUtil.mergeBlocks(tlChildren, myForeignChildren));
//BlockUtil.printBlocks(getTextRange(), children);
return BlockUtil.setParent(children, this);
}
示例14: manageComments
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
private boolean manageComments() {
if (mySettings.KEEP_FIRST_COLUMN_COMMENT && TokenSets.COMMENT_SET.contains(myType2)) {
if (!isAfterElementOrSemi(GroovyElementTypes.IMPORT_STATEMENT)) {
myResult = Spacing.createKeepingFirstColumnSpacing(0, Integer.MAX_VALUE, true, 1);
return true;
}
return false;
}
ASTNode prev = FormatterUtil.getPreviousNonWhitespaceLeaf(myChild2);
if (prev != null && prev.getElementType() == GroovyTokenTypes.mNLS) {
prev = FormatterUtil.getPreviousNonWhitespaceLeaf(prev);
}
if (prev != null && prev.getElementType() == GroovyTokenTypes.mSL_COMMENT) {
myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines());
return true;
}
return false;
}
示例15: buildChildren
import com.intellij.psi.formatter.FormatterUtil; //导入依赖的package包/类
@Override
protected List<Block> buildChildren() {
final ArrayList<Block> result = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
Indent currentIndent = getLabelIndent();
Wrap currentWrap = null;
while (child != null) {
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0){
result.add(createJavaBlock(child, mySettings, currentIndent, currentWrap, AlignmentStrategy.getNullStrategy()));
if (child.getElementType() == ElementType.COLON) {
currentIndent = Indent.getNoneIndent();
currentWrap =Wrap.createWrap(WrapType.ALWAYS, true);
}
}
child = child.getTreeNext();
}
return result;
}