Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 13b4c0eacc472effe9254532208cabdb28cd2dd0 (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
/*******************************************************************************
 * Copyright (c) 2008, 2017 Phil Muldoon 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:
 *    Phil Muldoon <pkmuldoon@picobot.org> - initial API.
 *    Red Hat - modifications for use with Valgrind plugins.
 *******************************************************************************/
package org.eclipse.linuxtools.internal.valgrind.ui.editor;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
import org.eclipse.jface.text.rules.EndOfLineRule;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.swt.SWT;
import org.eclipse.ui.PlatformUI;

public class SuppressionsElementScanner extends BufferedRuleBasedScanner {

	public static final String MEMCHECK = "Memcheck"; //$NON-NLS-1$
	public static final String[] MEMCHECK_SUPP_TYPES = new String[] { "Value0", "Value1", "Value2", "Value4", "Value8", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
			"Value16", //$NON-NLS-1$
			"Cond", //$NON-NLS-1$
			"Addr1", "Addr2", "Addr4", "Addr8", "Addr16", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
			"Jump", //$NON-NLS-1$
			"Param", //$NON-NLS-1$
			"Free", //$NON-NLS-1$
			"Overlap", //$NON-NLS-1$
			"Leak" //$NON-NLS-1$
	};
	public static final String[] CONTEXTS = new String[] { "obj", "fun" //$NON-NLS-1$ //$NON-NLS-2$
	};

	public SuppressionsElementScanner() {
		ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
		String[] tools = { MEMCHECK };
		Map<String, List<String>> kinds = new HashMap<>();
		kinds.put(MEMCHECK, Arrays.asList(MEMCHECK_SUPP_TYPES));

		IToken defaultToken = new Token(new TextAttribute(colorRegistry.get(ISuppressionsColorConstants.DEFAULT)));
		IToken toolToken = new Token(
				new TextAttribute(colorRegistry.get(ISuppressionsColorConstants.TOOL), null, SWT.BOLD));
		IToken suppKindToken = new Token(new TextAttribute(colorRegistry.get(ISuppressionsColorConstants.SUPP_TYPE)));
		IToken contextToken = new Token(
				new TextAttribute(colorRegistry.get(ISuppressionsColorConstants.CONTEXT), null, SWT.BOLD));
		IToken commentToken = new Token(new TextAttribute(colorRegistry.get(ISuppressionsColorConstants.COMMENT)));

		setDefaultReturnToken(defaultToken);
		setRules(new IRule[] { new EndOfLineRule("#", commentToken), //$NON-NLS-1$
				new SuppressionToolRule(tools, toolToken), new SuppressionKindRule(kinds, suppKindToken),
				new SuppressionToolRule(CONTEXTS, contextToken), new WhitespaceRule(c -> Character.isWhitespace(c)) });
	}
}

Back to the top