use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class DocStringUpdater method insertBeforeLine.
protected final void insertBeforeLine(int lineNumber, @NotNull String text) {
final Substring line = myOriginalDocString.getLines().get(lineNumber);
insert(line.getStartOffset(), text + '\n');
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class GoogleCodeStyleDocString method parseSectionHeader.
@NotNull
@Override
protected Pair<Substring, Integer> parseSectionHeader(int lineNum) {
final Substring line = getLine(lineNum);
final Matcher matcher = SECTION_HEADER.matcher(line);
if (matcher.matches()) {
final Substring title = line.getMatcherGroup(matcher, 1).trim();
if (isValidSectionTitle(title.toString())) {
return Pair.create(title, lineNum + 1);
}
}
return Pair.create(null, lineNum);
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class NumpyDocString method parseHeader.
@Override
protected int parseHeader(int startLine) {
final int nextNonEmptyLineNum = consumeEmptyLines(startLine);
final Substring line = getLineOrNull(nextNonEmptyLineNum);
if (line != null && SIGNATURE.matcher(line).matches()) {
mySignature = line.trim();
return nextNonEmptyLineNum + 1;
}
return nextNonEmptyLineNum;
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class PyDocstringGenerator method startTemplate.
public void startTemplate() {
Preconditions.checkNotNull(myDocStringOwner, "For this action docstring owner must be supplied");
final PyStringLiteralExpression docStringExpression = getDocStringExpression();
assert docStringExpression != null;
final TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(docStringExpression);
if (myAddedParams.size() > 1) {
throw new IllegalArgumentException("TemplateBuilder can be created only for one parameter");
}
final DocstringParam paramToEdit = getParamToEdit();
final DocStringFormat format = myDocStringFormat;
if (format == DocStringFormat.PLAIN) {
return;
}
final StructuredDocString parsed = DocStringUtil.parseDocString(format, docStringExpression);
final Substring substring;
if (paramToEdit.isReturnValue()) {
substring = parsed.getReturnTypeSubstring();
} else {
final String paramName = paramToEdit.getName();
substring = parsed.getParamTypeSubstring(paramName);
}
if (substring == null) {
return;
}
builder.replaceRange(substring.getTextRange(), getDefaultType(getParamToEdit()));
Template template = ((TemplateBuilderImpl) builder).buildInlineTemplate();
final VirtualFile virtualFile = myDocStringOwner.getContainingFile().getVirtualFile();
if (virtualFile == null)
return;
final Project project = myDocStringOwner.getProject();
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, docStringExpression.getTextOffset());
Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
if (targetEditor != null) {
TemplateManager.getInstance(project).startTemplate(targetEditor, template);
}
}
use of com.jetbrains.python.toolbox.Substring in project intellij-community by JetBrains.
the class DocStringReferenceProvider method referencesFromNames.
private static List<PsiReference> referencesFromNames(@NotNull PyStringLiteralExpression element, int offset, @NotNull StructuredDocString docString, @NotNull List<Substring> paramNames, @NotNull ReferenceType refType) {
List<PsiReference> result = new ArrayList<>();
for (Substring name : paramNames) {
final String s = name.toString();
if (PyNames.isIdentifier(s)) {
final TextRange range = name.getTextRange().shiftRight(offset);
result.add(new DocStringParameterReference(element, range, refType));
}
if (refType.equals(ReferenceType.PARAMETER_TYPE)) {
final Substring type = docString.getParamTypeSubstring(s);
if (type != null) {
result.addAll(parseTypeReferences(element, type, offset));
}
}
}
return result;
}
Aggregations