Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Query for Java Static Initializer #16838

Answered by jketema
mrigankpawagi asked this question in Q&A
Discussion options

Hi, I am a junior developer and need some help with writing a query to capture the static initializer (static { ... }) of a Java class. Is this currently supported? If yes, could someone please point me to the right place in the documentation? Many thanks!

You must be logged in to vote

Hi,

In the database the static initialiser block becomes a block statement that is part of a static initialiser method. The easiest way I could find to get to it is as follows:

from Class c, StaticInitializer i, BlockStmt s
where c.getAMethod() = i and i.getBody().getAChild() = s
select s

Replies: 1 comment 2 replies

Comment options

Hi,

In the database the static initialiser block becomes a block statement that is part of a static initialiser method. The easiest way I could find to get to it is as follows:

from Class c, StaticInitializer i, BlockStmt s
where c.getAMethod() = i and i.getBody().getAChild() = s
select s
You must be logged in to vote
2 replies
Comment options

Thanks for your response! Let me try this and let you know :)

Comment options

Thank you, this worked!

Answer selected by mrigankpawagi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /