jdk/src/java.base/share/classes/java/lang/StackTraceElement.java
author jwilhelm
Wed, 23 Mar 2016 20:14:36 +0100
changeset 37325 22145b2d3616
parent 37313 b0c043d9ad18
parent 36511 9d0388c6b336
child 41911 b3bb62588635
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37313
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    28
import java.util.Objects;
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    29
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An element in a stack trace, as returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Throwable#getStackTrace()}.  Each element represents a single stack frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * All stack frames except for the one at the top of the stack represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * a method invocation.  The frame at the top of the stack represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * execution point at which the stack trace was generated.  Typically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * this is the point at which the throwable corresponding to the stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public final class StackTraceElement implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    // Normally initialized by VM (public constructor added in 1.5)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    44
    private String moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    45
    private String moduleVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private String declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private int    lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Creates a stack trace element representing the specified execution
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    53
     * point. The {@link #getModuleName module name} and {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    54
     * #getModuleVersion module version} of the stack trace element will
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    55
     * be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @param declaringClass the fully qualified name of the class containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *        the execution point represented by the stack trace element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @param methodName the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *        represented by the stack trace element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param fileName the name of the file containing the execution point
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    62
     *         represented by the stack trace element, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *         this information is unavailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param lineNumber the line number of the source line containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *         execution point represented by this stack trace element, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *         a negative number if this information is unavailable. A value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *         of -2 indicates that the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *         is a native method
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    69
     * @throws NullPointerException if {@code declaringClass} or
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    70
     *         {@code methodName} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public StackTraceElement(String declaringClass, String methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                             String fileName, int lineNumber) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    75
        this(null, null, declaringClass, methodName, fileName, lineNumber);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    76
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    77
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    78
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    79
     * Creates a stack trace element representing the specified execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    80
     * point.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    81
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    82
     * @param moduleName the module name if the class containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    83
     *        execution point represented by the stack trace is in a named
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    84
     *        module; can be {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    85
     * @param moduleVersion the module version if the class containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    86
     *        execution point represented by the stack trace is in a named
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    87
     *        module that has a version; can be {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    88
     * @param declaringClass the fully qualified name of the class containing
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    89
     *        the execution point represented by the stack trace element
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    90
     * @param methodName the name of the method containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    91
     *        represented by the stack trace element
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    92
     * @param fileName the name of the file containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    93
     *        represented by the stack trace element, or {@code null} if
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    94
     *        this information is unavailable
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    95
     * @param lineNumber the line number of the source line containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    96
     *        execution point represented by this stack trace element, or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    97
     *        a negative number if this information is unavailable. A value
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    98
     *        of -2 indicates that the method containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    99
     *        is a native method
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   100
     * @throws NullPointerException if {@code declaringClass} is {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   101
     *         or {@code methodName} is {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   102
     * @since 9
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   103
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   104
    public StackTraceElement(String moduleName, String moduleVersion,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   105
                             String declaringClass, String methodName,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   106
                             String fileName, int lineNumber) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   107
        this.moduleName     = moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   108
        this.moduleVersion  = moduleVersion;
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7186
diff changeset
   109
        this.declaringClass = Objects.requireNonNull(declaringClass, "Declaring class is null");
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7186
diff changeset
   110
        this.methodName     = Objects.requireNonNull(methodName, "Method name is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.fileName       = fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.lineNumber     = lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
37313
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   115
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   116
    /**
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   117
     * Creates an empty stack frame element to be filled in by Throwable.
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   118
     */
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   119
    StackTraceElement() { }
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns the name of the source file containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * represented by this stack trace element.  Generally, this corresponds
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   124
     * to the {@code SourceFile} attribute of the relevant {@code class}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * file (as per <i>The Java Virtual Machine Specification</i>, Section
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * 4.7.7).  In some systems, the name may refer to some source code unit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * other than a file, such as an entry in source repository.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return the name of the file containing the execution point
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   130
     *         represented by this stack trace element, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *         this information is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns the line number of the source line containing the execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * point represented by this stack trace element.  Generally, this is
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   140
     * derived from the {@code LineNumberTable} attribute of the relevant
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   141
     * {@code class} file (as per <i>The Java Virtual Machine
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Specification</i>, Section 4.7.8).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return the line number of the source line containing the execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *         point represented by this stack trace element, or a negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *         number if this information is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public int getLineNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   153
     * Returns the module name of the module containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   154
     * represented by this stack trace element.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   155
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   156
     * @return the module name of the {@code Module} containing the execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   157
     *         point represented by this stack trace element; {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   158
     *         if the module name is not available.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   159
     * @since 9
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   160
     * @see java.lang.reflect.Module#getName()
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   161
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   162
    public String getModuleName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   163
        return moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   164
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   165
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   166
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   167
     * Returns the module version of the module containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   168
     * represented by this stack trace element.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   169
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   170
     * @return the module version of the {@code Module} containing the execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   171
     *         point represented by this stack trace element; {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   172
     *         if the module version is not available.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   173
     * @since 9
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   174
     * @see java.lang.module.ModuleDescriptor.Version
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   175
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   176
    public String getModuleVersion() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   177
        return moduleVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   178
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   179
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   180
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns the fully qualified name of the class containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * execution point represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   184
     * @return the fully qualified name of the {@code Class} containing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *         the execution point represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Returns the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * represented by this stack trace element.  If the execution point is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * contained in an instance or class initializer, this method will return
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   195
     * the appropriate <i>special method name</i>, {@code <init>} or
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   196
     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Machine Specification</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *         represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public String getMethodName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns true if the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * represented by this stack trace element is a native method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   210
     * @return {@code true} if the method containing the execution point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *         represented by this stack trace element is a native method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public boolean isNativeMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return lineNumber == -2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Returns a string representation of this stack trace element.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * format of this string depends on the implementation, but the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * examples may be regarded as typical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <li>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   223
     *   {@code "MyClass.mash(my.module@9.0/MyClass.java:101)"} - Here,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   224
     *   {@code "MyClass"} is the <i>fully-qualified name</i> of the class
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   225
     *   containing the execution point represented by this stack trace element,
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   226
     *   {@code "mash"} is the name of the method containing the execution
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   227
     *   point, {@code "my.module"} is the module name, {@code "9.0"} is the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   228
     *   module version, and {@code "101"} is the line number of the source
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *   line containing the execution point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <li>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   231
     *   {@code "MyClass.mash(my.module@9.0/MyClass.java)"} - As above, but the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   232
     *   line number is unavailable.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   233
     * <li>
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   234
     *   {@code "MyClass.mash(my.module@9.0/Unknown Source)"} - As above, but
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   235
     *   neither the file name nor the line  number are available.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <li>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   237
     *   {@code "MyClass.mash(my.module@9.0/Native Method)"} - As above, but
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   238
     *   neither the file name nor the line  number are available, and the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   239
     *   method containing the execution point is known to be a native method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * </ul>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   241
     * If the execution point is not in a named module, {@code "my.module@9.0/"}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   242
     * will be omitted from the above.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   243
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see    Throwable#printStackTrace()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public String toString() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   247
        String mid = "";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   248
        if (moduleName != null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   249
            mid = moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   250
            if (moduleVersion != null)
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   251
                mid += "@" + moduleVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   252
            mid += "/";
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   253
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   254
        return getClassName() + "." + methodName + "(" + mid +
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   255
             (isNativeMethod() ? "Native Method)" :
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   256
              (fileName != null && lineNumber >= 0 ?
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   257
               fileName + ":" + lineNumber + ")" :
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   258
                (fileName != null ?  ""+fileName+")" : "Unknown Source)")));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns true if the specified object is another
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   263
     * {@code StackTraceElement} instance representing the same execution
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   264
     * point as this instance.  Two stack trace elements {@code a} and
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   265
     * {@code b} are equal if and only if:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
   266
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *     equals(a.getFileName(), b.getFileName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *     a.getLineNumber() == b.getLineNumber()) &&
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   269
     *     equals(a.getModuleName(), b.getModuleName()) &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   270
     *     equals(a.getModuleVersion(), b.getModuleVersion()) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *     equals(a.getClassName(), b.getClassName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *     equals(a.getMethodName(), b.getMethodName())
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
   273
     * }</pre>
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   274
     * where {@code equals} has the semantics of {@link
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   275
     * java.util.Objects#equals(Object, Object) Objects.equals}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param  obj the object to be compared with this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return true if the specified object is another
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   279
     *         {@code StackTraceElement} instance representing the same
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         execution point as this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (obj==this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (!(obj instanceof StackTraceElement))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        StackTraceElement e = (StackTraceElement)obj;
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   288
        return e.declaringClass.equals(declaringClass) &&
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   289
            Objects.equals(moduleName, e.moduleName) &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   290
            Objects.equals(moduleVersion, e.moduleVersion) &&
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   291
            e.lineNumber == lineNumber &&
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   292
            Objects.equals(methodName, e.methodName) &&
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   293
            Objects.equals(fileName, e.fileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns a hash code value for this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        int result = 31*declaringClass.hashCode() + methodName.hashCode();
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   301
        result = 31*result + Objects.hashCode(moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   302
        result = 31*result + Objects.hashCode(moduleVersion);
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   303
        result = 31*result + Objects.hashCode(fileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        result = 31*result + lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private static final long serialVersionUID = 6992337162326171013L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}