tmf: Remove function name from ITmfCallsite
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / lookup / TmfCallsite.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
13 package org.eclipse.tracecompass.tmf.core.event.lookup;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.util.Objects;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23 * TMF call site information for source code lookup.
24 *
25 * @author Bernd Hufmann
26 */
27 public class TmfCallsite implements ITmfCallsite {
28
29 // ------------------------------------------------------------------------
30 // Attributes
31 // ------------------------------------------------------------------------
32
33 /** The file name string. */
34 private final @NonNull String fFileName;
35
36 /** The line number. */
37 private final @Nullable Long fLineNumber;
38
39 // ------------------------------------------------------------------------
40 // Constructors
41 // ------------------------------------------------------------------------
42
43 /**
44 * Default constructor.
45 *
46 * @param fileName
47 * - a file name
48 * @param functionName
49 * - a function name
50 * @param lineNumber
51 * - a line number
52 * @deprecated Use {@link #TmfCallsite(String, Long)} instead.
53 */
54 @Deprecated
55 public TmfCallsite(String fileName, String functionName, long lineNumber) {
56 this(checkNotNull(fileName), lineNumber);
57 }
58
59 /**
60 * Constructor
61 *
62 * @param fileName
63 * The source file's name
64 * @param lineNumber
65 * The line number in the source file
66 * @since 2.1
67 */
68 public TmfCallsite(@NonNull String fileName, @Nullable Long lineNumber) {
69 fFileName = fileName;
70 fLineNumber = lineNumber;
71 }
72
73 /**
74 * Copy Constructor.
75 *
76 * @param other
77 * - An other call site implementation
78 */
79 public TmfCallsite(@NonNull ITmfCallsite other) {
80 fFileName = other.getFileName();
81 fLineNumber = other.getLineNo();
82 }
83
84 // ------------------------------------------------------------------------
85 // Accessors
86 // ------------------------------------------------------------------------
87
88 @Override
89 public @NonNull String getFileName() {
90 return fFileName;
91 }
92
93 @Deprecated
94 @Override
95 public String getFunctionName() {
96 return ""; //$NON-NLS-1$
97 }
98
99 @Deprecated
100 @Override
101 public long getLineNumber() {
102 Long lineNumber = fLineNumber;
103 return (lineNumber == null ? -1 : lineNumber.longValue());
104 }
105
106
107 /**
108 * @since 2.1
109 */
110 @Override
111 public @Nullable Long getLineNo() {
112 return fLineNumber;
113 }
114
115 // ------------------------------------------------------------------------
116 // Operations
117 // ------------------------------------------------------------------------
118
119 @Override
120 public int hashCode() {
121 return Objects.hash(fFileName, fLineNumber);
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj) {
127 return true;
128 }
129 if (obj == null) {
130 return false;
131 }
132 if (getClass() != obj.getClass()) {
133 return false;
134 }
135 TmfCallsite other = (TmfCallsite) obj;
136
137 // fFileName cannot be null!
138 if (!fFileName.equals(other.fFileName)) {
139 return false;
140 }
141
142 if (fLineNumber != other.fLineNumber) {
143 return false;
144 }
145 return true;
146 }
147
148 @Override
149 public String toString() {
150 Long lineNumber = fLineNumber;
151
152 StringBuilder builder = new StringBuilder();
153 builder.append(fFileName).append(':');
154 builder.append(lineNumber == null ? "??" : Long.toString(lineNumber)); //$NON-NLS-1$
155 return builder.toString();
156 }
157 }
This page took 0.055954 seconds and 6 git commands to generate.