Menu

Extract the type of a VariableReference?

Developers
widheg
2009-08-26
2012-10-08
  • widheg

    widheg - 2009-08-26

    Hi all!
    How can I extract the type of a given VariableReference? For example, we have the following call to a method (i.e. a MethodReference):
    obj.foo();
    Then how do I make Recoder to report the type of 'obj'?
    Note, I can get hold of the 'obj' by calling getReferencePrefix() on my MethodReference object -- that call returns a VariableReference-object.

    Thanks for any answers and hints!

     
    • Tobias Gutzmann

      Tobias Gutzmann - 2009-08-27

      Hej,

      you should have the given ServiceConfiguration at hand. From it, you get the SourceInfo (getSourceInfo()). On it, you call getType(varRef). Therefore:

      serviceConfiguration.getSourceInfo().getType(varRef).
      You can be sure to get an instanceof of "ClassType". The code would be invalid otherwise (the only alternative to ClassType is PrimitiveType, on which no method can be called, obviously).

      Hope that helps.
      Tobias

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.