<commit_before>package cucumber.eclipse.editor.editors;

import gherkin.parser.ParseError;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;

import cucumber.eclipse.editor.Activator;

//import org.eclipse.core.

public class GherkinPopupMenuPrettyFormatActionDelegate implements
		IObjectActionDelegate {

	private Shell shell;
	private IFile docSelected;
	
	@Override
	public void selectionChanged(IAction arg0, ISelection arg1) {
		if (arg1 instanceof TreeSelection) {
			TreeSelection tree = (TreeSelection) arg1;
			docSelected = (IFile) tree.getFirstElement();
		}

	}

	@Override
	public void setActivePart(IAction arg0, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();

	}

	// ref: http://stackoverflow.com/a/5445161/480998
	public static String convertStreamToString(java.io.InputStream is,
			String charSet) {
		java.util.Scanner s = new java.util.Scanner(is, charSet)
				.useDelimiter("\\A");
		return s.hasNext() ? s.next() : "";
	}

	@Override
	public void run(IAction arg0) {
		
		IEditorPart editorPart = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();<commit_msg>Got pretty formatting working in plugin using Gherkin formatter..<commit_after>package cucumber.eclipse.editor.editors;

import gherkin.parser.ParseError;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import cucumber.eclipse.editor.Activator;



public class GherkinPopupMenuPrettyFormatActionDelegate implements
		IObjectActionDelegate {

	private Shell shell;
	private IFile docSelected;
	
	@Override
	public void selectionChanged(IAction arg0, ISelection arg1) {
		if (arg1 instanceof TreeSelection) {
			TreeSelection tree = (TreeSelection) arg1;
			docSelected = (IFile) tree.getFirstElement();
		}

	}

	@Override
	public void setActivePart(IAction arg0, IWorkbenchPart targetPart) {
		shell = targetPart.getSite().getShell();

	}

	@Override
	public void run(IAction arg0) {
		
		IEditorPart editorPart = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
{'fraction_non_alphanumeric': 0.10270109824873849, 'fraction_numerical': 0.0074205995844464235, 'mean_word_length': 5.753507014028056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2568134', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1028, 'n_words': 195}