How to get the name of a method?

How can I get the name of a method, before measure its time of execution?

[url
http://java.sun.com/developer/JDCTechTips/2003/tt0318.
html#2]DISCOVERING THE CALLING METHOD NAMEThis article uses Throwable.getStackTrace() which has been around longer than the one I mentioned (Thread.getStackTrace()):
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html#getStackTrace()
I actually meant to show Throwable.getStackTrace() in my original post but when I did a search on it Thread's was the first one I came across.

Similar Messages

  • How to get the name of the current tab.

    Hi Experts,
    I have two tabs in my tab strip and a button common to both the tabs.Can you please let me know how to get the name of the current tab in the event method of the push button.
    Thanks in advance.
    Regards,
    Arun

    1.Declare an Action for OnSelect event of Tabstrip. This event is triggered whenever any change in tab occurs.
    2. Declare an Import Parameter in this method
       Tab type String.
    3. This parameter has value of the selected TAB.
    4. You can set this value in some Attribute in Attribute Tab in this event only (OnSelect):
         wd_this->Att  = Tab.
    Att is the attribute created by you in Attributes Tab of View. ( of type String)
    5. Now the selected Tab ID is stored in this Attribute Att.
    6. In the Onaction of Button , retrieve the selected tab value from this attribute using :
               Data : lv type string.
                lv =  wd_this->Att
    Now lv has your selected TAB ID.
    I hope it would help you.
    Edited by: Saurav Mago on Oct 13, 2009 2:22 PM

  • How to get the name of a Data Element of a generic Table!

    Hi guys!
    In my function i have the following import paramenter
    i_outtab type standard table
    now i import a table and i want to get the dataelement of the fields.
    is there a way to do this??

    Hello Thomas
    Perhaps the following sample report may be useful for you.
    *& Report  ZUS_SDN_RTTI_STRUCT_COMPONENTS
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1145711"></a>
    *& Thread: How to get the name of a Data Element of a generic Table!
    REPORT  zus_sdn_rtti_struct_components.
    TYPE-POOLS: abap.
    TYPES: BEGIN OF ty_s_outtab.
    TYPES: bukrs    TYPE bukrs.
    TYPES: kunnr    TYPE kunnr.
    TYPES: END OF ty_s_outtab.
    DATA: gdo_data    TYPE REF TO data.
    DATA: gs_outtab   TYPE ty_s_outtab.
    DATA: go_typedescr  TYPE REF TO cl_abap_typedescr,
          go_structdescr  TYPE REF TO cl_abap_structdescr,
          go_datadescr    type ref to cl_abap_datadescr.
    DATA: gs_comp        TYPE abap_compdescr,
          gd_dtel        type string,
          gt_dfies        type ddfields.
    FIELD-SYMBOLS:
      <gs_struct> TYPE ANY.
    START-OF-SELECTION.
      BREAK-POINT.
      GET REFERENCE OF gs_outtab INTO gdo_data.
      ASSIGN gdo_data->* TO <gs_struct>.
      go_typedescr = cl_abap_typedescr=>describe_by_data( <gs_struct> ).
      go_structdescr ?= go_typedescr.
      BREAK-POINT.
      LOOP AT go_structdescr->components INTO gs_comp.
        go_datadescr = GO_STRUCTDESCR->GET_COMPONENT_TYPE( gs_comp-name ).
        gd_dtel = go_datadescr->get_relative_name( ).
        write: / syst-tabix, 'Data element =', gd_dtel.
      ENDLOOP.
    END-OF-SELECTION.
    Regards
      Uwe

  • How can i get the name of a method

    i have a method which is calling another method.
    how can this submethod get the name from the main method?
    Thanks
    Thorsten

    There was a post about this a while ago, but I can't find it.
    Check out the getStackTrace method of Throwable (not the printStackTrace method). getStackTrace returns a StackTraceElement array. Each StackTraceElement has a getMethodName() method. In the returned array, the StackTraceElement at index 0 is the stack frame that the Throwable was created in, and the element at index 1 is the stack frame that your method was called from.
        public String getCurrentMethodName () {
            StackTraceElement[] st = (new Throwable()).getStackTrace();
            // Index 0 is the stack frame of "getCurrentMethodName"
            // Index 1 is the stack frame of the method that called this.
            // Index 2 is the stack frame of the method that called THAT.
            // Note that st[1] should always exist because this method
            // will always be called from another method (main, at very
            // least).  
            return st[1].getMethodName();
        public void myMethod () {
            System.out.println("The name of this method is " + getCurrentMethodName());
        };Hope that helps. I didn't test it, but it should work.
    Jason

  • How to get the name of tag or variable

    Hi everyone,
    I am a newbie, I have problem on getting the name or tag of the variable from OLE for Processing Control(OPC) server, could anyone tell me how I can get the name of tag or variable from writting vb codes or please direct me to any helpful information. Here are
    my codes,
    Dim ItemsDef(NBR_ITEMS) As String
    Dim DeviceAddress As String
    Dim IndItem As Long
    DeviceAddress = "MBT:152.160.178.60"
    'Preparing the Handles for "AddItems"
    For IndItem = 1 To NBR_ITEMS
    ItemsDef(IndItem) = DeviceAddress & "!40000" & Format(IndItem) '40000 is the memory location of variable in the OPC, how can I get the variable name, what is the code or syntax?
    Next
    blah...
    Thank you,
    Calvin

    Hi Calvin,
    If you are looking for general information and examples about OPC, then we have lots of places for you to browse!
    Here is a small list, and you can probably find other links within these documents:
    **If you have Measurement Studio from National Instruments, then you can look at the "Measurement Studio Reference" help file. Search for OPC and in the overview you will find the methods for accessing the items on an OPC server.
    **Elsewhere in the help file, you can find a link to this Application Note on our developer zone
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?​openagent&F4921B34CA8F4A9786256874005BE3F7&cat=7CD​A3E51FEFC4AA2862568B80071A1E2
    **One more resource is http://www.ni.com/opc
    **Probably the most useful will be the examples yo
    u can find on our web site. You can go to http://www.ni.com/support and in Option 3 search the Example Code database for "opc".
    In the first example program (Controlling OPC Servers with the OPC Automation API in Visual Basic) that you should get when searching for "opc" in the example programs database, look for the line with this code: "browser.GetItemID(leaf)". There you can see the way the program creates an OPCBrowser from the server instance, and then gets the servers available items for use by the client. This sounds like the specific information you are looking for with the variable name.
    If you aren't able to find out your answer here or in the various help resources, then please feel free to contact us at National Instruments at http://www.ni.com/ask
    Regards,
    John N
    Applications Engineer
    National Instruments

  • How to get the name of the class which is currently in use

    Hi all,
    I have two classes Mother and Child, and I use this code to print the name of the class in use
      DATA m TYPE REF TO zmother.
      DATA class_name type string VALUE 'CHILD'.
      CREATE OBJECT m TYPE (class_name).
      CALL METHOD m->PrintName .
    So, what is the source code that I have to put in the PrintName methode?
    Thanks.

    Ok, but how can I get the name of the object class that calls the methode!
    REPORT  ztest_method.
    *       CLASS c1 DEFINITION
    CLASS c1 DEFINITION.
      PUBLIC SECTION.
        METHODS: get_data.
    ENDCLASS.                    "c1 DEFINITION
    *       CLASS c1 IMPLEMENTATION
    CLASS c1 IMPLEMENTATION.
      METHOD get_data.
    ****** What is the code to put here to know the name of this Class?*
      ENDMETHOD.                    "get_data
    ENDCLASS.                    "c1 IMPLEMENTATION
    DATA oref TYPE REF TO object.
    DATA: method TYPE string.
    DATA: cla_name(20).
    START-OF-SELECTION.
      cla_name = 'C1'.
      CREATE OBJECT oref TYPE (cla_name).
      BREAK-POINT.
      CALL METHOD oref->(method).

  • How to get the name and value of an attribute on a node/element that is not a child

    Hello,
    Can someone shed some wisdom on how I can compare 2 xml nodes for differences.
    My main challenge is I need to use the attributes/values of 'ProductDescription' and 'Features' as 'key' to identify the same node in
    another doc with the same layout, but different content.
    I am having trouble getting the name of the attribute on the node, 'ProductDescription' and 'Features'.  I can only seem to get the node names, but not the attributes on the node.  I need the name, because it can be different from doc to doc, so
    I can't hardcode this.
    Can someone please help with how to retrieve an attribute name/value on a node that is not a child.  Here's an example of what
    my xml looks like:
    DECLARE
    @myDoc1 xml
    ,@mydoc2 xml
    DECLARE
    @ProdID int
    SET @myDoc1 ='<ProductDescription ProductID="1" ProductName="Road Bike">
    <Features  featureID  = "1" featureName = "body">
      <Warranty>1 year parts and labor</Warranty>
      <Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    <features featureID = "2" featureName = "seat">
      <Warranty>1 year parts and labor</Warranty>
      <Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    </ProductDescription>
    SET @myDoc2 ='<ProductDescription ProductID="1" ProductName="Road Bike">
    <Features  featureID  = "1" featureName = "body">
      <Warranty>2 year parts and labor</Warranty>
      <Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    <features featureID = "2" featureName = "wheel">
      <Warranty>1 year parts and labor</Warranty>
      <Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    </ProductDescription>
    I need to compare the attributes of 'ProductDescription' and 'Features' from @mydoc1 against @mydoc2 to see if they are the same based on those 2 nodes first.  If they are, then i want to show the difference in the child elements. 
    This will eventually be an outer join to give me the differences betw the 2 docs based on those key values (node attributes).
    I used node('//*') for the path, and value('local-name(../.)', 'varchar(50)') as element
    ,value('.[not(@xsi:nil = "true")]','VARCHAR(255)') AS new_value
    ...etc...
    but that only gives me the node names, and the child elements.  It does not give me back the attribute names and values from the node itself.
    Thanks in advance for your help.
    cee

    Are you looking for something like this:
    DECLARE @myDoc1 xml
    SET @myDoc1 ='<ProductDescription ProductID="1" ProductName="Road Bike">
    <Features  featureID  = "1" featureName = "body">
      <Warranty>1 year parts and labor</Warranty>
      <Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    <Features featureID = "2" featureName = "seat">
      <Warranty>1 year parts and labor</Warranty>
      <Maintenance>2 year parts and labor extended maintenance is available</Maintenance>
    </Features>
    </ProductDescription>'
    SELECT T.c.value('local-name(.)', 'nvarchar(50)') AS name,
           T.c.value('.', 'nvarchar(50)')  AS value
    FROM   @myDoc1.nodes('ProductDescription/@*') AS T(c)
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to get the name of the attachment in Sender Mail Adaper?

    hi mates,
    I've scenario a where in I need to pick up a mail with an attachment and change its extension and send it to target system using file adapter.
    I'm able to pick up the mail with attachment using sender mail adapter but not able to get the name of the attachment so that I can use it in mapping or on the adapter configuration. How do I read the name of the attachment and manupulate it?
    I looked at the thread sender mail adapter - attachment name But the solution is not described. I think Stefan is talking about the SP!2 for PI 7.0. I'm on XI 3.0 what is the equivalent SP for that, SP20? Stefan, can you please throw me more light on it?
    I appreciate your valuable inputs
    thx in adv
    praveen

    Thanks Aamir.
    Earlier I replied to that thread asking for more details...but did not see the response...
    anyways, thanks for your quick help..
    but I wonder abt the PI SP12/ XI SP20 pre-requisite. We can have adapter modules on SPs lower than PI SP12/XI SP20 as well, can we not?
    thanks
    praveen

  • How to get the name before @ in an email id

    Hi All,
    How can i get the name before '@' in an email id, for example if i have [email protected], how do i get 'abc' in my query result.
    Thanks

    thinkingeye wrote:
    Hi All,
    How can i get the name before '@' in an email id, for example if i have [email protected], how do i get 'abc' in my query result.
    Thankscombine INSTR() & SUBSTR() functions

  • How to get the name of a duplicated control or created control and add a callback to it

    Hi All,
    Depending on how many input points I need, I am duplicating a numeric or string input with the DuplicateCtrl function. My question is, how do I get the name and id of the control that was just created, and how can i assign a callback to it? Alternately, would it be better to create a fresh ctrl instead of duplicating?
    Thanks in advance!
    Solved!
    Go to Solution.

    Hi TurboMetrologist,
    why are you trying to get the control constant name? Keep in mind that you cannot use that name to address the control; control names are actually simply macros in the include file associated to the UIR, that is, the compiler preprocesses the code and wherever it finds PANEL_CONTROL names substitutes the corresponding numeric value as parameters to the functions (and consequently 'control' parameter is an int and not a char*)
    That is why NewCtrl () or DuplicateCtrl () functions return a control ID: it is the handle to the new object, our only way to manipulate it. You will need to store this handle into a non-volatile memory so that you can access it durng program life.
    Additionally, there are other ways to assign some particular meaning to a control than swiching on the control constant name. You could for example use the callbackData parameter to differentiate between different copies of a control.
    Let me explain with an example. You told that you need several inputs (dynamically created as you don't know in advance how many of them to use); a clean solution could be to:
    Design a master copy of one control in the UIR editor, where it is easy to customize it; assign also a callback function, if it has to be common to all copies of the control
    Programmatically assign a callbackData value to that control, e.g. SetCtrlAttribute (..., ..., ATTR_CALLBACK_DATA, (void *)1);
    Duplicate the control and then assign a different callbackData
    for (i = 2; i < 5; i++) {
       handle = DuplicateCtrl (...);
       SetCtrlAttribute (..., handle, ATTR_CALLBACK_DATA, (void *)i);
    By operating this way, every time the control callback is fired by any control it will receive the assigned callbackData, and you will be able to differentiate your code by a simple switch:
    switch ((int)callbackData) {
       case 1:    // The master control
          break;
       case 2:    // The first duplicated control
          break;
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How to get the name of a cell style

    Hi, All,
    I have a question about how to get the cell style name used by each cell in a table.
    I looked at all the fonctions provides by: ICellStylesFacade and ITableStylesFacade, but I did not find the fonction I need.
    Can someone give me some advises?
    Thanks in advance!!

    String myFileName = request.getRequestURL().substring(request.getRequestURL().lastIndexOf("/")+1);
    or with javascript
    <H1><script>document.write(document.location.href.substring(document.location.href.lastIndexOf("/")+1))</script></H1>
    bye! :)

  • How to get the name of a field without specifying it as a string (somehow v

    Is it possible to get the name of a field (or method) somehow via the class in which it is declared?
    The reason why I ask is, that quite often the name of a field is important, because the name is the anchor for further processing, like for example when using reflection (e.g. Class.getfield(“NameOfTheField”)).
    Assume you have class FooSimple with the field “String firstName”.
    Now you would do something like this:
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField("firstName");
    The problem is, that the string “firstName” is kind of “hard coded”. When the name of the field in class FooSimple changes (e.g. to “theFirstName”), the invocation will not work anymore when you forget to change the string too.
    I think it would be very helpful to have access to the name of the field directly via the class by doing something like this.
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField(FooSimple.firstName.fieldName);
    The Java Compiler would then resolve “FooSimple.firstName.fieldName” to the string “firstName”. When later the name of the field is changed, the IDE would change the name everywhere where it is used. So if the name of the field would be changed to “theFirstName” the IDE would also change the statement to
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField(FooSimple.theFirstName.fieldName);
    A technique like this would be in my opinion much more safety and more generic.
    Any ideas?
    Best Regards.

    Well, I think the discussion is going in a wrong direction because the original issue was not to discuss if it is worth coding some helper classes or a framework or that like. Let me bring it back to my original point.
    Basically you can reduce my original question to this:
    Currently it is possible to use the reflection API on a class level without specifying the name of the class with a string constant.
    My issue is, that I think it would be a nice extension for Java, if the same would be possible for field variables of a Java class. Currently the only way you can do this is by specifying the field variable with a string constant.
    Let me bring some motivations which brought me to this issue.
    Assume you have an entity bean which represents a DB table and you use Java Persistence (either JPA or something like Hibernate). Then you would have a class looking like this (very simple sample to make this reply shorter).
    @Entity
    @Table(name = "PERSON")
    public class Person implements Serializable {
         @Column(name = "NAME")
         private String name;
    // … constructor, getter, setter, etc. not listed here
    }The whole issue of the design of JPA is, that such entity beans represent the mapping between the object model and the DB model, the mapping is expressed with annotations.
    Okay, now let’s assume you write a query in Query Language, e.g.
    String sql = “select p from Person p where name = :name”;“name” is the name of the field variable, “:name” is the parameter you later set with “Query.setParameter” method.
    What is not so nice is the fact, that you use the name of the class and the name of the field variables “hardcoded” to construct the query. Now you could think that basically this information is part of your entity class. First you start with the name of the class (i.e. the table name) to decouple this “hardcoding”.
    You could write instead:
    String sql = “select p from “ + Person.class.getSimpleName() + “ p where name = :name”;This is really nice, because whenever you change the name of your Person class, this change happens automatically for the sql statement as well.
    I think the next thoughts are obvious, now, since you have decoupled the “hardcoded” part of the name of the class, you would like to do the same for the names of the field variables. But now you are stuck, there is no way to do this using a similar technique like for the name of the class. Either you stay with the query as it is now, or, to make it a little bit better, you code string constants for the field variables and use them. This issue brought me to the point that I think it would be nice to have the possibility to get the name of a field variable in a similar way as you can get it for the name of the class.
    Conceptually it is just to go one level deeper, i.e.
    first level is to get the name of a class
    second level is to get the name of the field variable of a class.
    Another sample would be, if you want to code something by using reflection. You have perfectly access to the reflection API starting at the class level like Person.class.allTheNiceReflectionMethods. There is no need to specify the class first with a string constant first, you directly start with the class, you can even be generic and just work on the Class.class level and still have access to all these nice methods to get out the information you need.
    But if you need to start with a very specific field variable (like in the sample above), you must go by using a string constant like Person.class.getDeclaredField(“name”).
    So basically I think that there exist already millions of lines of Java code where a field variable is specified for further processing, especially in combination with the reflection functionality and everywhere the field variables are specified by these string constants in double quotes. I would assume, that everyone has the same problem, once changing the name of the field variable means to take care that also the content of the string which specifies the name of the field variable is changed.
    I am wondering why one of the replies commented, why the name of a field variable is changed, it sounds to me that this is something which basically never happens. I don’t know, I think that this happens actually quite often and thanks to all these nice IDEs and their “rename” feature this is usually no problem. From time to time names of classes change, name of field change, yes, they are often even completely rewritten, new field variables come in some are deleted, whatever it is. The way I currently can access the name of a class makes the code safer, because when I consequently go with Class.class.getSimpleName I always know, that when I rename the class all these statements are changed too If I delete such a class, I at least get a compile error.
    My very simple issues is, that I think it would be nice to have the same comfort not only on a class level but also on the level of field variables, nothing more, nothing less.
    To be honest, I have not browsed the forum yet if such an issue was already raised by other people (I will do this now), but somehow it is hard to imagine, that I am the first one.
    Best regards.

  • How to get the name of the file parent

    Hi,
    i have a file in this location
    File file = new File(MyFile.doc)
    file.getParent(); returns
    C:\Documents and Settings\Administrator\xyz
    now from the string obtained i just want to get the value "xyz".i.e. i want to get the name of the parent directory.
    how is it possible

    You may use String.indexOf()if(file.getParent().indexOf("/myProject/myPackage") != -1) {
        ...Or you might use regular expressions and Matcher class (or String.matches()) in case of higher complexity.

  • How to get the name of a class invoking

    Can a method get the name of the class invoking it?
    As:
    public void myMethod(){
       System.out.println("the name of the class invoking this method is: " + XXXXX);
    }Edited by: Maria1990 on Aug 17, 2010 8:46 AM

    Maria1990 wrote:
    .getStackTrace() gives me an array with the all details.Or, if you only care about the class, ask a SecurityManager.
    public final class ClassUtils {
        public static final Class[] getClassContext() {
            return new SecurityManager() {
                protected Class[] getClassContext(){return super.getClassContext();}
            }.getClassContext();
        private ClassUtils() {};
        public static final Class getCallingClass() { return getClassContext()[2];}
    }

  • How to get the name of the subform

    Hi All,
    My form is designed in the below structure.
    masgterpage-->form1-->table
                                  -->subform
    How can i get the name of the subform dynamically(as it varies from page to page, but the rest of the structure is same).
    Please help me.
    Thank you,
    Saravanakumar.

    Hi there,
    the name property would be the correct attribute to get the subform name, just by looking at the code it doesn't seem like it's doing the right thing
    I am assuming that you send Main in the function countChk() which would look something like this
    countChk(Main);
    And you probably want to make sure you are entering the right subform so you need to keep that loop at the end of the function
    but if you want to get through all the checkboxes inside that subform you must do a loop through that node to find each checkbox
    I am assuming that the function would probably look something like this
    function countChk(vNode) {//Starts vNode with Main
         for (var i = 0; i < vNode.nodes.length; i++) {
              if (vNode.nodes.item(i).className === "field") {
                   if (vNode.ui.oneOfChild.className === "checkButton") {
                        if (vNode.items.nodes.length > 1) {
                             if (vNode.value.oneOfChild.value == 1) {
                                  nChk++ ;
              }else if (vNode.nodes.item(i).className === "subform"){
                   if (vNode.nodes.item(i).name === "Door_Subform"){
                        countChk(vNode.nodes.item(i));
         }//endloop
    Hope this help!

Maybe you are looking for

  • Hyperion Enterprise web error message

    Hi, I am using Hyperion Enterprise 6.5 version, When i tried to enable web version of Hyperion enterprise web by browsing http:\\localhost\Heweb from the server Server Error in '/HEWeb' Application. Module not found:he.hecontainer Object variable or

  • Bars & Jutter

    Sorry if this question doesnt make sense.  Im so confused I dont even know what day of the week it is So Ive had some problem with bars being at the sides of my video, I read the forums and realised the project/video/output settings needed to match. 

  • I had my IMac unplugged for about a week plugged back in know it's asking for a keychain password???

    I had my iMac unplugged for about a week plugged it back in and now it's asking for a keychain password

  • How do I change the page order in Numbers

    I have a simple three page document/ In the top left it says "sheet 1, 3 pages". I want to change the order of page I and 2. Simple, one would think, but I cannot figure out how to do it without a tricky cut/paste operation. Surely one would think yo

  • Database query in toplink

    hi all, I need to fetch single row from table and have to print it on JSF page in outputText and inputputText boxes.... what should be the procedure??? how to write the query? and the resultset that is retrieved is in the form of vector how to put th