/[eiffelstudio]/branches/eth/eve/Src/framework/code_analysis/rules/control_structures/ca_object_test_failing_rule.e
ViewVC logotype

Contents of /branches/eth/eve/Src/framework/code_analysis/rules/control_structures/ca_object_test_failing_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: 3135 byte(s)
Changed .node_type calls to account for void types.
1 note
2 description: "[
3 RULE #7: Object test always failing
4
5 An object test will always fail if the type that the variable is tested
6 for does not conform to any type that conforms to the static type of the
7 tested variable. The whole if block will therefore never be executed and
8 it is redundant.
9 ]"
10 date: "$Date$"
11 revision: "$Revision$"
12
13 class
14 CA_OBJECT_TEST_FAILING_RULE
15
16 inherit
17 CA_STANDARD_RULE
18 rename
19 make_with_defaults as make
20 end
21
22 create
23 make
24
25 feature -- Access
26
27 title: STRING_32
28 do
29 Result := ca_names.object_test_failing_title
30 end
31
32 id: STRING_32 = "CA007"
33 -- <Precursor>
34
35 description: STRING_32
36 do
37 Result := ca_names.object_test_failing_description
38 end
39
40 feature {NONE} -- Implementation
41
42 register_actions (a_checker: attached CA_ALL_RULES_CHECKER)
43 do
44 a_checker.add_object_test_pre_action (agent process_ot)
45 a_checker.add_feature_pre_action (agent process_feature)
46 end
47
48 process_feature (a_feature: attached FEATURE_AS)
49 -- Sets the current feature.
50 do
51 current_feature := current_context.checking_class.feature_named_32 (a_feature.feature_names.first.visual_name_32)
52 end
53
54 process_ot (a_ot: attached OBJECT_TEST_AS)
55 local
56 l_type_1, l_type_2: TYPE_A
57 do
58 if attached a_ot.type then
59 l_type_1 := current_context.node_type (a_ot.expression, current_feature)
60 l_type_2 := current_context.node_type (a_ot.type, current_feature)
61
62 if
63 l_type_1 /= Void and l_type_2 /= Void
64 and then not has_common_child (l_type_1, l_type_2)
65 then
66 create_violation (a_ot)
67 end
68 end
69 end
70
71 has_common_child (a_t1, a_t2: attached TYPE_A): BOOLEAN
72 -- Is there a class that conforms to both `a_t1' and `a_t2'?
73 do
74 across system.classes as l_class loop
75 if
76 attached l_class.item
77 and then not l_class.item.actual_type.name.is_equal ("TYPE[G#1]")
78 and then not Result
79 and then l_class.item.actual_type.conform_to(current_context.checking_class, a_t1)
80 and then l_class.item.actual_type.conform_to(current_context.checking_class, a_t2)
81 then
82 Result := True
83 end
84 end
85 end
86
87 current_feature: FEATURE_I
88
89 create_violation (a_ot: attached OBJECT_TEST_AS)
90 local
91 l_violation: CA_RULE_VIOLATION
92 l_fix: CA_OBJECT_TEST_FAILING_FIX
93 do
94 create l_violation.make_with_rule (Current)
95
96 l_violation.set_location (a_ot.start_location)
97
98 if
99 attached {EXPR_CALL_AS} a_ot.expression as l_expr_call
100 and then attached {ACCESS_ID_AS} l_expr_call.call as l_access_id
101 then
102 l_violation.long_description_info.extend (l_access_id.access_name_32)
103 end
104
105 create l_fix.make_with_ot (current_context.checking_class, a_ot)
106 l_violation.fixes.extend (l_fix)
107
108 violations.extend (l_violation)
109 end
110
111 format_violation_description (a_violation: attached CA_RULE_VIOLATION; a_formatter: attached TEXT_FORMATTER)
112 do
113 a_formatter.add (ca_messages.object_test_failing_violation_1)
114
115 if attached {STRING_32} a_violation.long_description_info.first as l_feature_name then
116 a_formatter.add (l_feature_name)
117 end
118
119 a_formatter.add (ca_messages.object_test_failing_violation_2)
120 end
121
122 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23