use of com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine in project intellij-community by JetBrains.
the class AbstractRearrangerTest method doTest.
protected void doTest(@NotNull Map<String, ?> args) {
String text = (String) args.get("initial");
String expected = (String) args.get("expected");
@SuppressWarnings("unchecked") List<TextRange> ranges = (List<TextRange>) args.get("ranges");
Info info = parse(text);
if (!isEmpty(ranges) && !isEmpty(info.ranges)) {
fail("Duplicate ranges set: explicit: " + ranges + ", " + "derived: " + info.ranges + ", text:\n" + text);
}
if (isEmpty(info.ranges)) {
info.ranges = !isEmpty(ranges) ? ranges : Arrays.asList(TextRange.from(0, text.length()));
}
myFixture.configureByText(fileType, info.text);
final FoldingModel foldingModel = myFixture.getEditor().getFoldingModel();
for (final FoldingInfo foldingInfo : info.foldings) {
foldingModel.runBatchFoldingOperation(() -> {
FoldRegion region = foldingModel.addFoldRegion(foldingInfo.start, foldingInfo.end, foldingInfo.placeholder);
if (region != null)
region.setExpanded(false);
});
}
@SuppressWarnings("unchecked") List<ArrangementGroupingRule> groupingRules = (List<ArrangementGroupingRule>) args.get("groups");
if (groupingRules == null)
groupingRules = Collections.emptyList();
List<?> rules = (List<?>) args.get("rules");
List<ArrangementSectionRule> sectionRules = getSectionRules(rules);
@SuppressWarnings("unchecked") List<StdArrangementRuleAliasToken> aliases = (List<StdArrangementRuleAliasToken>) args.get("aliases");
CommonCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(myFixture.getProject()).getCurrentSettings().getCommonSettings(language);
final StdArrangementSettings arrangementSettings = aliases == null ? new StdArrangementSettings(groupingRules, sectionRules) : new StdArrangementExtendableSettings(groupingRules, sectionRules, aliases);
settings.setArrangementSettings(arrangementSettings);
ArrangementEngine engine = ServiceManager.getService(myFixture.getProject(), ArrangementEngine.class);
CommandProcessor.getInstance().executeCommand(getProject(), () -> engine.arrange(myFixture.getEditor(), myFixture.getFile(), info.ranges), null, null);
// Check expectation.
Info after = parse(expected);
assertEquals(after.text, myFixture.getEditor().getDocument().getText());
for (FoldingInfo it : after.foldings) {
FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(it.start);
assertNotNull("Expected to find fold region at offset " + it.start, foldRegion);
assertEquals(it.end, foldRegion.getEndOffset());
}
}
use of com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine in project android by JetBrains.
the class AndroidXmlFormatterTest method doTestArrangement.
private void doTestArrangement(String dst) {
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + getTestName(true) + ".xml", dst);
myFixture.configureFromExistingVirtualFile(f);
final ArrangementEngine engine = ServiceManager.getService(getProject(), ArrangementEngine.class);
WriteCommandAction.runWriteCommandAction(null, new Runnable() {
@Override
public void run() {
engine.arrange(myFixture.getEditor(), myFixture.getFile(), Arrays.asList(new TextRange(0, myFixture.getFile().getTextLength())));
}
});
myFixture.checkResultByFile(BASE_PATH + getTestName(true) + "_after.xml");
}
Aggregations