001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Dmitry B. Yershov
019: * @version $Revision: 1.1.2.1.4.3 $
020: */package java.lang;
021:
022: import java.io.Serializable;
023:
024: /**
025: * @com.intel.drl.spec_ref
026: */
027: public final class StackTraceElement implements Serializable {
028:
029: private static final long serialVersionUID = 6992337162326171013L;
030:
031: private final String declaringClass;
032:
033: private final String methodName;
034:
035: private final String fileName;
036:
037: private final int lineNumber;
038:
039: /**
040: * This method satisfies the requirements of the specification for the
041: * {@link StackTraceElement#StackTraceElement(String, String, String, int)
042: * StackTraceElement(String declaringClass, String methodName,
043: * String fileName, int lineNumber)} method.
044: * <p>
045: * Note that currently this constructor is not used by the VM.
046: * @api2vm
047: */
048: public StackTraceElement(String declaringClass, String methodName,
049: String fileName, int lineNumber) {
050: this .declaringClass = declaringClass.toString();
051: this .methodName = methodName.toString();
052: this .fileName = fileName;
053: this .lineNumber = lineNumber;
054: }
055:
056: /**
057: * @com.intel.drl.spec_ref
058: */
059: public boolean equals(Object obj) {
060: if (obj == this ) {
061: return true;
062: }
063: if (obj != null && obj instanceof StackTraceElement) {
064: StackTraceElement ste = (StackTraceElement) obj;
065: return declaringClass.equals(ste.declaringClass)
066: && methodName.equals(ste.methodName)
067: && (fileName == ste.fileName || (fileName != null && fileName
068: .equals(ste.fileName)))
069: && lineNumber == ste.lineNumber;
070: }
071: return false;
072: }
073:
074: /**
075: * @com.intel.drl.spec_ref
076: */
077: public String getClassName() {
078: return declaringClass;
079: }
080:
081: /**
082: * @com.intel.drl.spec_ref
083: */
084: public String getFileName() {
085: return fileName;
086: }
087:
088: /**
089: * @com.intel.drl.spec_ref
090: */
091: public int getLineNumber() {
092: return lineNumber;
093: }
094:
095: /**
096: * @com.intel.drl.spec_ref
097: */
098: public String getMethodName() {
099: return methodName;
100: }
101:
102: /**
103: * @com.intel.drl.spec_ref
104: */
105: public int hashCode() {
106: return declaringClass.hashCode() ^ methodName.hashCode();
107: }
108:
109: /**
110: * @com.intel.drl.spec_ref
111: */
112: public boolean isNativeMethod() {
113: return lineNumber == -2;
114: }
115:
116: /**
117: * @com.intel.drl.spec_ref
118: */
119: public String toString() {
120: StringBuffer sb = new StringBuffer();
121: sb.append(declaringClass).append('.').append(methodName);
122: if (fileName == null) {
123: sb.append(lineNumber == -2 ? "(Native Method)"
124: : "(Unknown Source)");
125: } else {
126: sb.append('(').append(fileName);
127: if (lineNumber >= 0) {
128: sb.append(':').append(lineNumber);
129: }
130: sb.append(')');
131: }
132: return sb.toString();
133: }
134: }
|