effect free methods in the Java Standard Library
I'm working on an analysis for Java programs that requires side-effect information about method calls. For standard library classes, I would like to compile a list of methods with read-only parameters. That is, methods that don't modify their arguments, or anything reachable from their arguments. I can infer a lot from the javadocs, but that will take time.
Could anyone suggest an easier reference or method for determining whether standard method calls modify their arguments? Is reading through the each javadoc entry really the best way?
Thanks!
EDIT: A bonus would be identifying methods that have no side-effects on the object either. For instance, stack.pop() would whereas stack.size() would not.
Well, all methods taking only primitive types/strings/Object/generic types as parameters should satisfy you without further consideration. And for java.lang and java.util this should cover most of the methods.
But you'd really better to limit packages you want to process, because standard jdk offers huge library of classes for all tasks and purposes.
edit
It's somewhat fuzzier for generic types declared as E extends ModifiableObject
, so see for yourself.
You might try running a type inference engine against the source code of the JDK.
Perhaps the paper Type qualifier inference for Java may be of use. (Full text does not appear to be online though)
Our DMS Software Reengineering Toolkit is a general purpose customizable program analysis and transformation tool. It has a Java Front End that parses Java and produces symbol tables, class inheritance relations, control and data flow information.
From this information, local information about whether a method M directly modifies an argument or anything reachable from an argument can be computed. A call graph can be constructed, and anything modified by a method X called directly or indirectly by M. That's in effect your answer. You'd have to apply this to the source of the code of interest, in your case, the Java Standard library.
Configuring DMS to do this isn't trivial even with all the supplied information. OTOH, this answer is going be pretty accurate (modulo conservative assumptions and reflection), repeatable, and easy to apply to any method you choose. Doing this by hand via Javadocs is likely to be extremely time consuming and error prone.
链接地址: http://www.djcxy.com/p/1424.html上一篇: 用于在类中封装Shell命令的模式
下一篇: 在Java标准库中使用免费的方法