1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Model exploration and traversing facilities
24 # Get the list of mclasses refined in 'self'.
25 fun redef_mclasses
: Set[MClass] do
26 var mclasses
= new HashSet[MClass]
27 for c
in mclassdefs
do
28 if not c
.is_intro
then mclasses
.add
(c
.mclass
)
33 # Get the list of all mclasses imported by 'self'.
34 fun imported_mclasses
: Set[MClass] do
35 var mclasses
= new HashSet[MClass]
36 for m
in in_importation
.greaters
do
37 if m
== self then continue
38 for c
in m
.mclassdefs
do mclasses
.add
(c
.mclass
)
46 # Get direct parents of 'self'.
47 fun parents
: Set[MClass] do
48 var ret
= new HashSet[MClass]
49 for mclassdef
in mclassdefs
do
50 for mclasstype
in mclassdef
.supertypes
do
51 ret
.add
(mclasstype
.mclass
)
57 # Get all ancestors of 'self'.
58 fun ancestors
: Set[MClass] do
59 var lst
= new HashSet[MClass]
60 for mclassdef
in self.mclassdefs
do
61 for super_mclassdef
in mclassdef
.in_hierarchy
.greaters
do
62 if super_mclassdef
== mclassdef
then continue # skip self
63 lst
.add
(super_mclassdef
.mclass
)
69 # Get the list of constructors available for 'self'.
70 fun constructors
: Set[MMethod] do
71 var res
= new HashSet[MMethod]
72 for mclassdef
in mclassdefs
do
73 for mpropdef
in mclassdef
.mpropdefs
do
74 if mpropdef
isa MMethodDef then
75 if mpropdef
.mproperty
.is_init
then res
.add
(mpropdef
.mproperty
)
82 # Get the list of methods introduced in 'self'.
83 fun intro_methods
: Set[MMethod] do
84 var res
= new HashSet[MMethod]
85 for mclassdef
in mclassdefs
do
86 for mpropdef
in mclassdef
.mpropdefs
do
87 if mpropdef
isa MMethodDef then
88 if mpropdef
.is_intro
and not mpropdef
.mproperty
.is_init
then res
.add
(mpropdef
.mproperty
)
95 # Get the list of locally refined methods in 'self'.
96 fun redef_methods
: Set[MMethod] do
97 var res
= new HashSet[MMethod]
98 for mclassdef
in mclassdefs
do
99 for mpropdef
in mclassdef
.mpropdefs
do
100 if mpropdef
isa MMethodDef then
101 if not mpropdef
.is_intro
and not mpropdef
.mproperty
.is_init
then res
.add
(mpropdef
.mproperty
)
108 # Get the list of methods inherited by 'self'.
109 fun inherited_methods
: Set[MMethod] do
110 var res
= new HashSet[MMethod]
111 for s
in ancestors
do
112 for m
in s
.intro_methods
do
113 if not self.intro_methods
.has
(m
) and not self.redef_methods
.has
(m
) then res
.add
(m
)
119 # Get the list of all virtual types available in 'self'.
120 fun virtual_types
: Set[MVirtualTypeProp] do
121 var res
= new HashSet[MVirtualTypeProp]
122 for mclassdef
in mclassdefs
do
123 for mpropdef
in mclassdef
.mpropdefs
do
124 if mpropdef
isa MVirtualTypeDef then
125 res
.add
(mpropdef
.mproperty
)
129 for ancestor
in ancestors
do
130 for mclassdef
in ancestor
.mclassdefs
do
131 for mpropdef
in mclassdef
.mpropdefs
do
132 if mpropdef
isa MVirtualTypeDef then
133 res
.add
(mpropdef
.mproperty
)
141 # Get the list of all parameter types in 'self'.
142 fun parameter_types
: Map[String, MType] do
143 var res
= new HashMap[String, MType]
144 for i
in [0..intro
.parameter_names
.length
[ do
145 res
[intro
.parameter_names
[i
]] = intro
.bound_mtype
.arguments
[i
]
150 fun is_class
: Bool do
151 return self.kind
== concrete_kind
or self.kind
== abstract_kind
154 fun is_interface
: Bool do
155 return self.kind
== interface_kind
159 return self.kind
== enum_kind
162 fun is_abstract
: Bool do
163 return self.kind
== abstract_kind