Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ca02084663eab92f6292d39a802dc7bfbc195e78 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*******************************************************************************
 * Copyright (c) 2013 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bernd Hufmann - Initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.core.event.lookup;


/**
 * TMF call site information for source code lookup.
 *
 * @since 2.0
 * @author Bernd Hufmann
 */
public class TmfCallsite implements ITmfCallsite {

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------

    /** The file name string. */
    final private String fFileName;

    /** The function name. */
    final private String fFunctionName;

    /** The line number. */
    final private long fLineNumber;

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------

    /**
     * Default constructor.
     *
     * @param fileName
     *            - a file name
     * @param functionName
     *            - a function name
     * @param lineNumber
     *            - a line number
     */
    public TmfCallsite(String fileName, String functionName, long lineNumber) {
        if (fileName == null) {
            throw new IllegalArgumentException();
        }
        fFileName = fileName;
        fFunctionName = functionName;
        fLineNumber = lineNumber;
    }

    /**
     * Copy Constructor.
     *
     * @param other
     *            - An other call site implementation
     */
    public TmfCallsite(ITmfCallsite other) {
        if ((other == null) || (other.getFileName() == null)) {
            throw new IllegalArgumentException();
        }
        fFileName = other.getFileName();
        fFunctionName = other.getFunctionName();
        fLineNumber = other.getLineNumber();
    }

    // ------------------------------------------------------------------------
    // Accessors
    // ------------------------------------------------------------------------

    @Override
    public String getFileName() {
        return fFileName;
    }

    @Override
    public String getFunctionName() {
        return fFunctionName;
    }

    @Override
    public long getLineNumber() {
        return fLineNumber;
    }

    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + fFileName.hashCode(); // fFileName cannot be null
        result = prime * result + ((fFunctionName == null) ? 0 : fFunctionName.hashCode());
        result = prime * result + (int) (fLineNumber ^ (fLineNumber >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        TmfCallsite other = (TmfCallsite) obj;

        // fFileName cannot be null!
        if (!fFileName.equals(other.fFileName)) {
            return false;
        }

        if (fFunctionName == null) {
            if (other.fFunctionName != null) {
                return false;
            }
        } else if (!fFunctionName.equals(other.fFunctionName)) {
            return false;
        }
        if (fLineNumber != other.fLineNumber) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(fFileName).append(':');
        builder.append(Long.toString(fLineNumber));
        if (fFunctionName != null) {
            builder.append(' ');
            builder.append(fFunctionName).append("()"); //$NON-NLS-1$
        }
        return builder.toString();
    }
}

Back to the top