1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
;
12 import org
.eclipse
.jdt
.annotation
.Nullable
;
13 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
16 * Factory to create {@link ICalledFunction}s.
18 * @author Matthew Khouzam
20 public class CalledFunctionFactory
{
22 private static final String SEPARATOR
= ": "; //$NON-NLS-1$
23 private static final String ERROR_MSG
= "Cannot create a called function of type : "; //$NON-NLS-1$
25 private CalledFunctionFactory() {
30 * Factory Method for a state value mapped called function
42 * @return an ICalledFunction with the specified propertiess
44 public static AbstractCalledFunction
create(long start
, long end
, int depth
, ITmfStateValue stateValue
, @Nullable ICalledFunction parent
) {
45 switch (stateValue
.getType()) {
47 throw new IllegalArgumentException(ERROR_MSG
+ stateValue
.getType() + SEPARATOR
+ stateValue
.toString());
49 throw new IllegalArgumentException(ERROR_MSG
+ stateValue
.getType() + SEPARATOR
+ stateValue
.toString());
51 return create(start
, end
, depth
, stateValue
.unboxInt(), parent
);
53 return create(start
, end
, depth
, stateValue
.unboxLong(), parent
);
55 throw new IllegalArgumentException(ERROR_MSG
+ stateValue
.getType() + SEPARATOR
+ stateValue
.toString());
57 return create(start
, end
, depth
, stateValue
.unboxStr(), parent
);
59 throw new IllegalArgumentException(ERROR_MSG
+ stateValue
.getType() + SEPARATOR
+ stateValue
.toString());
64 * Factory method to create a called function with a symbol that is a long
77 * @return an ICalledFunction with the specified propertiess
79 private static CalledFunction
create(long start
, long end
, int depth
, long value
, @Nullable ICalledFunction parent
) {
81 throw new IllegalArgumentException(Messages
.TimeError
+ '[' + start
+ ',' + end
+ ']');
83 return new CalledFunction(start
, end
, value
, depth
, parent
);
87 * Factory method to create a called function with a symbol that is a
100 * @return an ICalledFunction with the specified propertiess
102 private static CalledStringFunction
create(long start
, long end
, int depth
, String value
, @Nullable ICalledFunction parent
) {
104 throw new IllegalArgumentException(Messages
.TimeError
+ '[' + start
+ ',' + end
+ ']');
106 return new CalledStringFunction(start
, end
, value
, depth
, parent
);