Examples for Model entities

This module introduce flags in all mentities so they can be tagged as example. Flagged classes will be treated differently by the documentation tools.

See MEntity::is_example and MEntity::examples.

Introduced classes

class MExample

nitc :: MExample

An example from a MEntity flagged with is example.

Redefined classes

redef class MClass

nitc :: model_examples $ MClass

A named class
redef abstract class MEntity

nitc :: model_examples $ MEntity

A named and possibly documented entity in the model.
redef class MGroup

nitc :: model_examples $ MGroup

A group of modules in a package
redef class MPackage

nitc :: model_examples $ MPackage

A Nit package, that encompass a product
redef abstract class MProperty

nitc :: model_examples $ MProperty

A service (global property) that generalize method, attribute, etc.

All class definitions

redef class MClass

nitc :: model_examples $ MClass

A named class
redef abstract class MEntity

nitc :: model_examples $ MEntity

A named and possibly documented entity in the model.
class MExample

nitc $ MExample

An example from a MEntity flagged with is example.
redef class MGroup

nitc :: model_examples $ MGroup

A group of modules in a package
redef class MPackage

nitc :: model_examples $ MPackage

A Nit package, that encompass a product
redef abstract class MProperty

nitc :: model_examples $ MProperty

A service (global property) that generalize method, attribute, etc.
package_diagram nitc::model_examples model_examples nitc\>model\> model nitc::model_examples->nitc\>model\> ordered_tree ordered_tree nitc\>model\>->ordered_tree nitc nitc nitc\>model\>->nitc nitc\>frontend\> frontend nitc\>model\>->nitc\>frontend\> trees trees nitc\>model\>->trees more_collections more_collections nitc\>model\>->more_collections graph graph nitc\>model\>->graph json json nitc\>model\>->json ...ordered_tree ... ...ordered_tree->ordered_tree ...nitc ... ...nitc->nitc ...nitc\>frontend\> ... ...nitc\>frontend\>->nitc\>frontend\> ...trees ... ...trees->trees ...more_collections ... ...more_collections->more_collections ...graph ... ...graph->graph ...json ... ...json->json nitc::model_filters model_filters nitc::model_filters->nitc::model_examples nitc::model_collect model_collect nitc::model_collect->nitc::model_filters nitc::model_visitor model_visitor nitc::model_visitor->nitc::model_filters nitc::model_collect... ... nitc::model_collect...->nitc::model_collect nitc::model_visitor... ... nitc::model_visitor...->nitc::model_visitor

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module model_base

nitc :: model_base

The abstract concept of model and related common things
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module model

nitc :: model

Classes, types and properties

Children

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module api_auth

nitc :: api_auth

module api_base

nitc :: api_base

Base classes used by nitweb.
module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module commands_base

nitc :: commands_base

Documentation commands
module commands_catalog

nitc :: commands_catalog

Commands to retrieve Catalog related data
module commands_docdown

nitc :: commands_docdown

Doc down related queries
module commands_graph

nitc :: commands_graph

Graph commands
module commands_http

nitc :: commands_http

Initialize commands from HTTP requests
module commands_model

nitc :: commands_model

Doc commands about a Model or a MEntity
module commands_parser

nitc :: commands_parser

A parser that create DocCommand from a string
module commands_usage

nitc :: commands_usage

Commands about how mentities are used
module html_commands

nitc :: html_commands

Render commands results as HTML
module html_model

nitc :: html_model

Translate mentities to html blocks.
module inheritance_metrics

nitc :: inheritance_metrics

Collect metrics about inheritance usage
module json_commands

nitc :: json_commands

Translate command results to json
module json_model

nitc :: json_model

Make model entities Serializable.
module mclasses_metrics

nitc :: mclasses_metrics

Collect common metrics about mclasses
module md_commands

nitc :: md_commands

Render commands results as Markdown
module mendel_metrics

nitc :: mendel_metrics

The Mendel model helps to understand class hierarchies.
module metrics

nitc :: metrics

Various statistics about Nit models and programs
module mmodules_metrics

nitc :: mmodules_metrics

Collect common metrics about modules
module model_collect

nitc :: model_collect

Collect things from the model.
module model_index

nitc :: model_index

Search things from the Model
module model_visitor

nitc :: model_visitor

Simple visitor framework for Nit models.
module nitcatalog

nitc :: nitcatalog

Basic catalog generator for Nit packages
module nitdoc

nitc :: nitdoc

Generator of static API documentation for the Nit language
module nitmetrics

nitc :: nitmetrics

A program that collects various metrics on nit programs and libraries
module nitpackage

nitc :: nitpackage

Helpful features about packages
module nitpick

nitc :: nitpick

A program that collect potential style and code issues
module nitsmells

nitc :: nitsmells

module nituml

nitc :: nituml

UML generator in dot format.
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
module nitx

nitc :: nitx

nitx, a command tool that displays useful data about Nit code
module nullables_metrics

nitc :: nullables_metrics

Statistics about the usage of nullables
module readme_metrics

nitc :: readme_metrics

Collect common metrics about README files
module rta_metrics

nitc :: rta_metrics

Metrics from RTA
module static

nitc :: static

Nitdoc generation framework
module static_base

nitc :: static_base

Base entities shared by all the nitdoc code
module static_cards

nitc :: static_cards

Cards templates for the static documentation
module static_html

nitc :: static_html

Render documentation pages as HTML
module static_index

nitc :: static_index

Manage indexing of Nit model for Nitdoc QuickSearch.
module static_structure

nitc :: static_structure

Composes the pages of the static documentation
module term

nitc :: term

module term_model

nitc :: term_model

Markdown templates for Nit model MEntities.
module test_model_visitor

nitc :: test_model_visitor

Example of model_visitor
module uml

nitc :: uml

Group head module for UML generation services
module uml_base

nitc :: uml_base

Exposes the base class for UML generation of a Model
module uml_class

nitc :: uml_class

Provides facilities of exporting a Model to a UML class diagram
module uml_module

nitc :: uml_module

Services for generation of a UML package diagram based on a Model
module vim_autocomplete

nitc :: vim_autocomplete

Generate files used by the Vim plugin to autocomplete with doc
# Examples for Model entities
#
# This module introduce flags in all mentities so they can be tagged as example.
# Flagged classes will be treated differently by the documentation tools.
#
# See `MEntity::is_example` and `MEntity::examples`.
module model_examples

import model

# An example from a MEntity flagged with `is example`.
class MExample

	redef init do
		super
		mentity.mexample = self
	end

	# MEntity containing this example
	var mentity: MEntity

	# MEntities this example is for
	#
	# For each entity we provide a weight so examples can be ranked.
	var example_for = new ArrayMap[MEntity, Int]

	redef fun to_s do return mentity.full_name
end

redef class MEntity

	# Is `self` existing for an example purpose?
	#
	# All mentities annotated with `is example` or located inside a mentity that
	# is an example are considered as examples.
	fun is_example: Bool do return mexample != null

	# Return this entity as a MExample
	var mexample: nullable MExample = null

	# Examples found for `self`
	var examples = new Array[MExample]
end

redef class MPackage
	redef fun examples do
		var res = super
		for mgroup in mgroups do
			for example in mgroup.examples do
				if not res.has(example) then res.add example
			end
		end
		return res
	end
end

redef class MGroup
	redef var is_example is lazy do
		var parent = self.parent
		if parent != null and parent.is_example then return true
		return name == "examples"
	end

	redef fun examples do
		var res = super
		for mmodule in mmodules do
			for example in mmodule.examples do
				if not res.has(example) then res.add example
			end
		end
		return res
	end
end

redef class MClass
	redef var is_example is lazy do return intro.is_example

	redef fun examples do
		var res = super
		for mclassdef in mclassdefs do
			for example in mclassdef.examples do
				if not res.has(example) then res.add example
			end
		end
		return res
	end
end

redef class MProperty
	redef var is_example is lazy do return intro.is_example

	redef fun examples do
		var res = super
		for mpropdef in mpropdefs do
			for example in mpropdef.examples do
				if not res.has(example) then res.add example
			end
		end
		return res
	end
end
src/model/model_examples.nit:17,1--117,3