Property definitions

nitc $ FeatureEnvy :: defaultinit
class FeatureEnvy
	super BadConception
	var bad_methods = new Array[MMethodDef]

	redef fun name do return "FEM"

	redef fun desc do return "Feature envy"

	redef fun collect(mclassdef, model_builder): Bool do
		var mmethoddefs = call_analyze_methods(mclassdef,model_builder, filter)
		for mmethoddef in mmethoddefs do
			var max_class_call = mmethoddef.class_call.max
			# Check if the class with the maximum call is >= auto-call and the maximum call class is != of this class
			if mmethoddef.class_call[max_class_call] <= mmethoddef.total_self_call or max_class_call.mclass.full_name == mclassdef.mclass.full_name then continue
			self.bad_methods.add(mmethoddef)
		end
		self.score_rate
		return self.bad_methods.not_empty
	end

	redef fun print_result do
		print phase.toolcontext.format_h2("{desc}:")
		if self.bad_methods.not_empty then
			print "	Affected method(s):"
			for method in self.bad_methods do
				var max_class_call = method.class_call.max
				if max_class_call != null then
					# Check if the type of max call class is generique
					if max_class_call.mclass.mclass_type isa MGenericType and not phase.toolcontext.opt_move_generics.value then
						print "		-{method.name}({method.msignature.mparameters.join(", ")}) {method.total_self_call}/{method.class_call[max_class_call]}"
					else
						print "		-{method.name}({method.msignature.mparameters.join(", ")}) {method.total_self_call}/{method.class_call[max_class_call]} move to {max_class_call}"
					end
				end
			end
		end
	end

	redef fun score_rate do
		if self.bad_methods.not_empty then
			self.score = self.bad_methods.length.to_f / phase.average_number_of_method
		end
	end
end
src/metrics/codesmells_metrics.nit:257,1--300,3