PsiFile (String name, String text, Consumer<PsiBuilder> parser) { if (TEST_FILE_ELEMENT_TYPE == null) { TEST_FILE_ELEMENT_TYPE = new MyIFileElementType(); } TEST_PARSER = parser; LightVirtualFile virtualFile = new LightVirtualFile(name + '.' + myFileExt, JavaFileType.INSTANCE, text, -1); FileViewProvider viewProvider = new SingleRootFileViewProvider(PsiManager.getInstance(getProject()), virtualFile, true); return new PsiJavaFileImpl(viewProvider) { @NotNull @Override protected FileElement createFileElement(@NotNull CharSequence text) { return new FileElement(TEST_FILE_ELEMENT_TYPE, text); } }; }