<commit_before>/**
 * 
 */
package org.spoofax.sunshine.services.parser;

import java.io.File;
import java.util.Map;
import java.util.WeakHashMap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spoofax.sunshine.CompilerException;
import org.spoofax.sunshine.model.language.ALanguage;
import org.spoofax.sunshine.parser.model.ParserConfig;
import org.spoofax.sunshine.pipeline.connectors.ALinkOneToOne;
import org.spoofax.sunshine.pipeline.diff.Diff;
import org.spoofax.sunshine.services.LanguageService;
import org.spoofax.sunshine.services.analyzer.AnalysisResult;

/**
 * @author <NAME> <v.a.vergu add tudelft.nl>
 * 
 */
public class JSGLRLink extends ALinkOneToOne<File, AnalysisResult> {

	private static final Logger logger = LogManager.getLogger(JSGLRLink.class.getName());

	public final static int PARSE_TIMEOUT = 5000;

	private final Map<File, JSGLRI> parsers = new WeakHashMap<File, JSGLRI>();

	@Override
	public Diff<AnalysisResult> sinkWork(Diff<File> input) {
		JSGLRI parser = parsers.get(input.getPayload());
		if (parser == null) {
			parser = constructParser(input.getPayload());
			parsers.put(input.getPayload(), parser);
		}
		assert parser != null;

		AnalysisResult parseResult = parser.parse();
		logger.trace("Parsing of file {} produced AST {} and {} messages", input.getPayload(),<commit_msg>Do not try to parse a file that has been deleted<commit_after>/**
 * 
 */
package org.spoofax.sunshine.services.parser;

import java.io.File;
import java.util.Map;
import java.util.WeakHashMap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spoofax.sunshine.CompilerException;
import org.spoofax.sunshine.model.language.ALanguage;
import org.spoofax.sunshine.parser.model.ParserConfig;
import org.spoofax.sunshine.pipeline.connectors.ALinkOneToOne;
import org.spoofax.sunshine.pipeline.diff.Diff;
import org.spoofax.sunshine.pipeline.diff.DiffKind;
import org.spoofax.sunshine.services.LanguageService;
import org.spoofax.sunshine.services.analyzer.AnalysisResult;

/**
 * @author <NAME> <v.a.vergu add tudelft.nl>
 * 
 */
public class JSGLRLink extends ALinkOneToOne<File, AnalysisResult> {

	private static final Logger logger = LogManager.getLogger(JSGLRLink.class.getName());

	public final static int PARSE_TIMEOUT = 5000;

	private final Map<File, JSGLRI> parsers = new WeakHashMap<File, JSGLRI>();

	@Override
	public Diff<AnalysisResult> sinkWork(Diff<File> input) {
		if (input.getDiffKind() == DiffKind.DELETION) {
			logger.debug("File {} has been deleted therefore has no AST", input.getPayload()
					.getName());
			return null;
		}
		JSGLRI parser = parsers.get(input.getPayload());
		if (parser == null) {
			parser = constructParser(input.getPayload());
			parsers.put(input.getPayload(), parser);
		}
		assert parser != null;

		AnalysisResult parseResult = parser.parse();
		logger.trace("Parsing of file {} produced AST {} and {} messages", input.getPayload(),
{'fraction_non_alphanumeric': 0.12537512504168055, 'fraction_numerical': 0.0040013337779259755, 'mean_word_length': 5.211180124223603, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6746269', 'n_tokens_mistral': 1034, 'n_tokens_neox': 964, 'n_words': 200}