use of com.intellij.formatting.FormattingModel in project intellij-community by JetBrains.
the class IndentOptionsDetectorImpl method calcLineIndentInfo.
@Nullable
private List<LineIndentInfo> calcLineIndentInfo(@Nullable ProgressIndicator indicator) {
if (myDocument == null || myDocument.getLineCount() < 3 || isFileBigToDetect()) {
return null;
}
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject);
FormattingModelBuilder modelBuilder = LanguageFormatting.INSTANCE.forContext(myFile);
if (modelBuilder == null)
return null;
FormattingModel model = modelBuilder.createModel(myFile, settings);
Block rootBlock = model.getRootBlock();
return new FormatterBasedLineIndentInfoBuilder(myDocument, rootBlock, indicator).build();
}
use of com.intellij.formatting.FormattingModel in project intellij-community by JetBrains.
the class PsiViewerDialog method buildBlocks.
@Nullable
private static Block buildBlocks(@NotNull PsiElement rootElement) {
FormattingModelBuilder formattingModelBuilder = LanguageFormatting.INSTANCE.forContext(rootElement);
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(rootElement.getProject());
if (formattingModelBuilder != null) {
FormattingModel formattingModel = formattingModelBuilder.createModel(rootElement, settings);
return formattingModel.getRootBlock();
} else {
return null;
}
}
use of com.intellij.formatting.FormattingModel in project intellij-community by JetBrains.
the class JavaAutoDetectIndentTest method doTestLineToIndentMapping.
private static void doTestLineToIndentMapping(@NotNull String text, int... spacesForLine) {
configureFromFileText("x.java", text);
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(document);
Assert.assertNotNull(builder);
FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
Block block = model.getRootBlock();
List<LineIndentInfo> list = new FormatterBasedLineIndentInfoBuilder(document, block, null).build();
Assert.assertEquals(list.size(), spacesForLine.length);
for (int i = 0; i < spacesForLine.length; i++) {
int indentSize = list.get(i).getIndentSize();
Assert.assertEquals("Mismatch on line " + i, spacesForLine[i], indentSize);
}
}
use of com.intellij.formatting.FormattingModel in project intellij-community by JetBrains.
the class JavaFormatterPerformanceTest method testPerformance.
public void testPerformance() throws Exception {
final String name = getTestName(true) + ".java";
final String text = loadFile(name);
final PsiFile file = LightPlatformTestCase.createFile(name, text);
transformAllChildren(SourceTreeToPsiMap.psiElementToTree(file));
final CodeStyleSettings settings = new CodeStyleSettings();
PlatformTestUtil.startPerformanceTest("java formatting", 1000, () -> {
final FormattingModel model = LanguageFormatting.INSTANCE.forContext(file).createModel(file, settings);
((FormatterImpl) FormatterEx.getInstanceEx()).formatWithoutModifications(model.getDocumentModel(), model.getRootBlock(), settings, settings.getIndentOptions(StdFileTypes.JAVA), file.getTextRange());
}).cpuBound().useLegacyScaling().assertTiming();
}
use of com.intellij.formatting.FormattingModel in project intellij-community by JetBrains.
the class AbstractIndentAutoDetectionTest method getMaxUsedIndentInfo.
@NotNull
private IndentUsageInfo getMaxUsedIndentInfo() {
configureByFile(getFileNameWithExtension());
Document document = getDocument(myFile);
FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(myFile);
Assert.assertNotNull(builder);
FormattingModel model = builder.createModel(myFile, CodeStyleSettingsManager.getSettings(getProject()));
List<LineIndentInfo> lines = new FormatterBasedLineIndentInfoBuilder(document, model.getRootBlock(), null).build();
IndentUsageStatistics statistics = new IndentUsageStatisticsImpl(lines);
return statistics.getKMostUsedIndentInfo(0);
}
Aggregations