use of com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Section in project intellij-community by JetBrains.
the class PySectionBasedDocStringTest method testGoogleParamNamedLikeSection.
public void testGoogleParamNamedLikeSection() {
final GoogleCodeStyleDocString docString = findAndParseGoogleStyleDocString();
assertSize(1, docString.getSections());
final Section paramSection = docString.getSections().get(0);
assertSize(2, paramSection.getFields());
assertEquals("x", paramSection.getFields().get(0).getName());
assertEquals("args", paramSection.getFields().get(1).getName());
}
use of com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Section in project intellij-community by JetBrains.
the class PySectionBasedDocStringTest method testNumpySectionBlockBreaksOnDoubleEmptyLine.
public void testNumpySectionBlockBreaksOnDoubleEmptyLine() {
final NumpyDocString docString = findAndParseNumpyStyleDocString();
assertSize(1, docString.getSections());
final Section paramSection = docString.getSections().get(0);
assertEquals("parameters", paramSection.getNormalizedTitle());
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());
}
use of com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Section in project intellij-community by JetBrains.
the class SectionBasedDocStringUpdater method beforeApplyingModifications.
@Override
protected void beforeApplyingModifications() {
final List<AddParameter> newParams = new ArrayList<>();
for (AddParameter param : myAddParameterRequests) {
if (param.type != null) {
final Substring typeSub = myOriginalDocString.getParamTypeSubstring(param.name);
if (typeSub != null) {
replace(typeSub.getTextRange(), param.type);
continue;
}
final Substring nameSub = findParamNameSubstring(param.name);
if (nameSub != null) {
updateParamDeclarationWithType(nameSub, param.type);
continue;
}
}
newParams.add(param);
}
if (!newParams.isEmpty()) {
final SectionBasedDocStringBuilder paramBlockBuilder = createBuilder();
final Section firstParamSection = findFirstParametersSection();
// Insert whole new parameter block
if (firstParamSection == null) {
paramBlockBuilder.startParametersSection();
final SectionBasedDocStringBuilder builder = addParametersInBlock(paramBlockBuilder, newParams, getExpectedFieldIndent());
insertNewSection(builder, SectionBasedDocString.PARAMETERS_SECTION);
} else // Update existing parameter block
{
final SectionField firstParamField = ContainerUtil.getFirstItem(firstParamSection.getFields());
// Section exist, but empty
if (firstParamField == null) {
final String blockText = buildBlock(paramBlockBuilder, newParams, getExpectedFieldIndent(), getSectionIndent(firstParamSection));
insertAfterLine(getSectionTitleLastLine(firstParamSection), blockText);
} else {
// Section contain other parameter declarations
final String blockText = buildBlock(paramBlockBuilder, newParams, getFieldIndent(firstParamSection, firstParamField), getSectionIndent(firstParamSection));
insertBeforeLine(getFieldStartLine(firstParamField), blockText);
}
}
}
}
use of com.jetbrains.python.documentation.docstrings.SectionBasedDocString.Section in project intellij-community by JetBrains.
the class SectionBasedDocStringUpdater method addReturnValue.
@Override
public final void addReturnValue(@Nullable String type) {
if (StringUtil.isEmpty(type)) {
return;
}
final Substring typeSub = myOriginalDocString.getReturnTypeSubstring();
if (typeSub != null) {
replace(typeSub.getTextRange(), type);
return;
}
final Section returnSection = findFirstReturnSection();
if (returnSection != null) {
final List<SectionField> fields = returnSection.getFields();
if (!fields.isEmpty()) {
final SectionField firstField = fields.get(0);
final String newLine = createReturnLine(type, getSectionIndent(returnSection), getFieldIndent(returnSection, firstField));
insertBeforeLine(getFieldStartLine(firstField), newLine);
} else {
final String newLine = createReturnLine(type, getSectionIndent(returnSection), getExpectedFieldIndent());
insertAfterLine(getSectionTitleLastLine(returnSection), newLine);
}
} else {
final SectionBasedDocStringBuilder builder = createBuilder().withSectionIndent(getExpectedFieldIndent()).startReturnsSection().addReturnValue(null, type, "");
insertNewSection(builder, SectionBasedDocString.RETURNS_SECTION);
}
}
Aggregations