blob: a42c198c05579e3e75269f7c07096a6b8b0d84d1 [file] [log] [blame]
/*
* Copyright (c) 2007, 2010 Borland Software 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:
* Dmitry Stadnik (Borland) - initial API and implementation
*/
«IMPORT 'http://www.eclipse.org/gmf/2009/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::expressions::OCLExpressionFactory::_initInterpreterFactory»
«EXPAND xpt::Common::generatedMemberComment»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context, java.util.Map«EXPAND CodeStyle::G2('String', 'org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram» environment) {
return new Expression(body, context, environment);
}
«EXPAND xpt::Common::generatedMemberComment('This method will become private in the next release')»«REM»FIXME private or completely remove in the next release «ENDREM»
public static «container.getAbstractExpressionQualifiedClassName()» getExpression(String body, org.eclipse.emf.ecore.EClassifier context) {
return getExpression(body, context, «EXPAND CodeStyle::emptyMap('String, org.eclipse.emf.ecore.EClassifier') FOR container.editorGen.diagram»);
}
«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»
«EXPAND CodeStyle::SuppressWarnings('"rawtypes"') FOR container.editorGen.diagram
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»
«EXPAND CodeStyle::SuppressWarnings('"rawtypes"') FOR container.editorGen.diagram
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.valueOfIF language = gmfgen::GenLanguage::nregexp»!«ENDIF»matcher.matches());
}
}
«EXPAND additions
}
«ENDDEFINE»
«DEFINE additions FOR gmfgen::GenExpressionInterpreter»«ENDDEFINE»