Search in sources :

Example 71 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyUnwrapperTest method doNegativeTest.

private void doNegativeTest() {
    String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
    myFixture.configureByFile(before);
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            assertEmpty(options);
        }
    };
    h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 72 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyUnwrapperTest method doTest.

private void doTest(final int option) {
    String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
    String after = "refactoring/unwrap/" + getTestName(true) + "_after.py";
    myFixture.configureByFile(before);
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            assertTrue("No available options to unwrap", !options.isEmpty());
            options.get(option).actionPerformed(null);
        }
    };
    h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
    myFixture.checkResultByFile(after, true);
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 73 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyExtractSuperclassTest method testMultifileAppend.

public void testMultifileAppend() {
    // this is half-copy-paste of testMultifileNew. generalization won't make either easier to follow.
    String baseName = "/refactoring/extractsuperclass/multifile/";
    myFixture.configureByFiles(baseName + "source.py", baseName + "a/__init__.py", baseName + "a/b/__init__.py", baseName + "a/b/foo.py");
    final String className = "Foo";
    final String superclassName = "Suppa";
    final PyClass clazz = findClass(className);
    final List<PyMemberInfo<PyElement>> members = new ArrayList<>();
    final PyElement member = findMember(className, ".foo");
    members.add(MembersManager.findMember(clazz, member));
    final VirtualFile base_dir = myFixture.getFile().getVirtualFile().getParent();
    new WriteCommandAction.Simple(myFixture.getProject()) {

        @Override
        protected void run() throws Throwable {
            //TODO: Test via presenter
            //noinspection ConstantConditions
            final String path = base_dir.getPath() + "/a/b";
            PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path + "/foo.py");
        }
    }.execute();
    final PsiManager psi_mgr = PsiManager.getInstance(myFixture.getProject());
    VirtualFile vfile = base_dir.findChild("a");
    assertTrue(vfile.isDirectory());
    vfile = vfile.findChild(PyNames.INIT_DOT_PY);
    assertNotNull(vfile);
    vfile = base_dir.findChild("a").findChild("b");
    assertTrue(vfile.isDirectory());
    assertNotNull(vfile.findChild(PyNames.INIT_DOT_PY));
    vfile = vfile.findChild("foo.py");
    assertNotNull(vfile);
    PsiFile psi_file = psi_mgr.findFile(vfile);
    String result = psi_file.getText().trim();
    File expected_file = new File(getTestDataPath() + baseName, "target.append.py");
    String expected = psi_mgr.findFile(LocalFileSystem.getInstance().findFileByIoFile(expected_file)).getText().trim();
    assertEquals(expected, result);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) VirtualFile(com.intellij.openapi.vfs.VirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ArrayList(java.util.ArrayList) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) PyElement(com.jetbrains.python.psi.PyElement)

Example 74 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyTestCreatorTest method testCreateTest.

public void testCreateTest() throws Exception {
    myFixture.configureByFile("/create_tests/create_tst.py");
    final IMocksControl mockControl = createNiceControl();
    final CreateTestDialog dialog = mockControl.createMock(CreateTestDialog.class);
    expect(dialog.getFileName()).andReturn("tests.py").anyTimes();
    expect(dialog.getClassName()).andReturn("Spam").anyTimes();
    // Target dir is first module source
    final VirtualFile root = ModuleRootManager.getInstance(myFixture.getModule()).getSourceRoots()[0];
    expect(dialog.getTargetDir()).andReturn(root.getCanonicalPath()).anyTimes();
    expect(dialog.getMethods()).andReturn(Arrays.asList("eggs", "eggs_and_ham")).anyTimes();
    mockControl.replay();
    WriteCommandAction.runWriteCommandAction(myFixture.getProject(), () -> {
        final PsiFile file = PyTestCreator.generateTest(myFixture.getProject(), dialog).getContainingFile();
        myFixture.configureByText(file.getFileType(), file.getText());
        myFixture.checkResultByFile("/create_tests/create_tst.expected.py");
    });
}
Also used : IMocksControl(org.easymock.IMocksControl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile)

Example 75 with PsiFile

use of com.intellij.psi.PsiFile in project intellij-community by JetBrains.

the class PyUnwrapperTest method doNegativeTest.

private void doNegativeTest(final String optionName) {
    String before = "refactoring/unwrap/" + getTestName(true) + "_before.py";
    myFixture.configureByFile(before);
    UnwrapHandler h = new UnwrapHandler() {

        @Override
        protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
            for (AnAction option : options) {
                assertFalse("\"" + optionName + "\" is available to unwrap ", option.toString().contains(optionName));
            }
        }
    };
    h.invoke(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile());
}
Also used : UnwrapHandler(com.intellij.codeInsight.unwrap.UnwrapHandler) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

PsiFile (com.intellij.psi.PsiFile)1785 VirtualFile (com.intellij.openapi.vfs.VirtualFile)496 PsiElement (com.intellij.psi.PsiElement)468 Project (com.intellij.openapi.project.Project)267 Nullable (org.jetbrains.annotations.Nullable)267 NotNull (org.jetbrains.annotations.NotNull)248 Document (com.intellij.openapi.editor.Document)181 Editor (com.intellij.openapi.editor.Editor)168 XmlFile (com.intellij.psi.xml.XmlFile)126 PsiDirectory (com.intellij.psi.PsiDirectory)114 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)109 Module (com.intellij.openapi.module.Module)108 TextRange (com.intellij.openapi.util.TextRange)88 ArrayList (java.util.ArrayList)84 XmlTag (com.intellij.psi.xml.XmlTag)68 File (java.io.File)58 PsiManager (com.intellij.psi.PsiManager)56 PsiClass (com.intellij.psi.PsiClass)51 List (java.util.List)46 Language (com.intellij.lang.Language)45