Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made 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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.event; | |
14 | ||
15 | /** | |
16 | * <b><u>TmfTraceEvent</u></b> | |
17 | * <p> | |
18 | * A trace event associates a source code line to an event. The intent is to | |
19 | * provide the capability to open an editor at the line of code that produced | |
20 | * the event. | |
21 | * <p> | |
22 | * TODO: Concept is still a bit vague and should be aligned with the CDT | |
23 | * source lookup service. | |
24 | * TODO: Consider composition instead of extension | |
25 | */ | |
26 | public class TmfTraceEvent extends TmfEvent { | |
27 | ||
28 | // ------------------------------------------------------------------------ | |
29 | // Attributes | |
30 | // ------------------------------------------------------------------------ | |
31 | ||
32 | private final String fSourcePath; | |
33 | private final String fFileName; | |
34 | private final int fLineNumber; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Constructors | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | /** | |
41 | * @param originalTS | |
42 | * @param effectiveTS | |
43 | * @param source | |
44 | * @param type | |
45 | * @param content | |
46 | * @param reference | |
47 | * @param path | |
48 | * @param file | |
49 | * @param line | |
50 | */ | |
51 | public TmfTraceEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, TmfEventSource source, | |
52 | TmfEventType type, TmfEventReference reference, String path, String file, int line) | |
53 | { | |
54 | super(originalTS, effectiveTS, source, type, reference); | |
55 | fSourcePath = path; | |
56 | fFileName = file; | |
57 | fLineNumber = line; | |
58 | } | |
59 | ||
60 | /** | |
61 | * @param timestamp | |
62 | * @param source | |
63 | * @param type | |
64 | * @param content | |
65 | * @param reference | |
66 | * @param path | |
67 | * @param file | |
68 | * @param line | |
69 | */ | |
70 | public TmfTraceEvent(TmfTimestamp timestamp, TmfEventSource source, TmfEventType type, | |
71 | TmfEventReference reference, String path, String file, int line) | |
72 | { | |
73 | super(timestamp, source, type, reference); | |
74 | fSourcePath = path; | |
75 | fFileName = file; | |
76 | fLineNumber = line; | |
77 | } | |
78 | ||
79 | /** | |
80 | * @param other | |
81 | */ | |
82 | public TmfTraceEvent(TmfTraceEvent other) { | |
83 | super(other); | |
84 | fSourcePath = other.fSourcePath; | |
85 | fFileName = other.fFileName; | |
86 | fLineNumber = other.fLineNumber; | |
87 | } | |
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Accessors | |
91 | // ------------------------------------------------------------------------ | |
92 | ||
93 | /** | |
94 | * @return | |
95 | */ | |
96 | public String getSourcePath() { | |
97 | return fSourcePath; | |
98 | } | |
99 | ||
100 | /** | |
101 | * @return | |
102 | */ | |
103 | public String getFileName() { | |
104 | return fFileName; | |
105 | } | |
106 | ||
107 | /** | |
108 | * @return | |
109 | */ | |
110 | public int getLineNumber() { | |
111 | return fLineNumber; | |
112 | } | |
113 | ||
114 | // ------------------------------------------------------------------------ | |
115 | // Object | |
116 | // ------------------------------------------------------------------------ | |
117 | ||
118 | @Override | |
119 | public int hashCode() { | |
120 | int result = super.hashCode(); | |
121 | result = 37 * result + ((fSourcePath != null) ? fSourcePath.hashCode() : 0); | |
122 | result = 37 * result + ((fFileName != null) ? fFileName.hashCode() : 0); | |
123 | result = 37 * result + fLineNumber; | |
124 | return result; | |
125 | } | |
126 | ||
127 | @Override | |
128 | public boolean equals(Object other) { | |
129 | if (other instanceof TmfEvent) { | |
130 | return super.equals(other); | |
131 | } | |
132 | if (!(other instanceof TmfTraceEvent)) { | |
133 | return false; | |
134 | } | |
135 | TmfTraceEvent o = (TmfTraceEvent) other; | |
136 | return super.equals((TmfEvent) o) && fSourcePath.equals(o.fSourcePath) && | |
137 | fFileName.equals(o.fFileName) && fLineNumber == o.fLineNumber; | |
138 | ||
139 | } | |
140 | ||
141 | // TODO: Proper format | |
142 | @Override | |
143 | public String toString() { | |
144 | return "[TmfTraceEvent(" + fSourcePath + "," + fFileName + "," + fLineNumber + ")]"; | |
145 | } | |
146 | ||
147 | } |