com.intellij.util.FileContentUtilCore Java Examples

The following examples show how to use com.intellij.util.FileContentUtilCore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CsvChangeSeparatorAction.java    From intellij-csv-validator with Apache License 2.0 6 votes vote down vote up
@Override
public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected) {
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (psiFile == null) {
        return;
    }
    Language language = psiFile.getLanguage();
    if (!language.isKindOf(CsvLanguage.INSTANCE) || language instanceof CsvSeparatorHolder) {
        return;
    }
    CsvFileAttributes csvFileAttributes = ServiceManager.getService(psiFile.getProject(), CsvFileAttributes.class);
    csvFileAttributes.setFileSeparator(psiFile, this.mySeparator);
    FileContentUtilCore.reparseFiles(psiFile.getVirtualFile());

    FileEditor fileEditor = anActionEvent.getData(PlatformDataKeys.FILE_EDITOR);
    if (fileEditor != null) {
        fileEditor.selectNotify();
    }
}
 
Example #2
Source File: WeaveEditor.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #3
Source File: CsvChangeEscapeCharacterAction.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected) {
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (psiFile == null) {
        return;
    }
    CsvFileAttributes.getInstance(psiFile.getProject()).setEscapeCharacter(psiFile, this.myEscapeCharacter);
    FileContentUtilCore.reparseFiles(psiFile.getVirtualFile());

    FileEditor fileEditor = anActionEvent.getData(PlatformDataKeys.FILE_EDITOR);
    if (fileEditor != null) {
        fileEditor.selectNotify();
    }
}
 
Example #4
Source File: CsvDefaultSeparatorAction.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected) {
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (psiFile == null) {
        return;
    }
    CsvFileAttributes.getInstance(psiFile.getProject()).resetValueSeparator(psiFile);
    FileContentUtilCore.reparseFiles(psiFile.getVirtualFile());

    FileEditor fileEditor = anActionEvent.getData(PlatformDataKeys.FILE_EDITOR);
    if (fileEditor != null) {
        fileEditor.selectNotify();
    }
}
 
Example #5
Source File: CsvDefaultEscapeCharacterAction.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected) {
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (psiFile == null) {
        return;
    }
    CsvFileAttributes.getInstance(psiFile.getProject()).resetEscapeSeparator(psiFile);
    FileContentUtilCore.reparseFiles(psiFile.getVirtualFile());

    FileEditor fileEditor = anActionEvent.getData(PlatformDataKeys.FILE_EDITOR);
    if (fileEditor != null) {
        fileEditor.selectNotify();
    }
}
 
Example #6
Source File: CsvCustomSeparatorAction.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void setSelected(@NotNull AnActionEvent anActionEvent, boolean selected) {
    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);
    if (psiFile == null) {
        return;
    }

    FileEditor fileEditor = anActionEvent.getData(PlatformDataKeys.FILE_EDITOR);
    CsvValueSeparator currentSeparator = CsvHelper.getValueSeparator(psiFile);
    String customValueSeparator = JOptionPane.showInputDialog(fileEditor == null ? null : fileEditor.getComponent(),
            "Value separator",
            currentSeparator.getCharacter());

    if (customValueSeparator == null) {
        return;
    }
    if (customValueSeparator.length() == 0 || customValueSeparator.contains(" ")) {
        JOptionPane.showMessageDialog(fileEditor == null ? null : fileEditor.getComponent(), "Value separator must have at least one character and no spaces!");
        return;
    }

    CsvFileAttributes csvFileAttributes = ServiceManager.getService(psiFile.getProject(), CsvFileAttributes.class);
    csvFileAttributes.setFileSeparator(psiFile, new CsvValueSeparator(customValueSeparator));
    FileContentUtilCore.reparseFiles(psiFile.getVirtualFile());

    if (fileEditor != null) {
        fileEditor.selectNotify();
    }
}
 
Example #7
Source File: CsvFile.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
@Override
public void propertyChange(PropertyChangeEvent evt) {
    switch (evt.getPropertyName()) {
        case "defaultEscapeCharacter":
        case "defaultValueSeparator":
            FileContentUtilCore.reparseFiles(CsvFile.this.getVirtualFile());
            break;
        default:
            // does not influence file
            break;
    }
}
 
Example #8
Source File: FileUndoProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean shouldProcess(@Nonnull VFileEvent e, VirtualFile file) {
  if (!myIsInsideCommand || myProject.isDisposed()) {
    return false;
  }

  Object requestor = e.getRequestor();
  if (FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(requestor) /*|| requestor instanceof StorageManagerFileWriteRequestor*/) {
    return false;
  }
  return LocalHistory.getInstance().isUnderControl(file);
}
 
Example #9
Source File: VFilePropertyChangeEvent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void checkPropertyValuesCorrect(Object requestor, @VirtualFile.PropName @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);
  }
  switch (propertyName) {
    case VirtualFile.PROP_NAME:
      if (oldValue == null) throw new IllegalArgumentException("oldName must not be null");
      if (!(oldValue instanceof String)) throw new IllegalArgumentException("oldName must be String, got " + oldValue);
      if (newValue == null) throw new IllegalArgumentException("newName must not be null");
      if (!(newValue instanceof String)) throw new IllegalArgumentException("newName must be String, got " + newValue);
      break;
    case VirtualFile.PROP_ENCODING:
      if (oldValue == null) throw new IllegalArgumentException("oldCharset must not be null");
      if (!(oldValue instanceof Charset)) throw new IllegalArgumentException("oldValue must be Charset, got " + oldValue);
      break;
    case VirtualFile.PROP_WRITABLE:
      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);
      break;
    case VirtualFile.PROP_HIDDEN:
      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);
      break;
    case VirtualFile.PROP_SYMLINK_TARGET:
      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);
      }
      break;
    default:
      throw new IllegalArgumentException("Unknown property name '" + propertyName + "'. " + "Must be one of VirtualFile.{PROP_NAME|PROP_ENCODING|PROP_WRITABLE|PROP_HIDDEN|PROP_SYMLINK_TARGET}");
  }
}
 
Example #10
Source File: LanguageSubstitutors.java    From consulo with Apache License 2.0 5 votes vote down vote up
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());
    }
  }
}
 
Example #11
Source File: TextEditorComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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()))) {
      myEditorHighlighterUpdater.updateHighlighters();
    }
  }
}
 
Example #12
Source File: LatteIndexUtil.java    From intellij-latte with MIT License 4 votes vote down vote up
private static void reparseFiles(@NotNull Project project) {
    Collection<VirtualFile> virtualFiles = FileTypeIndex.getFiles(LatteFileType.INSTANCE, GlobalSearchScope.allScope(project));
    FileContentUtilCore.reparseFiles(virtualFiles);
    //FileContentUtil.reparseFiles(project, virtualFiles, false);
}
 
Example #13
Source File: VFilePropertyChangeEvent.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isRename() {
  return myPropertyName == VirtualFile.PROP_NAME && getRequestor() != FileContentUtilCore.FORCE_RELOAD_REQUESTOR;
}