Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5085b20f1f30a7aa0edb286de76e36fb72e7f2c0 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
 * Copyright (c) 2009, 2016 Alena Laskavaia
 *
 * 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
 *
 * Contributors:
 *    Alena Laskavaia  - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.codan.core.model;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;

/**
 * Abstract Implementation of IProblemLocation
 *
 * Clients may extend this class.
 */
public abstract class AbstractProblemLocation implements IProblemLocation {
	protected IResource file;
	protected int line;
	protected int posStart;
	protected int posEnd;
	protected Object extra;

	protected AbstractProblemLocation(IFile file, int line) {
		this((IResource) file, line);
	}

	/**
	 * @since 2.0
	 */
	protected AbstractProblemLocation(IResource file, int line) {
		this.file = file;
		this.line = line;
		this.posStart = -1;
		this.posEnd = -1;
	}

	protected AbstractProblemLocation(IFile file, int startChar, int endChar) {
		this((IResource) file, startChar, endChar);
	}

	/**
	 * @since 2.0
	 */
	protected AbstractProblemLocation(IResource file, int startChar, int endChar) {
		this.file = file;
		this.line = -1;
		this.posStart = startChar;
		this.posEnd = endChar;
	}

	/**
	 * Gets the extra data for the location. It is checker specific,
	 * for example can be problem backtrace.
	 *
	 * @return data object or null if non set
	 */
	@Override
	public Object getData() {
		return extra;
	}

	/**
	 * Sets extra data for the problem location.
	 *
	 * @param data
	 */
	public void setData(Object data) {
		this.extra = data;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getFile()
	 */
	@Override
	public IResource getFile() {
		return file;
	}

	/**
	 * @return resource for which marker is created
	 * @since 2.0
	 */
	public IResource getResource() {
		return file;
	}

	/**
	 * Problem line number referenced in problem view in location field
	 */
	@Override
	public int getLineNumber() {
		return getStartingLineNumber();
	}

	/**
	 * @return line number where problem starts
	 */
	public int getStartingLineNumber() {
		return line;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getStartPos()
	 */
	@Override
	public int getStartingChar() {
		return posStart;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see org.eclipse.cdt.codan.core.model.IProblemLocation#getEndingChar()
	 */
	@Override
	public int getEndingChar() {
		return posEnd;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((extra == null) ? 0 : extra.hashCode());
		result = prime * result + ((file == null) ? 0 : file.hashCode());
		result = prime * result + line;
		result = prime * result + posEnd;
		result = prime * result + posStart;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof AbstractProblemLocation))
			return false;
		AbstractProblemLocation other = (AbstractProblemLocation) obj;
		if (line != other.line)
			return false;
		if (posEnd != other.posEnd)
			return false;
		if (posStart != other.posStart)
			return false;
		if (extra == null) {
			if (other.extra != null)
				return false;
		} else if (!extra.equals(other.extra))
			return false;
		if (file == null) {
			if (other.file != null)
				return false;
		} else if (!file.equals(other.file))
			return false;
		return true;
	}
}

Back to the top