com.intellij.psi.formatter.DocumentBasedFormattingModel Java Examples
The following examples show how to use
com.intellij.psi.formatter.DocumentBasedFormattingModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DustFormattingModelBuilder.java From Intellij-Dust with MIT License | 6 votes |
/** * We have to override {@link com.intellij.formatting.templateLanguages.TemplateLanguageFormattingModelBuilder#createModel} * since after we delegate to some templated languages, those languages (xml/html for sure, potentially others) * delegate right back to us to format the DustTypes.OUTER_TYPE token we tell them to ignore, * causing an stack-overflowing loop. */ @NotNull public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { final PsiFile file = element.getContainingFile(); Block rootBlock; ASTNode node = element.getNode(); if (node.getElementType() == DustFileViewProvider.OUTER_TYPE) { // If we're looking at a DustTypes.HTML element, then we've been invoked by our templated // language. Make a dummy block to allow that formatter to continue return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings); } else { rootBlock = getRootBlock(file, file.getViewProvider(), settings); } return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file); }
Example #2
Source File: SoyFormattingModelBuilder.java From bamboo-soy with Apache License 2.0 | 5 votes |
@NotNull public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { final PsiFile file = element.getContainingFile(); if (element.getNode().getElementType() == SoyTypes.OTHER) { return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings); } else { return new DocumentBasedFormattingModel( getRootBlock(file, file.getViewProvider(), settings), element.getProject(), settings, file.getFileType(), file); } }
Example #3
Source File: SimpleTemplateLanguageFormattingModelBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public FormattingModel createModel(final PsiElement element, final CodeStyleSettings settings) { if (element instanceof PsiFile) { final FileViewProvider viewProvider = ((PsiFile)element).getViewProvider(); if (viewProvider instanceof TemplateLanguageFileViewProvider) { final Language language = ((TemplateLanguageFileViewProvider)viewProvider).getTemplateDataLanguage(); FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forLanguage(language); if (builder != null) { return builder.createModel(viewProvider.getPsi(language), settings); } } } final PsiFile file = element.getContainingFile(); return new DocumentBasedFormattingModel(new AbstractBlock(element.getNode(), Wrap.createWrap(WrapType.NONE, false), Alignment.createAlignment()) { @Override protected List<Block> buildChildren() { return Collections.emptyList(); } @Override public Spacing getSpacing(final Block child1, @Nonnull final Block child2) { return Spacing.getReadOnlySpacing(); } @Override public boolean isLeaf() { return true; } }, element.getProject(), settings, file.getFileType(), file); }
Example #4
Source File: TemplateLanguageFormattingModelBuilder.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) { final PsiFile file = element.getContainingFile(); Block rootBlock = getRootBlock(file, file.getViewProvider(), settings); return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, file.getFileType(), file); }