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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93177 - (show annotations)
Mon Oct 28 22:16:38 2013 UTC (6 years, 1 month ago) by zurfluhs
File size: 2871 byte(s)
Code Analysis:

- formatted version of rule violation description
- refactorings and other minor changes
1 note
2 description: "Summary description for {CA_UNUSED_ARGUMENT_RULE}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7 class
8 CA_UNUSED_ARGUMENT_RULE
9 inherit
10 CA_RULE
11
12 create
13 make
14
15 feature {NONE} -- Initialization
16 make
17 do
18 -- set the default parameters (subject to be changed by user)
19 is_enabled := True
20 create {CA_WARNING} severity
21 create violations.make
22 end
23
24 feature {NONE} -- Activation
25
26 register_actions (a_checker: CA_ALL_RULES_CHECKER)
27 do
28 a_checker.add_feature_pre_action (agent process_feature)
29 a_checker.add_body_pre_action (agent process_body)
30 a_checker.add_body_post_action (agent post_process_body)
31 a_checker.add_id_pre_action (agent process_id)
32 end
33
34 feature -- Properties
35
36 title: STRING
37 once
38 Result := "Unused argument"
39 end
40
41 description: STRING
42 once
43 Result := "A feature should only have arguments which are actually %
44 %needed and used in the computation."
45 end
46
47 options: LINKED_LIST[CA_RULE_OPTION]
48 once
49 create Result.make
50 end
51
52
53 is_system_wide: BOOLEAN
54 once
55 Result := False
56 end
57
58 format_violation_description (a_violation: CA_RULE_VIOLATION; a_formatter: TEXT_FORMATTER)
59 do
60 a_formatter.add_string ("Routine '")
61 if attached {FEATURE_AS} a_violation.long_description_info.first as l_feature then
62 a_formatter.add_feature_name (l_feature.feature_name.name_32, a_violation.affected_class)
63 else
64 a_formatter.add_char ('?')
65 end
66 a_formatter.add_string ("' has unused arguments.")
67 end
68
69 feature {NONE} -- Rule Checking
70
71 process_feature (a_feature_as: FEATURE_AS)
72 do
73 current_feature := a_feature_as
74 end
75
76 process_body (a_body_as: BODY_AS)
77 do
78 has_arguments := (a_body_as.arguments /= Void)
79 if has_arguments then
80 routine_body := a_body_as
81 create arg_ids.make
82 across a_body_as.arguments as l_args loop
83 across l_args.item.id_list as l_ids loop arg_ids.extend (l_ids.item) end
84 end
85 end
86 end
87
88 post_process_body (a_body: BODY_AS)
89 local
90 l_violation: CA_RULE_VIOLATION
91 do
92 if has_arguments and then not arg_ids.is_empty then
93 create l_violation.make_with_rule (Current)
94 l_violation.set_affected_class (checking_class)
95 l_violation.set_location (routine_body.start_location)
96 l_violation.long_description_info.extend (current_feature)
97 violations.extend (l_violation)
98 end
99 end
100
101 process_id (a_id_as: ID_AS)
102 local
103 id, j: INTEGER
104 do
105 -- TODO: ignore IDs from argument declaration!
106 if has_arguments then
107 id := a_id_as.name_id
108 -- Remove the ID from the argument list. Since it has appeared
109 -- this argument does not violate the rule.
110 if arg_ids.has (id) then
111 j := arg_ids.index_of (id, 1)
112 arg_ids.go_i_th (j)
113 arg_ids.remove
114 end
115 end
116 end
117
118 has_arguments: BOOLEAN
119 current_feature: FEATURE_AS
120 routine_body: BODY_AS
121 arg_ids: LINKED_LIST[INTEGER]
122
123 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23