<commit_before>package isabelle.eclipse.editors;

import isabelle.eclipse.core.text.IsabelleDocument;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;


public class IsabelleFileDocumentProvider extends TextFileDocumentProvider {

	private final Map<Object, IsabelleDocument> isabelleDocuments = new HashMap<Object, IsabelleDocument>();
	private final Map<Object, ResourceMarkerAnnotationModel> annotationModels = new HashMap<Object, ResourceMarkerAnnotationModel>();
	
	public IsabelleFileDocumentProvider() {
		super();
	}

	@Override
	public void connect(Object element) throws CoreException {
		super.connect(element);
		System.out.println("Connecting isabelle document provider");
		IDocument baseDocument = getDocument(element);
		if (baseDocument != null) {
			IsabelleDocument document = new IsabelleDocument(baseDocument);
			isabelleDocuments.put(element, document);
			
			IResource markerResource = getMarkerResource(element);
			ResourceMarkerAnnotationModel annotationModel = new ResourceMarkerAnnotationModel(markerResource);
			annotationModel.connect(document);
			annotationModels.put(element, annotationModel);
		}
	}
	
	public static IResource getMarkerResource(Object element) {
		
		IFile file = getFile(element);
		if (file != null) {
			return file;
		}
		
		// otherwise use workspace root as the marker resource
		return ResourcesPlugin.getWorkspace().getRoot();
	}
	
	private static IFile getFile(Object element) {
		
		if (element instanceof IAdaptable) {
			return (IFile) ((IAdaptable) element).getAdapter(IFile.class);
		}
		
		return null;
	}

	@Override
	public void disconnect(Object element) {
		IsabelleDocument document = isabelleDocuments.remove(element);
		
		ResourceMarkerAnnotationModel annotationModel = annotationModels.get(element);
		if (annotationModel != null) {
			annotationModel.disconnect(document);<commit_msg>Less explicit reference<commit_after>package isabelle.eclipse.editors;

import isabelle.eclipse.core.text.IsabelleDocument;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;


public class IsabelleFileDocumentProvider extends TextFileDocumentProvider {

	private final Map<Object, IsabelleDocument> isabelleDocuments = new HashMap<Object, IsabelleDocument>();
	private final Map<Object, IAnnotationModel> annotationModels = new HashMap<Object, IAnnotationModel>();
	
	public IsabelleFileDocumentProvider() {
		super();
	}

	@Override
	public void connect(Object element) throws CoreException {
		super.connect(element);
		System.out.println("Connecting isabelle document provider");
		IDocument baseDocument = getDocument(element);
		if (baseDocument != null) {
			IsabelleDocument document = new IsabelleDocument(baseDocument);
			isabelleDocuments.put(element, document);
			
			IResource markerResource = getMarkerResource(element);
			ResourceMarkerAnnotationModel annotationModel = new ResourceMarkerAnnotationModel(markerResource);
			annotationModel.connect(document);
			annotationModels.put(element, annotationModel);
		}
	}
	
	public static IResource getMarkerResource(Object element) {
		
		IFile file = getFile(element);
		if (file != null) {
			return file;
		}
		
		// otherwise use workspace root as the marker resource
		return ResourcesPlugin.getWorkspace().getRoot();
	}
	
	private static IFile getFile(Object element) {
		
		if (element instanceof IAdaptable) {
			return (IFile) ((IAdaptable) element).getAdapter(IFile.class);
		}
		
		return null;
	}

	@Override
	public void disconnect(Object element) {
		IsabelleDocument document = isabelleDocuments.remove(element);
		
		IAnnotationModel annotationModel = annotationModels.get(element);
		if (annotationModel != null) {
			annotationModel.disconnect(document);
{'fraction_non_alphanumeric': 0.09179899934740048, 'fraction_numerical': 0.0, 'mean_word_length': 5.811851851851852, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5278108', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1233, 'n_words': 275}