<commit_before>package mesfavoris.texteditor.internal;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;

import mesfavoris.bookmarktype.IBookmarkLocation;
import mesfavoris.bookmarktype.IGotoBookmark;
import mesfavoris.commons.core.AdapterUtils;
import mesfavoris.model.Bookmark;
import mesfavoris.texteditor.TextEditorUtils;

public class GotoExternalFileBookmark implements IGotoBookmark {

	@Override
	public boolean gotoBookmark(IWorkbenchWindow window, Bookmark bookmark, IBookmarkLocation bookmarkLocation) {
		if (!(bookmarkLocation instanceof ExternalFileBookmarkLocation)) {
			return false;
		}
		ExternalFileBookmarkLocation externalFileBookmarkLocation = (ExternalFileBookmarkLocation) bookmarkLocation;
		IEditorPart editorPart = openEditor(window, externalFileBookmarkLocation.getFileSystemPath());
		ITextEditor textEditor = AdapterUtils.getAdapter(editorPart, ITextEditor.class);
		if (textEditor == null) {
			return false;
		}
		if (externalFileBookmarkLocation.getLineNumber() != null) {
			return gotoLine(textEditor, externalFileBookmarkLocation.getLineNumber());
		}
		return true;
	}

	private boolean gotoLine(ITextEditor textEditor, int lineNumber) {
		try {
			TextEditorUtils.gotoLine(textEditor, lineNumber);
			return true;
		} catch (BadLocationException e) {
			return false;
		}
	}

	private IEditorPart openEditor(IWorkbenchWindow window, IPath filePath) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath);
		IFileInfo fetchInfo = fileStore.fetchInfo();
		if (fetchInfo.isDirectory() || !fetchInfo.exists()) {
			return null;
		}
		IWorkbenchPage page = window.getActivePage();
		try {
			IEditorPart editorPart = IDE.openEditorOnFileStore(page, fileStore);
			return editorPart;
		} catch (PartInitException e) {
			return null;
		}
	}

}
<commit_msg>Fixed GotoExternalFileBookmark<commit_after>package mesfavoris.texteditor.internal;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.ITextEditor;

import mesfavoris.bookmarktype.IBookmarkLocation;
import mesfavoris.bookmarktype.IGotoBookmark;
import mesfavoris.commons.core.AdapterUtils;
import mesfavoris.model.Bookmark;
import mesfavoris.texteditor.TextEditorUtils;

public class GotoExternalFileBookmark implements IGotoBookmark {

	@Override
	public boolean gotoBookmark(IWorkbenchWindow window, Bookmark bookmark, IBookmarkLocation bookmarkLocation) {
		if (!(bookmarkLocation instanceof ExternalFileBookmarkLocation)) {
			return false;
		}
		ExternalFileBookmarkLocation externalFileBookmarkLocation = (ExternalFileBookmarkLocation) bookmarkLocation;
		IEditorPart editorPart = openEditor(window, externalFileBookmarkLocation.getFileSystemPath());
		if (externalFileBookmarkLocation.getLineNumber() == null) {
			return true;
		}
		ITextEditor textEditor = AdapterUtils.getAdapter(editorPart, ITextEditor.class);
		if (textEditor == null) {
			return false;
		}
		return gotoLine(textEditor, externalFileBookmarkLocation.getLineNumber());
	}

	private boolean gotoLine(ITextEditor textEditor, int lineNumber) {
		try {
			TextEditorUtils.gotoLine(textEditor, lineNumber);
			return true;
		} catch (BadLocationException e) {
			return false;
		}
	}

	private IEditorPart openEditor(IWorkbenchWindow window, IPath filePath) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath);
		IFileInfo fetchInfo = fileStore.fetchInfo();
		if (fetchInfo.isDirectory() || !fetchInfo.exists()) {
			return null;
		}
		IWorkbenchPage page = window.getActivePage();
		try {
			IEditorPart editorPart = IDE.openEditorOnFileStore(page, fileStore);
			return editorPart;
		} catch (PartInitException e) {
			return null;
		}
	}

}

{'fraction_non_alphanumeric': 0.09097050213915785, 'fraction_numerical': 0.0, 'mean_word_length': 6.073248407643312, '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': '1121407', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1344, 'n_words': 255}