<commit_before># This file is part of NIT ( http://www.nitlanguage.org ).
#
# 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.

# Computes importation and class hierarchy lists.
module doc_hierarchies

import doc_structure
import doc_poset

# Insert inheritance / importation lists in the page.
class InheritanceListsPhase
	super DocPhase

	# Used to sort list by name.
	var name_sorter = new MEntityNameSorter

	redef fun apply do
		for page in doc.pages do
			if page isa MEntityPage then page.build_inh_list(self, doc)
		end
	end
end

redef class MEntityPage

	# Build importation / inheritance list for this page.
	fun build_inh_list(v: InheritanceListsPhase, doc: DocModel) do end
end

redef class MModulePage
	redef fun build_inh_list(v, doc) do
		var section = new ImportationListSection
		var imports = self.imports.to_a
		v.name_sorter.sort(imports)
		section.add_child new HierarchyListArticle(mentity, "Imports", imports)
		var clients = self.clients.to_a
		v.name_sorter.sort(clients)
		section.add_child new HierarchyListArticle(mentity, "Clients", clients)
		root.children.insert(section, 1)
	end
end

redef class MClassPage
	redef fun build_inh_list(v, doc) do
		var section = new InheritanceListSection
		var parents = self.parents.to_a
		v.name_sorter.sort(parents)
		section.add_child new HierarchyListArticle(mentity, "Parents", parents)
		var ancestors = self.ancestors.to_a
		v.name_sorter.sort(ancestors)
		section.add_child new HierarchyListArticle(mentity, "Ancestors", ancestors)
		var children = self.children.to_a
		v.name_sorter.sort(children)
		section.add_child new HierarchyListArticle(mentity, "Children", children)
		var descendants = self.descendants.to_a
		v.name_sorter.sort(descendants)
		section.add_child new HierarchyListArticle(mentity, "Descendants", descendants)
		root.children.insert(section, 1)
	end
end

# FIXME diff hack
class ImportationListSection
	super DocSection
end

# FIXME diff hack
class InheritanceListSection
	super DocSection
end

# Dislay a hierarchical list of mentities.
class HierarchyListArticle
	super MEntityArticle

	# Title displayed in the top of this list.
	var list_title: String

	# MEntities to display in this list.
	var mentities: Array[MEntity]<commit_msg>src/doc: make ImportationListSection and InheritanceListSection two MEntity articles since the lists are about a specific MEntity<commit_after># This file is part of NIT ( http://www.nitlanguage.org ).
#
# 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.

# Computes importation and class hierarchy lists.
module doc_hierarchies

import doc_structure
import doc_poset

# Insert inheritance / importation lists in the page.
class InheritanceListsPhase
	super DocPhase

	# Used to sort list by name.
	var name_sorter = new MEntityNameSorter

	redef fun apply do
		for page in doc.pages do
			if page isa MEntityPage then page.build_inh_list(self, doc)
		end
	end
end

redef class MEntityPage

	# Build importation / inheritance list for this page.
	fun build_inh_list(v: InheritanceListsPhase, doc: DocModel) do end
end

redef class MModulePage
	redef fun build_inh_list(v, doc) do
		var section = new ImportationListSection(mentity)
		var imports = self.imports.to_a
		v.name_sorter.sort(imports)
		section.add_child new HierarchyListArticle(mentity, "Imports", imports)
		var clients = self.clients.to_a
		v.name_sorter.sort(clients)
		section.add_child new HierarchyListArticle(mentity, "Clients", clients)
		root.children.insert(section, 1)
	end
end

redef class MClassPage
	redef fun build_inh_list(v, doc) do
		var section = new InheritanceListSection(mentity)
		var parents = self.parents.to_a
		v.name_sorter.sort(parents)
		section.add_child new HierarchyListArticle(mentity, "Parents", parents)
		var ancestors = self.ancestors.to_a
		v.name_sorter.sort(ancestors)
		section.add_child new HierarchyListArticle(mentity, "Ancestors", ancestors)
		var children = self.children.to_a
		v.name_sorter.sort(children)
		section.add_child new HierarchyListArticle(mentity, "Children", children)
		var descendants = self.descendants.to_a
		v.name_sorter.sort(descendants)
		section.add_child new HierarchyListArticle(mentity, "Descendants", descendants)
		root.children.insert(section, 1)
	end
end

# FIXME diff hack
class ImportationListSection
	super DocSection
	super MEntityComposite
end

# FIXME diff hack
class InheritanceListSection
	super DocSection
	super MEntityComposite
end

# Dislay a hierarchical list of mentities.
class HierarchyListArticle
	super MEntityArticle

	# Title displayed in the top of this list.
	var list_title: String

	# MEntities to display in this list.
	var mentities: Array[MEntity]
{'fraction_non_alphanumeric': 0.0661215783860647, 'fraction_numerical': 0.002132954141485958, 'mean_word_length': 4.892146596858638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1870878', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1726, 'n_words': 594}