mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Python: Extract template language commons
GitOrigin-RevId: 1919f022b88d2e8ff3a5966a4c836a38d0e3801c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a808c8544a
commit
a7bc6362df
Generated
+1
@@ -962,6 +962,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/python/intellij.pycharm.community.main.iml" filepath="$PROJECT_DIR$/python/intellij.pycharm.community.main.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/python-common-tests/intellij.python.commonTests.iml" filepath="$PROJECT_DIR$/python/python-common-tests/intellij.python.commonTests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/openapi/intellij.python.community.iml" filepath="$PROJECT_DIR$/python/openapi/intellij.python.community.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/python-core-impl/intellij.python.community.core.impl.iml" filepath="$PROJECT_DIR$/python/python-core-impl/intellij.python.community.core.impl.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/intellij.python.community.impl.iml" filepath="$PROJECT_DIR$/python/intellij.python.community.impl.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/pluginCore/intellij.python.community.plugin.iml" filepath="$PROJECT_DIR$/python/pluginCore/intellij.python.community.plugin.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/python/pluginCore/impl/intellij.python.community.plugin.impl.iml" filepath="$PROJECT_DIR$/python/pluginCore/impl/intellij.python.community.plugin.impl.iml" />
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ object PythonCommunityPluginModules {
|
||||
"intellij.python.community.plugin.java",
|
||||
"intellij.python.psi",
|
||||
"intellij.python.psi.impl",
|
||||
"intellij.python.community.core.impl",
|
||||
"intellij.python.pydev",
|
||||
"intellij.python.community.impl",
|
||||
"intellij.python.langInjection",
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="module" module-name="intellij.python.community.tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.python.commonTests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.fullLine.core.tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.core.impl" />
|
||||
</component>
|
||||
</module>
|
||||
+2
-2
@@ -5,7 +5,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.jetbrains.python.psi.PyNamedParameter
|
||||
import com.jetbrains.python.psi.PyParameterList
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil
|
||||
import com.jetbrains.python.psi.types.PyCallableParameter
|
||||
import com.jetbrains.python.psi.types.PyCallableParameterImpl
|
||||
import org.jetbrains.completion.full.line.language.ElementFormatter
|
||||
@@ -46,7 +46,7 @@ class ParameterListFormatter : ElementFormatter {
|
||||
|
||||
private fun includeDefaultValue(defaultValue: String): String {
|
||||
val sb = StringBuilder()
|
||||
val quotes = PyStringLiteralUtil.getQuotes(defaultValue)
|
||||
val quotes = PyStringLiteralCoreUtil.getQuotes(defaultValue)
|
||||
|
||||
sb.append("=")
|
||||
if (quotes != null) {
|
||||
|
||||
@@ -115,5 +115,6 @@
|
||||
<orderEntry type="library" name="jackson-dataformat-yaml" level="project" />
|
||||
<orderEntry type="library" name="jackson" level="project" />
|
||||
<orderEntry type="library" name="jackson-databind" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.core.impl" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="intellij.python.community" exported="" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis.impl" exported="" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PyStringLiteralCoreUtil {
|
||||
/**
|
||||
* Valid string prefix characters (lowercased) as defined in Python lexer.
|
||||
*/
|
||||
public static final String PREFIX_CHARACTERS = "ubcrf";
|
||||
|
||||
/**
|
||||
* Maximum length of a string prefix as defined in Python lexer.
|
||||
*/
|
||||
public static final int MAX_PREFIX_LENGTH = 3;
|
||||
|
||||
private static final ImmutableList<String> QUOTES = ImmutableList.of("'''", "\"\"\"", "'", "\"");
|
||||
|
||||
protected PyStringLiteralCoreUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pair where the first element is the prefix combined with the opening quote and the second is the closing quote.
|
||||
* <p>
|
||||
* If the given string literal is not properly quoted, e.g. the closing quote has fewer quotes as opposed to the
|
||||
* opening one, or it's missing altogether this method returns null.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <pre>
|
||||
* ur"foo" -> ("ur, ")
|
||||
* ur'bar -> null
|
||||
* """baz""" -> (""", """)
|
||||
* '''quux' -> null
|
||||
* </pre>
|
||||
*/
|
||||
@Nullable
|
||||
public static Pair<String, String> getQuotes(@NotNull String text) {
|
||||
final String prefix = getPrefix(text);
|
||||
final String mainText = text.substring(prefix.length());
|
||||
for (String quote : QUOTES) {
|
||||
final Pair<String, String> quotes = getQuotes(mainText, prefix, quote);
|
||||
if (quotes != null) {
|
||||
return quotes;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the end offset of the string prefix starting from {@code startOffset} in the given char sequence.
|
||||
* String prefix may contain only up to {@link #MAX_PREFIX_LENGTH} characters from {@link #PREFIX_CHARACTERS}
|
||||
* (case insensitively).
|
||||
*
|
||||
* @return end offset of found string prefix
|
||||
*/
|
||||
public static int getPrefixEndOffset(@NotNull CharSequence text, int startOffset) {
|
||||
int offset;
|
||||
for (offset = startOffset; offset < Math.min(startOffset + MAX_PREFIX_LENGTH, text.length()); offset++) {
|
||||
if (PREFIX_CHARACTERS.indexOf(Character.toLowerCase(text.charAt(offset))) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getPrefix(@NotNull CharSequence text) {
|
||||
return getPrefix(text, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts string prefix from the given char sequence using {@link #getPrefixEndOffset(CharSequence, int)}.
|
||||
*
|
||||
* @return extracted string prefix
|
||||
* @see #getPrefixEndOffset(CharSequence, int)
|
||||
*/
|
||||
@NotNull
|
||||
public static String getPrefix(@NotNull CharSequence text, int startOffset) {
|
||||
return text.subSequence(startOffset, getPrefixEndOffset(text, startOffset)).toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<String, String> getQuotes(@NotNull String text, @NotNull String prefix, @NotNull String quote) {
|
||||
final int length = text.length();
|
||||
final int n = quote.length();
|
||||
if (length >= 2 * n && text.startsWith(quote) && text.endsWith(quote)) {
|
||||
return Pair.create(prefix + text.substring(0, n), text.substring(length - n));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String stripQuotesAroundValue(String text) {
|
||||
Pair<String, String> quotes = getQuotes(text);
|
||||
if (quotes == null) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return text.substring(quotes.first.length(), text.length() - quotes.second.length());
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.lvcs" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.jdom" />
|
||||
<orderEntry type="module" module-name="intellij.python.community.core.impl" />
|
||||
</component>
|
||||
</module>
|
||||
+1
-1
@@ -101,7 +101,7 @@ public class PyFStringLikeCompletionContributor extends CompletionContributor im
|
||||
document.insertString(tailOffset, "}");
|
||||
}
|
||||
// It can happen when completion is invoked on multiple carets inside the same string
|
||||
String stringElemPrefix = PyStringLiteralUtil.getPrefix(docChars, stringElemStart);
|
||||
String stringElemPrefix = PyStringLiteralCoreUtil.getPrefix(docChars, stringElemStart);
|
||||
if (!PyStringLiteralUtil.isFormattedPrefix(stringElemPrefix)) {
|
||||
document.insertString(stringElemStart, "f");
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ public class PyStringConcatenationToFormatIntention extends PyBaseIntentionActio
|
||||
isUnicode = true;
|
||||
}
|
||||
if (!quotesDetected) {
|
||||
quotes = PyStringLiteralUtil.getQuotes(expression.getText());
|
||||
quotes = PyStringLiteralCoreUtil.getQuotes(expression.getText());
|
||||
quotesDetected = true;
|
||||
}
|
||||
String value = ((PyStringLiteralExpression)expression).getStringValue();
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ public class DocStringParameterReference extends PsiReferenceBase<PyStringLitera
|
||||
@Override
|
||||
public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException {
|
||||
TextRange range = getRangeInElement();
|
||||
Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(range.substring(myElement.getText()));
|
||||
Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(range.substring(myElement.getText()));
|
||||
|
||||
if (quotes != null) {
|
||||
range = TextRange.create(range.getStartOffset() + quotes.first.length(), range.getEndOffset() - quotes.second.length());
|
||||
|
||||
+2
-2
@@ -25,8 +25,8 @@ import com.intellij.psi.LanguageInjector;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.jetbrains.python.documentation.PyDocumentationSettings;
|
||||
import com.jetbrains.python.documentation.docstrings.DocStringUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -45,7 +45,7 @@ public class PyDocstringLanguageInjector implements LanguageInjector {
|
||||
int end = host.getTextLength() - 1;
|
||||
final String text = host.getText();
|
||||
|
||||
final Pair<String,String> quotes = PyStringLiteralUtil.getQuotes(text);
|
||||
final Pair<String,String> quotes = PyStringLiteralCoreUtil.getQuotes(text);
|
||||
final List<String> strings = StringUtil.split(text, "\n", false);
|
||||
|
||||
boolean gotExample = false;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jetbrains.python.lexer;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class PyStringLiteralLexer extends PyStringLiteralLexerBase {
|
||||
myLastState = initialState;
|
||||
|
||||
// the following could be parsing steps if we wanted this info as tokens
|
||||
final String prefix = PyStringLiteralUtil.getPrefix(buffer, myStart);
|
||||
final String prefix = PyStringLiteralCoreUtil.getPrefix(buffer, myStart);
|
||||
|
||||
myIsRaw = PyStringLiteralUtil.isRawPrefix(prefix);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.FutureFeature;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class PythonHighlightingLexer extends PythonLexer {
|
||||
@NotNull String tokenText,
|
||||
@NotNull LanguageLevel languageLevel,
|
||||
boolean unicodeImport) {
|
||||
final String prefix = PyStringLiteralUtil.getPrefix(tokenText);
|
||||
final String prefix = PyStringLiteralCoreUtil.getPrefix(tokenText);
|
||||
|
||||
if (tokenType == PyTokenTypes.SINGLE_QUOTED_STRING) {
|
||||
if (languageLevel.isPy3K()) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.jetbrains.python.psi;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
@@ -31,16 +30,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author Mikhail Golubev
|
||||
*/
|
||||
public final class PyStringLiteralUtil {
|
||||
/**
|
||||
* Valid string prefix characters (lowercased) as defined in Python lexer.
|
||||
*/
|
||||
public static final String PREFIX_CHARACTERS = "ubcrf";
|
||||
/**
|
||||
* Maximum length of a string prefix as defined in Python lexer.
|
||||
*/
|
||||
public static final int MAX_PREFIX_LENGTH = 3;
|
||||
private static final ImmutableList<String> QUOTES = ImmutableList.of("'''", "\"\"\"", "'", "\"");
|
||||
public final class PyStringLiteralUtil extends PyStringLiteralCoreUtil {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(PyStringLiteralUtil.class);
|
||||
|
||||
@@ -91,33 +81,6 @@ public final class PyStringLiteralUtil {
|
||||
return text != null && getQuotes(text) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pair where the first element is the prefix combined with the opening quote and the second is the closing quote.
|
||||
* <p>
|
||||
* If the given string literal is not properly quoted, e.g. the closing quote has fewer quotes as opposed to the
|
||||
* opening one, or it's missing altogether this method returns null.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <pre>
|
||||
* ur"foo" -> ("ur, ")
|
||||
* ur'bar -> null
|
||||
* """baz""" -> (""", """)
|
||||
* '''quux' -> null
|
||||
* </pre>
|
||||
*/
|
||||
@Nullable
|
||||
public static Pair<String, String> getQuotes(@NotNull String text) {
|
||||
final String prefix = getPrefix(text);
|
||||
final String mainText = text.substring(prefix.length());
|
||||
for (String quote : QUOTES) {
|
||||
final Pair<String, String> quotes = getQuotes(mainText, prefix, quote);
|
||||
if (quotes != null) {
|
||||
return quotes;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the range of the string literal text between the opening quote and the closing one.
|
||||
* If the closing quote is either missing or mismatched, this range spans until the end of the literal.
|
||||
@@ -140,43 +103,10 @@ public final class PyStringLiteralUtil {
|
||||
return new TextRange(startOffset, endOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the end offset of the string prefix starting from {@code startOffset} in the given char sequence.
|
||||
* String prefix may contain only up to {@link #MAX_PREFIX_LENGTH} characters from {@link #PREFIX_CHARACTERS}
|
||||
* (case insensitively).
|
||||
*
|
||||
* @return end offset of found string prefix
|
||||
*/
|
||||
public static int getPrefixEndOffset(@NotNull CharSequence text, int startOffset) {
|
||||
int offset;
|
||||
for (offset = startOffset; offset < Math.min(startOffset + MAX_PREFIX_LENGTH, text.length()); offset++) {
|
||||
if (PREFIX_CHARACTERS.indexOf(Character.toLowerCase(text.charAt(offset))) < 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
public static int getPrefixLength(@NotNull String text) {
|
||||
return getPrefixEndOffset(text, 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getPrefix(@NotNull CharSequence text) {
|
||||
return getPrefix(text, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts string prefix from the given char sequence using {@link #getPrefixEndOffset(CharSequence, int)}.
|
||||
*
|
||||
* @return extracted string prefix
|
||||
* @see #getPrefixEndOffset(CharSequence, int)
|
||||
*/
|
||||
@NotNull
|
||||
public static String getPrefix(@NotNull CharSequence text, int startOffset) {
|
||||
return text.subSequence(startOffset, getPrefixEndOffset(text, startOffset)).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the given prefix contains either 'u' or 'U' character
|
||||
*/
|
||||
@@ -212,16 +142,6 @@ public final class PyStringLiteralUtil {
|
||||
return quote == '"' ? '\'' : '"';
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<String, String> getQuotes(@NotNull String text, @NotNull String prefix, @NotNull String quote) {
|
||||
final int length = text.length();
|
||||
final int n = quote.length();
|
||||
if (length >= 2 * n && text.startsWith(quote) && text.endsWith(quote)) {
|
||||
return Pair.create(prefix + text.substring(0, n), text.substring(length - n));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static TextRange getTextRange(PsiElement element) {
|
||||
if (element instanceof PyStringLiteralExpression) {
|
||||
final List<TextRange> ranges = ((PyStringLiteralExpression)element).getStringValueTextRanges();
|
||||
@@ -255,13 +175,4 @@ public final class PyStringLiteralUtil {
|
||||
return o.getText();
|
||||
}
|
||||
}
|
||||
|
||||
public static String stripQuotesAroundValue(String text) {
|
||||
Pair<String, String> quotes = getQuotes(text);
|
||||
if (quotes == null) {
|
||||
return text;
|
||||
}
|
||||
|
||||
return text.substring(quotes.first.length(), text.length() - quotes.second.length());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public final class ParamHelper {
|
||||
// According to PEP 8 equal sign should be surrounded by spaces if annotation is present
|
||||
sb.append(parameterRenderedAsTyped ? " = " : "=");
|
||||
|
||||
final Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(defaultValue);
|
||||
final Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(defaultValue);
|
||||
if (quotes != null) {
|
||||
final String value = defaultValue.substring(quotes.getFirst().length(), defaultValue.length() - quotes.getSecond().length());
|
||||
sb.append(quotes.getFirst());
|
||||
@@ -197,7 +197,7 @@ public final class ParamHelper {
|
||||
@Nullable
|
||||
public static String getDefaultValueText(@Nullable PyExpression defaultValue) {
|
||||
if (defaultValue instanceof PyStringLiteralExpression) {
|
||||
final Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(defaultValue.getText());
|
||||
final Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(defaultValue.getText());
|
||||
if (quotes != null) {
|
||||
return quotes.getFirst() + ((PyStringLiteralExpression)defaultValue).getStringValue() + quotes.getSecond();
|
||||
}
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ public class PyElementGeneratorImpl extends PyElementGenerator {
|
||||
|
||||
@Override
|
||||
public PyStringLiteralExpression createStringLiteral(@NotNull StringLiteralExpression oldElement, @NotNull String unescaped) {
|
||||
Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(oldElement.getText());
|
||||
Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(oldElement.getText());
|
||||
if (quotes != null) {
|
||||
return createStringLiteralAlreadyEscaped(quotes.first + unescaped + quotes.second);
|
||||
}
|
||||
|
||||
+2
-5
@@ -10,10 +10,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.PyElementTypes;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.PyElementVisitor;
|
||||
import com.jetbrains.python.psi.PyFStringFragment;
|
||||
import com.jetbrains.python.psi.PyFormattedStringElement;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -46,7 +43,7 @@ public class PyFormattedStringElementImpl extends PyElementImpl implements PyFor
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return PyStringLiteralUtil.getPrefix(getText());
|
||||
return PyStringLiteralCoreUtil.getPrefix(getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.python.psi.PyPlainStringElement;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -22,7 +23,7 @@ public class PyPlainStringElementImpl extends LeafPsiElement implements PyPlainS
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return PyStringLiteralUtil.getPrefix(getText());
|
||||
return PyStringLiteralCoreUtil.getPrefix(getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.AbstractElementManipulator;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.psi.PyElementGenerator;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralExpression;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -66,7 +67,7 @@ public class PyStringLiteralExpressionManipulator extends AbstractElementManipul
|
||||
|
||||
@NotNull
|
||||
private static Pair<String, String> calculateQuotes(@NotNull String text) {
|
||||
final Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(text);
|
||||
final Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(text);
|
||||
|
||||
if (quotes == null || quotes.first == null && quotes.second == null) return Pair.createNonNull("\"", "\"");
|
||||
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public final class PyReplaceExpressionUtil implements PyElementTypes {
|
||||
@NotNull PsiElement newExpression,
|
||||
@NotNull TextRange textRange) {
|
||||
final String fullText = oldExpression.getText();
|
||||
final Pair<String, String> detectedQuotes = PyStringLiteralUtil.getQuotes(fullText);
|
||||
final Pair<String, String> detectedQuotes = PyStringLiteralCoreUtil.getQuotes(fullText);
|
||||
final Pair<String, String> quotes = detectedQuotes != null ? detectedQuotes : Pair.create("'", "'");
|
||||
final String prefix = fullText.substring(0, textRange.getStartOffset());
|
||||
final String suffix = fullText.substring(textRange.getEndOffset(), oldExpression.getTextLength());
|
||||
|
||||
+1
-1
@@ -563,7 +563,7 @@ abstract public class IntroduceHandler implements RefactoringActionHandler {
|
||||
if (data != null) {
|
||||
final PsiElement parent = data.getFirst();
|
||||
final String text = parent.getText();
|
||||
final Pair<String, String> detectedQuotes = PyStringLiteralUtil.getQuotes(text);
|
||||
final Pair<String, String> detectedQuotes = PyStringLiteralCoreUtil.getQuotes(text);
|
||||
final Pair<String, String> quotes = detectedQuotes != null ? detectedQuotes : Pair.create("'", "'");
|
||||
final TextRange range = data.getSecond();
|
||||
final String substring = range.substring(text);
|
||||
|
||||
@@ -208,7 +208,7 @@ public class PythonFoldingBuilder extends CustomFoldingBuilder implements DumbAw
|
||||
|
||||
private static String getLanguagePlaceholderForString(PyStringLiteralExpression stringLiteralExpression) {
|
||||
String stringText = stringLiteralExpression.getText();
|
||||
Pair<String, String> quotes = PyStringLiteralUtil.getQuotes(stringText);
|
||||
Pair<String, String> quotes = PyStringLiteralCoreUtil.getQuotes(stringText);
|
||||
if (quotes != null) {
|
||||
return quotes.second + "..." + quotes.second;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -106,8 +107,8 @@ public final class PythonStringUtil {
|
||||
|
||||
Pair<String, String> quotes = null;
|
||||
if (PyStringLiteralUtil.isQuoted(s)) {
|
||||
quotes = PyStringLiteralUtil.getQuotes(s);
|
||||
s = PyStringLiteralUtil.stripQuotesAroundValue(s);
|
||||
quotes = PyStringLiteralCoreUtil.getQuotes(s);
|
||||
s = PyStringLiteralCoreUtil.stripQuotesAroundValue(s);
|
||||
}
|
||||
|
||||
s = removeLastSuffix(s, separator);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
|
||||
if (stringLiteralExpression != null) {
|
||||
final String text = stringLiteralExpression.getText();
|
||||
final Pair<String,String> quotes =
|
||||
PyStringLiteralUtil.getQuotes(text);
|
||||
PyStringLiteralCoreUtil.getQuotes(text);
|
||||
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
|
||||
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
|
||||
String indent = getIndent(stringLiteralExpression);
|
||||
@@ -73,7 +73,7 @@ public class PyFillParagraphHandler extends ParagraphFillHandler {
|
||||
if (stringLiteralExpression != null) {
|
||||
final String text = stringLiteralExpression.getText();
|
||||
final Pair<String,String> quotes =
|
||||
PyStringLiteralUtil.getQuotes(text);
|
||||
PyStringLiteralCoreUtil.getQuotes(text);
|
||||
final PyDocStringOwner docStringOwner = PsiTreeUtil.getParentOfType(stringLiteralExpression, PyDocStringOwner.class);
|
||||
if (docStringOwner != null && stringLiteralExpression.equals(docStringOwner.getDocStringExpression())) {
|
||||
String indent = getIndent(stringLiteralExpression);
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class PyStatementMover extends LineMover {
|
||||
if (nearLine >= document.getLineCount() || nearLine <= 0) return false;
|
||||
final PyStringLiteralExpression stringLiteralExpression = PsiTreeUtil.getParentOfType(elementToMove1, PyStringLiteralExpression.class);
|
||||
if (stringLiteralExpression != null) {
|
||||
final Pair<String,String> quotes = PyStringLiteralUtil.getQuotes(stringLiteralExpression.getText());
|
||||
final Pair<String,String> quotes = PyStringLiteralCoreUtil.getQuotes(stringLiteralExpression.getText());
|
||||
if (quotes != null && (quotes.first.equals("'''") || quotes.first.equals("\"\"\""))) {
|
||||
final String text1 = document.getText(TextRange.create(start, end)).trim();
|
||||
final String text2 = document.getText(TextRange.create(document.getLineStartOffset(nearLine), document.getLineEndOffset(nearLine))).trim();
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.intellij.openapi.editor.highlighter.HighlighterIterator;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.jetbrains.python.psi.PyStringLiteralUtil;
|
||||
import com.jetbrains.python.psi.PyStringLiteralCoreUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BaseQuoteHandler implements MultiCharQuoteHandler {
|
||||
}
|
||||
if (getOpeningQuotesTokens().contains(iterator.getTokenType())) {
|
||||
int start = iterator.getStart();
|
||||
if (offset - start <= PyStringLiteralUtil.MAX_PREFIX_LENGTH) {
|
||||
if (offset - start <= PyStringLiteralCoreUtil.MAX_PREFIX_LENGTH) {
|
||||
if (getLiteralStartOffset(text, start) == offset) return true;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public class BaseQuoteHandler implements MultiCharQuoteHandler {
|
||||
}
|
||||
|
||||
private static int getLiteralStartOffset(CharSequence text, int start) {
|
||||
return PyStringLiteralUtil.getPrefixEndOffset(text, start);
|
||||
return PyStringLiteralCoreUtil.getPrefixEndOffset(text, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user