--- /dev/null
+# 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.
+
+# Extensions to the Nit model for foreign languages.
+module doc::model_ext
+
+intrude import model
+intrude import model::model_base
+
+# A type described by a text annoted with links.
+#
+# For use with Nitdoc only.
+class MRawType
+ super MType
+
+ redef var model: Model
+
+ # The parts that contitute the description of the type.
+ var parts: Sequence[MTypePart] = new Array[MTypePart]
+
+ redef fun as_nullable do
+ not_available
+ return self
+ end
+ redef fun need_anchor do
+ not_available
+ return false
+ end
+ redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do
+ not_available
+ return self
+ end
+ redef fun can_resolve_for(mtype, anchor, mmodule) do
+ not_available
+ return true
+ end
+ redef fun collect_mclassdefs(mmodule) do
+ not_available
+ return new HashSet[MClassDef]
+ end
+ redef fun collect_mclasses(mmodule) do
+ not_available
+ return new HashSet[MClass]
+ end
+ redef fun collect_mtypes(mmodule) do
+ not_available
+ return new HashSet[MClassType]
+ end
+
+ redef fun to_s do return parts.to_s
+
+ private fun not_available do
+ assert false else
+ sys.stderr.write "A `MRawType` is for documentation-purpose only so the requested operation is not available.\n"
+ end
+ end
+end
+
+# A part of a `RawType`.
+class MTypePart
+ super MEntity
+
+ redef var model: Model
+
+ # The textual content.
+ var text: String
+
+ # If the part links to another entity, the targeted entity.
+ var target: nullable MEntity
+
+ redef fun name do return text
+ redef fun to_s do return text
+
+ # Return a version of `self` that links to the specified entity.
+ fun link_to(target: nullable MEntity): MTypePart do
+ return new MTypePart(model, text, target)
+ end
+end
+
+# The “package” visiblity.
+#
+# Any visibility roughly equivalent to the default visibility of Java, that is
+# private for a collection of modules.
+fun package_visibility: MVisibility do return once new MVisibility("package", 2)
+
+# A class kind with no equivalent semantic in Nit.
+fun raw_kind(s: String): MClassKind do return new MClassKind(s, false)
# `MType`
#
# * labels: `MType`, `model_name` and `MEntity`. Must also have `MClassType`,
-# `MNullableType`, `MVirtualType` or `MSignature`, depending on the class of
-# the represented entity.
+# `MNullableType`, `MVirtualType`, `MRawType` or `MSignature`, depending on the
+# class of the represented entity.
#
# Additional label and relationships for `MClassType`:
#
#
# * `(:MNullableType)-[:TYPE]->(:MType)`: base type of the nullable type.
#
+# Additional attribute and relationship for `MRawType`:
+#
+# * `text`: JSON array of the parts’ text.
+# * `(:MRawType)-[:LINK]->(:MTypePart)`: the parts that link to another entity.
+#
# Additional attribute and relationships for `MSignature`:
#
# * `parameter_names`: JSON array representing the list of the parameter names.
#
# MParameters are also ranked by their position in the corresponding signature.
# Rank 0 for the first parameter, 1 for the next one and etc.
+#
+# `MTypePart`
+#
+# * labels: `MTypePart`, `model_name` and `MEntity`.
+# * `rank`: position in the `MRawType`.
+# * `(:MTypePart)-[:TARGET]->(:MEntity)`: the target of the link.
module neo
-import model
+import doc::model_ext
import neo4j
import toolcontext
abort
end
+ # Get the `MEntity` associated with `node`.
+ fun to_mentity(model: Model, node: NeoNode): MEntity do
+ if node.labels.has("MProject") then return to_mproject(model, node)
+ if node.labels.has("MGroup") then return to_mgroup(model, node)
+ if node.labels.has("MModule") then return to_mmodule(model, node)
+ if node.labels.has("MClass") then return to_mclass(model, node)
+ if node.labels.has("MClassDef") then return to_mclassdef(model, node)
+ if node.labels.has("MProperty") then return to_mproperty(model, node)
+ if node.labels.has("MPropDef") then return to_mpropdef(model, node)
+ if node.labels.has("MType") then return to_mtype(model, node)
+ if node.labels.has("MParameter") then return to_mparameter(model, node)
+ abort
+ end
+
# Make a new `NeoNode` based on `mentity`.
private fun make_node(mentity: MEntity): NeoNode do
var node = new NeoNode
if return_mtype != null then
node.out_edges.add(new NeoEdge(node, "RETURNTYPE", to_node(return_mtype)))
end
+ else if mtype isa MRawType then
+ node.labels.add "MRawType"
+ var text = new JsonArray
+ var rank = 0
+ for part in mtype.parts do
+ text.add part.text
+ if part.target != null then
+ var pnode = mtypepart_node(part)
+ pnode["rank"] = rank
+ node.out_edges.add(new NeoEdge(node, "LINK", pnode))
+ end
+ rank += 1
+ end
+ if not text.is_empty then node["text"] = text
+ end
+ return node
+ end
+
+ # Build a `NeoNode` representing `mtypepart`.
+ private fun mtypepart_node(mtypepart: MTypePart): NeoNode do
+ var node = make_node(mtypepart)
+ node.labels.add "MTypePart"
+ if mtypepart.target != null then
+ var target_node = to_node(mtypepart.target.as(not null))
+ node.out_edges.add(new NeoEdge(node, "TARGET", target_node))
end
return node
end
var mtype = new MSignature(mparameters, return_mtype)
mentities[node] = mtype
return mtype
+ else if node.labels.has("MRawType") then
+ var mtype = new MRawType(model)
+ var parts = node["text"]
+ if parts isa JsonArray then
+ for p in parts do
+ mtype.parts.add(new MTypePart(model, p.to_s, null))
+ end
+ for pnode in node.out_nodes("LINK") do
+ assert pnode.labels.has("MTypePart")
+ if not pnode.out_nodes("TARGET").is_empty then
+ var rank = pnode["rank"]
+ var target = to_mentity(model, pnode.out_nodes("TARGET").first)
+ assert rank isa Int
+ mtype.parts[rank] = mtype.parts[rank].link_to(target)
+ end
+ end
+ end
+ mentities[node] = mtype
+ return mtype
end
print "not yet implemented to_mtype for {node.labels.join(",")}"
abort
return protected_visibility
else if vis == private_visibility.to_s then
return private_visibility
+ else if vis == package_visibility.to_s then
+ return package_visibility
else
return none_visibility
end
return enum_kind
else if kind == extern_kind.to_s then
return extern_kind
+ else
+ return raw_kind(kind)
end
- abort
end
# Extract the `MDoc` from `node` and link it to `mentity`.