use of com.jetbrains.python.psi.stubs.PyFunctionStub in project intellij-community by JetBrains.
the class PyTargetExpressionImpl method getContainingClass.
@Override
public PyClass getContainingClass() {
final PyTargetExpressionStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PyClassStub) {
return ((PyClassStub) parentStub).getPsi();
}
if (parentStub instanceof PyFunctionStub) {
final StubElement functionParent = parentStub.getParentStub();
if (functionParent instanceof PyClassStub) {
return ((PyClassStub) functionParent).getPsi();
}
}
return null;
}
final PsiElement parent = PsiTreeUtil.getParentOfType(this, PyFunction.class, PyClass.class);
if (parent instanceof PyClass) {
return (PyClass) parent;
}
if (parent instanceof PyFunction) {
return ((PyFunction) parent).getContainingClass();
}
return null;
}
use of com.jetbrains.python.psi.stubs.PyFunctionStub in project intellij-community by JetBrains.
the class PyFunctionImpl method getTypeCommentAnnotation.
@Nullable
@Override
public String getTypeCommentAnnotation() {
final PyFunctionStub stub = getStub();
if (stub != null) {
return stub.getTypeComment();
}
final PsiComment comment = getTypeComment();
if (comment != null) {
return PyTypingTypeProvider.getTypeCommentValue(comment.getText());
}
return null;
}
use of com.jetbrains.python.psi.stubs.PyFunctionStub in project intellij-community by JetBrains.
the class PyFunctionImpl method getName.
@Nullable
@Override
public String getName() {
final PyFunctionStub stub = getStub();
if (stub != null) {
return stub.getName();
}
ASTNode node = getNameNode();
return node != null ? node.getText() : null;
}
use of com.jetbrains.python.psi.stubs.PyFunctionStub in project intellij-community by JetBrains.
the class PyFunctionImpl method getModifier.
/**
* Looks for two standard decorators to a function, or a wrapping assignment that closely follows it.
*
* @return a flag describing what was detected.
*/
@Nullable
public Modifier getModifier() {
final String deconame = getClassOrStaticMethodDecorator();
if (PyNames.CLASSMETHOD.equals(deconame)) {
return CLASSMETHOD;
} else if (PyNames.STATICMETHOD.equals(deconame)) {
return STATICMETHOD;
}
// implicit staticmethod __new__
final PyClass cls = getContainingClass();
if (cls != null && PyNames.NEW.equals(getName()) && cls.isNewStyleClass(null)) {
return STATICMETHOD;
}
final PyFunctionStub stub = getStub();
if (stub != null) {
return getModifierFromStub(stub);
}
final String funcName = getName();
if (funcName != null) {
PyAssignmentStatement currentAssignment = PsiTreeUtil.getNextSiblingOfType(this, PyAssignmentStatement.class);
while (currentAssignment != null) {
final String modifier = currentAssignment.getTargetsToValuesMapping().stream().filter(pair -> pair.getFirst() instanceof PyTargetExpression && funcName.equals(pair.getFirst().getName())).filter(pair -> pair.getSecond() instanceof PyCallExpression).map(pair -> interpretAsModifierWrappingCall((PyCallExpression) pair.getSecond(), this)).filter(interpreted -> interpreted != null && interpreted.getSecond() == this).map(interpreted -> interpreted.getFirst()).filter(wrapperName -> PyNames.CLASSMETHOD.equals(wrapperName) || PyNames.STATICMETHOD.equals(wrapperName)).findAny().orElse(null);
if (PyNames.CLASSMETHOD.equals(modifier)) {
return CLASSMETHOD;
} else if (PyNames.STATICMETHOD.equals(modifier)) {
return STATICMETHOD;
}
currentAssignment = PsiTreeUtil.getNextSiblingOfType(currentAssignment, PyAssignmentStatement.class);
}
}
return null;
}
use of com.jetbrains.python.psi.stubs.PyFunctionStub in project intellij-community by JetBrains.
the class PyFunctionImpl method getContainingClass.
public PyClass getContainingClass() {
final PyFunctionStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PyClassStub) {
return ((PyClassStub) parentStub).getPsi();
}
return null;
}
final PsiElement parent = PsiTreeUtil.getParentOfType(this, StubBasedPsiElement.class);
if (parent instanceof PyClass) {
return (PyClass) parent;
}
return null;
}
Aggregations