use of com.intellij.psi.formatter.DocumentBasedFormattingModel in project intellij-plugins by JetBrains.
the class DartFormattingModelBuilder method createModel.
@NotNull
@Override
public FormattingModel createModel(@NotNull PsiElement element, @NotNull CodeStyleSettings settings, @NotNull FormattingMode mode) {
// element can be DartFile, DartEmbeddedContent, DartExpressionCodeFragment
final PsiFile psiFile = element.getContainingFile();
final ASTNode rootNode = psiFile instanceof DartFile ? psiFile.getNode() : element.getNode();
final DartBlockContext context = new DartBlockContext(settings, mode);
final DartBlock rootBlock = new DartBlock(rootNode, null, null, settings, context);
return new DocumentBasedFormattingModel(rootBlock, element.getProject(), settings, psiFile.getFileType(), psiFile);
}
use of com.intellij.psi.formatter.DocumentBasedFormattingModel in project intellij-plugins by JetBrains.
the class HbFormattingModelBuilder method createModel.
/**
* 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 HbTokenTypes.OUTER_ELEMENT_TYPE token we tell them to ignore,
* causing an stack-overflowing loop of polite format-delegation.
*/
@NotNull
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
if (!HbConfig.isFormattingEnabled()) {
// to the templated language, which lets the users manage that separately)
return new SimpleTemplateLanguageFormattingModelBuilder().createModel(element, settings);
}
final PsiFile file = element.getContainingFile();
Block rootBlock;
ASTNode node = element.getNode();
if (node.getElementType() == HbTokenTypes.OUTER_ELEMENT_TYPE) {
// 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);
}
Aggregations