Hi,
it's quite common, with java beans event / swing, to avoid the creation of anonymous classes to handle all the various events by using the utility class java.beans.EventHandler, which is used this way, for example:
button.addActionListener(EventHandler.create( ActionListener.class, someInstance, "someMethod") );
This is quite a recognizable pattern that does introspection calls to someInstance.someMethod(). IMHO, UCDetector should then not mark someMethod() as never referenced.
I understand introspection is always a problem with static dead code analysis. But here it's a common pattern that is documented and even suggested in some java documentation to avoid having to much anonymous classes that just delegates to another method.
I know it's possible to mark those methods to be ignored by UCDetector, but that mean we lose track of them in the future and, in big projects, that mean a lot of markers to add.
Could this be added as a feature request?
David D.
Anonymous
To realize this feature request we need a new setting "Search method name in java files", which searches "someMethod" (including quotes) in java files.
This setting is similar to "Search class name in files" in UCDetector preferences on "Detect" tab.
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
I am not sure if this is a bug or if I just have the preferences set up incorrectly.
I have noticed that UCDetector is reporting methods as unused when the method is used.
Here is an example of what I am talking about.
JSF application… The following is in the jsp.
The ClassFormBean has the methods: getProducerDropdownHelper()
The producerDropdownHelper attribute is spring injected
The ProducerDropdownHelper class has the method getSortByProducerMap()
Hopefully, this is clear enough to determine if the issue is on my end or if this is a bug in UCDetector.
Let me know if I can provide more information.
By the way, I really like the ease of use so far. I have got around the above issue by using Search -> File and looking for the attribute name. If it shows in the jsp, I then track to the bean to make sure if it is used or not.
Jim
From user hstoerr posted in Open Discussion
When looking for unused bean properties it would be helpful if UCDetector could optionally look for occurrences of the bean property without the get prefix in e.g. JSP files or other expression languages. I do realize that that would mark common properties like name and id as used, but this might help if the bean properties are named descriptively.
More specifically: the Method
would be counted as referenced if there is a String somethingNicelyNamed in *.jsp. Probably this feature would need a configuration of the file types recognized as expression language. It might be worth looking at the character(s) before and after the String - these should be word separators, e.g. ", ., spaces etc