/*
 * generated by Xtext
 */
package org.nanosite.xtendency.tracer.validation
//import org.eclipse.xtext.validation.Check

/**
 * Custom validation rules. 
 *
 * see http://www.eclipse.org/Xtext/documentation.html#validation
 */
class TracingExecutionContextValidator extends AbstractTracingExecutionContextValidator {

//  public static val INVALID_NAME = 'invalidName'
//
//	@Check
//	def checkGreetingStartsWithCapital(Greeting greeting) {
//		if (!Character.isUpperCase(greeting.name.charAt(0))) {
//			warning('Name should start with a capital', 
//					MyDslPackage.Literals.GREETING__NAME,
//					INVALID_NAME)
//		}
//	}
}

/*
 * generated by Xtext
 */
package org.nanosite.xtendency.tracer.validation

import org.eclipse.xtext.validation.Check
import org.nanosite.xtendency.tracer.tracingExecutionContext.ExecutionContext
import org.eclipse.xtend.core.xtend.XtendField
import org.nanosite.xtendency.tracer.tracingExecutionContext.TracingExecutionContextPackage

//import org.eclipse.xtext.validation.Check

/**
 * Custom validation rules. 
 *
 * see http://www.eclipse.org/Xtext/documentation.html#validation
 */
class TracingExecutionContextValidator extends AbstractTracingExecutionContextValidator {

	@Check
	def checkAllParametersDefined(ExecutionContext ec){
		if (ec.function != null){
			val params = ec.function.parameters.map[name]
			val fields = ec.clazz.members.filter(XtendField).map[name]
			val args = ec.inits.map[it.param]
			for (p : params){
				if (!args.contains(p)){
					error("Parameter " + p + " must be initialized.", TracingExecutionContextPackage.Literals.EXECUTION_CONTEXT__FUNCTION)
				}
			}
			for (a : args){
				if (!params.contains(a) && a != "this" && !fields.exists[it == a]){
					warning("Function " + ec.function.name + " does not have a parameter named " + a + " and its class has no field with this name.", TracingExecutionContextPackage.Literals.EXECUTION_CONTEXT__INITS, args.indexOf(a))
				}
			}
		}
	}
}
