0

Is there any tool which can list all static fields in source code. It is difficult to write reliable regular expression, because static field definition may have several formats, different initializers, may be spanned across several lines with line cut in many positions.

In addition, in list there should be not static methods, "static" string constants, and "static" being substring of identifier name.

I need this functionality for analyze potential GC roots or state sharing fields. I use JProfiler, but it displays only static fields for classes currently loaded by Class Loader, but I have many classes which aren't loaded during runtime yet, or it is cumbersome to make them all loaded on runtime.

I would like to have a full list of static fields from source code, so I can group them into several categories afterwards:

  • final and not final fields
  • Initialized by constant value or not constant value
  • etc.
  • I think best would probably be a documentation tool like doxygen. In doxygen enable the GENERATE_XML and EXTRACT_STATIC (and maybe EXTRACT_ALL and others depending on what has been documented) and postprocess the resulting xml files. – albert Feb 14 at 12:10
1

You can try JArchitect and its code query language to get all the static fields enter image description here

You can customize the query to get only the static fields from a project, package or a class.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.