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 | |
7709e228 | 15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.equalsNullable; |
f47ed727 | 16 | |
8936d4f2 MK |
17 | import org.eclipse.jdt.annotation.NonNull; |
18 | ||
f47ed727 BH |
19 | /** |
20 | * TMF call site information for source code lookup. | |
21 | * | |
f47ed727 BH |
22 | * @author Bernd Hufmann |
23 | */ | |
24 | public class TmfCallsite implements ITmfCallsite { | |
25 | ||
26 | // ------------------------------------------------------------------------ | |
27 | // Attributes | |
28 | // ------------------------------------------------------------------------ | |
29 | ||
30 | /** The file name string. */ | |
8936d4f2 | 31 | private final @NonNull String fFileName; |
f47ed727 BH |
32 | |
33 | /** The function name. */ | |
a66d4a7e | 34 | private final String fFunctionName; |
f47ed727 BH |
35 | |
36 | /** The line number. */ | |
a66d4a7e | 37 | private final 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 | |
52 | */ | |
53 | public TmfCallsite(String fileName, String functionName, long lineNumber) { | |
54 | if (fileName == null) { | |
55 | throw new IllegalArgumentException(); | |
56 | } | |
57 | fFileName = fileName; | |
58 | fFunctionName = functionName; | |
59 | fLineNumber = lineNumber; | |
60 | } | |
61 | ||
62 | /** | |
63 | * Copy Constructor. | |
64 | * | |
65 | * @param other | |
66 | * - An other call site implementation | |
67 | */ | |
68 | public TmfCallsite(ITmfCallsite other) { | |
8936d4f2 | 69 | if (other == null) { |
f47ed727 BH |
70 | throw new IllegalArgumentException(); |
71 | } | |
72 | fFileName = other.getFileName(); | |
73 | fFunctionName = other.getFunctionName(); | |
74 | fLineNumber = other.getLineNumber(); | |
75 | } | |
76 | ||
77 | // ------------------------------------------------------------------------ | |
78 | // Accessors | |
79 | // ------------------------------------------------------------------------ | |
80 | ||
81 | @Override | |
8936d4f2 | 82 | public @NonNull String getFileName() { |
f47ed727 BH |
83 | return fFileName; |
84 | } | |
85 | ||
86 | @Override | |
87 | public String getFunctionName() { | |
88 | return fFunctionName; | |
89 | } | |
90 | ||
91 | @Override | |
92 | public long getLineNumber() { | |
93 | return fLineNumber; | |
94 | } | |
95 | ||
96 | // ------------------------------------------------------------------------ | |
97 | // Operations | |
98 | // ------------------------------------------------------------------------ | |
99 | ||
100 | @Override | |
101 | public int hashCode() { | |
102 | final int prime = 31; | |
103 | int result = 1; | |
7709e228 MK |
104 | // fFileName cannot be null! |
105 | result = prime * result + fFileName.hashCode(); | |
f47ed727 BH |
106 | result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode()); |
107 | result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32)); | |
108 | return result; | |
109 | } | |
110 | ||
111 | @Override | |
112 | public boolean equals(Object obj) { | |
113 | if (this == obj) { | |
114 | return true; | |
115 | } | |
116 | if (obj == null) { | |
117 | return false; | |
118 | } | |
119 | if (getClass() != obj.getClass()) { | |
120 | return false; | |
121 | } | |
122 | TmfCallsite other = (TmfCallsite) obj; | |
123 | ||
124 | // fFileName cannot be null! | |
125 | if (!fFileName.equals(other.fFileName)) { | |
126 | return false; | |
127 | } | |
128 | ||
7709e228 | 129 | if (!equalsNullable(fFunctionName, other.fFunctionName)) { |
f47ed727 BH |
130 | return false; |
131 | } | |
132 | if (fLineNumber != other.fLineNumber) { | |
133 | return false; | |
134 | } | |
135 | return true; | |
136 | } | |
137 | ||
138 | @Override | |
139 | public String toString() { | |
140 | StringBuilder builder = new StringBuilder(); | |
141 | builder.append(fFileName).append(':'); | |
142 | builder.append(Long.toString(fLineNumber)); | |
143 | if (fFunctionName != null) { | |
144 | builder.append(' '); | |
145 | builder.append(fFunctionName).append("()"); //$NON-NLS-1$ | |
146 | } | |
147 | return builder.toString(); | |
148 | } | |
149 | } |