当前位置: 首页>>代码示例>>Java>>正文


Java Template.addVariable方法代码示例

本文整理汇总了Java中com.intellij.codeInsight.template.Template.addVariable方法的典型用法代码示例。如果您正苦于以下问题:Java Template.addVariable方法的具体用法?Java Template.addVariable怎么用?Java Template.addVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.codeInsight.template.Template的用法示例。


在下文中一共展示了Template.addVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertMethod

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void insertMethod(@NotNull Project project, @NotNull Editor editor) {
    Template template = TemplateManager.getInstance(project).createTemplate("", "");
    template.addTextSegment("public function test");

    Expression nameExpr = new ConstantNode("");
    template.addVariable("name", nameExpr, nameExpr, true);
    template.addTextSegment("()");

    PhpLanguageLevel languageLevel = PhpProjectConfigurationFacade.getInstance(project).getLanguageLevel();
    if (languageLevel.hasFeature(PhpLanguageFeature.RETURN_VOID)) {
        template.addTextSegment(": void");
    }

    template.addTextSegment("\n{\n");
    template.addEndVariable();
    template.addTextSegment("\n}");
    template.setToIndent(true);
    template.setToReformat(true);
    template.setToShortenLongNames(true);
    TemplateManager.getInstance(project).startTemplate(editor, template, null);
}
 
开发者ID:jiripudil,项目名称:intellij-nette-tester,代码行数:23,代码来源:TesterGenerateTestMethodAction.java

示例2: expandForChooseExpression

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public final void expandForChooseExpression(@NotNull PsiElement expr, @NotNull Editor editor) {
  Project project = expr.getProject();
  Document document = editor.getDocument();
  PsiElement elementForRemoving = getElementToRemove(expr);
  document.deleteString(elementForRemoving.getTextRange().getStartOffset(), elementForRemoving.getTextRange().getEndOffset());
  TemplateManager manager = TemplateManager.getInstance(project);

  String templateString = getTemplateString(expr);
  if (templateString == null) {
    PostfixTemplatesUtils.showErrorHint(expr.getProject(), editor);
    return;
  }


  Template template = createTemplate(manager, templateString);

  if (shouldAddExpressionToContext()) {
    template.addVariable("expr", new TextExpression(expr.getText()), false);
  }

  setVariables(template, expr);
  manager.startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:StringBasedPostfixTemplate.java

示例3: addExprVariable

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
    ToStringIfNeedMacro toStringIfNeedMacro = new ToStringIfNeedMacro();
    MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
    macroCallNode.addParameter(new ConstantNode(expr.getText()));

    MacroCallNode node = new MacroCallNode(new VariableOfTypeMacro());
    node.addParameter(new ConstantNode(VIEW.toString()));
    template.addVariable("view", node, new EmptyNode(), false);

    template.addVariable("expr", macroCallNode, false);

    if (mWithAction) {
        template.addVariable("actionText", new EmptyNode(), false);
        template.addVariable("action", new EmptyNode(), false);
    }
}
 
开发者ID:takahirom,项目名称:android-postfix-plugin,代码行数:18,代码来源:SnackbarTemplate.java

示例4: buildTemplate

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@RequiredReadAction
@Override
public void buildTemplate(@NotNull CreateUnresolvedElementFixContext context, CSharpContextUtil.ContextType contextType, @NotNull PsiFile file, @NotNull Template template)
{
	template.addTextSegment(CreateUnresolvedMethodFix.calcModifier(context).getPresentableText());
	template.addTextSegment(" ");
	if(contextType == CSharpContextUtil.ContextType.STATIC)
	{
		template.addTextSegment("static ");
	}
	template.addVariable(new TypeRefExpression(myLikeMethod.getReturnTypeRef(), file), true);
	template.addTextSegment(" ");
	template.addTextSegment(myReferenceName);

	buildParameterList(context, file, template);

	template.addTextSegment("{\n");

	template.addVariable("$RETURN_STATEMENT$", new ReturnStatementExpression(), false);
	template.addEndVariable();

	template.addTextSegment("}");
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:24,代码来源:CreateUnresolvedMethodByLambdaTypeFix.java

示例5: buildParameterList

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
protected void buildParameterList(@NotNull CreateUnresolvedElementFixContext context, @NotNull PsiFile file, @NotNull Template template)
{
	template.addTextSegment("(");

	CSharpSimpleParameterInfo[] parameterInfos = myLikeMethod.getParameterInfos();

	for(int i = 0; i < parameterInfos.length; i++)
	{
		if(i != 0)
		{
			template.addTextSegment(", ");
		}

		CSharpSimpleParameterInfo parameterInfo = parameterInfos[i];

		template.addVariable(new ConstantNode(CSharpTypeRefPresentationUtil.buildShortText(parameterInfo.getTypeRef(), context.getExpression())), true);
		template.addTextSegment(" ");
		template.addVariable(new ConstantNode(parameterInfo.getNotNullName()), true);

	}
	template.addTextSegment(")");
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:23,代码来源:CreateUnresolvedMethodByLambdaTypeFix.java

示例6: setVariables

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void setVariables(@NotNull Template template, @NotNull PsiElement psiElement) {
	super.setVariables(template, psiElement);

	List<MyVariable> sortedVars = variables.stream().sorted(Comparator.comparing(s -> s.getNo())).collect(Collectors.toList());

	for (Variable variable : sortedVars) {
		template.addVariable(variable.getName(), variable.getExpression(), variable.getDefaultValueExpression(),
			variable.isAlwaysStopAt(), variable.skipOnStart());
	}
}
 
开发者ID:xylo,项目名称:intellij-postfix-templates,代码行数:12,代码来源:CustomJavaStringPostfixTemplate.java

示例7: setVariables

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
public void setVariables(@NotNull Template template, @NotNull PsiElement element) {
  MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());
  MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());
  type.addParameter(new VariableNode("expr", null));
  template.addVariable("type", type, type, false);
  template.addVariable("name", name, name, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ForeachPostfixTemplate.java

示例8: completeAttribute

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static void completeAttribute(Template template) {
  template.addTextSegment(" ");
  template.addVariable(new MacroCallNode(new CompleteMacro()), true);
  template.addTextSegment("=\"");
  template.addEndVariable();
  template.addTextSegment("\"");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:XmlTagInsertHandler.java

示例9: addRequiredSubTags

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static boolean addRequiredSubTags(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context) {

    if (!WebEditorOptions.getInstance().isAutomaticallyInsertRequiredSubTags()) return false;
    List<XmlElementDescriptor> requiredSubTags = GenerateXmlTagAction.getRequiredSubTags(descriptor);
    if (!requiredSubTags.isEmpty()) {
      template.addTextSegment(">");
      template.setToReformat(true);
    }
    for (XmlElementDescriptor subTag : requiredSubTags) {
      if (subTag == null) { // placeholder for smart completion
        template.addTextSegment("<");
        template.addVariable(new MacroCallNode(new CompleteSmartMacro()), true);
        continue;
      }
      String qname = subTag.getName();
      if (subTag instanceof XmlElementDescriptorImpl) {
        String prefixByNamespace = context.getPrefixByNamespace(((XmlElementDescriptorImpl)subTag).getNamespace());
        if (StringUtil.isNotEmpty(prefixByNamespace)) {
          qname = prefixByNamespace + ":" + subTag.getName();
        }
      }
      template.addTextSegment("<" + qname);
      addRequiredAttributes(subTag, null, template, file);
      completeTagTail(template, subTag, file, context, false);
    }
    if (!requiredSubTags.isEmpty()) {
      addTagEnd(template, descriptor, context);
    }
    return !requiredSubTags.isEmpty();
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:XmlTagInsertHandler.java

示例10: completeTagTail

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
private static void completeTagTail(Template template, XmlElementDescriptor descriptor, PsiFile file, XmlTag context, boolean firstLevel) {
  boolean completeIt = !firstLevel || descriptor.getAttributesDescriptors(null).length == 0;
  switch (descriptor.getContentType()) {
    case XmlElementDescriptor.CONTENT_TYPE_UNKNOWN:
      return;
    case XmlElementDescriptor.CONTENT_TYPE_EMPTY:
      if (completeIt) {
        template.addTextSegment("/>");
      }
      break;
    case XmlElementDescriptor.CONTENT_TYPE_MIXED:
       if (completeIt) {
         template.addTextSegment(">");
         if (firstLevel) {
           template.addEndVariable();
         }
         else {
           template.addVariable(new MacroCallNode(new CompleteMacro()), true);
         }
         addTagEnd(template, descriptor, context);
       }
       break;
     default:
       if (!addRequiredSubTags(template, descriptor, file, context)) {
         if (completeIt) {
           template.addTextSegment(">");
           template.addEndVariable();
           addTagEnd(template, descriptor, context);
         }
       }
       break;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:XmlTagInsertHandler.java

示例11: addExprVariable

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
    final ToStringIfNeedMacro toStringIfNeedMacro = new ToStringIfNeedMacro();
    MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
    macroCallNode.addParameter(new ConstantNode(expr.getText()));
    template.addVariable("expr", macroCallNode, false);
}
 
开发者ID:takahirom,项目名称:android-postfix-plugin,代码行数:8,代码来源:ToastTemplate.java

示例12: setVariables

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void setVariables(@NotNull Template template, @NotNull PsiElement element) {
    MacroCallNode node = new MacroCallNode(new VariableOfTypeMacro());
    node.addParameter(new ConstantNode(CONTEXT.toString()));
    template.addVariable("context", node, new ConstantNode(""), false);

}
 
开发者ID:takahirom,项目名称:android-postfix-plugin,代码行数:8,代码来源:ToastTemplate.java

示例13: addExprVariable

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@Override
protected void addExprVariable(@NotNull PsiElement expr, Template template) {
    final FindViewByIdMacro toStringIfNeedMacro = new FindViewByIdMacro();
    MacroCallNode macroCallNode = new MacroCallNode(toStringIfNeedMacro);
    macroCallNode.addParameter(new ConstantNode(expr.getText()));
    template.addVariable("expr", macroCallNode, false);
}
 
开发者ID:takahirom,项目名称:android-postfix-plugin,代码行数:8,代码来源:FindViewByIdTemplate.java

示例14: buildTemplate

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@RequiredReadAction
@Override
public void buildTemplate(@NotNull CreateUnresolvedElementFixContext context,
		CSharpContextUtil.ContextType contextType,
		@NotNull PsiFile file,
		@NotNull Template template)
{
	template.addTextSegment("public ");

	if(contextType == CSharpContextUtil.ContextType.STATIC)
	{
		template.addTextSegment("static ");
	}

	template.addTextSegment("event ");

	// get expected from method call expression not reference
	List<ExpectedTypeInfo> expectedTypeRefs = ExpectedTypeVisitor.findExpectedTypeRefs(context.getExpression());

	if(!expectedTypeRefs.isEmpty())
	{
		template.addVariable(new TypeRefExpression(expectedTypeRefs, file), true);
	}
	else
	{
		template.addVariable(new TypeRefExpression(new CSharpTypeRefByQName(file, DotNetTypes.System.Object), file), true);
	}

	template.addTextSegment(" ");
	template.addTextSegment(myReferenceName);
	template.addTextSegment("\n{\n");
	template.addTextSegment("add;remove;\n");
	template.addTextSegment("}");
	template.addEndVariable();
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:36,代码来源:CreateUnresolvedEventFix.java

示例15: buildTemplate

import com.intellij.codeInsight.template.Template; //导入方法依赖的package包/类
@RequiredReadAction
@Override
public void buildTemplate(@NotNull CreateUnresolvedElementFixContext context, CSharpContextUtil.ContextType contextType, @NotNull PsiFile file, @NotNull Template template)
{
	template.addTextSegment("public ");

	if(contextType == CSharpContextUtil.ContextType.STATIC)
	{
		template.addTextSegment("static ");
	}

	// get expected from method call expression not reference
	List<ExpectedTypeInfo> expectedTypeRefs = ExpectedTypeVisitor.findExpectedTypeRefs(context.getExpression());

	if(!expectedTypeRefs.isEmpty())
	{
		template.addVariable(new TypeRefExpression(expectedTypeRefs, file), true);
	}
	else
	{
		template.addVariable(new TypeRefExpression(new CSharpTypeRefByQName(file, DotNetTypes.System.Object), file), true);
	}

	template.addTextSegment(" ");
	template.addTextSegment(myReferenceName);
	template.addTextSegment(";");
	template.addEndVariable();
}
 
开发者ID:consulo,项目名称:consulo-csharp,代码行数:29,代码来源:CreateUnresolvedFieldFix.java


注:本文中的com.intellij.codeInsight.template.Template.addVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。