use of com.jetbrains.python.psi.PyTargetExpression 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.PyTargetExpression 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.PyTargetExpression in project intellij-community by JetBrains.
the class PyClassRefactoringTest method findField.
private PyElement findField(final String className, final String memberName) {
final PyClass aClass = findClass(className);
final PyTargetExpression attribute = aClass.findClassAttribute(memberName, false, null);
if (attribute != null) {
return attribute;
}
return aClass.findInstanceAttribute(memberName, false);
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyiResolveTest method testModuleAttributePyiOverPy.
// PY-21231
public void testModuleAttributePyiOverPy() {
final PsiElement result = doResolve();
assertInstanceOf(result, PyTargetExpression.class);
final PyTargetExpression target = (PyTargetExpression) result;
assertEquals("foo", target.getName());
final PsiFile containingFile = target.getContainingFile();
assertInstanceOf(containingFile, PyiFile.class);
}
use of com.jetbrains.python.psi.PyTargetExpression in project intellij-community by JetBrains.
the class PyLineMarkerProvider method getAttributeMarker.
@Nullable
private static LineMarkerInfo<PsiElement> getAttributeMarker(PyTargetExpression element) {
final String name = element.getReferencedName();
if (name == null) {
return null;
}
PyClass containingClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
if (containingClass == null)
return null;
for (PyClass ancestor : containingClass.getAncestorClasses(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()))) {
final PyTargetExpression ancestorAttr = ancestor.findClassAttribute(name, false, null);
if (ancestorAttr != null) {
return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, new TooltipProvider("Overrides attribute in " + ancestor.getName()), ourSuperAttributeNavigator);
}
}
return null;
}
Aggregations