/*******************************************************************************
* Copyright (c) 2008, 2009 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:
* Borland Software Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml.ast.env;
import org.eclipse.ocl.Environment;
import org.eclipse.ocl.lpg.BasicEnvironment;
import org.eclipse.ocl.options.BasicOption;
import org.eclipse.ocl.options.Customizable;
import org.eclipse.ocl.options.Option;
import org.eclipse.ocl.util.OCLUtil;
public class QVTParsingOptions {
private QVTParsingOptions() {
super();
}
public static final Option<Boolean> ENFORCE_EXPLICIT_SELF_VARIABLE =
new BasicOption<Boolean>("enforce.explicit.self", true); //$NON-NLS-1$
public static final Option<Boolean> ENABLE_CSTMODEL_TOKENS =
new BasicOption<Boolean>("enable.cstmodel.tokens", false); //$NON-NLS-1$
/**
* Obtains the value of the specified option's setting in the the given
* environment's options map, adapting the environment as necessary to the
* {@link Customizable} API. If not already set, return the option's
* {@linkplain #getDefaultValue() default value}.
*
* @param env an environment on which to query an option
* @param option an option to query
*
* @return value of the option
*
* @see Customizable#getValue(Option)
*/
public static <T> T getValue(Environment<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?> env, Option<T> option) {
Customizable custom = OCLUtil.getAdapter(env, Customizable.class);
if (custom == null) {
// go for the external basic-environment adapter that we provide
custom = OCLUtil.getAdapter(env, BasicEnvironment.class);
}
return custom.getValue(option);
}
/**
* Add an option to apply to the specified environment, adapting it as
* necessary to the {@link Customizable} API.
*
* @param env an environment on which to set an option
* @param option the option
* @param value the option's value
*
* @see Cusotmizable#setOption(Option, Object)
*/
public static <T> void setOption(Environment<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?> env, Option<T> option, T value) {
Customizable custom = OCLUtil.getAdapter(env, Customizable.class);
if (custom == null) {
// go for the external basic-environment adapter that we provide
custom = OCLUtil.getAdapter(env, BasicEnvironment.class);
}
custom.setOption(option, value);
}
}