Why in JetFormattingModelBuilder.createModel(element, settings) model created around given element, but not a PsiFile a whole?
E.g. why we now have:
kotlin/idea/src/org/jetbrains/jet/plugin/formatter/JetFormattingModelBuilder.java
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
JetBlock block = new JetBlock(
element.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
createSpacingBuilder(settings));
return FormattingModelProvider.createFormattingModelForPsiFile(
element.getContainingFile(), block, settings);
}
instead of (my exception, based on http://devnet.jetbrains.com/message/5216859#5216859
Q: And what Block do i need to pass to this FormattingModelProvider.createFormattingModelForPsiFile
A(Dmitry Jemerov): The block describing your entire file (with sub-blocks for AST nodes contained
in the file).
):
PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(JetLanguage.INSTANCE);
JetBlock block = new JetBlock(
containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
createSpacingBuilder(settings));
return FormattingModelProvider.createFormattingModelForPsiFile(
element.getContainingFile(), block, settings);
It is bug?
If so, similar bug in tutorial here http://confluence.jetbrains.com/display/IntelliJIDEA/Formatter
P.S. For Java we have:
/com/intellij/lang/java/JavaFormattingModelBuilder.class
public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) {
final FileElement fileElement = TreeUtil.getFileElement((TreeElement)SourceTreeToPsiMap.psiElementToTree(element));
LOG.assertTrue(fileElement != null, "File element should not be null for " + element);
CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
Block block = AbstractJavaBlock.createJavaBlock(fileElement, javaSettings);
FormattingDocumentModelImpl model = FormattingDocumentModelImpl.createOn(element.getContainingFile());
return new PsiBasedFormatterModelWithShiftIndentInside (element.getContainingFile(), block, model);
}
P.P.S. I’m implemeting KDoc lexer, parser & formatter (KT-1545, KT-3161 and other…) and got error: Intelij trying to reformat KDoc comment and says that function above is not covered by blocks.