<commit_before>/*******************************************************************************
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *******************************************************************************/
package org.jetbrains.kotlin.testframework.utils;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
import org.jetbrains.kotlin.testframework.editor.TextEditorTest;
import org.jetbrains.kotlin.utils.EditorUtil;
import org.junit.Assert;

public class EditorTestUtils {

	public static IEditorPart openInEditor(IFile file) throws PartInitException {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = window.getActivePage();
		
		FileEditorInput fileEditorInput = new FileEditorInput(file);
		IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
		
		return page.openEditor(fileEditorInput, defaultEditor.getId());
	}
	
	public static void assertByEditor(JavaEditor activeEditor, String expected) {
		String actual = EditorUtil.getSourceCode(activeEditor);
		
		expected = expected.replaceAll("<br>", System.lineSeparator());
		if (expected.contains(TextEditorTest.CARET)) {
			int caretOffset = activeEditor.getViewer().getTextWidget().getCaretOffset();
			actual = actual.substring(0, caretOffset) + TextEditorTest.CARET + actual.substring(caretOffset);
		}
		
		String expectedWithoutCR =  expected.replaceAll("\r", "");
		String actualWithoutCR = actual.replaceAll("\r", "");
		
		Assert.assertEquals(expectedWithoutCR, actualWithoutCR);
	}
}<commit_msg>Minor: Java code conventions.<commit_after>/*******************************************************************************
 * Copyright 2000-2014 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *******************************************************************************/
package org.jetbrains.kotlin.testframework.utils;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
import org.jetbrains.kotlin.testframework.editor.TextEditorTest;
import org.jetbrains.kotlin.utils.EditorUtil;
import org.junit.Assert;

public class EditorTestUtils {

	public static IEditorPart openInEditor(IFile file) throws PartInitException {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = window.getActivePage();
		
		FileEditorInput fileEditorInput = new FileEditorInput(file);
		IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
		
		return page.openEditor(fileEditorInput, defaultEditor.getId());
	}
	
	public static void assertByEditor(JavaEditor activeEditor, String expected) {
		String actual = EditorUtil.getSourceCode(activeEditor);
		
		expected = expected.replaceAll("<br>", System.lineSeparator());
		if (expected.contains(TextEditorTest.CARET)) {
			int caretOffset = activeEditor.getViewer().getTextWidget().getCaretOffset();
			actual = actual.substring(0, caretOffset) + TextEditorTest.CARET + actual.substring(caretOffset);
		}
		
		String expectedWithoutCR = expected.replaceAll("\r", "");
		String actualWithoutCR = actual.replaceAll("\r", "");
		
		Assert.assertEquals(expectedWithoutCR, actualWithoutCR);
	}
}
{'fraction_non_alphanumeric': 0.15822401614530776, 'fraction_numerical': 0.005247225025227043, 'mean_word_length': 5.8076923076923075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1571047', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1277, 'n_words': 335}