<commit_before>package org.yakindu.sct.model.stext.test.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Arrays;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.yakindu.base.expressions.expressions.Expression;
import org.yakindu.base.types.Type;
import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
import org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult;
import org.yakindu.base.types.typesystem.ITypeSystem;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ListBasedValidationIssueAcceptor;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue.Severity;
import org.yakindu.sct.model.stext.stext.EventDefinition;
import org.yakindu.sct.model.stext.stext.VariableDefinition;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;

import junit.framework.TestCase;

public abstract class AbstractTypeInferrerTest extends AbstractSTextTest {

	@Rule
	public ExpectedException exception = ExpectedException.none();
	@Inject
	protected ITypeSystem typeSystem;
	@Inject
	protected ITypeSystemInferrer typeInferrer;

	protected ListBasedValidationIssueAcceptor acceptor;

	
	protected Type inferType(String expression) {
		return inferTypeForExpression(expression, super.internalScope() + "\n" + super.interfaceScope());
	}

	protected Type inferType(String expression, String parserRule) {
		return inferType(expression, parserRule, super.internalScope() + "\n" + super.interfaceScope());
	}

	protected InferenceResult inferTypeResultForExpression(String expression, String scopes) {
		return inferTypeResult(expression, Expression.class.getSimpleName(), scopes);
	}
	
	@Deprecated
	protected Type inferTypeForExpression(String expression, String scopes) {
		return inferType(expression, Expression.class.getSimpleName(), scopes);
	}

	@Deprecated
	protected Type inferType(String expression, String parserRule, String scopes) {
 		InferenceResult inferTypeResult = inferTypeResult(expression, parserRule, scopes);
		if(inferTypeResult == null)
			return null;
		return inferTypeResult.getType();
	}
	
	protected InferenceResult inferTypeResult(String expression, String parserRule, String scopes) {
		EObject parseResult = super.parseExpression(expression, parserRule, scopes);
		assertNotNull(parseResult);
		acceptor = new ListBasedValidationIssueAcceptor();
		if (parseResult instanceof Expression) {
			return typeInferrer.infer((Expression) parseResult, acceptor);
		} else if (parseResult instanceof EventDefinition) {
			return typeInferrer.infer((EventDefinition) parseResult, acceptor);
		} else if (parseResult instanceof VariableDefinition) {
			return typeInferrer.infer((VariableDefinition) parseResult, acceptor);
		} else {
			throw new IllegalArgumentException("Unsupported parse result.");
		}
	}
	
	protected boolean isType(Type type, String typeName) {
		return typeSystem.isSame(type, typeSystem.getType(typeName));
	}<commit_msg>Remove obsolete code, the type will be dispatched by type inferrer (#1396)<commit_after>package org.yakindu.sct.model.stext.test.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Arrays;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.yakindu.base.expressions.expressions.Expression;
import org.yakindu.base.types.Type;
import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
import org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult;
import org.yakindu.base.types.typesystem.ITypeSystem;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ListBasedValidationIssueAcceptor;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue;
import org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue.Severity;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Inject;

import junit.framework.TestCase;

public abstract class AbstractTypeInferrerTest extends AbstractSTextTest {

	@Rule
	public ExpectedException exception = ExpectedException.none();
	@Inject
	protected ITypeSystem typeSystem;
	@Inject
	protected ITypeSystemInferrer typeInferrer;

	protected ListBasedValidationIssueAcceptor acceptor;

	
	protected Type inferType(String expression) {
		return inferTypeForExpression(expression, super.internalScope() + "\n" + super.interfaceScope());
	}

	protected Type inferType(String expression, String parserRule) {
		return inferType(expression, parserRule, super.internalScope() + "\n" + super.interfaceScope());
	}

	protected InferenceResult inferTypeResultForExpression(String expression, String scopes) {
		return inferTypeResult(expression, Expression.class.getSimpleName(), scopes);
	}
	
	@Deprecated
	protected Type inferTypeForExpression(String expression, String scopes) {
		return inferType(expression, Expression.class.getSimpleName(), scopes);
	}

	@Deprecated
	protected Type inferType(String expression, String parserRule, String scopes) {
 		InferenceResult inferTypeResult = inferTypeResult(expression, parserRule, scopes);
		if(inferTypeResult == null)
			return null;
		return inferTypeResult.getType();
	}
	
	protected InferenceResult inferTypeResult(String expression, String parserRule, String scopes) {
		EObject parseResult = super.parseExpression(expression, parserRule, scopes);
		assertNotNull(parseResult);
		acceptor = new ListBasedValidationIssueAcceptor();
		return typeInferrer.infer(parseResult, acceptor);
	}
	
	protected boolean isType(Type type, String typeName) {
		return typeSystem.isSame(type, typeSystem.getType(typeName));
	}
{'fraction_non_alphanumeric': 0.09159802306425041, 'fraction_numerical': 0.0006589785831960461, 'mean_word_length': 6.646095717884131, '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': '3879158', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1735, 'n_words': 358}