Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 42c3c6f162b89df15d3af3fce4e80323f4a7fd69 (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) 2007 Borland Software Corporation
 * 
 * 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2008/GenModel'»

«DEFINE RegexpExpressionFactory FOR gmfgen::GenExpressionInterpreter-»
«EXPAND xpt::Common::copyright FOR container.editorGen-»
package «container.expressionsPackageName»;

«EXPAND xpt::Common::generatedClassComment»
public class «className» {

	«EXPAND xpt::Common::generatedMemberComment»
	private «className»() {
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
			String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
		return new Expression(body, context, environment);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public static «container.getAbstractExpressionQualifiedClassName()» getExpression(
			String body, org.eclipse.emf.ecore.EClassifier context) {
		return getExpression(body, context, java.util.Collections.EMPTY_MAP);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	private static class Expression extends «container.getAbstractExpressionQualifiedClassName()» {

		«EXPAND xpt::Common::generatedMemberComment»
		private final java.util.regex.Pattern pattern;

		«EXPAND xpt::Common::generatedMemberComment»
		public Expression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map environment) {
			super(body, context);
			java.util.regex.Pattern p;
			try {
				p = java.util.regex.Pattern.compile(body);
			} catch (java.util.regex.PatternSyntaxException e) {
				setStatus(org.eclipse.core.runtime.IStatus.ERROR, e.getMessage(), e);
				p = null;
			}
			this.pattern = p;
		}

		«EXPAND xpt::Common::generatedMemberComment»
		protected Object doEvaluate(Object contextInstance, java.util.Map env) {
			if (pattern == null) {
				return null;
			}
			if (context() instanceof org.eclipse.emf.ecore.EDataType) {
				contextInstance = org.eclipse.emf.ecore.util.EcoreUtil.convertToString(
						(org.eclipse.emf.ecore.EDataType) context(), contextInstance);
			}
			java.util.regex.Matcher matcher = this.pattern.matcher(String.valueOf(contextInstance));
			return Boolean.valueOf(«IF language = gmfgen::GenLanguage::nregexp»!«ENDIF»matcher.matches());
		}
	}
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»

Back to the top