本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}