<commit_before>/*
 * generated by Xtext
 */
package dk.itu.smdp.group2.generator

import java.io.File
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import questionairemodel.Questionaire
import questionairemodel.Question
import questionairemodel.Option
import questionairemodel.Paragraph
import questionairemodel.Heading
import questionairemodel.ChoiceQuestion
import questionairemodel.Element

/**
 * Generates code from your model files on save.
 * 
 * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
 */
class QuestionaireGenerator implements IGenerator {

	String latex_cmd = "/usr/local/texlive/2012/bin/universal-darwin/pdflatex" //How to do this??

	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		resource.allContents.toIterable.filter(typeof(Questionaire)).forEach [ Questionaire it |
			val fname = it.name.toFirstUpper
			
			elements.forEach[removeQuotes]
			
			// generate Android implementation
			fsa.generateFile("android/" + fname + ".java", AndroidGenerator.compileToAndroid(it))
			//TODO: other Android stuff?
			
			
			// generate Latex
			fsa.generateFile("latex/" + fname +".tex", LatexGenerator.compileToLatex(it))
			//TODO: other Latex stuff?
			val projectName = resource.URI.segment(1)
			val project = ResourcesPlugin.workspace.root.getProject(projectName)
			var path = new File(project.location + "/src-gen/latex/")
			var cmd = #[latex_cmd, fname + ".tex"]
			Runtime.runtime.exec(cmd, null, path)
		]
	}
	
	def static removeQuotes(Element it){
		if(it instanceof Heading){
			text = text.replaceAll("^\"(.*)\"$", "$1")
		}
		if(it instanceof Paragraph){
			text = text.replaceAll("^\"(.*)\"$", "$1")
		}
		if(it instanceof Question){
			questionBase.title = questionBase.title.replaceAll("^\"(.*)\"$", "$1")
			if(questionBase.description != null) questionBase.description = questionBase.description.replaceAll("^\"(.*)\"$", "$1")
			if(it instanceof ChoiceQuestion) options.forEach[removeQuotes]
		}
		
	}
	
	def static removeQuotes(Option it){
		if(name!=null) name = name.replaceAll("^\"(.*)\"$", "$1")
		text = text.replaceAll("^\"(.*)\"$", "$1")
	}
}
<commit_msg>Adressing issue #4: Quotes are now also removed in Matrix questions.<commit_after>/*
 * generated by Xtext
 */
package dk.itu.smdp.group2.generator

import java.io.File
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.xtext.generator.IGenerator
import questionairemodel.Questionaire
import questionairemodel.Question
import questionairemodel.Option
import questionairemodel.Paragraph
import questionairemodel.Heading
import questionairemodel.ChoiceQuestion
import questionairemodel.Element
import questionairemodel.MatrixQuestion
import java.util.List

/**
 * Generates code from your model files on save.
 * 
 * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
 */
class QuestionaireGenerator implements IGenerator {

	String latex_cmd = "/usr/local/texlive/2012/bin/universal-darwin/pdflatex" //How to do this??
	
	static val repReg = #["^\"(.*)\"$", "$1"]

	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		resource.allContents.toIterable.filter(typeof(Questionaire)).forEach [ Questionaire it |
			val fname = it.name.toFirstUpper
			
			elements.forEach[removeQuotes]
			
			// generate Android implementation
			fsa.generateFile("android/" + fname + ".java", AndroidGenerator.compileToAndroid(it))
			//TODO: other Android stuff?
			
			
			// generate Latex
			fsa.generateFile("latex/" + fname +".tex", LatexGenerator.compileToLatex(it))
			//TODO: other Latex stuff?
			val projectName = resource.URI.segment(1)
			val project = ResourcesPlugin.workspace.root.getProject(projectName)
			var path = new File(project.location + "/src-gen/latex/")
			var cmd = #[latex_cmd, fname + ".tex"]
			Runtime.runtime.exec(cmd, null, path)
		]
	}
	
	def static removeQuotes(Element it){
		if(it instanceof Heading){
			text = text.replaceAll(repReg.get(0), repReg.get(1))
		}
		if(it instanceof Paragraph){
			text = text.replaceAll(repReg.get(0), repReg.get(1))
		}
		if(it instanceof Question){
			questionBase.title = questionBase.title.replaceAll(repReg.get(0), repReg.get(1))
			if(questionBase.description != null) questionBase.description = questionBase.description.replaceAll(repReg.get(0), repReg.get(1))
			if(it instanceof ChoiceQuestion) options.forEach[removeQuotes]
			if(it instanceof MatrixQuestion) {removeQuotes(rowNames);removeQuotes(columnNames)}
		}
		
	}
	
	def static removeQuotes(List<String> list) {
		var List<String> oldNames = list.immutableCopy
		list.clear
		oldNames.forEach[list.add(it.replaceAll(repReg.get(0), repReg.get(1)))]
	}
	
	def static removeQuotes(Option it){
		if(name!=null) name = name.replaceAll(repReg.get(0), repReg.get(1))
		text = text.replaceAll(repReg.get(0), repReg.get(1))
	}
}

{'fraction_non_alphanumeric': 0.13176470588235295, 'fraction_numerical': 0.006666666666666667, 'mean_word_length': 4.674082313681868, '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': '3321131', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1582, 'n_words': 325}