Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 19e404835165272c84c6a34f355d3ba8c7317c37 (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
/*******************************************************************************
 * Copyright (c) 2005, 2007 BEA Systems, Inc.
 * 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:
 *    jgarms@bea.com - initial API and implementation
 *******************************************************************************/
package org.eclipse.jdt.apt.tests;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.tests.builder.Problem;

/**
 * Represents a problem expected to be found by the test.
 * Similar to an IProblem, but allows skipping of offset and category
 *
 */
public class ExpectedProblem {

	private final String _location;
	private final String _message;
	private final IPath _resourcePath;
	private final int _start;
	private final int _end;
	
	public ExpectedProblem(String location, String message, IPath resourcePath) {
		this (location, message, resourcePath, -1, -1);
	}
	
	public ExpectedProblem(String location, 
			String message, 
			IPath resourcePath,
			int start,
			int end)
	{
		_location = location;
		_message = message;
		_resourcePath = resourcePath;
		_start = start;
		_end = end;
	}
	
	public String getLocation() {
		return _location;
	}
	
	public boolean equalsProblem(final Problem problem) {
		if (problem == null)
			return false;
		
		// Ignore the location, as this is what Problem.equals does as well
		//if (!_location.equals(problem.getLocation())) return false;
		if (!_message.equals(problem.getMessage())) return false;
		if (!_resourcePath.equals(problem.getResourcePath())) return false;
		if (_start != -1 && _start != problem.getStart()) return false;
		if (_end != -1 && _end != problem.getEnd()) return false;
		
		return true;
	}
	
	public String toString(){
  		return 
			"Problem : " 
			+ _message 
			+ " [ resource : <" 
			+ _resourcePath 
			+ ">" 
			+ (" range : <" + _start + "," + _end + ">")
			+ "]";
	}
}

Back to the top