Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / lookup / TmfCallsite.java
CommitLineData
f47ed727
BH
1/*******************************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.event.lookup;
14
15
16/**
17 * TMF call site information for source code lookup.
18 *
19 * @since 2.0
20 * @author Bernd Hufmann
21 */
22public class TmfCallsite implements ITmfCallsite {
23
24 // ------------------------------------------------------------------------
25 // Attributes
26 // ------------------------------------------------------------------------
27
28 /** The file name string. */
29 final private String fFileName;
30
31 /** The function name. */
32 final private String fFunctionName;
33
34 /** The line number. */
35 final private long fLineNumber;
36
37 // ------------------------------------------------------------------------
38 // Constructors
39 // ------------------------------------------------------------------------
40
41 /**
42 * Default constructor.
43 *
44 * @param fileName
45 * - a file name
46 * @param functionName
47 * - a function name
48 * @param lineNumber
49 * - a line number
50 */
51 public TmfCallsite(String fileName, String functionName, long lineNumber) {
52 if (fileName == null) {
53 throw new IllegalArgumentException();
54 }
55 fFileName = fileName;
56 fFunctionName = functionName;
57 fLineNumber = lineNumber;
58 }
59
60 /**
61 * Copy Constructor.
62 *
63 * @param other
64 * - An other call site implementation
65 */
66 public TmfCallsite(ITmfCallsite other) {
67 if ((other == null) || (other.getFileName() == null)) {
68 throw new IllegalArgumentException();
69 }
70 fFileName = other.getFileName();
71 fFunctionName = other.getFunctionName();
72 fLineNumber = other.getLineNumber();
73 }
74
75 // ------------------------------------------------------------------------
76 // Accessors
77 // ------------------------------------------------------------------------
78
79 @Override
80 public String getFileName() {
81 return fFileName;
82 }
83
84 @Override
85 public String getFunctionName() {
86 return fFunctionName;
87 }
88
89 @Override
90 public long getLineNumber() {
91 return fLineNumber;
92 }
93
94 // ------------------------------------------------------------------------
95 // Operations
96 // ------------------------------------------------------------------------
97
98 @Override
99 public int hashCode() {
100 final int prime = 31;
101 int result = 1;
102 result = prime * result + fFileName.hashCode(); // fFileName cannot be null
103 result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode());
104 result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32));
105 return result;
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
113 if (obj == null) {
114 return false;
115 }
116 if (getClass() != obj.getClass()) {
117 return false;
118 }
119 TmfCallsite other = (TmfCallsite) obj;
120
121 // fFileName cannot be null!
122 if (!fFileName.equals(other.fFileName)) {
123 return false;
124 }
125
126 if (fFunctionName == null) {
127 if (other.fFunctionName != null) {
128 return false;
129 }
130 } else if (!fFunctionName.equals(other.fFunctionName)) {
131 return false;
132 }
133 if (fLineNumber != other.fLineNumber) {
134 return false;
135 }
136 return true;
137 }
138
139 @Override
140 public String toString() {
141 StringBuilder builder = new StringBuilder();
142 builder.append(fFileName).append(':');
143 builder.append(Long.toString(fLineNumber));
144 if (fFunctionName != null) {
145 builder.append(' ');
146 builder.append(fFunctionName).append("()"); //$NON-NLS-1$
147 }
148 return builder.toString();
149 }
150}
This page took 0.060855 seconds and 5 git commands to generate.