本文整理汇总了Java中com.intellij.psi.PsiDirectory.add方法的典型用法代码示例。如果您正苦于以下问题:Java PsiDirectory.add方法的具体用法?Java PsiDirectory.add怎么用?Java PsiDirectory.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiDirectory
的用法示例。
在下文中一共展示了PsiDirectory.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFromTemplate
import com.intellij.psi.PsiDirectory; //导入方法依赖的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);
}
示例2: actionPerformed
import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
try {
Project project = e.getProject();
SpecflowFileContents content = lexer.analyze(new String(file.contentsToByteArray()), project.getName());
PsiFileFactory fileFactory = psiFileFactory.getInstance(project);
PsiDirectory directory = psiDirectoryFactory.getInstance(project).createDirectory(file.getParent());
directory.add(fileFactory.createFileFromText(file.getName()+"Feature.cs",content.feature));
directory.add(fileFactory.createFileFromText(file.getName()+"Steps.cs",content.steps));
} catch (IOException ioExeption) {
}
}
示例3: createSourceFile
import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
/**
* Writes a source file generated by a {@link Generator} to disk.
*
* @param project to write file in.
* @param generator to generate file with.
* @param directory to write file to.
*/
private static void createSourceFile(
Project project, Generator generator, PsiDirectory directory) {
PsiFile file =
PsiFileFactory.getInstance(project)
.createFileFromText(
String.format("%s.java", generator.getClassName()),
JavaLanguage.INSTANCE,
generator.generate());
directory.add(file);
}
示例4: createFile
import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
protected PsiFile createFile(Project project, @NotNull PsiDirectory psiDirectory, String fileName, String context, LanguageFileType fileType) {
PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(fileName, fileType, context);
// reformat class
CodeStyleManager.getInstance(project).reformat(psiFile);
if (psiFile instanceof PsiJavaFile) {
JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
styleManager.optimizeImports(psiFile);
styleManager.shortenClassReferences(psiFile);
}
psiDirectory.add(psiFile);
return psiFile;
}