Merge branch 'python-fixes'

This commit is contained in:
Andrey Vlasovskikh
2014-03-06 15:58:34 +04:00
2 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -205,7 +205,7 @@
<option name="OTHER" value="false" />
</context>
</template>
<template name="compd" value="{$KEY_EXPR$: $VAL_EXPR$ for $VAR$ in $ITERABLE$}" description="Generator comprehension" toReformat="false" toShortenFQNames="true">
<template name="compd" value="{$KEY_EXPR$: $VAL_EXPR$ for $VAR$ in $ITERABLE$}" description="Dict comprehension" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="collectionElementName(ITERABLE)" defaultValue="" alwaysStopAt="true" />
<variable name="KEY_EXPR" expression="" defaultValue="VAR" alwaysStopAt="true" />
@@ -228,7 +228,7 @@
<option name="OTHER" value="false" />
</context>
</template>
<template name="compdi" value="{$KEY_EXPR$: $VAL_EXPR$ for $VAR$ in $ITERABLE$ if $VAR_EXPR_IF$}" description="Generator comprehension with 'if'" toReformat="false" toShortenFQNames="true">
<template name="compdi" value="{$KEY_EXPR$: $VAL_EXPR$ for $VAR$ in $ITERABLE$ if $VAR_EXPR_IF$}" description="Dict comprehension with 'if'" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="collectionElementName(ITERABLE)" defaultValue="" alwaysStopAt="true" />
<variable name="KEY_EXPR" expression="" defaultValue="VAR" alwaysStopAt="true" />
@@ -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;
@@ -60,16 +61,15 @@ public class CollectionElementNameMacro extends Macro {
param = param.substring(0, lastParen);
}
}
final String result = smartUnpluralize(param);
return new TextResult(result);
final String result = smartUnPluralize(param);
return result != null && PyUtil.isPythonIdentifier(result) ? new TextResult(result) : null;
}
private static String smartUnpluralize(String param) {
private static String smartUnPluralize(String param) {
if (param.endsWith("_list")) {
return param.substring(0, param.length()-5);
}
final String result = StringUtil.unpluralize(param);
return result == null ? param : result;
return StringUtil.unpluralize(param);
}
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {