The abstract model visitor template.

Specific visitor must implement the visit method to perform the work.

Introduced properties

private var _current_entity: nullable MEntity

nitc :: ModelVisitor :: _current_entity

The current visited entity
private var _filter: ModelFilter

nitc :: ModelVisitor :: _filter

Filters to apply when visiting the model.
fun accept_mentity(mentity: MEntity, override_filter: nullable ModelFilter): Bool

nitc :: ModelVisitor :: accept_mentity

Should we accept this mentity from the view?
fun current_entity: nullable MEntity

nitc :: ModelVisitor :: current_entity

The current visited entity
protected fun current_entity=(current_entity: nullable MEntity)

nitc :: ModelVisitor :: current_entity=

The current visited entity
init defaultinit(filter: nullable ModelFilter)

nitc :: ModelVisitor :: defaultinit

fun enter_visit(e: nullable MEntity)

nitc :: ModelVisitor :: enter_visit

Visit the entity e.
fun filter: ModelFilter

nitc :: ModelVisitor :: filter

Filters to apply when visiting the model.
fun filter=(filter: nullable ModelFilter)

nitc :: ModelVisitor :: filter=

Filters to apply when visiting the model.
protected abstract fun visit(e: MEntity)

nitc :: ModelVisitor :: visit

Method to define in specific visitor.

Redefined properties

redef type SELF: ModelVisitor

nitc $ ModelVisitor :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _current_entity: nullable MEntity

nitc :: ModelVisitor :: _current_entity

The current visited entity
private var _filter: ModelFilter

nitc :: ModelVisitor :: _filter

Filters to apply when visiting the model.
fun accept_mentity(mentity: MEntity, override_filter: nullable ModelFilter): Bool

nitc :: ModelVisitor :: accept_mentity

Should we accept this mentity from the view?
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun current_entity: nullable MEntity

nitc :: ModelVisitor :: current_entity

The current visited entity
protected fun current_entity=(current_entity: nullable MEntity)

nitc :: ModelVisitor :: current_entity=

The current visited entity
init defaultinit(filter: nullable ModelFilter)

nitc :: ModelVisitor :: defaultinit

fun enter_visit(e: nullable MEntity)

nitc :: ModelVisitor :: enter_visit

Visit the entity e.
fun filter: ModelFilter

nitc :: ModelVisitor :: filter

Filters to apply when visiting the model.
fun filter=(filter: nullable ModelFilter)

nitc :: ModelVisitor :: filter=

Filters to apply when visiting the model.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
protected abstract fun visit(e: MEntity)

nitc :: ModelVisitor :: visit

Method to define in specific visitor.
package_diagram nitc::ModelVisitor ModelVisitor core::Object Object nitc::ModelVisitor->core::Object nitc::TestModelVisitor TestModelVisitor nitc::TestModelVisitor->nitc::ModelVisitor

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class TestModelVisitor

nitc :: TestModelVisitor

Example visitor that just count kind of entities.

Class definitions

nitc $ ModelVisitor
# The abstract model visitor template.
#
# Specific visitor must implement the `visit` method to perform the work.
abstract class ModelVisitor

	# Visit the entity `e`.
	#
	# This method setups `current_entity` and call `visit`.
	# If `e` is null, nothing is done.
	fun enter_visit(e: nullable MEntity) do
		if e == null then return
		if not accept_mentity(e) then return
		var old_entity = current_entity
		current_entity = e
		visit(e)
		current_entity = old_entity
	end

	# The current visited entity
	var current_entity: nullable MEntity = null

	# Method to define in specific visitor.
	#
	# It should not be called directly but used by `enter_visit`
	protected fun visit(e: MEntity) is abstract

	# Filters to apply when visiting the model.
	#
	# See ModelFilters for configuration.
	var filter: ModelFilter is lazy, writable, optional do
		return new ModelFilter(
			min_visibility = protected_visibility,
			accept_fictive = false,
			accept_test = false,
			accept_example = false,
			accept_redef = true,
			accept_extern = true,
			accept_attribute = true,
			accept_empty_doc = true
		)
	end

	# Should we accept this `mentity` from the view?
	#
	# If no `override_filter` is passed then use `self.filter`.
	fun accept_mentity(mentity: MEntity, override_filter: nullable ModelFilter): Bool do
		if override_filter != null then
			return override_filter.accept_mentity(mentity)
		end
		return filter.accept_mentity(mentity)
	end
end
src/model/model_visitor.nit:46,1--97,3