1 # $Id: link.rb,v 1.6 2012/01/18 18:36:33 machan Exp $
2
3 require 'tmdoc/tmstd'
4 require 'tmdoc/tmstd/docbook'
5 require 'tmdoc/constant'
6 require 'tmdoc/model/object'
7 require 'tmdoc/model/document/abstraction'
8 require 'tmdoc/model/document/path'
9
10
11 module TmDoc
12
13 module Model::Document
14
15 module Link
16
17 class File < Abstraction::Link::Source
18 alias file_name name
19 end
20
21
22
23 class Line < File
24 attr_reader :line_num
25
26
27 def initialize(name, line_num)
28 ASSERT.kind_of name, String
29 ASSERT.kind_of line_num, Integer
30
31 @line_num = line_num
32
33 super(name)
34 end
35
36
37 def to_s
38 str = format "#%d in <%s>", self.line_num, self.name
39
40 ASSERT.kind_of str, String
41 end
42 end
43
44
45
46 class SeqOfLine < TmStd::Lsm::Collection::Sequence::Abstract
47 LSM_ELEMENT_CLASS = Line
48 end
49
50 EMPTY_LINE = SeqOfLine.new
51
52
53
54 class SeqOfLinkToLogical < TmStd::Lsm::Collection::Sequence::Abstract
55 LSM_ELEMENT_CLASS = MDA::Link::Logical
56 end
57
58
59
60 class MapOfLineNumToLinks < TmStd::Lsm::Collection::Map::Abstract
61 LSM_DOMAIN_CLASS = Integer
62 LSM_RANGE_CLASS = SeqOfLinkToLogical
63 end
64
65
66
67 class Module < Abstraction::Link::Logical
68 attr_reader :above_path
69
70
71 def initialize(name, above_path)
72 ASSERT.opt_kind_of name, String
73 ASSERT.kind_of above_path, MD::Path
74
75 ASSERT.assert(above_path.empty? || name)
76
77 @above_path = above_path
78
79 super(name)
80 end
81
82
83 def a_link_to_above_module
84 a_link =
85 if self.above_path.empty?
86 nil
87 else
88 grand_above_path, above_name = self.above_path.pop
89 ASSERT.kind_of above_name, String, self.to_s
90
91 self.class.new above_name, grand_above_path
92 end
93
94 ASSERT.opt_kind_of a_link, Module
95 end
96
97
98 def to_s
99 str = format "%s(%s)", self.name, above_path.to_s
100
101 ASSERT.kind_of str, String
102 end
103 end
104
105
106
107 class ToplevelModule < Link::Module; end
108
109
110
111 class BuiltinModule < Link::Module; end
112
113
114
115 class UnknownModule < Link::Module; end
116
117
118
119 class Class < Link::Module; end
120
121
122
123 class UnknownClass < Link::Class; end
124
125
126
127 class Property < Abstraction::Link::Logical
128 attr_reader :module_path, :uniq_num
129
130
131 def initialize(module_path, name, uniq_num)
132 ASSERT.kind_of module_path, MD::Path
133 ASSERT.kind_of name, String
134 ASSERT.kind_of uniq_num, Integer
135
136 @module_path = module_path
137 @uniq_num = uniq_num
138
139 super(name)
140 end
141
142
143 def to_s
144 str = format "%s(%s)", self.name, module_path.to_s
145
146 ASSERT.kind_of str, String
147 end
148 end
149
150
151
152 class Location < Abstraction::Document
153 attr_reader :line_num, :a_link_to_file
154
155
156 def initialize(line_num, a_link_to_file)
157 ASSERT.kind_of line_num, Integer
158 ASSERT.kind_of a_link_to_file, File
159
160 @line_num = line_num
161 @a_link_to_file = a_link_to_file
162 end
163 end
164
165 end # TmDoc::Model::Document::Link
166
167 end # TmDoc::Model::Document
168
169 end # TmDoc