6 Replies Latest reply on Feb 23, 2005 8:27 AM by chiba

    Can I get info about containing object of some methodCall?

    rezahay

      Hello,
      Suppose I have the following MethodCall expr:

      ..........................
      someObj.someMethod
      ..........................

      If I use:

      curMethod.instrument(new ExprEditor()
      public void edit(MethodCall m) throws CannotCompileException {
      ...............

      then I can get information about the methodCall "someMethod". For analysis purposes I will also get information about "someObj", that the method is a method of the object "someObj". Is it possible to get such information using ExprEditor? Or I should get in another way and how?

      Thanks in advance

        • 1. Re: Can I get info about containing object of some methodCal
          chiba

          ExprEditor tells you the static type of someObj but
          it cannot show you the real value of someObj since
          ExprEditor runs during compile time or load time;
          the value of someObj is a runtime value, which does
          not exist at compile time.

          • 2. Re: Can I get info about containing object of some methodCal
            rezahay

            You are absolutely right. I want actually static information about "someObj", like object-type, ... .

            Would you please tell me how I can get this information?

            Thanks

            • 3. Re: Can I get info about containing object of some methodCal
              sirrurg

              Hi,

              simply have a look at the API oder better at the Tutorial too, there
              i guess u can find everything u want.
              The process of getting this info should be sth like this:

              1) load class
              2) get desired method
              3) use your XYZExprEditor, which should inherit from from javassist.expr.ExprEditor
              4) call CtMethod.instrument(XYZExprEditor) (of course in this case CtMethod should be an instance the method u want to look at)
              5) within your XYZExprEditor, there is a Method edit(MethodCall ...)
              which identifies an call to a method within a method body.

              With this class MethodCall u can get the desired infos i guess.

              Hopefully this info helped u a bit and i didnt make a mistake

              Bye

              • 4. Re: Can I get info about containing object of some methodCal
                rezahay

                Hi,

                Thank you for your response. But it doesn't solve my problem. As you can see from my previous mailing, I have already used ExprEditor to get information about "someMethod" in the following method-call expression:
                ..........................
                someObj.someMethod
                ..........................

                But I need information about "someObj". I need just static information like the name of "someObj", it type (class), ... .

                The question is: How can I get such static information about "someObj" using javassist?

                Thanks.

                • 5. Re: Can I get info about containing object of some methodCal
                  sirrurg

                  Hmmm ...
                  and sth like this doesnt solve ur problem?!?

                  
                  public void edit(MethodCall m) {
                  
                   CtClass c = m.getMethod().getClass();
                   c.getName();
                   ....
                  }


                  • 6. Re: Can I get info about containing object of some methodCal
                    chiba

                    I hope my reply is not too late.

                    The question is: How can I get such static information about "someObj" using javassist?


                    The real static information of the target object is quite restricted
                    probably more than you expect. The only information is the static
                    type of the target object, which is the class declaring the method.
                    For example,

                    String s = "foo";
                    int s = s.concat("bar").length();

                    In this example, the target expression of length() is s.concat("bar")
                    and it does not have a name. The only static information is the type
                    of the target expression is String.