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


Java FileTemplate.getText方法代码示例

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


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

示例1: createFromTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
public static PsiFile createFromTemplate(final PsiDirectory directory, final String name,
                                         String fileName, String templateName,
                                         @NonNls String... parameters) throws IncorrectOperationException {

    final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);
    String text;

    try {
        text = template.getText();
    } catch (Exception e) {
        throw new RuntimeException("Unable to load template for " +
                FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e);
    }

    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());

    final PsiFile file = factory.createFileFromText(fileName, WeexFileType.INSTANCE, text);
    CodeStyleManager.getInstance(directory.getProject()).reformat(file);
    return (PsiFile) directory.add(file);
}
 
开发者ID:misakuo,项目名称:weex-language-support,代码行数:21,代码来源:WeexTemplateFactory.java

示例2: getFileText

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
@Override
protected String getFileText() {
  if (!isDirectory) {
    String templateName = myReference.getNewFileTemplateName();
    if (templateName != null) {
      Project project = myReference.getElement().getProject();
      FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
      FileTemplate template = fileTemplateManager.getTemplate(templateName);
      if (template == null) template = fileTemplateManager.findInternalTemplate(templateName);

      if (template != null) {
        try {
          return template.getText(fileTemplateManager.getDefaultProperties());
        } catch (IOException ex) {
          throw new RuntimeException(ex);
        }
      }
    }
  }
  return super.getFileText();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:FileReferenceQuickFixProvider.java

示例3: createFileFromTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
@Nullable
public static VirtualFile createFileFromTemplate(final String templateName, final VirtualFile parent, final String fileName) {
  parent.refresh(false, false);
  final FileTemplate template = FileTemplateManager.getDefaultInstance().getJ2eeTemplate(templateName);
  try {
    final String text = template.getText(FileTemplateManager.getDefaultInstance().getDefaultProperties());
    VirtualFile file = parent.findChild(fileName);
    if (file == null) {
      file = parent.createChildData(AppEngineSupportProvider.class, fileName);
    }
    VfsUtil.saveText(file, text);
    return file;
  }
  catch (IOException e) {
    LOG.error(e);
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:AppEngineSupportProvider.java

示例4: getI18nizedText

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
public String getI18nizedText() {
  String propertyKey = StringUtil.escapeStringCharacters(getKey());
  I18nizedTextGenerator textGenerator = myResourceBundleManager.getI18nizedTextGenerator();
  if (textGenerator != null) {
    return generateText(textGenerator, propertyKey, getPropertiesFile(), myLiteralExpression);
  }

  String templateName = getTemplateName();
  LOG.assertTrue(templateName != null);
  FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
  Map<String, String> attributes = new THashMap<String, String>();
  attributes.put(PROPERTY_KEY_OPTION_KEY, propertyKey);
  attributes.put(RESOURCE_BUNDLE_OPTION_KEY, getResourceBundleText());
  attributes.put(PROPERTY_VALUE_ATTR, StringUtil.escapeStringCharacters(myDefaultPropertyValue));
  addAdditionalAttributes(attributes);
  String text = null;
  try {
    text = template.getText(attributes);
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return text;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:JavaI18nizeQuickFixDialog.java

示例5: createFromTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
public static PsiFile createFromTemplate(final PsiDirectory directory, final String name,
                                         String fileName, String templateName,
                                       @NonNls String... parameters) throws IncorrectOperationException {
    log.debug("createFromTemplate: dir:" + directory + ", filename: " + fileName);

    final FileTemplate template = FileTemplateManager.getInstance().getTemplate(templateName);

    Properties properties = new Properties(FileTemplateManager.getInstance().getDefaultProperties());

    Project project = directory.getProject();
    properties.setProperty("PROJECT_NAME", project.getName());
    properties.setProperty("NAME", fileName);


    String text;

    try {
        text = template.getText(properties);
    } catch (Exception e) {
        throw new RuntimeException("Unable to load template for " +
                                   FileTemplateManager.getInstance().internalTemplateToSubject(templateName), e);
    }

    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());

    log.debug("Create file from text");
    final PsiFile file = factory.createFileFromText(fileName, LuaFileType.LUA_FILE_TYPE, text);

    log.debug("Adding file to directory");
    return (PsiFile) directory.add(file);
}
 
开发者ID:internetisalie,项目名称:lua-for-idea,代码行数:32,代码来源:LuaTemplatesFactory.java

示例6: testSurroundWithTryCatchProperties

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的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

示例7: getEncodedContent

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
public static String getEncodedContent(VirtualFile virtualFile,
                                        Project project,
                                        Map<String, String> parameters) throws IOException {
  String text = VfsUtilCore.loadText(virtualFile);
  final FileTemplate template = FileTemplateManager.getInstance(project).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
  final String templateText = template.getText();
  final Pattern pattern = FileHeaderChecker.getTemplatePattern(template, project, new TIntObjectHashMap<String>());
  String result = convertTemplates(text, pattern, templateText);
  result = ProjectTemplateFileProcessor.encodeFile(result, virtualFile, project);
  for (Map.Entry<String, String> entry : parameters.entrySet()) {
    result = result.replace(entry.getKey(), "${" + entry.getValue() + "}");
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:SaveProjectAsTemplateAction.java

示例8: getText

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
private static String getText(final String templateName, @Nullable Project project) throws IOException {
  final FileTemplateManager templateManager = project == null ? FileTemplateManager.getDefaultInstance() : FileTemplateManager.getInstance(project);
  final FileTemplate template = templateManager.getJ2eeTemplate(templateName);
  if (template == null) {
    return "";
  }
  return template.getText(templateManager.getDefaultProperties());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ConfigFileFactoryImpl.java

示例9: getOrCreateFile

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
@NotNull
public static PyFile getOrCreateFile(String path, Project project) {
  final VirtualFile vfile = LocalFileSystem.getInstance().findFileByIoFile(new File(path));
  final PsiFile psi;
  if (vfile == null) {
    final File file = new File(path);
    try {
      final VirtualFile baseDir = project.getBaseDir();
      final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
      final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");
      final Properties properties = fileTemplateManager.getDefaultProperties();
      properties.setProperty("NAME", FileUtil.getNameWithoutExtension(file.getName()));
      final String content = (template != null) ? template.getText(properties) : null;
      psi = PyExtractSuperclassHelper.placeFile(project,
                                                StringUtil.notNullize(
                                                  file.getParent(),
                                                  baseDir != null ? baseDir
                                                    .getPath() : "."
                                                ),
                                                file.getName(),
                                                content
      );
    }
    catch (IOException e) {
      throw new IncorrectOperationException(String.format("Cannot create file '%s'", path));
    }
  }
  else {
    psi = PsiManager.getInstance(project).findFile(vfile);
  }
  if (!(psi instanceof PyFile)) {
    throw new IncorrectOperationException(PyBundle.message(
      "refactoring.move.module.members.error.cannot.place.elements.into.nonpython.file"));
  }
  return (PyFile)psi;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:PyUtil.java

示例10: testTemplateAttributesExpansionInCreatedDestinationModule

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
public void testTemplateAttributesExpansionInCreatedDestinationModule() {
  final FileTemplateManager instance = FileTemplateManager.getInstance(myFixture.getProject());
  final FileTemplate template = instance.getInternalTemplate("Python Script");
  assertNotNull(template);
  final String oldTemplateContent = template.getText();
  try {
    template.setText("NAME = '${NAME}'");
    doMoveSymbolTest("C", "b.py");
  }
  finally {
    template.setText(oldTemplateContent);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PyMoveTest.java

示例11: createClassFromTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
@Nullable
private static PsiClass createClassFromTemplate(@NotNull final Properties attributes, @Nullable final String templateName,
                                                @NotNull final PsiDirectory directoryRoot,
                                                @NotNull final String className) throws IncorrectOperationException {
  if (templateName == null) return null;
  if (templateName.equals(DO_NOT_CREATE_CLASS_TEMPLATE)) return null;

  final Project project = directoryRoot.getProject();
  try {
    final PsiDirectory directory = createParentDirectories(directoryRoot, className);
    final PsiFile psiFile = directory.findFile(className + "." + StdFileTypes.JAVA.getDefaultExtension());
    if (psiFile != null) {
      psiFile.delete();
    }

    final String rawClassName = extractClassName(className);
    final PsiFile existing = directory.findFile(rawClassName + ".java");
    if (existing instanceof PsiJavaFile) {
      final PsiClass[] classes = ((PsiJavaFile)existing).getClasses();
      if (classes.length > 0) {
        return classes[0];
      }
      return null;
    }

    final PsiClass aClass;
    if (templateName.equals(DEFAULT_CLASS_TEMPLATE)) {
      aClass = JavaDirectoryService.getInstance().createClass(directory, rawClassName);
    }
    else {
      final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
      FileTemplate fileTemplate = fileTemplateManager.getJ2eeTemplate(templateName);
      LOG.assertTrue(fileTemplate != null, templateName + " not found");
      final String text = fileTemplate.getText(attributes);
      aClass = JavaCreateFromTemplateHandler.createClassOrInterface(project, directory, text, true, fileTemplate.getExtension());
    }
    return (PsiClass)JavaCodeStyleManager.getInstance(project).shortenClassReferences(aClass);
  }
  catch (IOException e) {
    throw new IncorrectOperationException(e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:CreateClassUtil.java

示例12: createTestMethodTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的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

示例13: runOrApplyFileTemplate

import com.intellij.ide.fileTemplates.FileTemplate; //导入方法依赖的package包/类
private static void runOrApplyFileTemplate(Project project,
                                           VirtualFile file,
                                           String templateName,
                                           Properties properties,
                                           Properties conditions,
                                           boolean interactive) throws IOException {
  FileTemplateManager manager = FileTemplateManager.getInstance(project);
  FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
  Properties allProperties = manager.getDefaultProperties();
  if (!interactive) {
    allProperties.putAll(properties);
  }
  allProperties.putAll(conditions);
  String text = fileTemplate.getText(allProperties);
  Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
  Matcher matcher = pattern.matcher(text);
  StringBuffer builder = new StringBuffer();
  while (matcher.find()) {
    matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
  }
  matcher.appendTail(builder);
  text = builder.toString();

  TemplateImpl template = (TemplateImpl)TemplateManager.getInstance(project).createTemplate("", "", text);
  for (int i = 0; i < template.getSegmentsCount(); i++) {
    if (i == template.getEndSegmentNumber()) continue;
    String name = template.getSegmentName(i);
    String value = "\"" + properties.getProperty(name, "") + "\"";
    template.addVariable(name, value, value, true);
  }

  if (interactive) {
    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file);
    Editor editor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
    editor.getDocument().setText("");
    TemplateManager.getInstance(project).startTemplate(editor, template);
  }
  else {
    VfsUtil.saveText(file, template.getTemplateText());

    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile != null) {
      new ReformatCodeProcessor(project, psiFile, null, false).run();
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:MavenUtil.java


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