<commit_before>package xtraitj.tests

import com.google.inject.Inject
import org.eclipse.xtext.common.types.JvmDeclaredType
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import org.junit.runner.RunWith
import xtraitj.XtraitjInjectorProvider
import xtraitj.xtraitj.TJProgram

import static extension xtraitj.util.XtraitjModelUtil.*
import org.eclipse.xtext.common.types.JvmTypeReference

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(XtraitjInjectorProvider))
abstract class XtraitjAbstractTest {
	
	@Inject extension JvmTypesBuilder
	@Inject extension ParseHelper<TJProgram>
	
	def protected toTypeRef(Class<?> clazz) {
		'''
		trait T {}
		'''.
		parse.newTypeRef(clazz)
	}

	def protected getJavaMethod(Class<?> clazz, String methodName) {
		clazz.toTypeRef.getJavaMethod(methodName)
	}

	def protected getJavaMethod(JvmTypeReference typeRef, String methodName) {
		(typeRef.type as JvmDeclaredType).allFeatures.filter(JvmOperation).findFirst[simpleName == methodName]
	}

	def protected toResourceTypeRef(Class<?> clazz, Class<?>... typeArgs) {
		var typeArguments = ""
		if (typeArgs.length > 0) {
			typeArguments = "<" +
				typeArgs.map[name].join(", ") +
				">"
		}
		
		'''
		trait T {
			«clazz.name»«typeArguments» testField;
		}
		'''.
		parse.traits.head.fields.head.type<commit_msg>TypeReferences.getTypeForName instead of deprecated newTypeRef<commit_after>package xtraitj.tests

import com.google.inject.Inject
import org.eclipse.xtext.common.types.JvmDeclaredType
import org.eclipse.xtext.common.types.JvmOperation
import org.eclipse.xtext.common.types.JvmTypeReference
import org.eclipse.xtext.common.types.util.TypeReferences
import org.eclipse.xtext.junit4.InjectWith
import org.eclipse.xtext.junit4.XtextRunner
import org.eclipse.xtext.junit4.util.ParseHelper
import org.junit.runner.RunWith
import xtraitj.XtraitjInjectorProvider
import xtraitj.xtraitj.TJProgram

import static extension xtraitj.util.XtraitjModelUtil.*

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(XtraitjInjectorProvider))
abstract class XtraitjAbstractTest {
	
	@Inject extension TypeReferences
	@Inject extension ParseHelper<TJProgram>
	
	def protected toTypeRef(Class<?> clazz) {
		// the parsed element is used only as the context for
		// TypeReferences.getTypeForName
		getTypeForName(clazz,
			'''
			trait T {}
			'''.
			parse)
	}

	def protected getJavaMethod(Class<?> clazz, String methodName) {
		clazz.toTypeRef.getJavaMethod(methodName)
	}

	def protected getJavaMethod(JvmTypeReference typeRef, String methodName) {
		(typeRef.type as JvmDeclaredType).allFeatures.filter(JvmOperation).findFirst[simpleName == methodName]
	}

	def protected toResourceTypeRef(Class<?> clazz, Class<?>... typeArgs) {
		var typeArguments = ""
		if (typeArgs.length > 0) {
			typeArguments = "<" +
				typeArgs.map[name].join(", ") +
				">"
		}
		
		'''
		trait T {
			«clazz.name»«typeArguments» testField;
		}
		'''.
		parse.traits.head.fields.head.type
{'fraction_non_alphanumeric': 0.11220597584233948, 'fraction_numerical': 0.0025429116338207248, 'mean_word_length': 5.158512720156556, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1561294', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1058, 'n_words': 187}