From 59baaaf1e014dce136d020f253bc8ba6a57df1cf Mon Sep 17 00:00:00 2001 From: Valentina Kiryushkina Date: Tue, 1 Dec 2015 11:14:06 +0300 Subject: [PATCH] Cleanup --- .../PySubstitutionChunkReference.java | 43 +++++++++---------- ...ythonFormattedStringReferenceProvider.java | 24 +++++------ .../PyStringFormatCompletionContributor.java | 14 +++--- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/PySubstitutionChunkReference.java b/python/src/com/jetbrains/python/codeInsight/PySubstitutionChunkReference.java index 7450f5dd794a..e6859492b9c3 100644 --- a/python/src/com/jetbrains/python/codeInsight/PySubstitutionChunkReference.java +++ b/python/src/com/jetbrains/python/codeInsight/PySubstitutionChunkReference.java @@ -32,14 +32,14 @@ public class PySubstitutionChunkReference extends PsiReferenceBase myPosition) { return elements[myPosition]; } @@ -117,9 +114,9 @@ public class PySubstitutionChunkReference extends PsiReferenceBase chunks = PyStringFormatParser.filterSubstitutions( + private static PsiReference[] getReferencesFromFormatString(@NotNull final PyStringLiteralExpression element) { + final List chunks = PyStringFormatParser.filterSubstitutions( PyStringFormatParser.parseNewStyleFormat(element.getStringValue())); return getReferencesFromChunks(element, chunks); } - private static PsiReference[] getReferencesFromPercentString(@NotNull StringLiteralExpression element) { - List + private static PsiReference[] getReferencesFromPercentString(@NotNull final PyStringLiteralExpression element) { + final List chunks = PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parsePercentFormat(element.getStringValue())); return getReferencesFromChunks(element, chunks); } @NotNull - private static PsiReference[] getReferencesFromChunks(@NotNull StringLiteralExpression element, - List chunks) { - PsiReference[] result = new PsiReference[chunks.size()]; + private static PsiReference[] getReferencesFromChunks(@NotNull final PyStringLiteralExpression element, + @NotNull final List chunks) { + final PsiReference[] result = new PsiReference[chunks.size()]; for (int i = 0; i < chunks.size(); i++) { - PyStringFormatParser.SubstitutionChunk chunk = chunks.get(i); + final PyStringFormatParser.SubstitutionChunk chunk = chunks.get(i); result[i] = new PySubstitutionChunkReference(element, chunk, i); } return result; diff --git a/python/src/com/jetbrains/python/codeInsight/completion/PyStringFormatCompletionContributor.java b/python/src/com/jetbrains/python/codeInsight/completion/PyStringFormatCompletionContributor.java index 90f1d46de05d..2214822954fa 100644 --- a/python/src/com/jetbrains/python/codeInsight/completion/PyStringFormatCompletionContributor.java +++ b/python/src/com/jetbrains/python/codeInsight/completion/PyStringFormatCompletionContributor.java @@ -64,15 +64,15 @@ public class PyStringFormatCompletionContributor extends CompletionContributor { final PyExpression[] arguments = getFormatFunctionKeyWordArguments(original); for (PyExpression argument : arguments) { result = result.withPrefixMatcher(getPrefix(parameters.getOffset(), argument.getContainingFile())); - tryToAddKeysFromStarArgument(result, argument); - tryToAddKeyWordArgument(result, argument); + addKeysFromStarArgument(result, argument); + addKeyWordArgument(result, argument); } } } else if (PyUtil.instanceOf(parent, PyKeywordArgument.class, PyReferenceExpression.class)) { final PyArgumentList argumentList = PsiTreeUtil.getParentOfType(original, PyArgumentList.class); result = result.withPrefixMatcher(getPrefix(parameters.getOffset(), parent.getContainingFile())); - tryToAddElementsFromFormattedString(result, argumentList); + addElementsFromFormattedString(result, argumentList); } } } @@ -98,7 +98,7 @@ public class PyStringFormatCompletionContributor extends CompletionContributor { return PyExpression.EMPTY_ARRAY; } - private static void tryToAddKeysFromStarArgument(@NotNull final CompletionResultSet result, @NotNull final PyExpression arg) { + private static void addKeysFromStarArgument(@NotNull final CompletionResultSet result, @NotNull final PyExpression arg) { if (arg instanceof PyStarArgument) { final PyDictLiteralExpression dict = ObjectUtils.chooseNotNull(PsiTreeUtil.getChildOfType(arg, PyDictLiteralExpression.class), getDictFromReference(arg)); @@ -125,7 +125,7 @@ public class PyStringFormatCompletionContributor extends CompletionContributor { return null; } - private static void tryToAddKeyWordArgument(@NotNull final CompletionResultSet result, @NotNull final PyExpression arg) { + private static void addKeyWordArgument(@NotNull final CompletionResultSet result, @NotNull final PyExpression arg) { if (arg instanceof PyKeywordArgument) { final String keyword = ((PyKeywordArgument)arg).getKeyword(); if (keyword!= null) { @@ -142,8 +142,8 @@ public class PyStringFormatCompletionContributor extends CompletionContributor { .withAutoCompletionPolicy(AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE); } - private static void tryToAddElementsFromFormattedString(@NotNull final CompletionResultSet result, - @Nullable final PyArgumentList argumentList) { + private static void addElementsFromFormattedString(@NotNull final CompletionResultSet result, + @Nullable final PyArgumentList argumentList) { if (argumentList != null) { final PyReferenceExpression pyReferenceExpression = PsiTreeUtil.getPrevSiblingOfType(argumentList, PyReferenceExpression.class); final PyStringLiteralExpression formattedString = PsiTreeUtil.getChildOfType(pyReferenceExpression, PyStringLiteralExpression.class);