use of com.perl5.lang.perl.psi.stubs.PerlPolyNamedElementType in project Perl5-IDEA by Camelcade.
the class PerlIndentProcessor method getNodeIndent.
@NotNull
public Indent getNodeIndent(@NotNull ASTNode node) {
IElementType nodeType = node.getElementType();
ASTNode parent = node.getTreeParent();
ASTNode grandParent = parent != null ? parent.getTreeParent() : null;
IElementType parentNodeType = parent != null ? parent.getElementType() : null;
IElementType grandParentNodeType = grandParent != null ? grandParent.getElementType() : null;
ASTNode prevSibling = FormatterUtil.getPreviousNonWhitespaceSibling(node);
IElementType prevSiblingElementType = prevSibling != null ? prevSibling.getElementType() : null;
ASTNode nextSibling = FormatterUtil.getNextNonWhitespaceSibling(node);
IElementType nextSiblingElementType = nextSibling != null ? nextSibling.getElementType() : null;
boolean isFirst = prevSibling == null;
boolean isLast = nextSibling == null;
if (parentNodeType == ATTRIBUTES) {
return Indent.getContinuationIndent();
}
if (isFirst && BLOCK_OPENERS.contains(nodeType) || isLast && BLOCK_CLOSERS.contains(nodeType)) {
return Indent.getNoneIndent();
}
if (VARIABLE_DECLARATIONS.contains(parentNodeType) && (nodeType == LEFT_PAREN || nodeType == RIGHT_PAREN)) {
return Indent.getNoneIndent();
}
boolean forceFirstIndent = false;
if (HEREDOC_BODIES_TOKENSET.contains(nodeType)) {
PsiElement psi = node.getPsi();
assert psi instanceof PerlHeredocElementImpl;
if (!((PerlHeredocElementImpl) psi).isIndentable()) {
return Indent.getAbsoluteNoneIndent();
}
forceFirstIndent = true;
}
if (getAbsoluteUnindentableTokens().contains(nodeType)) {
return Indent.getAbsoluteNoneIndent();
}
if (nodeType == BLOCK && MULTI_PARAM_BLOCK_CONTAINERS.contains(parentNodeType)) {
return Indent.getNoneIndent();
}
if (parent == null || grandParent == null && nodeType != HEREDOC_END_INDENTABLE && !HEREDOC_BODIES_TOKENSET.contains(nodeType)) {
return Indent.getNoneIndent();
}
if (getUnindentableTokens().contains(nodeType) || (nodeType instanceof PerlPolyNamedElementType && !(node.getPsi() instanceof PerlPolyNamedNestedCallElementBase))) {
return Indent.getNoneIndent();
}
if (parentNodeType == STRING_LIST && (nodeType == QUOTE_SINGLE_OPEN || nodeType == QUOTE_SINGLE_CLOSE)) {
return Indent.getNoneIndent();
}
if (nodeType == STRING_CONTENT && (parentNodeType == STRING_LIST || parentNodeType == LP_STRING_QW)) {
return Indent.getContinuationIndent();
}
// defined by parent
if (getUnindentableContainers().contains(parentNodeType)) {
// a little magic for sub attributes
if (parentNodeType == SUB_DEFINITION) {
if (nodeType == COLON && nextSiblingElementType == ATTRIBUTE || nodeType == ATTRIBUTE && prevSiblingElementType != COLON) {
return Indent.getContinuationIndent();
}
}
return Indent.getNoneIndent();
}
if (PerlFormattingContext.COMMA_LIKE_SEQUENCES.contains(parentNodeType)) {
return grandParentNodeType == STATEMENT ? Indent.getContinuationWithoutFirstIndent() : Indent.getContinuationIndent();
}
if (parentNodeType == CALL_ARGUMENTS) {
return Indent.getContinuationIndent();
}
if (getBlockLikeContainers().contains(parentNodeType)) {
return Indent.getNormalIndent();
}
return forceFirstIndent ? Indent.getContinuationIndent() : Indent.getContinuationWithoutFirstIndent();
}
Aggregations