fe7432591d1c949a6a17a373d98d350c2810fab3
[nit.git] / src / doc / model_ext.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Extensions to the Nit model for foreign languages.
16 module doc::model_ext
17
18 intrude import model
19 intrude import model::model_base
20
21 # A type described by a text annoted with links.
22 #
23 # For use with Nitdoc only.
24 class MRawType
25 super MType
26
27 redef var model: Model
28
29 # The parts that contitute the description of the type.
30 var parts: Sequence[MTypePart] = new Array[MTypePart]
31
32 redef fun as_nullable do
33 not_available
34 return self
35 end
36 redef fun need_anchor do
37 not_available
38 return false
39 end
40 redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do
41 not_available
42 return self
43 end
44 redef fun can_resolve_for(mtype, anchor, mmodule) do
45 not_available
46 return true
47 end
48 redef fun collect_mclassdefs(mmodule) do
49 not_available
50 return new HashSet[MClassDef]
51 end
52 redef fun collect_mclasses(mmodule) do
53 not_available
54 return new HashSet[MClass]
55 end
56 redef fun collect_mtypes(mmodule) do
57 not_available
58 return new HashSet[MClassType]
59 end
60
61 redef fun to_s do return parts.to_s
62
63 private fun not_available do
64 assert false else
65 sys.stderr.write "A `MRawType` is for documentation-purpose only so the requested operation is not available.\n"
66 end
67 end
68 end
69
70 # A part of a `RawType`.
71 class MTypePart
72 super MEntity
73
74 redef var model: Model
75
76 # The textual content.
77 var text: String
78
79 # If the part links to another entity, the targeted entity.
80 var target: nullable MEntity
81
82 redef fun name do return text
83 redef fun to_s do return text
84
85 # Return a version of `self` that links to the specified entity.
86 fun link_to(target: nullable MEntity): MTypePart do
87 return new MTypePart(model, text, target)
88 end
89 end
90
91 # The “package” visiblity.
92 #
93 # Any visibility roughly equivalent to the default visibility of Java, that is
94 # private for a collection of modules.
95 fun package_visibility: MVisibility do return once new MVisibility("package", 2)
96
97 # A class kind with no equivalent semantic in Nit.
98 fun raw_kind(s: String): MClassKind do return new MClassKind(s, false)