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


Java TemplateManager.startTemplate方法代码示例

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


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

示例1: expandForChooseExpression

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的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

示例2: invoke

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  final XmlTag rootTag = myTargetFile.getDocument().getRootTag();

  OpenFileDescriptor descriptor = new OpenFileDescriptor(
    project,
    myTargetFile.getVirtualFile(),
    rootTag.getValue().getTextRange().getEndOffset()
  );
  Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
  TemplateManager manager = TemplateManager.getInstance(project);
  final Template template = manager.createTemplate("", "");

  addTextTo(template, rootTag);

  manager.startTemplate(targetEditor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:CreateXmlElementIntentionAction.java

示例3: doFix

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
protected void doFix(@NotNull Project project,
                     @NotNull @GrModifier.ModifierConstant String[] modifiers,
                     @NotNull @NonNls String fieldName,
                     @NotNull TypeConstraint[] typeConstraints,
                     @NotNull PsiElement context) throws IncorrectOperationException {
  JVMElementFactory factory = JVMElementFactories.getFactory(myTargetClass.getLanguage(), project);
  if (factory == null) return;

  PsiField field = factory.createField(fieldName, PsiType.INT);
  if (myTargetClass instanceof GroovyScriptClass) {
    field.getModifierList().addAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD);
  }

  for (@GrModifier.ModifierConstant String modifier : modifiers) {
    PsiUtil.setModifierProperty(field, modifier, true);
  }

  field = CreateFieldFromUsageHelper.insertField(myTargetClass, field, context);
  JavaCodeStyleManager.getInstance(project).shortenClassReferences(field.getParent());

  Editor newEditor = IntentionUtils.positionCursor(project, myTargetClass.getContainingFile(), field);

  Template template = CreateFieldFromUsageHelper.setupTemplate(field, typeConstraints, myTargetClass, newEditor, context, false);
  TemplateManager manager = TemplateManager.getInstance(project);
  manager.startTemplate(newEditor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateFieldFix.java

示例4: invoke

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  final XmlTag rootTag = myTargetFile.getDocument().getRootTag();

  OpenFileDescriptor descriptor = new OpenFileDescriptor(
    project,
    myTargetFile.getVirtualFile(),
    rootTag.getValue().getTextRange().getEndOffset()
  );
  Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
  TemplateManager manager = TemplateManager.getInstance(project);
  final Template template = manager.createTemplate("", "");

  addTextTo(template, rootTag);

  manager.startTemplate(targetEditor, template);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:CreateXmlElementIntentionAction.java

示例5: doFix

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
protected void doFix(@NotNull Project project,
                     @NotNull @GrModifier.ModifierConstant String[] modifiers,
                     @NotNull @NonNls String fieldName,
                     @NotNull TypeConstraint[] typeConstraints,
                     @NotNull PsiElement context) throws IncorrectOperationException {
  JVMElementFactory factory = JVMElementFactories.getFactory(myTargetClass.getLanguage(), project);
  if (factory == null) return;

  PsiField field = factory.createField(fieldName, PsiType.INT);
  if (myTargetClass instanceof GroovyScriptClass) {
    field.getModifierList().addAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD);
  }

  for (@GrModifier.ModifierConstant String modifier : modifiers) {
    PsiUtil.setModifierProperty(field, modifier, true);
  }

  field = CreateFieldFromUsageHelper.insertField(myTargetClass, field, context);
  JavaCodeStyleManager.getInstance(project).shortenClassReferences(field.getParent());

  Editor newEditor = QuickfixUtil.positionCursor(project, myTargetClass.getContainingFile(), field);

  Template template = CreateFieldFromUsageHelper.setupTemplate(field, typeConstraints, myTargetClass, newEditor, context, false);
  TemplateManager manager = TemplateManager.getInstance(project);
  manager.startTemplate(newEditor, template);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:CreateFieldFix.java

示例6: invoke

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
	if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

	final XmlTag rootTag = myTargetFile.getDocument().getRootTag();

	OpenFileDescriptor descriptor = new OpenFileDescriptor(
			project,
			myTargetFile.getVirtualFile(),
			rootTag.getValue().getTextRange().getEndOffset()
	);
	Editor targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
	TemplateManager manager = TemplateManager.getInstance(project);
	final Template template = manager.createTemplate("", "");

	addTextTo(template, rootTag);

	manager.startTemplate(targetEditor, template);
}
 
开发者ID:consulo,项目名称:consulo-xml,代码行数:20,代码来源:CreateXmlElementIntentionAction.java

示例7: applyFix

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor)
{
	final PsiElement element = descriptor.getPsiElement();
	final Editor editor = BaseCreateFix.getEditor(project, element.getContainingFile());
	if(editor == null)
	{
		return;
	}

	final String shortenedType = JSResolveUtil.getShortenedType(this.type, element);
	final TemplateManager templateManager = TemplateManager.getInstance(project);
	Template template = templateManager.createTemplate("", "", shortenedType + "($SELECTION$)");
	template.setToReformat(true);

	final int offset = element.getTextOffset();
	editor.getSelectionModel().setSelection(offset, offset + element.getTextLength());
	editor.getCaretModel().moveToOffset(offset);
	templateManager.startTemplate(editor, element.getText(), template);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:JSUnresolvedFunctionInspection.java

示例8: applyFix

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
    Method method = (Method)methodReference.resolve();
    if (method != null) {
      Parameter[] parameters = method.getParameters();
      int paramParameterIndex = ClassUtils.getParamIndex(method, "params");
      int conditionParameterIndex = ClassUtils.getParamIndex(method, new String[]{ "condition", "expression", "sql"});

      if (paramParameterIndex > -1
              && conditionParameterIndex > -1
              && conditionParameterIndex == paramParameterIndex - 1
              && methodReference.getParameters().length > conditionParameterIndex) {
          String condition = methodReference.getParameters()[conditionParameterIndex].getText();
          String[] conditionParams = DatabaseUtils.extractParamsFromCondition(condition);

          ArrayCreationExpression array = null;
          if (methodReference.getParameters().length > paramParameterIndex) {
              PsiElement paramParameter = methodReference.getParameters()[paramParameterIndex];
              if (paramParameter instanceof ArrayCreationExpression)
                  array = (ArrayCreationExpression)paramParameter;
              paramParameter.delete();
          }

          TemplateManager templateManager = TemplateManager.getInstance(project);
          Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
          if (editor == null || methodReference.getParameterList() == null) return;

          editor.getCaretModel().moveToOffset(methodReference.getParameterList().getLastChild().getTextRange().getEndOffset());
          PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
          Template template = templateManager.createTemplate("", "");
          template.setToReformat(true);
          buildParamArray(template, conditionParams, array, conditionParameterIndex);

          PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
          templateManager.startTemplate(editor, template);
      }
    }

}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:40,代码来源:MissedParamQuickFix.java

示例9: applyFix

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
        List<PhpDocPropertyTag> propertyTags = this.comment.getPropertyTags();

        Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        if (editor == null)
            return;
        Document document = editor.getDocument();
        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
        TemplateManager templateManager = TemplateManager.getInstance(project);
        Template template = templateManager.createTemplate("", "");
        template.setToReformat(true);
        for (VirtualProperty missingProperty: this.missingProperties)
        {

            String propertyText = "* @property "+ (missingProperty.getType() != null ? missingProperty.getType() : "") + " $" +missingProperty.getName();
            if ( missingProperty.getComment() != null) {
                propertyText += " " + missingProperty.getComment();
            }
            template.addTextSegment("\n" + propertyText);
        }
        template.addTextSegment("\n");

        int offset =  comment.getLastChild().getTextOffset();
        if (propertyTags.size() > 0) {
            PhpDocPropertyTag phpDocPropertyTag = propertyTags.get(comment.getPropertyTags().size() - 1);
            offset = phpDocPropertyTag.getTextOffset() + phpDocPropertyTag.getTextLength();
        }
        editor.getCaretModel().moveToOffset(offset);
        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
        templateManager.startTemplate(editor, template);
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:33,代码来源:MissingPropertiesQuickFix.java

示例10: showRenameTemplate

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context,
                                      PsiNameIdentifierOwner element,
                                      PsiReference... references) {
  context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(
    context);
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN",
                           false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:HighlightUtils.java

示例11: showRenameTemplate

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
  context = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(context);
  final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
  final Collection<PsiReference> references = query.findAll();
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN", false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:HighlightUtil.java

示例12: expand

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
  PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
  if (expr == null) return;
  Project project = context.getProject();

  Document document = editor.getDocument();
  document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
  TemplateManager manager = TemplateManager.getInstance(project);

  Template template = manager.createTemplate("", "");
  template.setToReformat(true);
  template.addTextSegment("for (");
  MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());

  String variable = "variable";
  type.addParameter(new VariableNode(variable, null));
  MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());

  template.addVariable("type", type, type, false);
  template.addTextSegment(" ");
  template.addVariable("name", name, name, true);

  template.addTextSegment(" : ");
  template.addVariable(variable, new TextExpression(expr.getText()), false);
  template.addTextSegment(") {\n");
  template.addEndVariable();
  template.addTextSegment("\n}");

  manager.startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:ForeachPostfixTemplate.java

示例13: expand

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
  PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
  if (expr == null) {
    PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
    return;
  }

  Pair<String, String> bounds = calculateBounds(expr);
  if (bounds == null) {
    PostfixTemplatesUtils.showErrorHint(context.getProject(), editor);
    return;
  }
  Project project = context.getProject();

  Document document = editor.getDocument();
  document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
  TemplateManager manager = TemplateManager.getInstance(project);

  Template template = manager.createTemplate("", "");
  template.setToReformat(true);
  template.addTextSegment("for (" + suggestIndexType(expr) + " ");
  MacroCallNode index = new MacroCallNode(new SuggestVariableNameMacro());
  String indexVariable = "index";
  template.addVariable(indexVariable, index, index, true);
  template.addTextSegment(" = " + bounds.first + "; ");
  template.addVariableSegment(indexVariable);
  template.addTextSegment(getComparativeSign(expr));
  template.addTextSegment(bounds.second);
  template.addTextSegment("; ");
  template.addVariableSegment(indexVariable);
  template.addTextSegment(getOperator());
  template.addTextSegment(") {\n");
  template.addEndVariable();
  template.addTextSegment("\n}");

  manager.startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:39,代码来源:ForIndexedPostfixTemplate.java

示例14: showRenameTemplate

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context, PsiNameIdentifierOwner element) {
  context = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(context);
  final Query<PsiReference> query = ReferencesSearch.search(element, element.getUseScope());
  final Collection<PsiReference> references = query.findAll();
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN", false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:28,代码来源:HighlightUtil.java

示例15: showRenameTemplate

import com.intellij.codeInsight.template.TemplateManager; //导入方法依赖的package包/类
public static void showRenameTemplate(PsiElement context,
                                      PsiNameIdentifierOwner element,
                                      PsiReference... references) {
  context = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(
    context);
  final Project project = context.getProject();
  final FileEditorManager fileEditorManager =
    FileEditorManager.getInstance(project);
  final Editor editor = fileEditorManager.getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final TemplateBuilderImpl builder = new TemplateBuilderImpl(context);
  final Expression macroCallNode = new MacroCallNode(
    new SuggestVariableNameMacro());
  final PsiElement identifier = element.getNameIdentifier();
  builder.replaceElement(identifier, "PATTERN", macroCallNode, true);
  for (PsiReference reference : references) {
    builder.replaceElement(reference, "PATTERN", "PATTERN",
                           false);
  }
  final Template template = builder.buildInlineTemplate();
  final TextRange textRange = context.getTextRange();
  final int startOffset = textRange.getStartOffset();
  editor.getCaretModel().moveToOffset(startOffset);
  final TemplateManager templateManager =
    TemplateManager.getInstance(project);
  templateManager.startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:30,代码来源:HighlightUtils.java


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