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.
1
  • 1
    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
    Commented Feb 14, 2019 at 12:10

1 Answer 1

2

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 agree to our terms of service and acknowledge you have read our privacy policy.

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