Skip to main content
summaryrefslogtreecommitdiffstats
blob: 7bd88e7e6e2d4b9f5a7dc837bfe6f63761d7a9d1 (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
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.objectteams.otdt.debug.tests;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IJavaModelMarker;

// from org.eclipse.jdt.core.tests.builder
public class Problem implements Comparable {
	private String location;
	private String message;
	private IPath resourcePath;
	private int start = -1, end = -1, categoryId = -1;
	private String sourceId;
	private int severity = IMarker.SEVERITY_ERROR;

	public Problem(String location, String message, IPath resourcePath, int start, int end, int categoryId, int severity) {
		this.location = location;
		this.message = message;
		this.resourcePath = resourcePath;
		this.start = start;
		this.end = end;
		this.categoryId = categoryId;
		this.severity = severity;
//		if ((start > 0 || end > 0) && categoryId <= 0) {
//			System.out.print("is categoryId properly set ? new Problem(\"" + location + "\", \"" + message + "\", \"" + resourcePath + "\"");
//			System.out.print(", " + start + ", " + end +  ", " + categoryId);
//			System.out.println(")");
//		}
	}

	public Problem(IMarker marker){
		this.location = marker.getAttribute(IMarker.LOCATION, ""); //$NON-NLS-1$
		this.message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
		this.resourcePath = marker.getResource().getFullPath();
		this.start = marker.getAttribute(IMarker.CHAR_START, -1);
		this.end = marker.getAttribute(IMarker.CHAR_END, -1);
		this.categoryId = marker.getAttribute(IJavaModelMarker.CATEGORY_ID, -1);
		this.sourceId = marker.getAttribute(IMarker.SOURCE_ID, "missing");
		this.severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
	}
	public int getCategoryId() {
		return this.categoryId;
	}

/**
 * Return the IMarker.SOURCE_ID attribute of the underlying marker if any.
 * Value null denotes a problem created from explicit structural attributes
 * (instead of using a source marker). Value "missing" denotes that the marker
 * used to initialize the problem had no IMarker.SOURCE_ID attribute.
 * @return the IMarker.SOURCE_ID attribute of the underlying marker if any
 */
public String getSourceId() {
	return this.sourceId;
}
	/**
	 * Gets the location.
	 * @return Returns a String
	 */
	public String getLocation() {
		return this.location;
	}
	/**
	 * Gets the message.
	 * @return Returns a String
	 */
	public String getMessage() {
		return this.message;
	}
	/**
	 * Gets the resourcePath.
	 * @return Returns a IPath
	 */
	public IPath getResourcePath() {
		return this.resourcePath;
	}

public int getSeverity() {
	return this.severity;
}

	public int getStart() {
		return this.start;
	}

	public int getEnd() {
		return this.end;
	}

	public String toString(){
// ignore locations since the builder no longer finds exact Java elements
//		return "Problem : " + message + " [ resource : <" + resourcePath + "> location <"+ location + "> ]";
		return
			"Problem : "
			+ this.message
			+ " [ resource : <"
			+ this.resourcePath
			+ ">"
			+ (" range : <" + this.start + "," + this.end + ">")
			+ (" category : <" + this.categoryId + ">")
			+ (" severity : <" + this.severity + ">")
			+ "]";
	}

	public boolean equals(Object o){
		if(o instanceof Problem){
			return toString().equals(o.toString());
		}
		return false;
	}

	public int compareTo(Object o) {
		if(o instanceof Problem){
			Problem problem = (Problem) o;
			/* Replace initial implementation with toString() comparison otherwise the problems order may change
			 * when different VM are used (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213570)...
			if (!(this.getLocation().equals(problem.getLocation()))) {
				return this.getLocation().compareTo(problem.getLocation());
			}
			if (this.getStart() < problem.getStart()) {
				return -1;
			}
			if (this.getEnd() < problem.getEnd()) {
				return -1;
			}
			return this.getMessage().compareTo(problem.getMessage());
			*/
			return toString().compareTo(problem.toString());
		}
		return -1;
	}
}

Back to the top