/[eiffelstudio]/branches/eth/eve/Src/framework/code_analysis/rules/features/ca_export_can_be_restricted_rule.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/code_analysis/rules/features/ca_export_can_be_restricted_rule.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96896 - (show annotations)
Mon Mar 23 03:09:39 2015 UTC (4 years, 6 months ago) by schmisam
File size: 3547 byte(s)
Changed .node_type calls to account for void types.
1 note
2 description: "[
3 RULE #75: Feature export can be restricted
4
5 An exported feature that is used only in unqualified calls may be changed to secret.
6 ]"
7 date: "$Date$"
8 revision: "$Revision$"
9
10 class
11 CA_EXPORT_CAN_BE_RESTRICTED_RULE
12
13 inherit
14 CA_STANDARD_RULE
15
16 AST_ITERATOR
17 redefine
18 process_nested_as
19 end
20
21 create
22 make
23
24 feature -- Initialization
25
26 make
27 do
28 make_with_defaults
29 checks_library_classes := False
30 end
31
32 feature -- Access
33
34 title: STRING_32
35 do
36 Result := ca_names.export_can_be_restricted_title
37 end
38
39 id: STRING_32 = "CA075"
40 -- <Precursor>
41
42 description: STRING_32
43 do
44 Result := ca_names.export_can_be_restricted_description
45 end
46
47 feature {NONE} -- Implementation
48
49 register_actions (a_checker: attached CA_ALL_RULES_CHECKER)
50 do
51 a_checker.add_class_pre_action (agent class_check)
52 end
53
54 class_check (a_class: CLASS_AS)
55 -- Checks `a_class' for features that are exported but never called in a qualified way.
56 local
57 l_clients: ARRAYED_LIST[CLASS_C]
58 l_has_clients_outside_hierarchy: BOOLEAN
59 do
60 l_clients := current_context.checking_class.clients
61
62 across
63 current_context.checking_class.written_in_features as l_feat
64 loop
65 -- Only check features that are exported
66 if not l_feat.item.export_status.is_none then
67 from
68 l_clients.start
69 l_has_clients_outside_hierarchy := False
70 until
71 l_clients.after
72 or l_has_clients_outside_hierarchy
73 loop
74 if
75 not l_clients.item.inherits_from (current_context.checking_class)
76 and then l_feat.item.callers_32 (l_clients.item, 0) /= Void
77 then
78 l_has_clients_outside_hierarchy := True
79 elseif
80 l_feat.item.callers_32 (l_clients.item, 0) /= Void
81 and then not has_qualified_calls (l_feat.item, l_clients.item)
82 then
83 create_violation (l_feat.item.ast)
84 end
85
86 l_clients.forth
87 end
88 end
89 end
90 end
91
92 has_qualified_calls (a_feature: E_FEATURE; a_class: CLASS_C): BOOLEAN
93 do
94 found_qualified_call := False
95
96 current_feature := a_feature.associated_feature_i
97 current_feature_name := a_feature.name_32
98 a_class.ast.process (Current)
99
100 Result := found_qualified_call
101 end
102
103 process_nested_as (a_nested: attached NESTED_AS)
104 do
105 if
106 attached {ACCESS_FEAT_AS} a_nested as l_feat
107 and then l_feat.access_name_32.is_equal (current_feature_name)
108 and then attached current_context.node_type (a_nested.target, current_feature) as l_type
109 and then l_type.name.is_equal (current_context.checking_class.name)
110 then
111 found_qualified_call := True
112 end
113 end
114
115 current_feature: FEATURE_I
116 -- Feature currently being checked.
117
118 current_feature_name: STRING
119 -- Name of the feature being checked.
120
121 found_qualified_call: BOOLEAN
122 -- Has there been a qualified call found of the current feature?
123
124 create_violation (a_feature: attached FEATURE_AS)
125 local
126 l_violation: CA_RULE_VIOLATION
127 do
128 create l_violation.make_with_rule (Current)
129
130 l_violation.set_location (a_feature.start_location)
131 l_violation.long_description_info.extend (current_feature_name)
132
133 violations.extend (l_violation)
134 end
135
136 format_violation_description (a_violation: attached CA_RULE_VIOLATION; a_formatter: attached TEXT_FORMATTER)
137 do
138 a_formatter.add (ca_messages.local_used_for_result_violation_1)
139
140 if attached {STRING_32} a_violation.long_description_info.first as l_feature_name then
141 a_formatter.add (l_feature_name)
142 end
143
144 a_formatter.add (ca_messages.local_used_for_result_violation_2)
145 end
146
147 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23