mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
PY-4717 In Numpy-style docstring two empty lines in a row terminate current section
The same way Napoleon parses them.
This commit is contained in:
@@ -90,4 +90,9 @@ public class NumpyDocString extends SectionBasedDocString {
|
||||
public String getSignature() {
|
||||
return mySignature != null ? mySignature.toString() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSectionBreak(int lineNum, int curSectionIndent) {
|
||||
return super.isSectionBreak(lineNum, curSectionIndent) || (isEmpty(lineNum) && isEmptyOrDoesNotExist(lineNum + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +150,15 @@ public abstract class SectionBasedDocString implements StructuredDocString {
|
||||
final List<SectionField> fields = new ArrayList<SectionField>();
|
||||
final int sectionIndent = getIndent(getLine(sectionStartLine));
|
||||
while (!isSectionBreak(lineNum, sectionIndent)) {
|
||||
final Pair<SectionField, Integer> result = parseSectionField(lineNum, title, sectionIndent);
|
||||
if (result.getFirst() == null) {
|
||||
break;
|
||||
if (!isEmpty(lineNum)) {
|
||||
final Pair<SectionField, Integer> result = parseSectionField(lineNum, title, sectionIndent);
|
||||
if (result.getFirst() != null) {
|
||||
fields.add(result.getFirst());
|
||||
lineNum = result.getSecond();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
fields.add(result.getFirst());
|
||||
lineNum = skipEmptyLines(result.getSecond());
|
||||
lineNum++;
|
||||
}
|
||||
return Pair.create(new Section(title, fields), lineNum);
|
||||
}
|
||||
@@ -208,20 +211,20 @@ public abstract class SectionBasedDocString implements StructuredDocString {
|
||||
return title == null ? null : SECTION_ALIASES.get(title.toLowerCase());
|
||||
}
|
||||
|
||||
private boolean isEmptyOrDoesNotExist(int lineNum) {
|
||||
protected boolean isEmptyOrDoesNotExist(int lineNum) {
|
||||
return lineNum < 0 || lineNum >= myLines.size() || isEmpty(lineNum);
|
||||
}
|
||||
|
||||
private boolean isEmpty(int lineNum) {
|
||||
protected boolean isEmpty(int lineNum) {
|
||||
return StringUtil.isEmptyOrSpaces(getLine(lineNum));
|
||||
}
|
||||
|
||||
private boolean isSectionStart(int lineNum) {
|
||||
protected boolean isSectionStart(int lineNum) {
|
||||
final Pair<String, Integer> pair = parseSectionHeader(lineNum);
|
||||
return pair.getFirst() != null;
|
||||
}
|
||||
|
||||
private boolean isSectionBreak(int lineNum, int curSectionIndent) {
|
||||
protected boolean isSectionBreak(int lineNum, int curSectionIndent) {
|
||||
return lineNum >= myLines.size() ||
|
||||
isSectionStart(lineNum) ||
|
||||
(!isEmpty(lineNum) && getIndent(getLine(lineNum)) <= curSectionIndent);
|
||||
@@ -281,7 +284,6 @@ public abstract class SectionBasedDocString implements StructuredDocString {
|
||||
/**
|
||||
* If both substrings share the same origin, returns new substring that includes both of them. Otherwise return {@code null}.
|
||||
*
|
||||
* @param s1
|
||||
* @param s2 substring to concat with
|
||||
* @return new substring as described
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
def func():
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
|
||||
x
|
||||
First line
|
||||
Second line
|
||||
|
||||
Line after single break
|
||||
|
||||
|
||||
Not included
|
||||
"""
|
||||
@@ -221,6 +221,21 @@ public class PySectionBasedDocStringTest extends PyTestCase {
|
||||
assertEquals("Return specified diagonals.", docString.getSummary());
|
||||
}
|
||||
|
||||
public void testNumpySectionBlockBreaksOnDoubleEmptyLine() {
|
||||
final NumpyDocString docString = findAndParseNumpyStyleDocString();
|
||||
assertSize(1, docString.getSections());
|
||||
final Section paramSection = docString.getSections().get(0);
|
||||
assertEquals("parameters", paramSection.getTitle());
|
||||
assertSize(1, paramSection.getFields());
|
||||
final SectionField param1 = paramSection.getFields().get(0);
|
||||
assertEquals("x", param1.getName());
|
||||
assertEmpty(param1.getType());
|
||||
assertEquals("First line\n" +
|
||||
"Second line\n" +
|
||||
"\n" +
|
||||
"Line after single break", param1.getDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return super.getTestDataPath() + "/docstrings";
|
||||
|
||||
Reference in New Issue
Block a user