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


Java PsiFileFactory.createFileFromText方法代码示例

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


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

示例1: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的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: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
public static PsiFile createFromTemplate(PsiDirectory directory, String fileName, String templateName) throws IncorrectOperationException {
	final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);

	Project project = directory.getProject();

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

	final PsiFileFactory factory = PsiFileFactory.getInstance(project);
	PsiFile file = factory.createFileFromText(fileName, NullShaderFileType.INSTANCE, text);

	file = (PsiFile) directory.add(file);

	return file;
}
 
开发者ID:warlockcodes,项目名称:Null-Engine,代码行数:20,代码来源:NullShaderTemplatesFactory.java

示例3: parseXmlFileInTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback,
                                              @NotNull Map<String, String> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.html", HTMLLanguage.INSTANCE, templateString, false, true);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile =
    (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TemplateToken.java

示例4: processTags

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
private static void processTags(@NotNull Project project,
                                @Nullable String templateText,
                                @NotNull PairProcessor<XmlTag, Boolean> processor) {
  if (StringUtil.isNotEmpty(templateText)) {
    final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project);
    XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.HTML, templateText);
    XmlTag tag = xmlFile.getRootTag();
    boolean firstTag = true;

    while (tag != null) {
      processor.process(tag, firstTag);
      firstTag = false;
      tag = PsiTreeUtil.getNextSiblingOfType(tag, XmlTag.class);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:EmmetUpdateTagAction.java

示例5: getEnumValues

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@Nullable
public static Set<String> getEnumValues(Project project, @NotNull String regExp) {
  final PsiFileFactory factory = PsiFileFactory.getInstance(project);
  final PsiFile file = factory.createFileFromText("dummy.regexp", RegExpFileType.INSTANCE, regExp);
  final RegExpPattern pattern = (RegExpPattern)file.getFirstChild();
  if (pattern == null) {
    return null;
  }
  final RegExpBranch[] branches = pattern.getBranches();
  final Set<String> values = new HashSet<String>();
  for (RegExpBranch branch : branches) {
    if (analyzeBranch(branch)) {
      values.add(branch.getUnescapedText());
    }
  }
  return values;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:RegExpUtil.java

示例6: parseXmlFileInTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(TemplateImpl template,
                                              CustomTemplateCallback callback,
                                              List<Pair<String, String>> attributes) {
  XmlTag dummyRootTag = null;
  String templateString = template.getString();
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
  if (!containsAttrsVar(template)) {
    XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString);
    dummyRootTag = dummyFile.getRootTag();
    if (dummyRootTag != null) {
      addMissingAttributes(dummyRootTag, attributes);
    }
  }

  templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
  XmlFile xmlFile = (XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
  VirtualFile vFile = xmlFile.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return xmlFile;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:TemplateToken.java

示例7: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
/**
 * Creates new Gitignore file or uses an existing one.
 *
 * @param directory working directory
 * @return file
 *
 * @throws IncorrectOperationException
 */
@Nullable
public PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
    final String filename = fileType.getIgnoreLanguage().getFilename();
    final PsiFile currentFile = directory.findFile(filename);
    if (currentFile != null) {
        return currentFile;
    }
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    final IgnoreLanguage language = fileType.getIgnoreLanguage();

    String content = StringUtil.join(TEMPLATE_NOTE, Constants.NEWLINE);
    if (language.isSyntaxSupported() && !IgnoreBundle.Syntax.GLOB.equals(language.getDefaultSyntax())) {
        content = StringUtil.join(
                content,
                IgnoreBundle.Syntax.GLOB.getPresentation(),
                Constants.NEWLINE,
                Constants.NEWLINE
        );
    }
    final PsiFile file = factory.createFileFromText(filename, fileType, content);
    return (PsiFile) directory.add(file);
}
 
开发者ID:hsz,项目名称:idea-gitignore,代码行数:31,代码来源:IgnoreTemplatesFactory.java

示例8: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的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().getInternalTemplate(templateName);

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

    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:consulo,项目名称:consulo-lua,代码行数:27,代码来源:LuaTemplatesFactory.java

示例9: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
public static PsiElement createFromTemplate(PsiDirectory directory, String fileName, Template template, String text2) {
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    if ((new File(fileName)).exists()) {
        throw new RuntimeException("File already exists");
    }
    final PsiFile file = factory.createFileFromText(fileName, GCMLanguageType.INSTANCE, text2);
    return directory.add(file);
}
 
开发者ID:datathings,项目名称:greycat-idea-plugin,代码行数:9,代码来源:GCMTemplatesFactory.java

示例10: createFromTemplate

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

示例11: createVirtualFile

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
private PsiFile createVirtualFile(String resource, String content) {
    PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);
    PsiFile psiFile = fileFactory.createFileFromText(resource, ProtoLanguage.INSTANCE, content);
    try {
        psiFile.getVirtualFile().setWritable(false);
    } catch (IOException e) {
        throw new RuntimeException("Could not mark " + resource + " as read-only.");
    }
    return psiFile;
}
 
开发者ID:protostuff,项目名称:protobuf-jetbrains-plugin,代码行数:12,代码来源:BundledFileProviderImpl.java

示例12: copyFile

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
public static PsiFile copyFile(@NotNull PsiFile file, @NotNull StringBuilder fileContentWithoutKey) {
  final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(file.getProject());
  PsiFile copy = psiFileFactory.createFileFromText(file.getName(), file.getFileType(), fileContentWithoutKey);
  VirtualFile vFile = copy.getVirtualFile();
  if (vFile != null) {
    vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
  }
  return copy;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:PostfixLiveTemplate.java

示例13: loadContentAsFile

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
public static PsiFile loadContentAsFile(Project project, InputStream stream, LanguageFileType fileType) throws IOException {
  final StringBuilder builder = new StringBuilder();
  try {
    int nextByte;
    while ((nextByte = stream.read()) >= 0) {
      builder.append((char)nextByte);
    }
  }
  finally {
    stream.close();
  }
  final PsiFileFactory factory = PsiFileFactory.getInstance(project);
  return factory.createFileFromText("_ant_dummy__." + fileType.getDefaultExtension(), fileType, builder, LocalTimeCounter.currentTime(), false, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:CustomAntElementsRegistry.java

示例14: createFromTemplate

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
public static PsiFile createFromTemplate(@NotNull final PsiDirectory directory,
                                         @NotNull final String name,
                                         @NotNull String fileName,
                                         @NotNull String templateName,
                                         boolean allowReformatting,
                                         @NonNls String... parameters) throws IncorrectOperationException {
  final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName);

  Project project = directory.getProject();

  Properties properties = new Properties(FileTemplateManager.getInstance(project).getDefaultProperties());
  JavaTemplateUtil.setPackageNameAttribute(properties, directory);
  properties.setProperty(NAME_TEMPLATE_PROPERTY, name);
  properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, name.substring(0, 1).toLowerCase() + name.substring(1));
  for (int i = 0; i < parameters.length; i += 2) {
    properties.setProperty(parameters[i], parameters[i + 1]);
  }
  String text;
  try {
    text = template.getText(properties);
  }
  catch (Exception e) {
    throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName), e);
  }

  final PsiFileFactory factory = PsiFileFactory.getInstance(project);
  PsiFile file = factory.createFileFromText(fileName, GroovyFileType.GROOVY_FILE_TYPE, text);

  file = (PsiFile)directory.add(file);

  if (file != null && allowReformatting && template.isReformatCode()) {
    new ReformatCodeProcessor(project, file, null, false).run();
  }

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

示例15: createFile

import com.intellij.psi.PsiFileFactory; //导入方法依赖的package包/类
@NotNull
public static PointcutFile createFile(Project project, String text) {
    String name = "dummy.goaop";

    PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);

    return (PointcutFile) fileFactory.createFileFromText(name, GoAopFileType.INSTANCE, text);
}
 
开发者ID:goaop,项目名称:idea-plugin,代码行数:9,代码来源:PointcutElementFactory.java


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