<commit_before>package org.xtendroid.json

import org.eclipse.xtend.lib.macro.AbstractFieldProcessor
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
import org.eclipse.xtend.lib.macro.declaration.Visibility
import org.json.JSONObject
import org.json.JSONException

@Active(JsonPropertyProcessor)
annotation JsonProperty {
}

class JsonPropertyProcessor extends AbstractFieldProcessor {

   override doTransform(MutableFieldDeclaration field, extension TransformationContext context) {
// if (field.initializer == null)
// field.addError("A Preference field must have an initializer.")

		if (!field.declaringType.declaredFields.exists[ it.simpleName == "_jsonObj"]) {
			var f = field.declaringType.addField("_jsonObj") []
			f.setType(JSONObject.newTypeReference)
			f.setFinal(true)
			f.setVisibility(Visibility::PROTECTED)
						
			var c = field.declaringType.addConstructor [
			]
			c.addParameter("jsonObj", JSONObject.newTypeReference)
			c.body = [
				'''
					this._jsonObj = jsonObj;
				'''
			]
		}

      // add synthetic init-method
      var getter = if(field.type.simpleName.equalsIgnoreCase("Boolean")) "is" else "get"
      val orgName = field.simpleName
      field.simpleName = "_" + field.simpleName
      field.declaringType.addMethod(getter + orgName.upperCaseFirst) [
         visibility = Visibility::PUBLIC
         returnType = field.type
         exceptions = #[ JSONException.newTypeReference ]
         
         // reassign the initializer expression to be the init method’s body
         // this automatically removes the expression as the field’s initializer
         body = [
            '''
					return _jsonObj.get«field.type»("«orgName»");
				'''
         ]
      ]
   }
   
   def upperCaseFirst(String s) {
      s.toFirstUpper
   }
}<commit_msg>handling of primitive types<commit_after>package org.xtendroid.json

import org.eclipse.xtend.lib.macro.AbstractFieldProcessor
import org.eclipse.xtend.lib.macro.Active
import org.eclipse.xtend.lib.macro.TransformationContext
import org.eclipse.xtend.lib.macro.declaration.MutableFieldDeclaration
import org.eclipse.xtend.lib.macro.declaration.Visibility
import org.json.JSONObject
import org.json.JSONException

@Active(JsonPropertyProcessor)
annotation JsonProperty {
}

class JsonPropertyProcessor extends AbstractFieldProcessor {

   override doTransform(MutableFieldDeclaration field, extension TransformationContext context) {
// if (field.initializer == null)
// field.addError("A Preference field must have an initializer.")

		if (!field.declaringType.declaredFields.exists[ it.simpleName == "_jsonObj"]) {
			var f = field.declaringType.addField("_jsonObj") []
			f.setType(JSONObject.newTypeReference)
			f.setFinal(true)
			f.setVisibility(Visibility::PROTECTED)
						
			var c = field.declaringType.addConstructor [
			]
			c.addParameter("jsonObj", JSONObject.newTypeReference)
			c.body = [
				'''
					this._jsonObj = jsonObj;
				'''
			]
		}

      // add synthetic init-method
      var getter = if(field.type.simpleName.equalsIgnoreCase("Boolean")) "is" else "get"
      val orgName = field.simpleName
      field.simpleName = "_" + field.simpleName
      field.declaringType.addMethod(getter + orgName.upperCaseFirst) [
         visibility = Visibility::PUBLIC
         returnType = field.type
         exceptions = #[ JSONException.newTypeReference ]
         
         // reassign the initializer expression to be the init method’s body
         // this automatically removes the expression as the field’s initializer
         body = [
            '''
					return _jsonObj.get«field.type.simpleName.upperCaseFirst»("«orgName»");
				'''
         ]
      ]
   }
   
   def upperCaseFirst(String s) {
      s.toFirstUpper
   }
}
{'fraction_non_alphanumeric': 0.10305541170378042, 'fraction_numerical': 0.0, 'mean_word_length': 3.3997722095671983, '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': '3012797', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1097, 'n_words': 225}