@NotNull ReferenceType refType) {
List<PsiReference> result = new ArrayList<PsiReference>();
for (Substring name : paramNames) {
- final String s = trimLeadingStars(name).toString();
+ final String s = name.toString();
if (PyNames.isIdentifier(s)) {
final TextRange range = name.getTextRange().shiftRight(offset);
result.add(new DocStringParameterReference(element, range, refType));
for (SectionField field : fields) {
final Substring nameSub = field.getNameAsSubstring();
if (nameRefType != null && nameSub != null && !nameSub.isEmpty()) {
- final TextRange range = trimLeadingStars(nameSub).getTextRange().shiftRight(offset);
+ final TextRange range = nameSub.getTextRange().shiftRight(offset);
result.add(new DocStringParameterReference(element, range, nameRefType));
}
final Substring typeSub = field.getTypeAsSubstring();
}
return foundTag == null ? null : new TextRange(result, result + foundTag.length());
}
-
- @NotNull
- private static Substring trimLeadingStars(@NotNull Substring name) {
- int firstNotStar = 0;
- while (firstNotStar < name.length() && name.charAt(firstNotStar) == '*') {
- firstNotStar++;
- }
- return name.substring(firstNotStar).trimLeft();
- }
}
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
+import com.jetbrains.python.PyNames;
import com.jetbrains.python.toolbox.Substring;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
type = name;
name = null;
}
- if (name != null ? !isValidFieldName(name) : type.isEmpty()) {
+ if (name != null) {
+ name = cleanUpName(name);
+ }
+ if (name != null ? !PyNames.isIdentifierString(name.toString()) : type.isEmpty()) {
return Pair.create(null, lineNum);
}
description = colonSeparatedParts.get(1);
package com.jetbrains.python.documentation;
import com.intellij.openapi.util.Pair;
+import com.jetbrains.python.PyNames;
import com.jetbrains.python.toolbox.Substring;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
type = name;
name = null;
}
- if (name != null? !isValidFieldName(name) : type.isEmpty()) {
+ if (name != null) {
+ name = cleanUpName(name);
+ }
+ if (name != null? !PyNames.isIdentifierString(name.toString()) : type.isEmpty()) {
return Pair.create(null, lineNum);
}
final Pair<List<Substring>, Integer> parsedDescription = parseIndentedBlock(lineNum + 1, getLineIndentSize(lineNum));
import org.jetbrains.annotations.Nullable;
import java.util.*;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @see <a href="http://sphinxcontrib-napoleon.readthedocs.org/en/latest/index.html">Napoleon</a>
*/
public abstract class SectionBasedDocString extends DocStringLineParser implements StructuredDocString {
- protected static final Pattern FIELD_NAME = Pattern.compile("\\**\\s*(\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*)");
/**
* Frequently used section types
}
@NotNull
- protected static String extractFieldName(@NotNull CharSequence s) {
- final Matcher matcher = FIELD_NAME.matcher(s);
- if (matcher.matches()) {
- return matcher.group(1);
+ protected static Substring cleanUpName(@NotNull Substring name) {
+ int firstNotStar = 0;
+ while (firstNotStar < name.length() && name.charAt(firstNotStar) == '*') {
+ firstNotStar++;
}
- return s.toString();
- }
-
- public static boolean isValidFieldName(@NotNull CharSequence s) {
- return FIELD_NAME.matcher(s).matches();
+ return name.substring(firstNotStar).trimLeft();
}
public static class Section {
@NotNull
public String getName() {
- return myName == null ? "" : extractFieldName(myName.toString());
+ return myName == null ? "" : myName.toString();
}
@Nullable
Map<String, Substring> unexpected = Maps.newHashMap();
for (Substring s : docString.getParameterSubstrings()) {
- unexpected.put(StringUtil.trimLeading(s.getValue(), '*').trim(), s);
+ unexpected.put(s.toString(), s);
}
for (PyParameter p : realParams) {
private static List<PyParameter> getMissingParams(StructuredDocString docString, PyParameter[] realParams) {
List<PyParameter> missing = new ArrayList<PyParameter>();
+ final List<String> docStringParameters = docString.getParameters();
for (PyParameter p : realParams) {
if (p.isSelf() || p instanceof PySingleStarParameter || p instanceof PyTupleParameter) {
continue;
}
//noinspection ConstantConditions
- if (!docString.getParameters().contains(p.getName())) {
+ if (!docStringParameters.contains(p.getName())) {
missing.add(p);
}
}
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
generator.withParam(myMissingText);
}
else if (myUnexpected != null) {
- generator.withoutParam(StringUtil.trimLeading(myUnexpected, '*').trim());
+ generator.withoutParam(myUnexpected.trim());
}
generator.buildAndInsert();
}
def varagrs_dont_exist():
"""
Args:
- <weak_warning descr="Unexpected parameter *args in docstring">*args</weak_warning>:
- <weak_warning descr="Unexpected parameter **kwargs in docstring">**kwargs</weak_warning>:
+ *<weak_warning descr="Unexpected parameter args in docstring">args</weak_warning>:
+ **<weak_warning descr="Unexpected parameter kwargs in docstring">kwargs</weak_warning>:
"""
def varagrs_undefined(x, <weak_warning descr="Missing parameter args in docstring">*args</weak_warning>, y, <weak_warning descr="Missing parameter kwargs in docstring">**kwargs</weak_warning>):
runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() {
@Override
public void run() {
- doInspectionTest(PyDocstringInspection.class, PyBundle.message("QFIX.docstring.remove.$0", "*args"), true, true);
+ doInspectionTest(PyDocstringInspection.class, PyBundle.message("QFIX.docstring.remove.$0", "args"), true, true);
}
});
}
runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() {
@Override
public void run() {
- doInspectionTest(PyDocstringInspection.class, PyBundle.message("QFIX.docstring.remove.$0", "**kwargs"), true, true);
+ doInspectionTest(PyDocstringInspection.class, PyBundle.message("QFIX.docstring.remove.$0", "kwargs"), true, true);
}
});
}