Ask Your Question
0

How can I get the modifiers of a variable?

asked Dec 19 '11

JasperT gravatar image JasperT
33 1 5 11

Hi, I want to get the modifiers of a variable, when it is used, can I do that?

Resource@modifiers <Entity methodOrField, Modifier>:

  <entity([
      package("subfolder"),
      class("Const"),
      field("JASPER")
    ]),static()>,
  <entity([
      package("subfolder"),
      class("Const"),
      field("JASPER")
    ]),final()>

Resource@methodBodies: <Entity method, AstNode body>:

qualifiedName("Const.JASPER")[@javaType=entity([primitive(int())]

Resource@fields: <loc fileAndPosition, Entity field>

<|project://SampleJava/src/subfolder/TestX.java|(365,6,<-1,-1>,<-1,-1>),entity([
      package("subfolder"),
      class("Const"),
      field("JASPER")
    ])

>

Resource@fieldDecls: <loc fileAndPosition, Entity field>

  <|project://SampleJava/src/subfolder/Const.java|(45,36,<-1,-1>,<-1,-1>),entity([
      package("subfolder"),
      class("Const"),
      field("JASPER")
    ])>

Big question is, if I encounter a qualifiedName of type int in an AstNode, how can I easily extract the modifiers for it? Somewhere should also be a field constructor containing the modifiers, but that is not in the methodBodies, because it's on class level.

delete close flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered Dec 29 '11

JurgenVinju gravatar image JurgenVinju flag of Netherlands
554 6 20
http://jurgen.vinju.org/

Its possible, and rather complicated. You should tie some of the relations of JDT together and use locations. Were adding better API for this now. Thanks!

link delete flag offensive edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]
Also see the Rascal Tutor.

Question tools

Follow
1 follower

subscribe to rss feed

Stats

Asked: Dec 19 '11

Seen: 13 times

Last updated: Dec 29 '11