Search in sources :

Example 66 with PyClass

use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.

the class PyExtractSuperclassTest method testMultifileNew.

public void testMultifileNew() {
    String baseName = "/refactoring/extractsuperclass/multifile/";
    myFixture.configureByFile(baseName + "source.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 {
            //noinspection ConstantConditions
            final String path = base_dir.getPath() + "/a/b";
            PyExtractSuperclassHelper.extractSuperclass(clazz, members, superclassName, path);
        }
    }.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());
    vfile = vfile.findChild(PyNames.INIT_DOT_PY);
    assertNotNull(vfile);
    PsiFile psi_file = psi_mgr.findFile(vfile);
    String result = psi_file.getText().trim();
    File expected_file = new File(getTestDataPath() + baseName, "target.new.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 67 with PyClass

use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.

the class PyPullUpInfoModelTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    myFixture.configureByFile("/refactoring/pullup/pyPullUpInfoModel.py");
    final PyClass childClass = getClassByName("ChildWithDependencies");
    final PyClass parentClass = getClassByName("SomeParent");
    mySut = new PyPullUpInfoModel(childClass, new MocksControl(MocksControl.MockType.NICE).createMock(PyPullUpView.class));
    mySut.setSuperClass(parentClass);
    myMemberInfos = new PyMemberInfoStorage(childClass).getClassMemberInfos(childClass);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MocksControl(org.easymock.internal.MocksControl) PyMemberInfoStorage(com.jetbrains.python.refactoring.classes.PyMemberInfoStorage)

Example 68 with PyClass

use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.

the class PyPullUpPresenterTest method configureByClass.

/**
   * Creates presenter (sut) by class
   *
   * @param name name of class
   * @return presenter
   */
private PyPullUpPresenterImpl configureByClass(@NotNull final String name) {
    final PyClass childClass = getClassByName(name);
    final PyMemberInfoStorage storage = new PyMemberInfoStorage(childClass);
    return new PyPullUpPresenterImpl(myView, storage, childClass);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyMemberInfoStorage(com.jetbrains.python.refactoring.classes.PyMemberInfoStorage)

Example 69 with PyClass

use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.

the class PyPullUpPresenterTest method testConflicts.

/**
   * Ensures that presenter displays conflicts if destination class already has that members
   */
public void testConflicts() throws Exception {
    final PyPullUpPresenterImpl sut = configureByClass("ChildWithConflicts");
    configureParent();
    final Collection<PyMemberInfo<PyElement>> infos = getMemberInfos(sut);
    final Capture<MultiMap<PyClass, PyMemberInfo<?>>> conflictCapture = new Capture<>();
    EasyMock.expect(myView.showConflictsDialog(EasyMock.capture(conflictCapture), EasyMock.<Collection<PyMemberInfo<?>>>anyObject())).andReturn(false).anyTimes();
    EasyMock.expect(myView.getSelectedMemberInfos()).andReturn(infos).anyTimes();
    final PyClass parent = getClassByName("ParentWithConflicts");
    EasyMock.expect(myView.getSelectedParent()).andReturn(parent).anyTimes();
    myMocksControl.replay();
    sut.okClicked();
    final MultiMap<PyClass, PyMemberInfo<?>> conflictMap = conflictCapture.getValue();
    Assert.assertTrue("No conflicts found, while it should", conflictMap.containsKey(parent));
    final Collection<String> conflictedMemberNames = Collections2.transform(conflictMap.get(parent), NameTransformer.INSTANCE);
    Assert.assertThat("Failed to find right conflicts", conflictedMemberNames, Matchers.containsInAnyOrder("extends Bar", "CLASS_FIELD", "self.instance_field", "my_func(self)", "__init__(self)"));
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MultiMap(com.intellij.util.containers.MultiMap) PyMemberInfo(com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo) Collection(java.util.Collection) Capture(org.easymock.Capture)

Example 70 with PyClass

use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.

the class Py3UnresolvedReferencesInspectionTest method testMetaclassStub.

public void testMetaclassStub() {
    doMultiFileTest("a.py");
    final Project project = myFixture.getProject();
    Collection<PyClass> classes = PyClassNameIndex.find("M", project, GlobalSearchScope.allScope(project));
    for (PyClass cls : classes) {
        final PsiFile file = cls.getContainingFile();
        if (file instanceof PyFile) {
            assertNotParsed((PyFile) file);
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile)

Aggregations

PyClass (com.jetbrains.python.psi.PyClass)88 PyFunction (com.jetbrains.python.psi.PyFunction)32 PsiElement (com.intellij.psi.PsiElement)22 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)15 Nullable (org.jetbrains.annotations.Nullable)15 PyElement (com.jetbrains.python.psi.PyElement)12 PyMemberInfo (com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo)9 PyFile (com.jetbrains.python.psi.PyFile)8 PsiFile (com.intellij.psi.PsiFile)7 Project (com.intellij.openapi.project.Project)6 Editor (com.intellij.openapi.editor.Editor)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MultiMap (com.intellij.util.containers.MultiMap)5 PyMethodMember (com.jetbrains.python.codeInsight.override.PyMethodMember)4 PyMemberInfoStorage (com.jetbrains.python.refactoring.classes.PyMemberInfoStorage)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 PsiNamedElement (com.intellij.psi.PsiNamedElement)3 PyHierarchyNodeDescriptor (com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)3 ControlFlow (com.intellij.codeInsight.controlflow.ControlFlow)2