use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyUserSkeletonsClassMembersProvider method findClassMember.
public static PsiElement findClassMember(@NotNull PyClass cls, @NotNull String name, boolean isDefinition) {
final PyFunction function = cls.findMethodByName(name, false, null);
if (function != null) {
final PyUtil.MethodFlags methodFlags = PyUtil.MethodFlags.of(function);
final boolean instanceMethod = methodFlags == null || methodFlags.isInstanceMethod();
if (isDefinition ^ instanceMethod) {
return function;
}
}
if (!isDefinition) {
final PyTargetExpression instanceAttribute = cls.findInstanceAttribute(name, false);
if (instanceAttribute != null) {
return instanceAttribute;
}
}
final PyTargetExpression classAttribute = cls.findClassAttribute(name, false, null);
if (classAttribute != null) {
return classAttribute;
}
return null;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyUserSkeletonsClassMembersProvider method getClassMembers.
public static Collection<PyCustomMember> getClassMembers(@NotNull PyClass cls, boolean isDefinition) {
final List<PyCustomMember> result = new ArrayList<>();
for (PyFunction function : cls.getMethods()) {
final String name = function.getName();
final PyUtil.MethodFlags methodFlags = PyUtil.MethodFlags.of(function);
final boolean instanceMethod = methodFlags == null || methodFlags.isInstanceMethod();
if (name != null && (isDefinition ^ instanceMethod)) {
result.add(new PyCustomMember(name, function));
}
}
if (!isDefinition) {
for (PyTargetExpression attribute : cls.getInstanceAttributes()) {
final String name = attribute.getName();
if (name != null) {
result.add(new PyCustomMember(name, attribute));
}
}
}
for (PyTargetExpression attribute : cls.getClassAttributes()) {
final String name = attribute.getName();
if (name != null) {
result.add(new PyCustomMember(name, attribute));
}
}
return result;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyCallSignatureTypeProvider method getReturnType.
@Override
public Ref<PyType> getReturnType(@NotNull final PyCallable callable, @NotNull TypeEvalContext context) {
if (callable instanceof PyFunction) {
PyFunction function = (PyFunction) callable;
PySignature signature = PySignatureCacheManager.getInstance(function.getProject()).findSignature(function);
if (signature != null && signature.getReturnType() != null) {
final String typeName = signature.getReturnType().getTypeQualifiedName();
if (typeName != null) {
final PyType type = PyTypeParser.getTypeByName(function, typeName);
if (type != null) {
return Ref.create(PyDynamicallyEvaluatedType.create(type));
}
}
}
}
return null;
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyCallHierarchyTest method doTestCallHierarchy.
private void doTestCallHierarchy(String... fileNames) throws Exception {
configureByFiles(fileNames);
final PsiElement targetElement = TargetElementUtil.findTargetElement(myFixture.getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
assert targetElement != null : "Cannot find referenced element";
assert targetElement instanceof PyFunction : "Referenced element is not PyFunction";
PyFunction function = (PyFunction) targetElement;
checkHierarchyTreeStructure(function);
}
use of com.jetbrains.python.psi.PyFunction in project intellij-community by JetBrains.
the class PyChangeSignatureTest method changeSignature.
private void changeSignature(@Nullable String newName, @Nullable List<PyParameterInfo> parameters) {
final PyChangeSignatureHandler changeSignatureHandler = new PyChangeSignatureHandler();
final PyFunction function = (PyFunction) changeSignatureHandler.findTargetMember(myFixture.getFile(), myFixture.getEditor());
assertNotNull(function);
final PyFunction newFunction = PyChangeSignatureHandler.getSuperMethod(function);
assertNotNull(newFunction);
final PyMethodDescriptor method = new PyMethodDescriptor(newFunction);
final TestPyChangeSignatureDialog dialog = new TestPyChangeSignatureDialog(newFunction.getProject(), method);
try {
if (newName != null) {
dialog.setNewName(newName);
}
if (parameters != null) {
dialog.setParameterInfos(parameters);
}
final String validationError = dialog.validateAndCommitData();
assertTrue(validationError, validationError == null);
final BaseRefactoringProcessor baseRefactoringProcessor = dialog.createRefactoringProcessor();
assert baseRefactoringProcessor instanceof PyChangeSignatureProcessor;
final PyChangeSignatureProcessor processor = (PyChangeSignatureProcessor) baseRefactoringProcessor;
processor.run();
} finally {
Disposer.dispose(dialog.getDisposable());
}
}
Aggregations