Don't suggest collection names in live templates that aren't valid Python identifier (PY-12308)

This commit is contained in:
Andrey Vlasovskikh
2014-03-06 15:51:16 +04:00
parent 20a0571ca9
commit 816b0e43e2
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.template.*;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.psi.PyUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@@ -61,7 +62,7 @@ public class CollectionElementNameMacro extends Macro {
}
}
final String result = smartUnpluralize(param);
return new TextResult(result);
return result != null && PyUtil.isPythonIdentifier(result) ? new TextResult(result) : null;
}
private static String smartUnpluralize(String param) {