<commit_before>/**
 * Copyright (c) 2014 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.model.stext.inferrer;

import static org.yakindu.base.types.typesystem.DefaultTypeSystem.BOOLEAN;
import static org.yakindu.base.types.typesystem.DefaultTypeSystem.INTEGER;
import static org.yakindu.base.types.typesystem.DefaultTypeSystem.VOID;

import org.eclipse.emf.ecore.EObject;
import org.yakindu.base.expressions.expressions.ElementReferenceExpression;
import org.yakindu.base.expressions.expressions.Expression;
import org.yakindu.base.expressions.expressions.FeatureCall;
import org.yakindu.base.expressions.inferrer.ExpressionsTypeInferrer;
import org.yakindu.base.types.Operation;
import org.yakindu.base.types.Type;
import org.yakindu.sct.model.sgraph.Scope;
import org.yakindu.sct.model.stext.stext.ActiveStateReferenceExpression;
import org.yakindu.sct.model.stext.stext.EventDefinition;
import org.yakindu.sct.model.stext.stext.EventRaisingExpression;
import org.yakindu.sct.model.stext.stext.EventValueReferenceExpression;
import org.yakindu.sct.model.stext.stext.Guard;
import org.yakindu.sct.model.stext.stext.TimeEventSpec;
import org.yakindu.sct.model.stext.stext.VariableDefinition;

/**
 * @author <NAME>uelder - Initial contribution and API
 * 
 */
public class STextTypeInferrer extends ExpressionsTypeInferrer {

	public static final String VARIABLE_DEFINITION = "Cannot assign a value of type %s to a variable of type %s.";
	public static final String EVENT_DEFINITION = "Cannot assign a value of type %s to an event of type %s.";
	public static final String GUARD = "The evaluation result of a guard expression must be of type boolean";
	public static final String TIME_SPEC = "The evaluation result of a time expression must be of type integer";
	public static final String VARIABLE_VOID_TYPE = "'void' is an invalid type for variables";
	public static final String MISSING_VALUE = "Need to assign a value to an event of type %s.";

	public Object infer(VariableDefinition e) {
		Type type = inferTypeDispatch(e.getType());
		assertNotType(type, VARIABLE_VOID_TYPE, getType(VOID));
		if (e.getInitialValue() == null)
			return inferTypeDispatch(type);
		Type type2 = inferTypeDispatch(e.getInitialValue());
		assertAssignable(type, type2, String.format(VARIABLE_DEFINITION, type2, type));
		return inferTypeDispatch(type);
	}
	
	public Object infer(Operation e) {
		return inferTypeDispatch(e.getType() != null ? e.getType() : getType(VOID));
	}

	public Object infer(EventDefinition e) {
		// if an event is used within an expression, the type is boolean and the
		// value indicates if the event is raised or not
		return getType(BOOLEAN);<commit_msg>updated type inference for Property<commit_after>/**
 * Copyright (c) 2014 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.sct.model.stext.inferrer;

import static org.yakindu.base.types.typesystem.DefaultTypeSystem.BOOLEAN;
import static org.yakindu.base.types.typesystem.DefaultTypeSystem.INTEGER;
import static org.yakindu.base.types.typesystem.DefaultTypeSystem.VOID;

import org.eclipse.emf.ecore.EObject;
import org.yakindu.base.expressions.expressions.ElementReferenceExpression;
import org.yakindu.base.expressions.expressions.Expression;
import org.yakindu.base.expressions.expressions.FeatureCall;
import org.yakindu.base.expressions.inferrer.ExpressionsTypeInferrer;
import org.yakindu.base.types.Operation;
import org.yakindu.base.types.Property;
import org.yakindu.base.types.Type;
import org.yakindu.sct.model.sgraph.Scope;
import org.yakindu.sct.model.stext.stext.ActiveStateReferenceExpression;
import org.yakindu.sct.model.stext.stext.EventDefinition;
import org.yakindu.sct.model.stext.stext.EventRaisingExpression;
import org.yakindu.sct.model.stext.stext.EventValueReferenceExpression;
import org.yakindu.sct.model.stext.stext.Guard;
import org.yakindu.sct.model.stext.stext.TimeEventSpec;
import org.yakindu.sct.model.stext.stext.VariableDefinition;

/**
 * @author <NAME> - Initial contribution and API
 * 
 */
public class STextTypeInferrer extends ExpressionsTypeInferrer {

	public static final String VARIABLE_DEFINITION = "Cannot assign a value of type %s to a variable of type %s.";
	public static final String EVENT_DEFINITION = "Cannot assign a value of type %s to an event of type %s.";
	public static final String GUARD = "The evaluation result of a guard expression must be of type boolean";
	public static final String TIME_SPEC = "The evaluation result of a time expression must be of type integer";
	public static final String VARIABLE_VOID_TYPE = "'void' is an invalid type for variables";
	public static final String MISSING_VALUE = "Need to assign a value to an event of type %s.";

	public Object infer(VariableDefinition e) {
		Type type = inferTypeDispatch(e.getType());
		assertNotType(type, VARIABLE_VOID_TYPE, getType(VOID));
		if (e.getInitialValue() == null)
			return inferTypeDispatch(type);
		Type type2 = inferTypeDispatch(e.getInitialValue());
		assertAssignable(type, type2, String.format(VARIABLE_DEFINITION, type2, type));
		return inferTypeDispatch(type);
	}
	
	public Object infer(Property p){
		Type type = inferTypeDispatch(p.getType());
		assertNotType(type, VARIABLE_VOID_TYPE, getType(VOID));
		return inferTypeDispatch(type);
		
	}
	
	public Object infer(Operation e) {
		return inferTypeDispatch(e.getType() != null ? e.getType() : getType(VOID));
	}

	public Object infer(EventDefinition e) {
		// if an event is used within an expression, the type is boolean and the
		// value indicates if the event is raised or not
		return getType(BOOLEAN);
{'fraction_non_alphanumeric': 0.0930306905370844, 'fraction_numerical': 0.003516624040920716, 'mean_word_length': 5.225870646766169, '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': '1571401', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1940, 'n_words': 541}