FormattingModelBuilder

Why here http://confluence.jetbrains.com/display/IntelliJIDEA/Formatter FormattingModel created around given element but not a PsiFile a whole?

E.g. why we have

public class SimpleFormattingModelBuilder implements FormattingModelBuilder {

    @NotNull

    @Override

    public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {

        return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(),

                new SimpleBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false),

                        Alignment.createAlignment(), createSpaceBuilder(settings)), settings);

    }

     ...

instead of

public class SimpleFormattingModelBuilder implements FormattingModelBuilder {

    @NotNull

    @Override

    public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {

        PsiFile containingFile =element.getContainingFile().getViewProvider().getPsi(SimpleLanguage.INSTANCE);
        return FormattingModelProvider.createFormattingModelForPsiFile(element.getContainingFile(),

                new SimpleBlock(containingFile, Wrap.createWrap(WrapType.NONE, false),

                        Alignment.createAlignment(), createSpaceBuilder(settings)), settings);

    }



     


my exception is based on http://devnet.jetbrains.com/message/5216859#5216859

Q: And what Block do i need to pass to thisFormattingModelProvider.createFormattingModelForPsiFile

A(Dmitry Jemerov): The block describing your entire file (with sub-blocks for AST nodes contained

in the file).




If it is bug, please also provide answer to http://devnet.jetbrains.com/thread/444830?tstart=0

5 comments

Hi Sergey,

I consider that to be a custom language tutorial bug. Even FormattingModelProvider.createFormattingModelForPsiFile() javadoc says that root block should be provided

Denis

0

Thanks for answer. Do I need to create a bug report somewhere?

0

I've created corresponding ticket - IDEA-107927.

Denis

0

Please sign in to leave a comment.