protected void doTest() throws Exception { String name = getTestName(); String text = loadFile(name + "." + myFileExt); myFile = createPsiFile(name, text); myFile.putUserData(IndexingDataKeys.VIRTUAL_FILE, myFile.getVirtualFile()); ensureParsed(myFile); checkResult(name, myFile); } }
protected static String buildStubTreeText(@NotNull Project project, @NotNull VirtualFile file, @NotNull String fileContent, boolean checkErrors) throws IOException { String path = file.getPath(); PsiFile psi = PsiFileFactory.getInstance(project).createFileFromText(file.getName(), file.getFileType(), fileContent); if (checkErrors) { assertFalse(path + " contains error elements", DebugUtil.psiToString(psi, true).contains("PsiErrorElement")); } String full = DebugUtil.stubTreeToString(GoFileElementType.INSTANCE.getBuilder().buildStubTree(psi)); psi.putUserData(IndexingDataKeys.VIRTUAL_FILE, file); FileContentImpl content = new FileContentImpl(file, fileContent, file.getCharset()); PsiFile psiFile = content.getPsiFile(); String fast = DebugUtil.stubTreeToString(GoFileElementType.INSTANCE.getBuilder().buildStubTree(psiFile)); if (!Comparing.strEqual(full, fast)) { System.err.println(path); UsefulTestCase.assertSameLines(full, fast); } return fast; }
@Override protected MongoConsoleView createConsoleView() { MongoConsoleView res = new MongoConsoleView(getProject()); PsiFile file = res.getFile(); assert file.getContext() == null; file.putUserData(MONGO_SHELL_FILE, Boolean.TRUE); return res; }
@Override protected LanguageConsoleView createConsoleView() { LanguageConsoleImpl consoleView = new LanguageConsoleImpl(getProject(), "Bash", BashFileType.BASH_LANGUAGE); consoleView.getFile().putUserData(BashFile.LANGUAGE_CONSOLE_MARKER, true); return consoleView; }
@NotNull private TSMetaModelImpl doGetExternalModel(final @NotNull PsiFile contextFile) { final PsiFile originalFile = contextFile.getOriginalFile(); final VirtualFile vFile = originalFile.getVirtualFile(); final Project project = originalFile.getProject(); CachedValue<TSMetaModelImpl> externalModelCache = originalFile.getUserData(EXTERNAL_MODEL_CACHE_KEY); if (externalModelCache == null) { externalModelCache = CachedValuesManager.getManager(project).createCachedValue( () -> ApplicationManager.getApplication().runReadAction( (Computable<CachedValueProvider.Result<TSMetaModelImpl>>) () -> { final List<VirtualFile> excludes = vFile == null ? Collections.emptyList() : Collections.singletonList(vFile); final TSMetaModelBuilder builder = new TSMetaModelBuilder(project, excludes); final TSMetaModelImpl model = builder.buildModel(); return CachedValueProvider.Result.create(model, builder.getFiles()); }), false); originalFile.putUserData(EXTERNAL_MODEL_CACHE_KEY, externalModelCache); } return externalModelCache.getValue(); }
file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file.getNode()); return state.items;
@Override public void prepareMovedFile(PsiFile file, PsiDirectory moveDestination, Map<PsiElement, PsiElement> oldToNewMap) { file.putUserData(ORIGINAL_PACKAGE_NAME, ((PerlFileImpl)file).getFilePackageName()); String newFilePath = moveDestination.getVirtualFile().getPath() + '/' + file.getName(); VirtualFile newClassRoot = PerlUtil.getFileClassRoot(moveDestination.getProject(), newFilePath); if (newClassRoot != null) { String newRelativePath = newFilePath.substring(newClassRoot.getPath().length()); String newPackageName = PerlPackageUtil.getPackageNameByPath(newRelativePath); if (newPackageName != null) { for (PsiReference reference : ReferencesSearch.search(file, file.getUseScope()).findAll()) { PerlPsiUtil.renameElement(reference.getElement(), newPackageName); } } } }
@Override public synchronized TSMetaModel getTypeSystemMeta(@Nullable final PsiFile contextFile) { if (contextFile == null || !TSMetaModelBuilder.isTsFile(contextFile)) { return myCachedValue.getValue(); } final TSMetaModelImpl externalModel = doGetExternalModel(contextFile); final Project project = contextFile.getProject(); CachedValue<TSMetaModelImpl> fileModelCache = contextFile.getUserData(FILE_MODEL_CACHE_KEY); if (fileModelCache == null) { fileModelCache = CachedValuesManager.getManager(project).createCachedValue( () -> ApplicationManager.getApplication().runReadAction( (Computable<CachedValueProvider.Result<TSMetaModelImpl>>) () -> { final TSMetaModelBuilder builder = new TSMetaModelBuilder(project); final TSMetaModelImpl modelForFile = builder.buildModelForFile(contextFile); return CachedValueProvider.Result.create(modelForFile, contextFile); }), false); contextFile.putUserData(FILE_MODEL_CACHE_KEY, fileModelCache); } final TSMetaModelImpl fileModel = fileModelCache.getValue(); return new TSMetaModelImpl(Arrays.asList(externalModel, fileModel)); }
file.putUserData(FILE_COPY_KEY, new SoftReference<Trinity<PsiFile,Document, Long>>(Trinity.create(copy, document, combinedOffsets))); final Document document = copy.getViewProvider().getDocument(); assert document != null; file.putUserData(FILE_COPY_KEY, new SoftReference<Trinity<PsiFile,Document, Long>>(Trinity.create(copy, document, combinedOffsets)));
PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(posFile.getProject()); PsiFile file = psiFileFactory.createFileFromText("a.bnf", BnfLanguage.INSTANCE, text, true, false); file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file.getNode()); String text2 = text + (StringUtil.isEmptyOrSpaces(tailText)? "a ::= " : tailText); PsiFile file2 = psiFileFactory.createFileFromText("a.bnf", BnfLanguage.INSTANCE, text2, true, false); file2.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state); TreeUtil.ensureParsed(file2.getNode());