use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyHierarchyNodeDescriptor method update.
@Override
public boolean update() {
boolean changes = super.update();
final CompositeAppearance oldText = myHighlightedText;
myHighlightedText = new CompositeAppearance();
NavigatablePsiElement element = (NavigatablePsiElement) getPsiElement();
if (element == null) {
final String invalidPrefix = IdeBundle.message("node.hierarchy.invalid");
if (!myHighlightedText.getText().startsWith(invalidPrefix)) {
myHighlightedText.getBeginning().addText(invalidPrefix, HierarchyNodeDescriptor.getInvalidPrefixAttributes());
}
return true;
}
final ItemPresentation presentation = element.getPresentation();
if (presentation != null) {
if (element instanceof PyFunction) {
final PyClass cls = ((PyFunction) element).getContainingClass();
if (cls != null) {
myHighlightedText.getEnding().addText(cls.getName() + ".");
}
}
myHighlightedText.getEnding().addText(presentation.getPresentableText());
myHighlightedText.getEnding().addText(" " + presentation.getLocationString(), HierarchyNodeDescriptor.getPackageNameAttributes());
}
myName = myHighlightedText.getText();
if (!Comparing.equal(myHighlightedText, oldText)) {
changes = true;
}
return changes;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PythonDocumentationMap method transformPattern.
@Nullable
private static String transformPattern(@NotNull String urlPattern, QualifiedName moduleQName, @Nullable PsiNamedElement element, String pyVersion) {
Map<String, String> macros = new HashMap<>();
macros.put("element.name", element == null ? null : element.getName());
PyClass pyClass = element == null ? null : PsiTreeUtil.getParentOfType(element, PyClass.class, false);
macros.put("class.name", pyClass == null ? null : pyClass.getName());
if (element != null) {
StringBuilder qName = new StringBuilder(moduleQName.toString()).append(".");
if (element instanceof PyFunction && ((PyFunction) element).getContainingClass() != null) {
qName.append(((PyFunction) element).getContainingClass().getName()).append(".");
}
qName.append(element.getName());
macros.put("element.qname", qName.toString());
} else {
macros.put("element.qname", "");
}
macros.put("function.name", element instanceof PyFunction ? element.getName() : "");
macros.put("module.name", moduleQName.toString());
macros.put("python.version", pyVersion);
final String pattern = transformPattern(urlPattern, macros);
if (pattern == null) {
return rootForPattern(urlPattern);
}
return pattern;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PySuperTypesHierarchyTreeStructure method buildChildren.
@NotNull
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final List<PyHierarchyNodeDescriptor> res = new ArrayList<>();
if (descriptor instanceof PyHierarchyNodeDescriptor) {
final PyHierarchyNodeDescriptor pyDescriptor = (PyHierarchyNodeDescriptor) descriptor;
final PsiElement element = pyDescriptor.getPsiElement();
if (element instanceof PyClass) {
final PyClass cls = (PyClass) element;
final PyClass[] superClasses = cls.getSuperClasses(null);
for (PyClass superClass : superClasses) {
res.add(new PyHierarchyNodeDescriptor(descriptor, superClass, false));
}
}
}
return res.toArray();
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyOverrideTest method testQualified.
public void testQualified() {
// PY-2171
myFixture.configureByFile("override/" + getTestName(true) + ".py");
PyClass dateClass = PyClassNameIndex.findClass("datetime.date", myFixture.getProject());
assertNotNull(dateClass);
PyFunction initMethod = dateClass.findMethodByName(PyNames.INIT, false, null);
assertNotNull(initMethod);
PyOverrideImplementUtil.overrideMethods(myFixture.getEditor(), getTopLevelClass(0), Collections.singletonList(new PyMethodMember(initMethod)), false);
myFixture.checkResultByFile("override/" + getTestName(true) + "_after.py", true);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyInheritorsSearchTest method testSimple.
public void testSimple() throws Exception {
setupProject();
final PyClass pyClass = findClass("A");
Collection<PyClass> inheritors = PyClassInheritorsSearch.search(pyClass, false).findAll();
assertEquals(2, inheritors.size());
}
Aggregations