use of org.jetbrains.plugins.groovy.formatter.blocks.GroovyBlock in project intellij-community by JetBrains.
the class GroovyFormattingModelBuilder method createModel.
@Override
@NotNull
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
ASTNode node = element.getNode();
assert node != null;
PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(GroovyLanguage.INSTANCE);
assert containingFile != null : element.getContainingFile();
ASTNode astNode = containingFile.getNode();
assert astNode != null;
CommonCodeStyleSettings groovySettings = settings.getCommonSettings(GroovyLanguage.INSTANCE);
GroovyCodeStyleSettings customSettings = settings.getCustomSettings(GroovyCodeStyleSettings.class);
final AlignmentProvider alignments = new AlignmentProvider();
if (customSettings.USE_FLYING_GEESE_BRACES) {
element.accept(new PsiRecursiveElementVisitor() {
@Override
public void visitElement(PsiElement element) {
if (GeeseUtil.isClosureRBrace(element)) {
GeeseUtil.calculateRBraceAlignment(element, alignments);
} else {
super.visitElement(element);
}
}
});
}
final GroovyBlock block = new GroovyBlock(astNode, Indent.getAbsoluteNoneIndent(), null, new FormattingContext(groovySettings, alignments, customSettings, false));
return new GroovyFormattingModel(containingFile, block, FormattingDocumentModelImpl.createOn(containingFile));
}
Aggregations