A very basic analysis which identifies those classes that can never be instantiated (e.g.,
java.lang.Math) by user code.
A class is not instantiable if it only defines private constructors and these constructors
are not called by any static method and the class is also not Serializable. However,
if the static initializer creates an instance of the respective class then it is possible that
this a class is rated as not client instantiable though it is possible that an instance
exists and may even be used.
Note
A more precise analysis is available that uses the fixpoint computations framework.
,
The analysis does not take reflective instantiations into account!
,
If this class is queried (after performing the analysis) about a class that
was not analyzed, the result will be that the class is considered to be
instantiable.
This information is relevant in various contexts, e.g., to determine a
precise call graph. For example, instance methods of those objects that cannot be
created are always dead. However, this analysis only provides the information whether the
class is instantiable by client code!
val instantiableClasses = project.get(InstantiableClassesKey)
,
This analysis does not consider protected and/or package visible constructors as
it assumes that classes may be added to the respective package later on (open-packages
assumption.)
A very basic analysis which identifies those classes that can never be instantiated (e.g.,
java.lang.Math) by user code.A class is not instantiable if it only defines private constructors and these constructors are not called by any static method and the class is also not Serializable. However, if the static initializer creates an instance of the respective class then it is possible that this a class is rated as not client instantiable though it is possible that an instance exists and may even be used.
A more precise analysis is available that uses the fixpoint computations framework.
,The analysis does not take reflective instantiations into account!
,If this class is queried (after performing the analysis) about a class that was not analyzed, the result will be that the class is considered to be instantiable. This information is relevant in various contexts, e.g., to determine a precise call graph. For example, instance methods of those objects that cannot be created are always dead. However, this analysis only provides the information whether the class is instantiable by client code!
Usage
Use the InstantiableClassesKey to query a project about the instantiable classes.
val instantiableClasses = project.get(InstantiableClassesKey),This analysis does not consider protected and/or package visible constructors as it assumes that classes may be added to the respective package later on (open-packages assumption.)