當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。