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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations