use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class SectionBasedDocStringUpdater method removeParameter.
@Override
public void removeParameter(@NotNull final String name) {
for (Section section : myOriginalDocString.getParameterSections()) {
final List<SectionField> sectionFields = section.getFields();
for (SectionField field : sectionFields) {
final Substring nameSub = ContainerUtil.find(field.getNamesAsSubstrings(), substring -> substring.toString().equals(name));
if (nameSub != null) {
if (field.getNamesAsSubstrings().size() == 1) {
final int endLine = getFieldEndLine(field);
if (sectionFields.size() == 1) {
removeLinesAndSpacesAfter(getSectionStartLine(section), endLine + 1);
} else {
final int startLine = getFieldStartLine(field);
if (ContainerUtil.getLastItem(sectionFields) == field) {
removeLines(startLine, endLine + 1);
} else {
removeLinesAndSpacesAfter(startLine, endLine + 1);
}
}
} else {
final Substring wholeParamName = expandParamNameSubstring(nameSub);
remove(wholeParamName.getStartOffset(), wholeParamName.getEndOffset());
}
break;
}
}
}
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class TagBasedDocString method parseTag.
protected int parseTag(int lineno, String tagPrefix) {
final Substring lineWithPrefix = getLine(lineno).trimLeft();
if (lineWithPrefix.startsWith(tagPrefix)) {
final Substring line = lineWithPrefix.substring(tagPrefix.length());
final Matcher strictTagMatcher = RE_STRICT_TAG_LINE.matcher(line);
final Matcher looseTagMatcher = RE_LOOSE_TAG_LINE.matcher(line);
Matcher tagMatcher = null;
if (strictTagMatcher.matches()) {
tagMatcher = strictTagMatcher;
} else if (looseTagMatcher.matches()) {
tagMatcher = looseTagMatcher;
}
if (tagMatcher != null) {
final Substring tagName = line.getMatcherGroup(tagMatcher, 1);
final Substring argName = line.getMatcherGroup(tagMatcher, 2).trim();
final TextRange firstArgLineRange = line.getMatcherGroup(tagMatcher, 3).trim().getTextRange();
final int linesCount = getLineCount();
final int argStart = firstArgLineRange.getStartOffset();
int argEnd = firstArgLineRange.getEndOffset();
while (lineno + 1 < linesCount) {
final Substring nextLine = getLine(lineno + 1).trim();
if (nextLine.isEmpty() || nextLine.startsWith(tagPrefix)) {
break;
}
argEnd = nextLine.getTextRange().getEndOffset();
lineno++;
}
final Substring argValue = new Substring(argName.getSuperString(), argStart, argEnd);
final String tagNameString = tagName.toString();
if (argName.isEmpty()) {
mySimpleTagValues.put(tagNameString, argValue);
} else {
if ("param".equals(tagNameString) || "parameter".equals(tagNameString) || "arg".equals(tagNameString) || "argument".equals(tagNameString)) {
final Matcher argTypeMatcher = RE_ARG_TYPE.matcher(argName);
if (argTypeMatcher.matches()) {
final Substring type = argName.getMatcherGroup(argTypeMatcher, 1).trim();
final Substring arg = argName.getMatcherGroup(argTypeMatcher, 2);
getTagValuesMap(TYPE).put(arg, type);
} else {
getTagValuesMap(tagNameString).put(argName, argValue);
}
} else {
getTagValuesMap(tagNameString).put(argName, argValue);
}
}
}
}
return lineno;
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class TagBasedDocStringUpdater method removeParameter.
@Override
public void removeParameter(@NotNull String name) {
final List<Substring> nameSubs = myOriginalDocString.getParameterSubstrings();
for (Substring sub : nameSubs) {
if (sub.toString().equals(name)) {
final int startLine = sub.getStartLine();
final int nextAfterBlock = myOriginalDocString.consumeIndentedBlock(startLine + 1, getLineIndentSize(startLine));
removeLinesAndSpacesAfter(startLine, nextAfterBlock);
}
}
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class DocStringReferenceProvider method referencesFromFields.
@NotNull
private static List<PsiReference> referencesFromFields(@NotNull PyStringLiteralExpression element, int offset, @NotNull List<SectionBasedDocString.SectionField> fields, @Nullable ReferenceType nameRefType) {
final List<PsiReference> result = new ArrayList<>();
for (SectionBasedDocString.SectionField field : fields) {
for (Substring nameSub : field.getNamesAsSubstrings()) {
if (nameRefType != null && nameSub != null && !nameSub.isEmpty()) {
final TextRange range = nameSub.getTextRange().shiftRight(offset);
result.add(new DocStringParameterReference(element, range, nameRefType));
}
}
final Substring typeSub = field.getTypeAsSubstring();
if (typeSub != null && !typeSub.isEmpty()) {
result.addAll(parseTypeReferences(element, typeSub, offset));
}
}
return result;
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class DocStringUpdater method insertAfterLine.
protected final void insertAfterLine(int lineNumber, @NotNull String text) {
final Substring line = myOriginalDocString.getLines().get(lineNumber);
insert(line.getEndOffset(), '\n' + text);
}
Aggregations