<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2008 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Collect things from a `Model`.
#
# **Warning**
#
# `model_collect` offers a flattened view of the model without considering any
# main module.
# For this reason, `model_collect` lists all the definitions reachable from all
# modules
#
# This is usefull for tools that need a global view of a model like `nitdoc`,
# `nitx` or `nituml`.
# It shoul not be used for compiling stuffs like computing VFT, where the listed
# entities could not be reachable depending on the modules really imported.
module model_collect

import model_views

redef class MModule

	# Collect mclassdefs introduced in `self` with `visibility >= to min_visibility`.
	fun collect_intro_mclassdefs(view: ModelView): Set[MClassDef] do
		var res = new HashSet[MClassDef]
		for mclassdef in mclassdefs do
			if not mclassdef.is_intro then continue
			if not view.accept_mentity(mclassdef) then continue
			res.add mclassdef
		end
		return res
	end

	# Collect mclassdefs redefined in `self` with `visibility >= to min_visibility`.
	fun collect_redef_mclassdefs(view: ModelView): Set[MClassDef] do
		var res = new HashSet[MClassDef]
		for mclassdef in mclassdefs do
			if mclassdef.is_intro then continue<commit_msg>model_collect: collect more on MModule hierarchy<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# Copyright 2008 <NAME> <<EMAIL>>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Collect things from a `Model`.
#
# **Warning**
#
# `model_collect` offers a flattened view of the model without considering any
# main module.
# For this reason, `model_collect` lists all the definitions reachable from all
# modules
#
# This is usefull for tools that need a global view of a model like `nitdoc`,
# `nitx` or `nituml`.
# It shoul not be used for compiling stuffs like computing VFT, where the listed
# entities could not be reachable depending on the modules really imported.
module model_collect

import model_views

redef class MModule

	# Collect all transitive imports.
	fun collect_ancestors(view: ModelView): Set[MModule] do
		var res = new HashSet[MModule]
		for mentity in in_importation.greaters do
			if mentity == self then continue
			if not view.accept_mentity(mentity) then continue
			res.add mentity
		end
		return res
	end

	# Collect direct imports.
	fun collect_parents(view: ModelView): Set[MModule] do
		var res = new HashSet[MModule]
		for mentity in in_importation.direct_greaters do
			if mentity == self then continue
			if not view.accept_mentity(mentity) then continue
			res.add mentity
		end
		return res
	end

	# Collect direct children (modules that directly import `self`).
	fun collect_children(view: ModelView): Set[MModule] do
		var res = new HashSet[MModule]
		for mentity in in_importation.direct_smallers do
			if mentity == self then continue
			if not view.accept_mentity(mentity) then continue
			res.add mentity
		end
		return res
	end

	# Collect all transitive children.
	fun collect_descendants(view: ModelView): Set[MModule] do
		var res = new HashSet[MModule]
		for mentity in in_importation.smallers do
			if mentity == self then continue
			if not view.accept_mentity(mentity) then continue
			res.add mentity
		end
		return res
	end

	# Collect mclassdefs introduced in `self` with `visibility >= to min_visibility`.
	fun collect_intro_mclassdefs(view: ModelView): Set[MClassDef] do
		var res = new HashSet[MClassDef]
		for mclassdef in mclassdefs do
			if not mclassdef.is_intro then continue
			if not view.accept_mentity(mclassdef) then continue
			res.add mclassdef
		end
		return res
	end

	# Collect mclassdefs redefined in `self` with `visibility >= to min_visibility`.
	fun collect_redef_mclassdefs(view: ModelView): Set[MClassDef] do
		var res = new HashSet[MClassDef]
		for mclassdef in mclassdefs do
			if mclassdef.is_intro then continue
{'fraction_non_alphanumeric': 0.06872228939943571, 'fraction_numerical': 0.0032245062474808546, 'mean_word_length': 4.3423035522066735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '940665', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1452, 'n_words': 617}