Search in sources :

Example 1 with RearrangeCodeProcessor

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();
    }
}
Also used : RearrangeCodeProcessor(com.intellij.codeInsight.actions.RearrangeCodeProcessor) Project(com.intellij.openapi.project.Project) SelectionModel(com.intellij.openapi.editor.SelectionModel) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 2 with RearrangeCodeProcessor

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RearrangeCodeProcessor(com.intellij.codeInsight.actions.RearrangeCodeProcessor) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor)

Example 3 with RearrangeCodeProcessor

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) RearrangeCodeProcessor(com.intellij.codeInsight.actions.RearrangeCodeProcessor) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor)

Example 4 with RearrangeCodeProcessor

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();
    }
}
Also used : RearrangeCodeProcessor(com.intellij.codeInsight.actions.RearrangeCodeProcessor)

Aggregations

RearrangeCodeProcessor (com.intellij.codeInsight.actions.RearrangeCodeProcessor)4 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 SelectionModel (com.intellij.openapi.editor.SelectionModel)1 Project (com.intellij.openapi.project.Project)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1 PsiFile (com.intellij.psi.PsiFile)1