abapOpenChecks icon indicating copy to clipboard operation
abapOpenChecks copied to clipboard

Feature: check for class/object member access without 'me'/class-name

Open smb opened this issue 5 years ago • 3 comments

class/object member access should always use either 'me' or the class name:

good:

me->my_variable = i_param. cl_my_class_name=>do_nothing( ). me->do_something( ). me->obj->do_something_else( ).

bad (using same variables / methods as above):

my_variable = i_param. " is my_variable local or class/object member? do_nothing( ). " object method or static call? local definition or inherited? do_something( ). " object method or static call? local definition or inherited? obj->do_something_else( ). " is obj local or class/object member?

could be much more complex with multiple chained objects, methods returning interfaces/classes/objects, etc.

as you already mentioned it's going to be difficult to implement this kind of check so i will leave this here for now, maybe there are some ideas / approaches out there.

smb avatar Apr 15 '19 21:04 smb

good and bad in above depends on the development guidelines, so suggest it is a setting what the user prefers

in case variables are prefixed, no need for the "me->" and class names

larshp avatar Apr 16 '19 05:04 larshp

yep - you are right, user settings would be great.

smb avatar Apr 16 '19 12:04 smb

Hmm.. I don't know if this is really necessary. And since this is not recommended by SAP (see Styleguides) I don't think this is needed. - At least not for instance method. Especially because methods should be instance methods by default I'd say, that the check should only have a look at static method calls. And if there isn't the class name added, then throw a warning, error, etc. ( user setting ) so my suggestion is something like this:

class zcl_my_class implementation. 
  " good - no CodeInspector notification
  method good_example. 
      zcl_my_class=>static_method_call( param ). 
      instance_method_call( param ). " same like me->instance_method_call( param ).
  endmethod.  

  " bad - CodeInspector does not like the static method call 
  method bad_example. 
      static_method_call( param ). " CodeInspector will throw a warning
      instance_method_call( param ).
  endmethod. 
endclass. 

what do you think?

DennstedtB avatar Aug 14 '19 06:08 DennstedtB