use of com.intellij.formatting.Block in project oxy-template-support-plugin by mutant-industries.
the class OxyTemplateForeignElementWrapper method buildChildren.
@NotNull
public List<Block> buildChildren() {
final FileViewProvider provider = myNode.getPsi().getContainingFile().getViewProvider();
PsiElement element = provider.findElementAt(textRange.getStartOffset(), OxyTemplate.INSTANCE);
assert element != null;
while (OxyTemplateHelper.checkRangeContainsParent(element, textRange, OxyTemplateTypes.T_TEMPLATE_HTML_CODE)) {
element = element.getParent();
}
ASTNode child = element.getNode();
final Alignment textAlignment = Alignment.createAlignment();
ArrayList<Block> result = new ArrayList<>();
while (child != null) {
if (!textRange.contains(child.getTextRange())) {
if (child.getStartOffset() < getTextRange().getEndOffset()) {
while (child.getFirstChildNode() != null && !textRange.contains((child = child.getFirstChildNode()).getTextRange())) ;
} else {
break;
}
}
if (!FormatterUtil.containsWhiteSpacesOnly(child) && child.getTextLength() > 0) {
child = processChild(result, child, null, chooseAlignment(child, textAlignment), indent);
}
child = nextNode(child);
}
return result;
}
use of com.intellij.formatting.Block in project ballerina by ballerina-lang.
the class BallerinaBlock method buildChildren.
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<>();
ASTNode child = node.getFirstChildNode();
IElementType parentElementType = node.getElementType();
while (child != null) {
IElementType childElementType = child.getElementType();
if (childElementType != TokenType.WHITE_SPACE) {
Indent indent = Indent.getNoneIndent();
if (isInsideADefinitionElement(childElementType)) {
if (child.getFirstChildNode() != null && child.getLastChildNode() != null) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == COMMENT_STATEMENT) {
if (isADefinitionElement(parentElementType) || isACodeBlock(parentElementType)) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == WORKER_DECLARATION) {
if (parentElementType == FORK_JOIN_STATEMENT) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == WORKER_BODY) {
if (parentElementType == WORKER_DECLARATION) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == RECORD_KEY_VALUE) {
indent = Indent.getSpaceIndent(4);
} else if (childElementType == CODE_BLOCK_BODY || childElementType == NON_EMPTY_CODE_BLOCK_BODY || childElementType == ENUM_FIELD_LIST) {
indent = Indent.getSpaceIndent(4);
} else if (childElementType == EXPRESSION_LIST) {
if (parentElementType == VARIABLE_REFERENCE) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == FIELD_DEFINITION) {
if (parentElementType == PRIVATE_STRUCT_BODY) {
indent = Indent.getSpaceIndent(4);
}
} else if (childElementType == MATCH_PATTERN_CLAUSE) {
indent = Indent.getSpaceIndent(4);
} else if (childElementType == OBJECT_BODY) {
indent = Indent.getSpaceIndent(4);
} else if (childElementType == OBJECT_FIELD_DEFINITION) {
indent = Indent.getSpaceIndent(4);
} else if (childElementType == STREAMING_QUERY_STATEMENT) {
indent = Indent.getSpaceIndent(4);
}
// If the child node text is empty, the IDEA core will throw an exception.
if (!child.getText().isEmpty()) {
Block block = new BallerinaBlock(child, Alignment.createAlignment(), indent, null, mySettings, spacingBuilder);
blocks.add(block);
}
}
child = child.getTreeNext();
}
return blocks;
}
Aggregations