private void saveOrDiscardIfNeeded(FileEditorInput file) {
   TextFileDocumentProvider docProvider = file == null ? null : getTextDocumentProvider(file);
   if (docProvider != null && file != null && file.exists() && inputConnected) {
     if (docProvider.canSaveDocument(file)
         && ui.confirmOperation(
                 "Changes Detected",
                 "Manifest file '"
                     + file.getFile().getFullPath().toOSString()
                     + "' has been changed. Do you want to save changes or discard them?",
                 new String[] {"Save", "Discard"},
                 0)
             == 0) {
       try {
         docProvider.saveDocument(
             new NullProgressMonitor(), file, docProvider.getDocument(file), true);
       } catch (CoreException e) {
         Log.log(e);
         ui.errorPopup("Failed Saving File", ExceptionUtil.getMessage(e));
       }
     } else {
       try {
         docProvider.resetDocument(file);
       } catch (CoreException e) {
         Log.log(e);
       }
     }
     disconnect(docProvider, file);
   }
 }
 public IAnnotationModel getAnnotationModel() {
   FileEditorInput input = editorInput.getValue();
   if (input != null) {
     TextFileDocumentProvider provider = getTextDocumentProvider(input);
     if (provider != null) {
       return provider.getAnnotationModel(input);
     }
   }
   return null;
 }
 @Override
 protected IDocument compute() {
   FileEditorInput input = editorInput.getValue();
   if (input != null) {
     TextFileDocumentProvider provider = getTextDocumentProvider(input);
     if (provider != null) {
       return provider.getDocument(input);
     }
   }
   return new Document("");
 }
 private TextFileDocumentProvider getTextDocumentProvider(FileEditorInput input) {
   IDocumentProvider docProvider =
       DocumentProviderRegistry.getDefault().getDocumentProvider(input);
   if (docProvider instanceof TextFileDocumentProvider) {
     TextFileDocumentProvider textDocProvider = (TextFileDocumentProvider) docProvider;
     if (!docProviders.contains(textDocProvider)) {
       textDocProvider.addElementStateListener(dirtyStateListener);
       onDispose(
           (d) -> {
             textDocProvider.removeElementStateListener(dirtyStateListener);
           });
       docProviders.add(textDocProvider);
     }
     return textDocProvider;
   }
   return null;
 }
 private void disconnect(TextFileDocumentProvider provider, FileEditorInput input) {
   if (inputConnected) {
     provider.disconnect(input);
     inputConnected = false;
   } else {
     throw new IllegalStateException(
         "Attempting to disconnect input '"
             + input.getFile().getName()
             + "' while no inputs are connected");
   }
 }
 private void connect(TextFileDocumentProvider provider, FileEditorInput input) {
   if (!inputConnected) {
     try {
       provider.connect(input);
       inputConnected = true;
     } catch (CoreException e) {
       Log.log(e);
     }
   } else {
     throw new IllegalStateException(
         "Attempting to connect input '"
             + input.getFile().getName()
             + "' while previous input is still connected.");
   }
 }