/**
* Returns a comment that immediately follows function header and precedes any child statement (including docstring).
- * It's supposed to start with conventional "type:" prefix and contain function type in PEP 484 compatible format
+ * It must start with conventional "type:" prefix and contain function type in PEP 484 compatible format
* (https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code).
* <p/>
- * Use {@link #getTypeCommentAnnotation()} to make sure that the comment indeed starts with "type:" and get its content
- * with the prefix stripped.
+ * Use {@link #getTypeCommentAnnotation()} to get its content with the prefix stripped accessing either stubs or AST.
*
* @see #getTypeCommentAnnotation()
*/
@Override
public boolean accepts(@NotNull PsiComment comment, ProcessingContext context) {
final PyFunction func = PsiTreeUtil.getParentOfType(comment, PyFunction.class);
- if (func != null && func.getTypeComment() == comment) {
- return PyTypingTypeProvider.getTypeCommentValue(comment.getText()) != null;
- }
- return false;
+ return func != null && func.getTypeComment() == comment;
}
});
public PsiComment getTypeComment() {
final PyStatementList statements = getStatementList();
if (statements.getStatements().length != 0) {
- return as(statements.getFirstChild(), PsiComment.class);
+ final PsiComment comment = as(statements.getFirstChild(), PsiComment.class);
+ if (comment != null && PyTypingTypeProvider.getTypeCommentValue(comment.getText()) != null) {
+ return comment;
+ }
}
return null;
}