private void updateTab(@NotNull JBTabsPaneImpl tabsPane, int index, WeaveIdentifier identifier, @NotNull WeaveDataType dataType) { Icon icon = iconsMap.containsKey(dataType.getText()) ? iconsMap.get(dataType.getText()) : AllIcons.FileTypes.Any_type; String title = (identifier == null ? "output" : identifier.getName()); tabsPane.setTitleAt(index, title); tabsPane.setIconAt(index, icon); contentTypes.put(title, dataType.getText()); VirtualFile vfile = inputOutputFiles.get(title); if (vfile != null) { vfile.putUserData(newFileDataTypeKey, dataType.getText()); FileContentUtilCore.reparseFiles(vfile); } Editor oldEditor = editors.get(title); FileType newType = fileTypes.containsKey(dataType.getText()) ? fileTypes.get(dataType.getText()) : FileTypes.UNKNOWN; ((EditorEx) oldEditor).setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(project, newType)); }
public static void checkPropertyValuesCorrect(Object requestor, @NotNull String propertyName, Object oldValue, Object newValue) { if (Comparing.equal(oldValue, newValue) && FileContentUtilCore.FORCE_RELOAD_REQUESTOR != requestor) { throw new IllegalArgumentException("Values must be different, got the same: " + oldValue); } if (VirtualFile.PROP_NAME.equals(propertyName)) { if (oldValue == null) throw new IllegalArgumentException("oldName must not be null"); if (newValue == null) throw new IllegalArgumentException("newName must not be null"); } else if (VirtualFile.PROP_ENCODING.equals(propertyName)) { if (oldValue == null) throw new IllegalArgumentException("oldCharset must not be null"); } else if (VirtualFile.PROP_WRITABLE.equals(propertyName)) { if (!(oldValue instanceof Boolean)) throw new IllegalArgumentException("oldWriteable must be boolean, got "+oldValue); if (!(newValue instanceof Boolean)) throw new IllegalArgumentException("newWriteable must be boolean, got "+newValue); } else if (VirtualFile.PROP_HIDDEN.equals(propertyName)) { if (!(oldValue instanceof Boolean)) throw new IllegalArgumentException("oldHidden must be boolean, got "+oldValue); if (!(newValue instanceof Boolean)) throw new IllegalArgumentException("newHidden must be boolean, got "+newValue); } else if (VirtualFile.PROP_SYMLINK_TARGET.equals(propertyName)) { if (oldValue != null && !(oldValue instanceof String)) throw new IllegalArgumentException("oldSymTarget must be String, got "+oldValue); if (newValue != null && !(newValue instanceof String)) throw new IllegalArgumentException("newSymTarget must be String, got "+newValue); } }
private void rebuildStub() { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { myManager.dropResolveCaches(); final VirtualFile vFile = getVirtualFile(); if (vFile != null && vFile.isValid()) { final Document doc = FileDocumentManager.getInstance().getCachedDocument(vFile); if (doc != null) { FileDocumentManager.getInstance().saveDocument(doc); } FileContentUtilCore.reparseFiles(vFile); StubTreeLoader.getInstance().rebuildStubTree(vFile); } } }, ModalityState.NON_MODAL); }
private void setPlainTextStatus(@NotNull final Project project, final boolean isAdded, @NotNull final VirtualFile... files) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { ProjectPlainTextFileTypeManager projectPlainTextFileTypeManager = ProjectPlainTextFileTypeManager.getInstance(project); for (VirtualFile file : files) { if (projectPlainTextFileTypeManager.hasProjectContaining(file)) { ensureProjectFileSetAdded(project, projectPlainTextFileTypeManager); if (isAdded ? projectPlainTextFileTypeManager.addFile(file) : projectPlainTextFileTypeManager.removeFile(file)) { FileBasedIndex.getInstance().requestReindex(file); } } } FileContentUtilCore.reparseFiles(files); } }); }
public void reparseFiles(final List<String> extensions) { final List<VirtualFile> filesToReparse = Lists.newArrayList(); ProjectRootManager.getInstance(myProject).getFileIndex().iterateContent(new ContentIterator() { @Override public boolean processFile(VirtualFile fileOrDir) { if (!fileOrDir.isDirectory() && extensions.contains(fileOrDir.getExtension())) { filesToReparse.add(fileOrDir); } return true; } }); FileContentUtilCore.reparseFiles(filesToReparse); PyUtil.rehighlightOpenEditors(myProject); DaemonCodeAnalyzer.getInstance(myProject).restart(); }
public static void checkPropertyValuesCorrect(Object requestor, @Nonnull String propertyName, Object oldValue, Object newValue) { if (Comparing.equal(oldValue, newValue) && FileContentUtilCore.FORCE_RELOAD_REQUESTOR != requestor) { throw new IllegalArgumentException("Values must be different, got the same: " + oldValue); } if (VirtualFile.PROP_NAME.equals(propertyName)) { if (oldValue == null) throw new IllegalArgumentException("oldName must not be null"); if (newValue == null) throw new IllegalArgumentException("newName must not be null"); } else if (VirtualFile.PROP_ENCODING.equals(propertyName)) { if (oldValue == null) throw new IllegalArgumentException("oldCharset must not be null"); } else if (VirtualFile.PROP_WRITABLE.equals(propertyName)) { if (!(oldValue instanceof Boolean)) throw new IllegalArgumentException("oldWriteable must be boolean, got "+oldValue); if (!(newValue instanceof Boolean)) throw new IllegalArgumentException("newWriteable must be boolean, got "+newValue); } else if (VirtualFile.PROP_HIDDEN.equals(propertyName)) { if (!(oldValue instanceof Boolean)) throw new IllegalArgumentException("oldHidden must be boolean, got "+oldValue); if (!(newValue instanceof Boolean)) throw new IllegalArgumentException("newHidden must be boolean, got "+newValue); } else if (VirtualFile.PROP_SYMLINK_TARGET.equals(propertyName)) { if (oldValue != null && !(oldValue instanceof String)) throw new IllegalArgumentException("oldSymTarget must be String, got "+oldValue); if (newValue != null && !(newValue instanceof String)) throw new IllegalArgumentException("newSymTarget must be String, got "+newValue); } }
private void rebuildStub() { ApplicationManager.getApplication().invokeLater(() -> { if (!myManager.isDisposed()) { myManager.dropPsiCaches(); } final VirtualFile vFile = getVirtualFile(); if (vFile != null && vFile.isValid()) { final Document doc = FileDocumentManager.getInstance().getCachedDocument(vFile); if (doc != null) { FileDocumentManager.getInstance().saveDocument(doc); } FileContentUtilCore.reparseFiles(vFile); StubTreeLoader.getInstance().rebuildStubTree(vFile); } }, ModalityState.NON_MODAL); }
@Override public void propertyChanged(@NotNull final VirtualFilePropertyEvent e) { if(VirtualFile.PROP_NAME.equals(e.getPropertyName())){ // File can be invalidated after file changes name (extension also // can changes). The editor should be removed if it's invalid. updateValidProperty(); if (Comparing.equal(e.getFile(), myFile) && (FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(e.getRequestor()) || !Comparing.equal(e.getOldValue(), e.getNewValue()))) { updateHighlighters(); } } }
private static void processLanguageSubstitution(@Nonnull final VirtualFile file, @Nonnull Language originalLang, @Nonnull final Language substitutedLang) { if (file instanceof VirtualFileWindow) { // Injected files are created with substituted language, no need to reparse: // com.intellij.psi.impl.source.tree.injected.MultiHostRegistrarImpl#doneInjecting return; } Language prevSubstitutedLang = SUBSTITUTED_LANG_KEY.get(file); final Language prevLang = ObjectUtil.notNull(prevSubstitutedLang, originalLang); if (!prevLang.is(substitutedLang)) { if (file.replace(SUBSTITUTED_LANG_KEY, prevSubstitutedLang, substitutedLang)) { if (prevSubstitutedLang == null) { return; // no need to reparse for the first language substitution } if (ApplicationManager.getApplication().isUnitTestMode()) { return; } file.putUserData(REPARSING_SCHEDULED, true); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { if (file.replace(REPARSING_SCHEDULED, true, null)) { LOG.info("Reparsing " + file.getPath() + " because of language substitution " + prevLang.getID() + "->" + substitutedLang.getID()); FileContentUtilCore.reparseFiles(file); } } }, ModalityState.defaultModalityState()); } } }
@Override public void propertyChanged(@Nonnull final VirtualFilePropertyEvent e) { if (VirtualFile.PROP_NAME.equals(e.getPropertyName())) { // File can be invalidated after file changes name (extension also // can changes). The editor should be removed if it's invalid. updateValidProperty(); if (Comparing.equal(e.getFile(), myFile) && (FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(e.getRequestor()) || !Comparing.equal(e.getOldValue(), e.getNewValue()))) { updateHighlighters(); } } }
@Override public void reparseFiles(@NotNull Collection<VirtualFile> files, boolean includeOpenFiles) { FileContentUtilCore.reparseFiles(files); }
private boolean shouldProcess(VirtualFileEvent e) { return !myProject.isDisposed() && LocalHistory.getInstance().isUnderControl(e.getFile()) && myIsInsideCommand && !FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(e.getRequestor()); }