本文整理汇总了Java中com.intellij.psi.formatter.FormatterUtil.getPreviousNonWhitespaceSibling方法的典型用法代码示例。如果您正苦于以下问题:Java FormatterUtil.getPreviousNonWhitespaceSibling方法的具体用法?Java FormatterUtil.getPreviousNonWhitespaceSibling怎么用?Java FormatterUtil.getPreviousNonWhitespaceSibling使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.formatter.FormatterUtil
的用法示例。
在下文中一共展示了FormatterUtil.getPreviousNonWhitespaceSibling方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: getDefaultSubtreeIndent
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Nullable
private static Indent getDefaultSubtreeIndent(@NotNull ASTNode child, @NotNull CommonCodeStyleSettings.IndentOptions indentOptions) {
final ASTNode parent = child.getTreeParent();
final IElementType childNodeType = child.getElementType();
if (childNodeType == JavaElementType.ANNOTATION) {
if (parent.getPsi() instanceof PsiArrayInitializerMemberValue) {
return Indent.getNormalIndent();
}
return Indent.getNoneIndent();
}
final ASTNode prevElement = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if (prevElement != null && prevElement.getElementType() == JavaElementType.MODIFIER_LIST) {
return Indent.getNoneIndent();
}
if (childNodeType == JavaDocElementType.DOC_TAG) return Indent.getNoneIndent();
if (childNodeType == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) return Indent.getSpaceIndent(1);
if (child.getPsi() instanceof PsiFile) return Indent.getNoneIndent();
if (parent != null) {
final Indent defaultChildIndent = getChildIndent(parent, indentOptions);
if (defaultChildIndent != null) return defaultChildIndent;
}
return null;
}
示例4: getVariableDeclarationSubElementAlignment
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 Alignment getVariableDeclarationSubElementAlignment(@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 null;
}
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 null;
}
return myAlignmentStrategy.getAlignment(childType);
}
示例5: 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);
}
示例6: 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
*/
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;
}
示例7: getDefaultSubtreeIndent
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Nullable
private static Indent getDefaultSubtreeIndent(@NotNull ASTNode child, @NotNull CommonCodeStyleSettings.IndentOptions indentOptions) {
final ASTNode parent = child.getTreeParent();
final IElementType childNodeType = child.getElementType();
if (childNodeType == JavaElementType.ANNOTATION) {
if (parent.getPsi() instanceof PsiArrayInitializerMemberValue) {
return Indent.getNormalIndent();
}
return Indent.getNoneIndent();
}
final ASTNode prevElement = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if (prevElement != null && prevElement.getElementType() == JavaElementType.MODIFIER_LIST) {
return Indent.getNoneIndent();
}
if (childNodeType == JavaDocElementType.DOC_TAG) return Indent.getNoneIndent();
if (childNodeType == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) return Indent.getSpaceIndent(1);
if (child.getPsi() instanceof PsiFile) return Indent.getNoneIndent();
if (parent != null) {
final Indent defaultChildIndent = getChildIndent(parent, indentOptions);
if (defaultChildIndent != null) return defaultChildIndent;
}
if (child.getTreeParent() instanceof PsiLambdaExpression && child instanceof PsiCodeBlock) {
return Indent.getNoneIndent();
}
return null;
}
示例8: 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);
}
示例9: getTypeOfPreviousElement
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
private IElementType getTypeOfPreviousElement(ASTNode myNode) {
ASTNode prevSibling = FormatterUtil.getPreviousNonWhitespaceSibling(myNode);
IElementType prevType = prevSibling != null ? prevSibling.getElementType() : null;
return prevType;
}
示例10: getDefaultSubtreeIndent
import com.intellij.psi.formatter.FormatterUtil; //导入方法依赖的package包/类
@Nullable
private static Indent getDefaultSubtreeIndent(@NotNull ASTNode child, @NotNull CommonCodeStyleSettings.IndentOptions indentOptions)
{
final ASTNode parent = child.getTreeParent();
final IElementType childNodeType = child.getElementType();
if(childNodeType == JavaElementType.ANNOTATION)
{
if(parent.getPsi() instanceof PsiArrayInitializerMemberValue)
{
return Indent.getNormalIndent();
}
return Indent.getNoneIndent();
}
final ASTNode prevElement = FormatterUtil.getPreviousNonWhitespaceSibling(child);
if(prevElement != null && prevElement.getElementType() == JavaElementType.MODIFIER_LIST && !isMethodParameterAnnotation(prevElement))
{
return Indent.getNoneIndent();
}
if(childNodeType == JavaDocElementType.DOC_TAG)
{
return Indent.getNoneIndent();
}
if(childNodeType == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS)
{
return Indent.getSpaceIndent(1);
}
if(child.getPsi() instanceof PsiFile)
{
return Indent.getNoneIndent();
}
if(parent != null)
{
final Indent defaultChildIndent = getChildIndent(parent, indentOptions);
if(defaultChildIndent != null)
{
return defaultChildIndent;
}
if(parent.getPsi() instanceof PsiLambdaExpression && child instanceof PsiCodeBlock)
{
return Indent.getNoneIndent();
}
}
return null;
}