use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyQtTypeProvider method getCallableType.
@Nullable
@Override
public PyType getCallableType(@NotNull PyCallable callable, @NotNull TypeEvalContext context) {
if (callable instanceof PyFunction) {
final String qualifiedName = callable.getQualifiedName();
if (qualifiedName != null && qualifiedName.startsWith("PyQt")) {
final QualifiedName name = QualifiedName.fromDottedString(qualifiedName);
final String qtVersion = name.getComponents().get(0);
final String docstring = ((PyFunction) callable).getDocStringValue();
if (docstring != null && docstring.contains("[signal]")) {
final PyClass aClass = PyClassNameIndex.findClass(qtVersion + "." + ourQtBoundSignal, callable.getProject());
if (aClass != null)
return new PyClassTypeImpl(aClass, false);
}
}
}
return null;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyChangeBaseClassQuickFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
assert pyClass != null;
final PyArgumentList expressionList = pyClass.getSuperClassExpressionList();
if (expressionList != null && expressionList.getArguments().length != 0) {
final PyExpression argument = expressionList.getArguments()[0];
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(argument);
builder.replaceElement(argument, argument.getText());
final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
if (virtualFile != null) {
final Editor editor = FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, virtualFile), true);
assert editor != null;
builder.run(editor, false);
}
}
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyImplementMethodsQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
final Editor editor = PyQuickFixUtil.getEditor(file);
if (editor != null && startElement instanceof PyClass) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
ArrayList<PyMethodMember> list = new ArrayList<>();
for (PyFunction function : myToImplement) {
list.add(new PyMethodMember(function));
}
PyOverrideImplementUtil.overrideMethods(editor, (PyClass) startElement, list, true);
} else {
PyOverrideImplementUtil.chooseAndOverrideOrImplementMethods(project, editor, (PyClass) startElement, myToImplement, "Select Methods to Implement", true);
}
}
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyClassRefactoringHandler method doRefactor.
private void doRefactor(Project project, PsiElement element1, PsiElement element2, Editor editor, PsiFile file, DataContext dataContext) {
if (ApplicationManagerEx.getApplicationEx().isUnitTestMode())
return;
CommonRefactoringUtil.checkReadOnlyStatus(project, file);
final PyClass clazz = PyUtil.getContainingClassOrSelf(element1);
if (!inClass(clazz, project, editor, "refactoring.pull.up.error.cannot.perform.refactoring.not.inside.class"))
return;
assert clazz != null;
final PyMemberInfoStorage infoStorage = PyMembersRefactoringSupport.getSelectedMemberInfos(clazz, element1, element2);
doRefactorImpl(project, clazz, infoStorage, editor);
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyClassNameIndex method findClass.
/**
* @deprecated use {@link com.jetbrains.python.psi.PyPsiFacade#createClassByQName(String, PsiElement)} or skeleton may be found
*/
@Deprecated
@Nullable
public static PyClass findClass(@NotNull String qName, Project project, GlobalSearchScope scope) {
int pos = qName.lastIndexOf(".");
String shortName = pos > 0 ? qName.substring(pos + 1) : qName;
for (PyClass pyClass : find(shortName, project, scope)) {
if (qName.equals(pyClass.getQualifiedName())) {
return pyClass;
}
}
return null;
}
Aggregations