mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed renaming prefix for static roots (PY-9307).
This commit is contained in:
@@ -33,6 +33,8 @@ public abstract class PyElementGenerator {
|
||||
public abstract PyStringLiteralExpression createStringLiteralFromString(@Nullable PsiFile destination, String unescaped);
|
||||
public abstract PyStringLiteralExpression createStringLiteralFromString(@NotNull String unescaped);
|
||||
|
||||
public abstract PyStringLiteralExpression createStringLiteral(@NotNull PyStringLiteralExpression oldElement, @NotNull String unescaped);
|
||||
|
||||
public abstract PyListLiteralExpression createListLiteral();
|
||||
|
||||
public abstract ASTNode createComma();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -13,6 +14,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
import com.jetbrains.python.PythonLanguage;
|
||||
import com.jetbrains.python.PythonStringUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -66,6 +68,16 @@ public class PyElementGeneratorImpl extends PyElementGenerator {
|
||||
return createStringLiteralFromString(null, unescaped);
|
||||
}
|
||||
|
||||
public PyStringLiteralExpression createStringLiteral(@NotNull PyStringLiteralExpression oldElement, @NotNull String unescaped) {
|
||||
Pair<String, String> quotes = PythonStringUtil.getQuotes(oldElement.getText());
|
||||
if (quotes != null) {
|
||||
return createStringLiteralAlreadyEscaped(quotes.first + unescaped + quotes.second);
|
||||
}
|
||||
else {
|
||||
return createStringLiteralFromString(unescaped);
|
||||
}
|
||||
}
|
||||
|
||||
public PyStringLiteralExpression createStringLiteralFromString(@Nullable PsiFile destination, @NotNull String unescaped) {
|
||||
boolean useDouble = !unescaped.contains("\"");
|
||||
boolean useMulti = unescaped.matches(".*(\r|\n).*");
|
||||
@@ -253,18 +265,20 @@ public class PyElementGeneratorImpl extends PyElementGenerator {
|
||||
public PyNamedParameter createParameter(@NotNull String name, @Nullable String defaultValue, @Nullable String annotation,
|
||||
@NotNull LanguageLevel languageLevel) {
|
||||
String parameterText = name;
|
||||
if (annotation != null)
|
||||
if (annotation != null) {
|
||||
parameterText += ": " + annotation;
|
||||
if (defaultValue != null)
|
||||
}
|
||||
if (defaultValue != null) {
|
||||
parameterText += " = " + defaultValue;
|
||||
}
|
||||
|
||||
return createFromText(languageLevel, PyNamedParameter.class, "def f(" + parameterText + "): pass", PATH_PARAMETER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PyKeywordArgument createKeywordArgument(LanguageLevel languageLevel, String keyword, String value) {
|
||||
PyCallExpression callExpression = (PyCallExpression) createExpressionFromText(languageLevel, "foo(" + keyword + "=" + value + ")");
|
||||
return (PyKeywordArgument) callExpression.getArguments()[0];
|
||||
PyCallExpression callExpression = (PyCallExpression)createExpressionFromText(languageLevel, "foo(" + keyword + "=" + value + ")");
|
||||
return (PyKeywordArgument)callExpression.getArguments()[0];
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user