use of com.jetbrains.python.inspections.quickfix.DocstringQuickFix in project intellij-community by JetBrains.
the class PyIncorrectDocstringInspection method buildVisitor.
@NotNull
@Override
public Visitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
return new Visitor(holder, session) {
@Override
protected void checkDocString(@NotNull PyDocStringOwner node) {
final PyStringLiteralExpression docstringExpr = node.getDocStringExpression();
if (docstringExpr != null) {
checkParameters(node, docstringExpr);
}
}
private void checkParameters(@NotNull PyDocStringOwner pyDocStringOwner, @NotNull PyStringLiteralExpression node) {
final StructuredDocString docString = DocStringUtil.parseDocString(node);
if (docString instanceof PlainDocString) {
return;
}
if (pyDocStringOwner instanceof PyFunction) {
final PyParameter[] realParams = ((PyFunction) pyDocStringOwner).getParameterList().getParameters();
final List<PyNamedParameter> missingParams = getMissingParams(docString, realParams);
if (!missingParams.isEmpty()) {
for (PyNamedParameter param : missingParams) {
registerProblem(param, PyBundle.message("INSP.missing.parameter.in.docstring", param.getName()), new DocstringQuickFix(param, null));
}
}
final List<Substring> unexpectedParams = getUnexpectedParams(docString, realParams);
if (!unexpectedParams.isEmpty()) {
for (Substring param : unexpectedParams) {
final ProblemsHolder holder = getHolder();
if (holder != null) {
holder.registerProblem(node, param.getTextRange(), PyBundle.message("INSP.unexpected.parameter.in.docstring", param), new DocstringQuickFix(null, param.getValue()));
}
}
}
}
}
};
}
use of com.jetbrains.python.inspections.quickfix.DocstringQuickFix in project intellij-community by JetBrains.
the class PyMissingOrEmptyDocstringInspection method buildVisitor.
@NotNull
@Override
public Visitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
return new Visitor(holder, session) {
@Override
protected void checkDocString(@NotNull PyDocStringOwner node) {
final PyStringLiteralExpression docStringExpression = node.getDocStringExpression();
if (docStringExpression == null) {
for (PyInspectionExtension extension : Extensions.getExtensions(PyInspectionExtension.EP_NAME)) {
if (extension.ignoreMissingDocstring(node)) {
return;
}
}
PsiElement marker = null;
if (node instanceof PyClass) {
final ASTNode n = ((PyClass) node).getNameNode();
if (n != null)
marker = n.getPsi();
} else if (node instanceof PyFunction) {
final ASTNode n = ((PyFunction) node).getNameNode();
if (n != null)
marker = n.getPsi();
} else if (node instanceof PyFile) {
final TextRange tr = new TextRange(0, 0);
final ProblemsHolder holder = getHolder();
if (holder != null) {
holder.registerProblem(node, tr, PyBundle.message("INSP.no.docstring"));
}
return;
}
if (marker == null)
marker = node;
if (node instanceof PyFunction || (node instanceof PyClass && ((PyClass) node).findInitOrNew(false, null) != null)) {
registerProblem(marker, PyBundle.message("INSP.no.docstring"), new DocstringQuickFix(null, null));
} else {
registerProblem(marker, PyBundle.message("INSP.no.docstring"));
}
} else if (StringUtil.isEmptyOrSpaces(docStringExpression.getStringValue())) {
registerProblem(docStringExpression, PyBundle.message("INSP.empty.docstring"));
}
}
};
}
Aggregations