Commit | Line | Data |
---|---|---|
f47ed727 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2014 Ericsson |
f47ed727 BH |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.event.lookup; |
f47ed727 | 14 | |
0c65e461 AM |
15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
16 | ||
7a0ebe01 | 17 | import java.util.Objects; |
f47ed727 | 18 | |
8936d4f2 | 19 | import org.eclipse.jdt.annotation.NonNull; |
0c65e461 | 20 | import org.eclipse.jdt.annotation.Nullable; |
8936d4f2 | 21 | |
f47ed727 BH |
22 | /** |
23 | * TMF call site information for source code lookup. | |
24 | * | |
f47ed727 BH |
25 | * @author Bernd Hufmann |
26 | */ | |
27 | public class TmfCallsite implements ITmfCallsite { | |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | /** The file name string. */ | |
8936d4f2 | 34 | private final @NonNull String fFileName; |
f47ed727 | 35 | |
f47ed727 | 36 | /** The line number. */ |
0c65e461 | 37 | private final @Nullable Long fLineNumber; |
f47ed727 BH |
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 | |
0c65e461 | 52 | * @deprecated Use {@link #TmfCallsite(String, Long)} instead. |
f47ed727 | 53 | */ |
0c65e461 | 54 | @Deprecated |
f47ed727 | 55 | public TmfCallsite(String fileName, String functionName, long lineNumber) { |
0c65e461 AM |
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) { | |
f47ed727 | 69 | fFileName = fileName; |
f47ed727 BH |
70 | fLineNumber = lineNumber; |
71 | } | |
72 | ||
73 | /** | |
74 | * Copy Constructor. | |
75 | * | |
76 | * @param other | |
77 | * - An other call site implementation | |
78 | */ | |
0c65e461 | 79 | public TmfCallsite(@NonNull ITmfCallsite other) { |
f47ed727 | 80 | fFileName = other.getFileName(); |
0c65e461 | 81 | fLineNumber = other.getLineNo(); |
f47ed727 BH |
82 | } |
83 | ||
84 | // ------------------------------------------------------------------------ | |
85 | // Accessors | |
86 | // ------------------------------------------------------------------------ | |
87 | ||
88 | @Override | |
8936d4f2 | 89 | public @NonNull String getFileName() { |
f47ed727 BH |
90 | return fFileName; |
91 | } | |
92 | ||
0c65e461 | 93 | @Deprecated |
f47ed727 BH |
94 | @Override |
95 | public String getFunctionName() { | |
0c65e461 | 96 | return ""; //$NON-NLS-1$ |
f47ed727 BH |
97 | } |
98 | ||
0c65e461 | 99 | @Deprecated |
f47ed727 BH |
100 | @Override |
101 | public long getLineNumber() { | |
0c65e461 AM |
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() { | |
f47ed727 BH |
112 | return fLineNumber; |
113 | } | |
114 | ||
115 | // ------------------------------------------------------------------------ | |
116 | // Operations | |
117 | // ------------------------------------------------------------------------ | |
118 | ||
119 | @Override | |
120 | public int hashCode() { | |
0c65e461 | 121 | return Objects.hash(fFileName, fLineNumber); |
f47ed727 BH |
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 | ||
f47ed727 BH |
142 | if (fLineNumber != other.fLineNumber) { |
143 | return false; | |
144 | } | |
145 | return true; | |
146 | } | |
147 | ||
148 | @Override | |
149 | public String toString() { | |
0c65e461 AM |
150 | Long lineNumber = fLineNumber; |
151 | ||
f47ed727 BH |
152 | StringBuilder builder = new StringBuilder(); |
153 | builder.append(fFileName).append(':'); | |
0c65e461 | 154 | builder.append(lineNumber == null ? "??" : Long.toString(lineNumber)); //$NON-NLS-1$ |
f47ed727 BH |
155 | return builder.toString(); |
156 | } | |
157 | } |