use of com.jetbrains.python.toolbox.Substring 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.toolbox.Substring in project intellij-community by JetBrains.
the class EpydocStringTest method testTagWithParamValue.
public void testTagWithParamValue() {
EpydocString docString = createEpydocDocString("@type m: number");
final Substring s = docString.getTagValue("type", "m");
assertNotNull(s);
assertEquals("number", s.toString());
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class EpydocStringTest method testMultilineTag.
public void testMultilineTag() {
EpydocString docString = createEpydocDocString(" @param b: The y intercept of the line. The X{y intercept} of a\n" + " line is the point at which it crosses the y axis (M{x=0}).");
final Substring s = docString.getTagValue("param", "b");
assertNotNull(s);
assertEquals("The y intercept of the line. The X{y intercept} of a line is the point at which it crosses the y axis (M{x=0}).", s.concatTrimmedLines(" "));
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class EpydocStringTest method testTagValue.
public void testTagValue() {
EpydocString docString = createEpydocDocString("@rtype: C{str}");
Substring s = docString.getTagValue("rtype");
assertNotNull(s);
assertEquals("C{str}", s.toString());
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class SectionBasedDocString method parseGenericField.
@NotNull
protected Pair<SectionField, Integer> parseGenericField(int lineNum, int sectionIndent) {
final Pair<List<Substring>, Integer> pair = parseIndentedBlock(lineNum, getSectionIndentationThreshold(sectionIndent));
final Substring firstLine = ContainerUtil.getFirstItem(pair.getFirst());
final Substring lastLine = ContainerUtil.getLastItem(pair.getFirst());
if (firstLine != null && lastLine != null) {
return Pair.create(new SectionField((Substring) null, null, firstLine.union(lastLine).trim()), pair.getSecond());
}
return Pair.create(null, pair.getSecond());
}
Aggregations