Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search


Implicitly define a variable named 'help' in the context of every OCL expression that is parsed. Docu follows

public static class MyEnvironmentFactory extends AbstractEnvironmentFactory {
  public EvaluationEnvironment createEvaluationEnvironment() {
     EvaluationEnvironment evalEnv = new EvalEnvironment();
     evalEnv.add("help", OCLHelperFactory.eINSTANCE.createHelper());
     return evalEnv;
  protected Environment createEnvironment(EPackage packageContext) {
     return new MyEnvironment(packageContext);
  protected EClassifier asEClassifier(Object context) {
     return (EClassifier) context;
  protected EOperation asEOperation(Object operation) {
     return (EOperation) operation;
  protected EStructuralFeature asEStructuralFeature(Object property) {
     return (EStructuralFeature) property;
  public Environment createEnvironment(Environment parent) {
     return new MyEnvironment(parent);

private static class MyEnvironment extends EcoreEnvironment {
  public MyEnvironment(EPackage packageContext) {
  private void init() {
     Variable vdcl = ExpressionsFactory.eINSTANCE.createVariable();
     vdcl.setType(TypeUtil.resolveType(this, OCLHelperPackage.eINSTANCE.getEClassifier("Helper")));
     this.addElement("help", vdcl, true);
  public MyEnvironment(Environment parent) {
  protected void collectStates(EClassifier owner, List pathPrefix, List states) {
     super.collectStates(owner, pathPrefix, states);
  public EClassifier lookupPathName(List names) {
     if (names.get(0).equals("Helper")) {
        return OCLHelperPackage.eINSTANCE.getEClassifier((String) names.get(0));				      }
     return super.lookupPathName(names);

IOCLHelper helper = HelperUtil.createOCLHelper(new MyEnvironmentFactory());
System.out.println(helper.evaluate(org, "help.testmethod(")); 08:39, 10 October 2006 (EDT)

Back to the top