diff options
Diffstat (limited to 'python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java')
-rw-r--r-- | python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java b/python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java index 744dc9731b41..bb0e29f800a7 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyElementGeneratorImpl.java @@ -24,6 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; +import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.impl.PsiFileFactoryImpl; import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.psi.tree.TokenSet; @@ -86,8 +87,9 @@ public class PyElementGeneratorImpl extends PyElementGenerator { } + @Override public PyStringLiteralExpression createStringLiteralFromString(@NotNull String unescaped) { - return createStringLiteralFromString(null, unescaped); + return createStringLiteralFromString(null, unescaped, true); } public PyStringLiteralExpression createStringLiteral(@NotNull PyStringLiteralExpression oldElement, @NotNull String unescaped) { @@ -100,7 +102,11 @@ public class PyElementGeneratorImpl extends PyElementGenerator { } } - public PyStringLiteralExpression createStringLiteralFromString(@Nullable PsiFile destination, @NotNull String unescaped) { + + @Override + public PyStringLiteralExpression createStringLiteralFromString(@Nullable PsiFile destination, + @NotNull String unescaped, + final boolean preferUTF8) { boolean useDouble = !unescaped.contains("\""); boolean useMulti = unescaped.matches(".*(\r|\n).*"); String quotes; @@ -115,7 +121,7 @@ public class PyElementGeneratorImpl extends PyElementGenerator { VirtualFile vfile = destination == null ? null : destination.getVirtualFile(); Charset charset; if (vfile == null) { - charset = Charset.forName("US-ASCII"); + charset = (preferUTF8 ? Charset.forName("UTF-8") : Charset.forName("US-ASCII")); } else { charset = vfile.getCharset(); @@ -191,7 +197,7 @@ public class PyElementGeneratorImpl extends PyElementGenerator { final LeafPsiElement[] leafs = PsiTreeUtil.getChildrenOfType(list, LeafPsiElement.class); if (leafs != null) { final Deque<LeafPsiElement> commas = Queues.newArrayDeque(Collections2.filter(Arrays.asList(leafs), COMMAS_ONLY)); - if (! commas.isEmpty()) { + if (!commas.isEmpty()) { final LeafPsiElement lastComma = commas.getLast(); if (PsiTreeUtil.getNextSiblingOfType(lastComma, PyExpression.class) == null) { //Comma has no expression after it lastComma.delete(); @@ -297,7 +303,7 @@ public class PyElementGeneratorImpl extends PyElementGenerator { AccessDirection accessDirection) { String propertyText; if (accessDirection == AccessDirection.DELETE) { - propertyText = "@" + propertyName +".deleter\ndef " + propertyName + "(self):\n del self." + fieldName; + propertyText = "@" + propertyName + ".deleter\ndef " + propertyName + "(self):\n del self." + fieldName; } else if (accessDirection == AccessDirection.WRITE) { propertyText = "@" + propertyName + ".setter\ndef " + propertyName + "(self, value):\n self." + fieldName + " = value"; @@ -415,6 +421,12 @@ public class PyElementGeneratorImpl extends PyElementGenerator { PyExpressionStatement.class, content + "\n"); } + @NotNull + @Override + public PsiElement createNewLine() { + return createFromText(LanguageLevel.getDefault(), PsiWhiteSpace.class, " \n\n "); + } + private static class CommasOnly extends NotNullPredicate<LeafPsiElement> { @Override protected boolean applyNotNull(@NotNull final LeafPsiElement input) { |