PY-9795 Remove parameters and sections with trailing empty lines if any

This commit is contained in:
Mikhail Golubev
2015-08-27 17:26:23 +03:00
parent 920a79c645
commit 596070b338
7 changed files with 25 additions and 12 deletions

View File

@@ -100,7 +100,7 @@ public abstract class DocStringLineParser {
return blockEnd + 1;
}
protected int skipEmptyLines(int lineNum) {
public int skipEmptyLines(int lineNum) {
while (lineNum < getLineCount() && isEmpty(lineNum)) {
lineNum++;
}

View File

@@ -63,15 +63,27 @@ public abstract class DocStringUpdater<T extends DocStringLineParser> {
replace(startOffset, endOffset, "");
}
/**
* @param startLine inclusive
* @param endLine exclusive
*/
protected final void removeLines(int startLine, int endLine) {
final List<Substring> lines = myOriginalDocString.getLines();
final int startOffset = lines.get(startLine).getStartOffset();
final int endOffset = endLine < lines.size() - 1 ? lines.get(endLine + 1).getStartOffset() : lines.get(endLine).getEndOffset();
final int endOffset = endLine < lines.size() ? lines.get(endLine).getStartOffset() : lines.get(endLine - 1).getEndOffset();
remove(startOffset, endOffset);
}
protected final void removeLinesAndSpacesAfter(int startLine, int endLine) {
removeLines(startLine, skipEmptyLines(endLine));
}
private int skipEmptyLines(int startLine) {
return Math.min(myOriginalDocString.skipEmptyLines(startLine), myOriginalDocString.getLineCount() - 1);
}
protected final void removeLine(int line) {
removeLines(line, line);
removeLines(line, line + 1);
}
protected final void insertBeforeLine(int lineNumber, @NotNull String text) {

View File

@@ -87,12 +87,14 @@ public abstract class SectionBasedDocStringUpdater extends DocStringUpdater<Sect
for (Section section : myOriginalDocString.getParameterSections()) {
for (SectionField param : section.getFields()) {
if (param.getName().equals(name)) {
final int startLine, endLine = getFieldEndLine(param);
if (section.getFields().size() == 1) {
removeLines(getSectionStartLine(section), getFieldEndLine(param));
startLine = getSectionStartLine(section);
}
else {
removeLines(getFieldStartLine(param), getFieldEndLine(param));
startLine = getFieldStartLine(param);
}
removeLinesAndSpacesAfter(startLine, endLine + 1);
break;
}
}

View File

@@ -66,12 +66,7 @@ public class TagBasedDocStringUpdater extends DocStringUpdater<TagBasedDocString
if (sub.toString().equals(name)) {
final int startLine = sub.getStartLine();
final int nextAfterBlock = myOriginalDocString.parseIndentedBlock(startLine + 1, getLineIndentSize(startLine));
if (nextAfterBlock != startLine + 1) {
removeLines(startLine, nextAfterBlock - 1);
}
else {
removeLine(startLine);
}
removeLinesAndSpacesAfter(startLine, nextAfterBlock);
}
}
}

View File

@@ -4,4 +4,7 @@ def foo():
<weak_warning descr="Unexpected parameter c in docstring"><caret>c</weak_warning> (int): start of description
continuation line 1
continuation line 2
Returns:
Nothing:
"""

View File

@@ -1,3 +1,5 @@
def foo():
"""
Returns:
Nothing:
"""

View File

@@ -1,6 +1,5 @@
def f(a, d):
"""
:param a : foo
:param d : quux
"""