Search in sources :

Example 11 with PyElement

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

the class PyElementNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    final PyElement value = getValue();
    final String name = value.getName();
    final ItemPresentation presentation = value.getPresentation();
    String presentableText = name != null ? name : PyNames.UNNAMED_ELEMENT;
    Icon presentableIcon = value.getIcon(0);
    if (presentation != null) {
        final String text = presentation.getPresentableText();
        if (text != null) {
            presentableText = text;
        }
        final Icon icon = presentation.getIcon(false);
        if (icon != null) {
            presentableIcon = icon;
        }
    }
    data.setPresentableText(presentableText);
    data.setIcon(presentableIcon);
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) PyElement(com.jetbrains.python.psi.PyElement)

Example 12 with PyElement

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

the class PyStringReferenceSearch method processQuery.

public void processQuery(@NotNull final ReferencesSearch.SearchParameters params, @NotNull final Processor<PsiReference> consumer) {
    final PsiElement element = params.getElementToSearch();
    if (!(element instanceof PyElement) && !(element instanceof PsiDirectory)) {
        return;
    }
    SearchScope searchScope = params.getEffectiveSearchScope();
    if (searchScope instanceof GlobalSearchScope) {
        searchScope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) searchScope, PythonFileType.INSTANCE);
    }
    String name = PyUtil.computeElementNameForStringSearch(element);
    if (StringUtil.isEmpty(name)) {
        return;
    }
    params.getOptimizer().searchWord(name, searchScope, UsageSearchContext.IN_STRINGS, true, element);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) SearchScope(com.intellij.psi.search.SearchScope) PsiElement(com.intellij.psi.PsiElement) PyElement(com.jetbrains.python.psi.PyElement)

Example 13 with PyElement

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

the class PyCallHierarchyTreeStructureBase method buildChildren.

@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
    final List<PyHierarchyNodeDescriptor> descriptors = new ArrayList<>();
    if (descriptor instanceof PyHierarchyNodeDescriptor) {
        final PyHierarchyNodeDescriptor pyDescriptor = (PyHierarchyNodeDescriptor) descriptor;
        final PsiElement element = pyDescriptor.getPsiElement();
        final boolean isCallable = element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile;
        HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
        if (!(element instanceof PyElement) || !isCallable || nodeDescriptor == null) {
            return ArrayUtil.EMPTY_OBJECT_ARRAY;
        }
        final List<PsiElement> children = getChildren((PyElement) element);
        final HashMap<PsiElement, PyHierarchyNodeDescriptor> callerToDescriptorMap = new HashMap<>();
        PsiElement baseClass = element instanceof PyFunction ? ((PyFunction) element).getContainingClass() : null;
        for (PsiElement caller : children) {
            if (isInScope(baseClass, caller, myScopeType)) {
                PyHierarchyNodeDescriptor callerDescriptor = callerToDescriptorMap.get(caller);
                if (callerDescriptor == null) {
                    callerDescriptor = new PyHierarchyNodeDescriptor(descriptor, caller, false);
                    callerToDescriptorMap.put(caller, callerDescriptor);
                    descriptors.add(callerDescriptor);
                }
            }
        }
    }
    return ArrayUtil.toObjectArray(descriptors);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PyFile(com.jetbrains.python.psi.PyFile) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PyFunction(com.jetbrains.python.psi.PyFunction) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PsiElement(com.intellij.psi.PsiElement) PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PyElement

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

the class PyMembersRefactoringSupport method getSelectedMemberInfos.

public static PyMemberInfoStorage getSelectedMemberInfos(PyClass clazz, PsiElement element1, PsiElement element2) {
    final PyMemberInfoStorage infoStorage = new PyMemberInfoStorage(clazz);
    for (PyMemberInfo<PyElement> member : infoStorage.getClassMemberInfos(clazz)) {
        final PyElement function = member.getMember();
        member.setChecked(PsiTreeUtil.isAncestor(function, element1, false) || PsiTreeUtil.isAncestor(function, element2, false));
    }
    return infoStorage;
}
Also used : PyElement(com.jetbrains.python.psi.PyElement)

Example 15 with PyElement

use of com.jetbrains.python.psi.PyElement 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)

Aggregations

PyElement (com.jetbrains.python.psi.PyElement)21 PyClass (com.jetbrains.python.psi.PyClass)12 PyMemberInfo (com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo)8 ArrayList (java.util.ArrayList)7 NotNull (org.jetbrains.annotations.NotNull)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 PsiElement (com.intellij.psi.PsiElement)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 PsiManager (com.intellij.psi.PsiManager)2 MultiMap (com.intellij.util.containers.MultiMap)2 PyFunction (com.jetbrains.python.psi.PyFunction)2 File (java.io.File)2 Nullable (org.jetbrains.annotations.Nullable)2 LocalQuickFixOnPsiElement (com.intellij.codeInspection.LocalQuickFixOnPsiElement)1 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ItemPresentation (com.intellij.navigation.ItemPresentation)1 Project (com.intellij.openapi.project.Project)1 PsiComment (com.intellij.psi.PsiComment)1