module nitx
import model_utils
-import modelize_property
+import modelize
# Main class of the nit index tool
# NitIndex build the model using the toolcontext argument
# then wait for query on std in to display documentation
class NitIndex
private var toolcontext: ToolContext
- private var model: Model
- private var mbuilder: ModelBuilder
- private var mainmodule: MModule
- private var arguments: Array[String]
- private var renderer: PagerMatchesRenderer
+ private var model: Model is noinit
+ private var mbuilder: ModelBuilder is noinit
+ private var mainmodule: MModule is noinit
+ private var arguments: Array[String] is noinit
+ private var renderer: PagerMatchesRenderer is noinit
# New constructor to use the pre-calculated model when interpreting a module
init with_infos(mbuilder: ModelBuilder, mmodule: MModule) do
renderer = new PagerMatchesRenderer(self)
end
- init(toolcontext: ToolContext) do
+ init do
# We need a model to collect stufs
- self.toolcontext = toolcontext
self.arguments = toolcontext.option_context.rest
if arguments.length > 2 then
private class IndexQuery
var string: String
var keyword: String
- init(string: String, keyword: String) do
- self.string = string
- self.keyword = keyword
- end
end
private class IndexQueryPair
super IndexQuery
var category: String
- init(string: String, keyword: String, category: String) do
- super(string, keyword)
- self.category = category
- end
end
# A match to a query in the nit index
private class PagerMatchesRenderer
var index: NitIndex
- init(index: NitIndex) do self.index = index
fun render_matches(query: IndexQuery, matches: Collection[IndexMatch]) do
var pager = new Pager
var res = new FlatBuffer
if arity > 0 then
res.append("[")
- for i in [0..intro.parameter_names.length[ do
- res.append(intro.parameter_names[i])
- if i < intro.parameter_names.length - 1 then res.append(", ")
+ for i in [0..mparameters.length[ do
+ res.append(mparameters[i].name)
+ if i < mparameters.length - 1 then res.append(", ")
end
res.append("]")
end
end
redef class MParameterType
- redef fun to_console do return mclass.intro.parameter_names[rank]
+ redef fun to_console do return name
end
redef class MVirtualType
end
end
-redef class AAttrPropdef
- private fun read_accessor: String do
- var ret = "fun "
- #FIXME bug with standard::stream::FDStream::fd
- var name = mreadpropdef.mproperty.name
- if mpropdef.mproperty.visibility.to_s == "public" then ret = "{ret}{name.green}"
- if mpropdef.mproperty.visibility.to_s == "private" then ret = "{ret}{name.red}"
- if mpropdef.mproperty.visibility.to_s == "protected" then ret = "{ret}{name.yellow}"
- ret = "{ret}: {n_type.to_s}"
- if n_kwredef != null then ret = "redef {ret}"
- return ret
- end
-
- private fun write_accessor: String do
- var ret = "fun "
- var name = "{mreadpropdef.mproperty.name}="
- if n_readable != null and n_readable.n_visibility != null then
- if n_readable.n_visibility isa APublicVisibility then ret = "{ret}{name.green}"
- if n_readable.n_visibility isa APrivateVisibility then ret = "{ret}{name.red}"
- if n_readable.n_visibility isa AProtectedVisibility then ret = "{ret}{name.yellow}"
- else
- ret = "{ret}{name.red}"
- end
- ret = "{ret}({mreadpropdef.mproperty.name}: {n_type.to_s})"
- if n_kwredef != null then ret = "redef {ret}"
- return ret
- end
-end
-
# Redef String class to add a function to color the string
redef class String