<commit_before>package org.csstudio.sds.language.script.ui.editor;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.csstudio.sds.language.script.parser.ScriptParser;
import org.csstudio.sds.language.script.ui.rules.RuleProvider;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.ui.part.FileEditorInput;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.RhinoException;

import de.desy.language.editor.core.parser.AbstractLanguageParser;
import de.desy.language.editor.ui.editor.LanguageEditor;
import de.desy.language.editor.ui.editor.highlighting.AbstractRuleProvider;

public class ScriptEditor extends LanguageEditor {

	private DefaultDamagerRepairer _defaultDamagerRepairer;

	public ScriptEditor() {
	}

	@Override
	protected AbstractLanguageParser doGetLanguageParser() {
		return new ScriptParser();
	}

	@Override
	protected IPresentationDamager doGetPresentationDamager(
			ITokenScanner codeScannerUsedForHighligthing) {
		return new ScriptPresentationDamager();
	}

	@Override
	protected IPresentationRepairer doGetPresentationRepairer(
			ITokenScanner codeScannerUsedForHighligthing) {
		return this.getDefaultDamagerRepairer(codeScannerUsedForHighligthing);
	}

	@Override
	protected AbstractRuleProvider doGetRuleProviderForHighlighting() {
		return new RuleProvider();
	}

	private DefaultDamagerRepairer getDefaultDamagerRepairer(
			ITokenScanner codeScannerUsedForHighligthing) {
		if (_defaultDamagerRepairer == null) {
			_defaultDamagerRepairer = new DefaultDamagerRepairer(
					codeScannerUsedForHighligthing);
		}
		return _defaultDamagerRepairer;
	}
	
	@Override
	protected void determineAdditionalErrors() {
		doHandleSourceModifiedAndSaved(null);
	}

	@Override
	protected void doHandleSourceModifiedAndSaved(
			IProgressMonitor progressMonitor) {
		IFile sourceRessource = ((FileEditorInput) getEditorInput()).getFile();
		try {
			InputStream contents = sourceRessource.getContents();

			String scriptString = ""; //$NON-NLS-1$

			BufferedReader reader = new BufferedReader(new InputStreamReader(
					contents));
			while (reader.ready()) {
				scriptString = scriptString + reader.readLine() + System.getProperty("line.separator");
			}
			reader.close();

			Context scriptContext = Context.enter();
			ImporterTopLevel scriptScope = new ImporterTopLevel(scriptContext);

			try {
				scriptContext.evaluateString(scriptScope, scriptString,
						sourceRessource.getName(), 1, null); //$NON-NLS-1$
			} catch (RhinoException re) {
				IMarker errorMarker = sourceRessource
						.createMarker(IMarker.PROBLEM);
				errorMarker.setAttribute(IMarker.SEVERITY,
						IMarker.SEVERITY_ERROR);
				errorMarker.setAttribute(IMarker.LINE_NUMBER, re.lineNumber());
				errorMarker.setAttribute(IMarker.MESSAGE, re.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			Context.exit();
		}
	}
}<commit_msg>add new method from class AbstractLanguageParser<commit_after>package org.csstudio.sds.language.script.ui.editor;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.csstudio.sds.language.script.parser.ScriptParser;
import org.csstudio.sds.language.script.ui.rules.RuleProvider;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.presentation.IPresentationDamager;
import org.eclipse.jface.text.presentation.IPresentationRepairer;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.ITokenScanner;
import org.eclipse.ui.part.FileEditorInput;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.RhinoException;

import de.desy.language.editor.core.parser.AbstractLanguageParser;
import de.desy.language.editor.ui.editor.LanguageEditor;
import de.desy.language.editor.ui.editor.highlighting.AbstractRuleProvider;

public class ScriptEditor extends LanguageEditor {

	private DefaultDamagerRepairer _defaultDamagerRepairer;

	public ScriptEditor() {
	}

	@Override
	protected AbstractLanguageParser doGetLanguageParser() {
		return new ScriptParser();
	}

	@Override
	protected IPresentationDamager doGetPresentationDamager(
			ITokenScanner codeScannerUsedForHighligthing) {
		return new ScriptPresentationDamager();
	}

	@Override
	protected IPresentationRepairer doGetPresentationRepairer(
			ITokenScanner codeScannerUsedForHighligthing) {
		return this.getDefaultDamagerRepairer(codeScannerUsedForHighligthing);
	}

	@Override
	protected AbstractRuleProvider doGetRuleProviderForHighlighting() {
		return new RuleProvider();
	}

	private DefaultDamagerRepairer getDefaultDamagerRepairer(
			ITokenScanner codeScannerUsedForHighligthing) {
		if (_defaultDamagerRepairer == null) {
			_defaultDamagerRepairer = new DefaultDamagerRepairer(
					codeScannerUsedForHighligthing);
		}
		return _defaultDamagerRepairer;
	}
	
	@Override
	protected void determineAdditionalErrors() {
		doHandleSourceModifiedAndSaved(null);
	}

	@Override
	protected void doHandleSourceModifiedAndSaved(
			IProgressMonitor progressMonitor) {
		IFile sourceRessource = ((FileEditorInput) getEditorInput()).getFile();
		try {
			InputStream contents = sourceRessource.getContents();

			String scriptString = ""; //$NON-NLS-1$

			BufferedReader reader = new BufferedReader(new InputStreamReader(
					contents));
			while (reader.ready()) {
				scriptString = scriptString + reader.readLine() + System.getProperty("line.separator");
			}
			reader.close();

			Context scriptContext = Context.enter();
			ImporterTopLevel scriptScope = new ImporterTopLevel(scriptContext);

			try {
				scriptContext.evaluateString(scriptScope, scriptString,
						sourceRessource.getName(), 1, null); //$NON-NLS-1$
			} catch (RhinoException re) {
				IMarker errorMarker = sourceRessource
						.createMarker(IMarker.PROBLEM);
				errorMarker.setAttribute(IMarker.SEVERITY,
						IMarker.SEVERITY_ERROR);
				errorMarker.setAttribute(IMarker.LINE_NUMBER, re.lineNumber());
				errorMarker.setAttribute(IMarker.MESSAGE, re.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			Context.exit();
		}
	}

	@Override
	protected IContentAssistProcessor getContentAssistProcessor() {
		// TODO Auto-generated method stub
		return null;
	}
}
{'fraction_non_alphanumeric': 0.09337000579038796, 'fraction_numerical': 0.0008685581933989577, 'mean_word_length': 5.649663137632339, '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': '4160429', 'n_tokens_mistral': 2280, 'n_tokens_neox': 2048, 'n_words': 343}