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


Java FileTemplateDescriptor.getFileName方法代码示例

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


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

示例1: createTestClassFromCodeTemplate

import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static PsiClass createTestClassFromCodeTemplate(final CreateTestDialog d,
                                                        final FileTemplateDescriptor fileTemplateDescriptor,
                                                        final PsiDirectory targetDirectory) {
  final String templateName = fileTemplateDescriptor.getFileName();
  final FileTemplate fileTemplate = FileTemplateManager.getInstance(targetDirectory.getProject()).getCodeTemplate(templateName);
  final Properties defaultProperties = FileTemplateManager.getInstance(targetDirectory.getProject()).getDefaultProperties();
  Properties properties = new Properties(defaultProperties);
  properties.setProperty(FileTemplate.ATTRIBUTE_NAME, d.getClassName());
  final PsiClass targetClass = d.getTargetClass();
  if (targetClass != null && targetClass.isValid()) {
    properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, targetClass.getQualifiedName());
  }
  try {
    final PsiElement psiElement = FileTemplateUtil.createFromTemplate(fileTemplate, templateName, properties, targetDirectory);
    if (psiElement instanceof PsiClass) {
      return (PsiClass)psiElement;
    }
    return null;
  }
  catch (Exception e) {
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:JavaTestGenerator.java

示例2: FileTemplateNode

import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
FileTemplateNode(FileTemplateDescriptor descriptor) {
  this(descriptor.getDisplayName(),
       descriptor.getIcon(),
       descriptor instanceof FileTemplateGroupDescriptor ? ContainerUtil.map2List(((FileTemplateGroupDescriptor)descriptor).getTemplates(), new Function<FileTemplateDescriptor, FileTemplateNode>() {
         @Override
         public FileTemplateNode fun(FileTemplateDescriptor s) {
           return new FileTemplateNode(s);
         }
       }) : Collections.<FileTemplateNode>emptyList(),
       descriptor instanceof FileTemplateGroupDescriptor ? null : descriptor.getFileName());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:FileTemplateTabAsTree.java

示例3: createTestMethodTemplate

import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
public static Template createTestMethodTemplate(MethodKind methodKind,
                                                TestFramework descriptor,
                                                PsiClass targetClass,
                                                @Nullable String name,
                                                boolean automatic,
                                                Set<String> existingNames) {
  FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
  String templateName = templateDesc.getFileName();
  FileTemplate fileTemplate = FileTemplateManager.getInstance(targetClass.getProject()).getCodeTemplate(templateName);
  Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");

  String templateText;
  try {
    templateText = fileTemplate.getText(new Properties());
  }
  catch (IOException e) {
    LOG.warn(e);
    templateText = fileTemplate.getText();
  }

  if (name == null) name = methodKind.getDefaultName();

  if (existingNames != null && !existingNames.add(name)) {
    int idx = 1;
    while (existingNames.contains(name)) {
      final String newName = name + (idx++);
      if (existingNames.add(newName)) {
        name = newName;
        break;
      }
    }
  }

  templateText = StringUtil.replace(templateText, "${BODY}", "");

  int from = 0;
  while (true) {
    int index = templateText.indexOf("${NAME}", from);
    if (index == -1) break;

    template.addTextSegment(templateText.substring(from, index));

    if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
      name = StringUtil.capitalize(name);
    }
    else {
      name = StringUtil.decapitalize(name);
    }
    if (from == 0) {
      Expression nameExpr = new ConstantNode(name);
      template.addVariable("name", nameExpr, nameExpr, !automatic);
    }
    else {
      template.addVariableSegment("name");
    }

    from = index + "${NAME}".length();
  }
  template.addTextSegment(templateText.substring(from, templateText.length()));

  template.setToIndent(true);
  template.setToReformat(true);
  template.setToShortenLongNames(true);

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

示例4: createTestMethodTemplate

import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
                                                 TestFramework descriptor,
                                                 PsiClass targetClass,
                                                 @Nullable String name,
                                                 boolean automatic) {
  FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
  String templateName = templateDesc.getFileName();
  FileTemplate fileTemplate = FileTemplateManager.getInstance().getCodeTemplate(templateName);
  Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");

  String templateText;
  try {
    templateText = fileTemplate.getText(new Properties());
  }
  catch (IOException e) {
    LOG.warn(e);
    templateText = fileTemplate.getText();
  }

  if (name == null) name = methodKind.getDefaultName();

  templateText = StringUtil.replace(templateText, "${BODY}", "");

  int from = 0;
  while (true) {
    int index = templateText.indexOf("${NAME}", from);
    if (index == -1) break;

    template.addTextSegment(templateText.substring(from, index));

    if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
      name = StringUtil.capitalize(name);
    }
    else {
      name = StringUtil.decapitalize(name);
    }
    if (from == 0) {
      Expression nameExpr = new ConstantNode(name);
      template.addVariable("name", nameExpr, nameExpr, !automatic);
    }
    else {
      template.addVariableSegment("name");
    }

    from = index + "${NAME}".length();
  }
  template.addTextSegment(templateText.substring(from, templateText.length()));

  template.setToIndent(true);
  template.setToReformat(true);
  template.setToShortenLongNames(true);

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

示例5: createTestMethodTemplate

import com.intellij.ide.fileTemplates.FileTemplateDescriptor; //导入方法依赖的package包/类
private static Template createTestMethodTemplate(MethodKind methodKind,
                                                 TestFramework descriptor,
                                                 PsiClass targetClass,
                                                 @Nullable String name,
                                                 boolean automatic) {
  FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
  String templateName = templateDesc.getFileName();
  FileTemplate fileTemplate = FileTemplateManager.getInstance(targetClass.getProject()).getCodeTemplate(templateName);
  Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");

  String templateText;
  try {
    templateText = fileTemplate.getText(new Properties());
  }
  catch (IOException e) {
    LOG.warn(e);
    templateText = fileTemplate.getText();
  }

  if (name == null) name = methodKind.getDefaultName();

  templateText = StringUtil.replace(templateText, "${BODY}", "");

  int from = 0;
  while (true) {
    int index = templateText.indexOf("${NAME}", from);
    if (index == -1) break;

    template.addTextSegment(templateText.substring(from, index));

    if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
      name = StringUtil.capitalize(name);
    }
    else {
      name = StringUtil.decapitalize(name);
    }
    if (from == 0) {
      Expression nameExpr = new ConstantNode(name);
      template.addVariable("name", nameExpr, nameExpr, !automatic);
    }
    else {
      template.addVariableSegment("name");
    }

    from = index + "${NAME}".length();
  }
  template.addTextSegment(templateText.substring(from, templateText.length()));

  template.setToIndent(true);
  template.setToReformat(true);
  template.setToShortenLongNames(true);

  return template;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:55,代码来源:TestIntegrationUtils.java


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