use of com.intellij.codeInsight.actions.RearrangeCodeProcessor in project intellij-community by JetBrains.
the class RearrangeCodeAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
final Editor editor = e.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
Document document = editor.getDocument();
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null) {
return;
}
SelectionModel model = editor.getSelectionModel();
if (model.hasSelection()) {
new RearrangeCodeProcessor(file, model).run();
} else {
new RearrangeCodeProcessor(file).run();
}
}
use of com.intellij.codeInsight.actions.RearrangeCodeProcessor in project android by JetBrains.
the class AndroidXmlFormatterTest method testLayout8.
public void testLayout8() throws Exception {
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + "layout8.xml", "res/layout/layout.xml");
myFixture.configureFromExistingVirtualFile(f);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
RearrangeCodeProcessor processor = new RearrangeCodeProcessor(new ReformatCodeProcessor(getProject(), false));
processor.run();
}
});
myFixture.checkResultByFile(BASE_PATH + "layout8_after.xml");
}
use of com.intellij.codeInsight.actions.RearrangeCodeProcessor in project android by JetBrains.
the class AndroidXmlFormatterTest method testLayoutNonFirstNamespace.
// Regression test for http://b.android.com/196833
// "Android" style for XML formatting doesn't insert a newline character before the first attribute
// (even when that setting is enabled) is a namespace declaration. However, it does it only when
// namespace declaration is already first attribute in the list. Given that Android XML formatting
// by default rearranges attributes, it would lead to weird results: if namespace declaration is
// not on the first line, on first "Reformat Code" run it would but namespace first and keep the
// line break if it was already there, and on the second run it would remove line break.
public void testLayoutNonFirstNamespace() throws Exception {
final VirtualFile f = myFixture.copyFileToProject(BASE_PATH + "layout_non_first_namespace.xml", "res/layout/layout.xml");
myFixture.configureFromExistingVirtualFile(f);
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
RearrangeCodeProcessor processor = new RearrangeCodeProcessor(new ReformatCodeProcessor(getProject(), false));
processor.run();
}
});
myFixture.checkResultByFile(BASE_PATH + "layout_non_first_namespace_after.xml");
}
use of com.intellij.codeInsight.actions.RearrangeCodeProcessor in project intellij-community by JetBrains.
the class RearrangeBeforeCheckinHandler method runCheckinHandlers.
@Override
public void runCheckinHandlers(@NotNull final Runnable finishAction) {
final Runnable performCheckoutAction = new Runnable() {
@Override
public void run() {
FileDocumentManager.getInstance().saveAllDocuments();
finishAction.run();
}
};
if (VcsConfiguration.getInstance(myProject).REARRANGE_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) {
new RearrangeCodeProcessor(myProject, CheckinHandlerUtil.getPsiFiles(myProject, myPanel.getVirtualFiles()), COMMAND_NAME, performCheckoutAction).run();
} else {
performCheckoutAction.run();
}
}
Aggregations