mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
PY-9795 Remove parameters and sections with trailing empty lines if any
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
"""
|
||||
@@ -1,3 +1,5 @@
|
||||
def foo():
|
||||
"""
|
||||
Returns:
|
||||
Nothing:
|
||||
"""
|
||||
@@ -1,6 +1,5 @@
|
||||
def f(a, d):
|
||||
"""
|
||||
:param a : foo
|
||||
|
||||
:param d : quux
|
||||
"""
|
||||
Reference in New Issue
Block a user