use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class TransformClassicClassQuickFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement psiElement = descriptor.getPsiElement();
psiElement = PsiTreeUtil.getParentOfType(psiElement, PyClass.class);
if (psiElement != null) {
PyClass pyClass = (PyClass) psiElement;
PyExpression[] superClassExpressions = pyClass.getSuperClassExpressions();
PyElementGenerator generator = PyElementGenerator.getInstance(project);
if (superClassExpressions.length == 0) {
pyClass.replace(generator.createFromText(LanguageLevel.getDefault(), PyClass.class, "class " + pyClass.getName() + "(" + PyNames.OBJECT + "):\n " + pyClass.getStatementList().getText()));
} else {
StringBuilder stringBuilder = new StringBuilder("class ");
stringBuilder.append(pyClass.getName()).append("(");
for (PyExpression expression : superClassExpressions) {
stringBuilder.append(expression.getText()).append(", ");
}
stringBuilder.append(PyNames.OBJECT).append(":\n ");
stringBuilder.append(pyClass.getStatementList().getText());
pyClass.replace(generator.createFromText(LanguageLevel.getDefault(), PyClass.class, stringBuilder.toString()));
}
}
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyElementNode method getChildrenImpl.
@Override
protected Collection<AbstractTreeNode> getChildrenImpl() {
PyElement value = getValue();
// for performance reasons, we don't show nested functions here
if (value instanceof PyClass) {
final PyClass pyClass = (PyClass) value;
List<AbstractTreeNode> result = new ArrayList<>();
for (PyClass aClass : pyClass.getNestedClasses()) {
result.add(new PyElementNode(myProject, aClass, getSettings()));
}
for (PyFunction function : pyClass.getMethods()) {
result.add(new PyElementNode(myProject, function, getSettings()));
}
return result;
}
return Collections.emptyList();
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyFileNode method getChildrenImpl.
@Override
public Collection<AbstractTreeNode> getChildrenImpl() {
PyFile value = (PyFile) getValue();
List<AbstractTreeNode> children = new ArrayList<>();
for (PyClass child : value.getTopLevelClasses()) {
children.add(new PyElementNode(myProject, child, getSettings()));
}
for (PyFunction function : value.getTopLevelFunctions()) {
children.add(new PyElementNode(myProject, function, getSettings()));
}
return children;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPullUpPresenterImpl method isWritable.
private boolean isWritable() {
final Collection<PyMemberInfo<PyElement>> infos = myView.getSelectedMemberInfos();
if (infos.isEmpty()) {
return true;
}
final PyElement element = infos.iterator().next().getMember();
final Project project = element.getProject();
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, myView.getSelectedParent()))
return false;
final PyClass container = PyUtil.getContainingClassOrSelf(element);
if (container == null || !CommonRefactoringUtil.checkReadOnlyStatus(project, container))
return false;
for (final PyMemberInfo<PyElement> info : infos) {
final PyElement member = info.getMember();
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, member))
return false;
}
return true;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyPullUpViewSwingImpl method configure.
@Override
public void configure(@NotNull final PyPullUpViewInitializationInfo configInfo) {
super.configure(configInfo);
for (final PyClass parent : configInfo.getParents()) {
myParentsComboBoxModel.addElement(parent);
}
myPresenter.parentChanged();
myParentsCombo.addItemListener(this);
}
Aggregations