/
CallStackSymbolFactory.java
64 lines (57 loc) · 2.55 KB
/
CallStackSymbolFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
* Copyright (c) 2017 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.tracecompass.internal.analysis.callstack.core.callstack;
import java.util.regex.Pattern;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackElement;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ICallStackSymbol;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.ResolvableSymbol;
import org.eclipse.tracecompass.internal.analysis.callstack.core.base.StringSymbol;
/**
* A factory that creates the appropriate symbol for a given element
*
* @author Geneviève Bastien
*/
public final class CallStackSymbolFactory {
private static final Pattern IS_NUMBER = Pattern.compile("[0-9A-Fa-f]+"); //$NON-NLS-1$
private CallStackSymbolFactory() {
// Utility class, not to be instantiated
}
/**
* Create a callstack symbol for a given element
*
* @param symbol
* the symbol, could be an number address, a string, or really
* anything
* @param element
* the element to lookup
* @param timestamp
* the time to lookup
* @return an {@link ICallStackSymbol} with the data to be shown.
*/
public static ICallStackSymbol createSymbol(Object symbol, ICallStackElement element, long timestamp) {
if (symbol instanceof Long || symbol instanceof Integer) {
long longAddress = ((Long) symbol).longValue();
return new ResolvableSymbol(longAddress, element.getSymbolKeyAt(timestamp), timestamp);
}
if (symbol instanceof String) {
String strSymbol = (String) symbol;
if (IS_NUMBER.matcher(strSymbol).matches()) {
try {
long longAddress = Long.parseUnsignedLong(strSymbol, 16);
return new ResolvableSymbol(longAddress, element.getSymbolKeyAt(timestamp), timestamp);
} catch (NumberFormatException e) {
// Not a long number, use a string symbol
}
}
}
return new StringSymbol(symbol);
}
}