Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3a3215931f1426a50406cdf857ff43682f78e528 (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) 2013 Google, Inc and others.
 *
 * 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:
 * 	   Sergey Prigogin (Google) - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.core.parser;

import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * Container for include export patterns, for example "IWYU pragma: export",
 * "IWYU pragma: begin_exports" and "IWYU pragma: end_exports".
 * @see "https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md"
 *
 * @since 5.5
 */
public class IncludeExportPatterns {
	private final Pattern includeExportPattern;
	private final Pattern includeBeginExportsPattern;
	private final Pattern includeEndExportsPattern;

	public IncludeExportPatterns(String exportPattern, String beginExportsPattern,
			String endExportsPattern) {
		this.includeExportPattern = compilePattern(exportPattern);
		this.includeBeginExportsPattern = compilePattern(beginExportsPattern);
		this.includeEndExportsPattern = compilePattern(endExportsPattern);
	}

	private Pattern compilePattern(String pattern) {
		try {
			return pattern == null ? null : Pattern.compile(pattern);
		} catch (PatternSyntaxException e) {
			return null;
		}
	}

	/**
	 * Returns the include export pattern, e.g. "IWYU pragma: export".
	 */
	public Pattern getIncludeExportPattern() {
		return includeExportPattern;
	}

	/**
	 * Returns the include export pattern, e.g. "IWYU pragma: begin_exports".
	 */
	public Pattern getIncludeBeginExportsPattern() {
		return includeBeginExportsPattern;
	}

	/**
	 * Returns the include export pattern, e.g. "IWYU pragma: end_exports".
	 */
	public Pattern getIncludeEndExportsPattern() {
		return includeEndExportsPattern;
	}
}

Back to the top