Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 96031b72aef2b16b4210db0ef16b2b6160fe49ba (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
package org.eclipse.cdt.arduino.core.internal.console;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;

public abstract class ArduinoErrorParser extends ArduinoConsoleParser {

	public static final String LINK_OFFSET = "arduino.link.offset"; //$NON-NLS-1$
	public static final String LINK_LENGTH = "arduino.link.length"; //$NON-NLS-1$

	private final Pattern errorPattern;

	public ArduinoErrorParser(String pattern, int flags, String lineQualifier) {
		super(pattern, flags, lineQualifier);
		this.errorPattern = Pattern.compile(pattern);
	}

	public ArduinoErrorParser(String pattern) {
		this(pattern, 0, null);
	}

	protected abstract String getFileName(Matcher matcher);

	protected abstract int getLineNumber(Matcher matcher);

	protected abstract String getMessage(Matcher matcher);

	protected abstract int getSeverity(Matcher matcher);

	protected abstract int getLinkOffset(Matcher matcher);

	protected abstract int getLinkLength(Matcher matcher);

	public IMarker generateMarker(IFolder buildDirectory, String text) {
		Matcher matcher = errorPattern.matcher(text);
		if (matcher.matches()) {
			String fileName = getFileName(matcher);

			IFile file = buildDirectory.getFile(fileName);
			if (file.exists()) {
				try {
					IMarker marker = file.createMarker(ICModelMarker.C_MODEL_PROBLEM_MARKER);
					marker.setAttribute(IMarker.MESSAGE, getMessage(matcher));
					marker.setAttribute(IMarker.SEVERITY, getSeverity(matcher));
					marker.setAttribute(IMarker.LINE_NUMBER, getLineNumber(matcher));
					marker.setAttribute(IMarker.CHAR_START, -1);
					marker.setAttribute(IMarker.CHAR_END, -1);
					marker.setAttribute(LINK_OFFSET, getLinkOffset(matcher));
					marker.setAttribute(LINK_LENGTH, getLinkLength(matcher));
					return marker;
				} catch (CoreException e) {
					Activator.log(e);
					return null;
				}
			}
		}
		return null;
	}

}

Back to the top