• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JavaTemplateUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.ide.fileTemplates.JavaTemplateUtil的典型用法代码示例。如果您正苦于以下问题:Java JavaTemplateUtil类的具体用法?Java JavaTemplateUtil怎么用?Java JavaTemplateUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JavaTemplateUtil类属于com.intellij.ide.fileTemplates包,在下文中一共展示了JavaTemplateUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateMemberPrototypes

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members)
  throws IncorrectOperationException {

  final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);

  final GrMethod getter = genGetter(aClass, template);
  final GrMethod setter = genSetter(aClass, template);

  final ArrayList<GroovyGenerationInfo<GrMethod>> result = new ArrayList<GroovyGenerationInfo<GrMethod>>();
  if (getter != null) result.add(new GroovyGenerationInfo<GrMethod>(getter, true));
  if (setter != null) result.add(new GroovyGenerationInfo<GrMethod>(setter, true));

  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:GroovyGeneratePropertyMissingHandler.java


示例2: generateMethodPrototype

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass,
                                               PsiMethod method,
                                               PsiSubstitutor substitutor) {
  final Project project = aClass.getProject();
  final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(templName);
  final GrMethod result = (GrMethod)GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);

  setupModifierList(result);
  setupOverridingMethodBody(project, method, result, template, substitutor);
  setupReturnType(result, method);

  setupAnnotations(aClass, method, result);

  GroovyChangeContextUtil.encodeContextInfo(result);
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GroovyOverrideImplementUtil.java


示例3: setupCatchBlock

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
public void setupCatchBlock(String exceptionName, PsiElement context, PsiCatchSection catchSection) {
  final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance().getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
  LOG.assertTrue(catchBodyTemplate != null);

  final Properties props = new Properties();
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
  if (context != null && context.isPhysical()) {
    final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
    if (directory != null) {
      JavaTemplateUtil.setPackageNameAttribute(props, directory);
    }
  }

  final PsiCodeBlock codeBlockFromText;
  try {
    codeBlockFromText = PsiElementFactory.SERVICE.getInstance(myProject).createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
  }
  catch (ProcessCanceledException ce) {
    throw ce;
  }
  catch (Exception e) {
    throw new IncorrectOperationException("Incorrect file template", e);
  }
  catchSection.getCatchBlock().replace(codeBlockFromText);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:JavaPsiImplementationHelperImpl.java


示例4: generateMemberPrototypes

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members)
  throws IncorrectOperationException {

  final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(templName);

  final GrMethod getter = genGetter(aClass, template);
  final GrMethod setter = genSetter(aClass, template);

  final ArrayList<GroovyGenerationInfo<GrMethod>> result = new ArrayList<GroovyGenerationInfo<GrMethod>>();
  if (getter != null) result.add(new GroovyGenerationInfo<GrMethod>(getter, true));
  if (setter != null) result.add(new GroovyGenerationInfo<GrMethod>(setter, true));

  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:18,代码来源:GroovyGeneratePropertyMissingHandler.java


示例5: generateMethodPrototype

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
public static GrMethod generateMethodPrototype(GrTypeDefinition aClass,
                                               PsiMethod method,
                                               PsiSubstitutor substitutor) {
  final Project project = aClass.getProject();
  final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);

  String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(templName);
  final GrMethod result = (GrMethod)GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);

  setupModifierList(result);
  setupOverridingMethodBody(project, method, result, template, substitutor);
  setupReturnType(result, method);

  setupAnnotations(aClass, method, result);

  GroovyChangeContextUtil.encodeContextInfo(result);
  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:GroovyOverrideImplementUtil.java


示例6: checkFileHeader

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
static ProblemDescriptor checkFileHeader(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean onTheFly)
{
	TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<>();
	FileTemplate defaultTemplate = FileTemplateManager.getInstance(file.getProject()).getDefaultTemplate(JavaTemplateUtil.FILE_HEADER_TEMPLATE_NAME);
	Pattern pattern = FileTemplateUtil.getTemplatePattern(defaultTemplate, file.getProject(), offsetToProperty);
	Matcher matcher = pattern.matcher(file.getViewProvider().getContents());
	if(!matcher.matches())
	{
		return null;
	}

	PsiComment element = PsiTreeUtil.findElementOfClassAtRange(file, matcher.start(1), matcher.end(1), PsiComment.class);
	if(element == null)
	{
		return null;
	}

	LocalQuickFix[] fixes = createQuickFix(matcher, offsetToProperty, file.getProject(), onTheFly);
	String description = InspectionsBundle.message("default.file.template.description");
	return manager.createProblemDescriptor(element, description, onTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:FileHeaderChecker.java


示例7: setupCatchBlock

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
public void setupCatchBlock(@NotNull String exceptionName, @NotNull PsiType exceptionType, PsiElement context, @NotNull PsiCatchSection catchSection) {
  final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
  LOG.assertTrue(catchBodyTemplate != null);

  Properties props = FileTemplateManager.getInstance(myProject).getDefaultProperties();
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
  props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION_TYPE, exceptionType.getCanonicalText());
  if (context != null && context.isPhysical()) {
    final PsiDirectory directory = context.getContainingFile().getContainingDirectory();
    if (directory != null) {
      JavaTemplateUtil.setPackageNameAttribute(props, directory);
    }
  }

  final PsiCodeBlock codeBlockFromText;
  try {
    codeBlockFromText = PsiElementFactory.SERVICE.getInstance(myProject).createCodeBlockFromText("{\n" + catchBodyTemplate.getText(props) + "\n}", null);
  }
  catch (ProcessCanceledException ce) {
    throw ce;
  }
  catch (Exception e) {
    throw new IncorrectOperationException("Incorrect file template", (Throwable)e);
  }
  catchSection.getCatchBlock().replace(codeBlockFromText);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:JavaPsiImplementationHelperImpl.java


示例8: createInterface

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isInterface()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));
  }
  return someClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例9: createEnum

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createEnum(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isEnum()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));
  }
  return someClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例10: createAnnotationType

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createAnnotationType(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isAnnotationType()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName, dir.getProject()));
  }
  return someClass;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例11: testSurroundWithTryCatchProperties

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
public void testSurroundWithTryCatchProperties() {
  FileTemplate template = FileTemplateManager.getInstance(getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
  String old = template.getText();
  template.setText("// ${DS} \n" +
                   "${EXCEPTION}.printStackTrace();");
  try {
    doTest(new JavaWithTryCatchSurrounder());
  }
  finally {
    template.setText(old);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:JavaSurroundWithTest.java


示例12: generateMemberPrototypes

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members)
  throws IncorrectOperationException {

  final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);

  final GrMethod method = genMethod(aClass, template);
  return method != null
         ? Collections.singletonList(new GroovyGenerationInfo<GrMethod>(method, true))
         : Collections.<GenerationInfo>emptyList();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:GroovyGenerateMethodMissingHandler.java


示例13: setupOverridingMethodBody

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
private static void setupOverridingMethodBody(Project project,
                                              PsiMethod method,
                                              GrMethod resultMethod,
                                              FileTemplate template,
                                              PsiSubstitutor substitutor) {
  final PsiType returnType = substitutor.substitute(getSuperReturnType(method));

  String returnTypeText = "";
  if (returnType != null) {
    returnTypeText = returnType.getPresentableText();
  }
  Properties properties = FileTemplateManager.getInstance(project).getDefaultProperties();

  properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnTypeText);
  properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
  properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(method, resultMethod));
  JavaTemplateUtil.setClassAndMethodNameProperties(properties, method.getContainingClass(), resultMethod);

  try {
    String bodyText = StringUtil.replace(template.getText(properties), ";", "");
    GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile("\n " + bodyText + "\n", false, null);

    GrOpenBlock block = resultMethod.getBlock();
    block.getNode().addChildren(file.getFirstChild().getNode(), null, block.getRBrace().getNode());
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:GroovyOverrideImplementUtil.java


示例14: createDialog

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
public JavaI18nizeQuickFixDialog createDialog(final Project project, final Editor editor, final PsiFile psiFile) {
  JspFile jspFile = (JspFile)psiFile;

  TextRange selectedRange = JavaI18nUtil.getSelectedRange(editor, psiFile);
  if (selectedRange == null) return null;
  String text = editor.getDocument().getText(selectedRange);
  return new JavaI18nizeQuickFixDialog(project, jspFile, null, text, null, false, true){
    @Override
    protected String getTemplateName() {
      return JavaTemplateUtil.TEMPLATE_I18NIZED_JSP_EXPRESSION;
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:I18nizeJspHandlerProvider.java


示例15: createInterface

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createInterface(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_INTERFACE_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isInterface()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName));
  }
  return someClass;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例16: createEnum

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createEnum(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_ENUM_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isEnum()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName));
  }
  return someClass;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例17: createAnnotationType

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@Override
@NotNull
public PsiClass createAnnotationType(@NotNull PsiDirectory dir, @NotNull String name) throws IncorrectOperationException {
  String templateName = JavaTemplateUtil.INTERNAL_ANNOTATION_TYPE_TEMPLATE_NAME;
  PsiClass someClass = createClassFromTemplate(dir, name, templateName);
  if (!someClass.isAnnotationType()) {
    throw new IncorrectOperationException(getIncorrectTemplateMessage(templateName));
  }
  return someClass;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:JavaDirectoryServiceImpl.java


示例18: generateMemberPrototypes

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members)
  throws IncorrectOperationException {

  final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
  final FileTemplate template = FileTemplateManager.getInstance().getCodeTemplate(templName);

  final GrMethod method = genMethod(aClass, template);
  return method != null
         ? Collections.singletonList(new GroovyGenerationInfo<GrMethod>(method, true))
         : Collections.<GenerationInfo>emptyList();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:GroovyGenerateMethodMissingHandler.java


示例19: setupOverridingMethodBody

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
private static void setupOverridingMethodBody(Project project,
                                              PsiMethod method,
                                              GrMethod resultMethod,
                                              FileTemplate template,
                                              PsiSubstitutor substitutor) {
  final PsiType returnType = substitutor.substitute(getSuperReturnType(method));

  String returnTypeText = "";
  if (returnType != null) {
    returnTypeText = returnType.getPresentableText();
  }
  Properties properties = FileTemplateManager.getInstance().getDefaultProperties(project);

  properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnTypeText);
  properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
  properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(method, resultMethod));
  JavaTemplateUtil.setClassAndMethodNameProperties(properties, method.getContainingClass(), resultMethod);

  try {
    String bodyText = StringUtil.replace(template.getText(properties), ";", "");
    final GrCodeBlock newBody = GroovyPsiElementFactory.getInstance(project).createMethodBodyFromText("\n " + bodyText + "\n");

    resultMethod.setBlock(newBody);
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:GroovyOverrideImplementUtil.java


示例20: setupMethodBody

import com.intellij.ide.fileTemplates.JavaTemplateUtil; //导入依赖的package包/类
public static void setupMethodBody(PsiMethod result, PsiMethod originalMethod, PsiClass targetClass) throws IncorrectOperationException
{
	boolean isAbstract = originalMethod.hasModifierProperty(PsiModifier.ABSTRACT) || originalMethod.hasModifierProperty(PsiModifier.DEFAULT);
	String templateName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
	FileTemplate template = FileTemplateManager.getInstance(result.getProject()).getCodeTemplate(templateName);
	setupMethodBody(result, originalMethod, targetClass, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:8,代码来源:OverrideImplementUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LoginContextFactory类代码示例发布时间:2022-05-22
下一篇:
Java OutputBitStream类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap