本文整理匯總了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;
}