Search in sources :

Example 1 with Substring

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()));
                        }
                    }
                }
            }
        }
    };
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) PlainDocString(com.jetbrains.python.documentation.docstrings.PlainDocString) NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) DocstringQuickFix(com.jetbrains.python.inspections.quickfix.DocstringQuickFix) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Substring

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());
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) EpydocString(com.jetbrains.python.documentation.docstrings.EpydocString)

Example 3 with Substring

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(" "));
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) EpydocString(com.jetbrains.python.documentation.docstrings.EpydocString)

Example 4 with Substring

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());
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) EpydocString(com.jetbrains.python.documentation.docstrings.EpydocString)

Example 5 with Substring

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());
}
Also used : Substring(com.jetbrains.python.toolbox.Substring) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Substring (com.jetbrains.python.toolbox.Substring)24 NotNull (org.jetbrains.annotations.NotNull)6 ArrayList (java.util.ArrayList)5 StructuredDocString (com.jetbrains.python.psi.StructuredDocString)4 TextRange (com.intellij.openapi.util.TextRange)3 PsiReference (com.intellij.psi.PsiReference)3 EpydocString (com.jetbrains.python.documentation.docstrings.EpydocString)3 Section (com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Section)3 SectionField (com.jetbrains.python.documentation.docstrings.SectionBasedDocString.SectionField)3 Matcher (java.util.regex.Matcher)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 Editor (com.intellij.openapi.editor.Editor)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PlainDocString (com.jetbrains.python.documentation.docstrings.PlainDocString)1 DocstringQuickFix (com.jetbrains.python.inspections.quickfix.DocstringQuickFix)1