<commit_before>package fr.inria.diverse.melange.processors

import com.google.inject.Inject
import fr.inria.diverse.melange.algebra.ModelTypeAlgebra
import fr.inria.diverse.melange.ast.MetamodelExtensions
import fr.inria.diverse.melange.metamodel.melange.Metamodel
import fr.inria.diverse.melange.utils.AspectToEcore

/**
 * This class merges all aspects into the Metamodel
 */
class AspectsWeaver extends DispatchMelangeProcessor
{
	@Inject ModelTypeAlgebra algebra
	@Inject extension MetamodelExtensions
	@Inject extension AspectToEcore

	def dispatch void preProcess(Metamodel mm) {
		mm.aspects.forEach[asp |
			if (asp.isComplete) {
				val className = asp.aspectAnnotationValue
				val cls = mm.findClass(className)
				asp.aspectedClass = cls

				if (asp.aspectedClass !== null) {
					asp.inferEcoreFragment
					algebra.weaveAspect(mm, asp)
				}
			}
		]
	}
}
<commit_msg>Fix AspectWeaver: when Xtext fail to find aspected class, retrieve it with the Properties file a.k.a call the A-Team<commit_after>package fr.inria.diverse.melange.processors

import com.google.inject.Inject
import fr.inria.diverse.melange.algebra.ModelTypeAlgebra
import fr.inria.diverse.melange.ast.MetamodelExtensions
import fr.inria.diverse.melange.metamodel.melange.Metamodel
import fr.inria.diverse.melange.utils.AspectToEcore
import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder
import fr.inria.diverse.melange.eclipse.EclipseProjectHelper
import org.eclipse.core.resources.IProject
import fr.inria.diverse.melange.metamodel.melange.Aspect
import java.util.Properties

/**
 * This class merges all aspects into the Metamodel
 */
class AspectsWeaver extends DispatchMelangeProcessor
{
	@Inject ModelTypeAlgebra algebra
	@Inject extension MetamodelExtensions
	@Inject extension AspectToEcore
	@Inject extension EclipseProjectHelper

	def dispatch void preProcess(Metamodel mm) {
		mm.aspects.forEach[asp |
			
			if (asp.isComplete) {
				var className = asp.aspectAnnotationValue
				var cls = mm.findClass(className)
				
				if(cls == null){
					className = getAspectedClassName(mm,asp)
					cls = mm.findClass(className)
				}
				
				asp.aspectedClass = cls

				if (asp.aspectedClass !== null) {
					asp.inferEcoreFragment
					algebra.weaveAspect(mm, asp)
				}
			}
		]
	}
	
	/**
	 * Look in Properties file to get the class associated to the aspect
	 */
	def String getAspectedClassName(Metamodel mm, Aspect asp){
		var res = ""
		
		val typeAspect = asp.aspectTypeRef.type
		val fqnAspect = typeAspect.getQualifiedName()
		val IProject aspectProject = typeAspect.eResource.project
		val file = aspectProject.getFile("/META-INF/xtend-gen/"+aspectProject.getName()+".k3_aspect_mapping.properties")
		val Properties properties = new Properties();
		properties.load(file.getContents());
		res = properties.entrySet.findFirst[elem | elem.value.equals(fqnAspect)].key as String
		val cut = res.lastIndexOf('.')
		res = res.substring(cut+1)
	    
	    return res
	}
}

{'fraction_non_alphanumeric': 0.09219380888290714, 'fraction_numerical': 0.0006729475100942127, 'mean_word_length': 4.308928571428571, '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': '7595393', 'n_tokens_mistral': 1086, 'n_tokens_neox': 967, 'n_words': 198}