Filled completion menu for iter live template.

This commit is contained in:
Evgeny Gerashchenko
2012-02-08 15:58:02 +04:00
parent f64ecd7eb5
commit 4b87d02627
3 changed files with 31 additions and 12 deletions
+3 -3
View File
@@ -39,11 +39,11 @@
<option name="KOTLIN_STATEMENT" value="true"/>
</context>
</template>
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.iter"
<template resource-bundle="org.jetbrains.jet.plugin.JetBundle" key="livetemplate.description.iter"
name="iter" toReformat="true" toShortenFQNames="true"
value="for ($VAR$ in $ITERABLE$) {&#10;$END$&#10;}">
<variable alwaysStopAt="false" defaultValue="kotlinIterableVariable()" expression="" name="ITERABLE" />
<variable alwaysStopAt="false" defaultValue="kotlinSuggestVariableName()" expression="" name="VAR" />
<variable alwaysStopAt="true" defaultValue="" expression="kotlinIterableVariable()" name="ITERABLE" />
<variable alwaysStopAt="true" defaultValue="&quot;i&quot;" expression="kotlinSuggestVariableName()" name="VAR" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
@@ -41,7 +41,7 @@ livetemplate.description.anonymous=Anonymous class
livetemplate.description.exfun=Extension function
livetemplate.description.exval=Extension read-only property
livetemplate.description.exvar=Extension read-write property
macro.variable.of.type=kotlinVariableOfType(Type)
macro.variable.of.type=kotlinVariable()
macro.iterable.variable=kotlinIterableVariable()
macro.suggest.variable.name=kotlinSuggestVariableName()
macro.fun.parameters=functionParameters()
@@ -1,17 +1,26 @@
package org.jetbrains.jet.plugin.liveTemplates.macro;
import com.intellij.codeInsight.template.Expression;
import com.intellij.codeInsight.template.ExpressionContext;
import com.intellij.codeInsight.template.Macro;
import com.intellij.codeInsight.template.Result;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.plugin.JetBundle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author Evgeny Gerashchenko
* @since 2/7/12
*/
public class JetIterableVariableMacro extends Macro {
public class JetIterableVariableMacro extends BaseJetVariableMacro {
private static final List<String> ACCEPTED_FQ_NAMES = Arrays.asList(
"jet.Array", "java.lang.Iterable", "<java_root>.java.lang.Iterable", "jet.Iterable");
@Override
public String getName() {
return "kotlinIterableVariable";
@@ -23,8 +32,18 @@ public class JetIterableVariableMacro extends Macro {
}
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
// TODO
return null;
protected boolean isSuitable(@NotNull VariableDescriptor variableDescriptor) {
// TODO more sophisticated check needed
JetType outType = variableDescriptor.getOutType();
List<JetType> types = new ArrayList<JetType>(TypeUtils.getAllSupertypes(outType));
types.add(outType);
for (JetType type : types) {
ClassifierDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
if (ACCEPTED_FQ_NAMES.contains(DescriptorUtils.getFQName(declarationDescriptor))) {
return true;
}
}
return false;
}
}