All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.ocl.options.ParsingOptions Maven / Gradle / Ivy

/**
 * 
 *
 * Copyright (c) 2007, 2010 IBM 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:
 *   IBM - Initial API and implementation
 *   E.D.Willink - Bugs 295166
 *   Borland - Bug 242880
 *
 * 
 *
 * $Id: ParsingOptions.java,v 1.10 2011/03/09 13:07:03 auhl Exp $
 */

package org.eclipse.ocl.options;

import org.eclipse.ocl.Environment;
import org.eclipse.ocl.lpg.BasicEnvironment;
import org.eclipse.ocl.util.OCLUtil;
import org.eclipse.ocl.utilities.UMLReflection;



/**
 * Options applicable to {@link Environment}s to
 * {@linkplain Customizable customize} their parsing behaviour.
 * 
 * @author Christian W. Damus (cdamus)
 * 
 * @since 1.2
 */
public class ParsingOptions {

    /**
     * 

* Parsing option indicating whether to reference the defined property or * operation in a def: expression as a constrained element of the * constraint, in addition to the context classifier. The well-formedness * rules for definition constraints in the OCL 2.0 Specification require * that a definition constraint reference only its context classifier as * a constrained element. *

* The default value of this option is false. For compatibility * with the 1.1 release behaviour, set this option true. Note * that this is not necessary for loading and processing constraints * created by the 1.1 release, only for persisting constraints that will be * consumed by the 1.1 release. *

*/ public static final Option DEFINITION_CONSTRAINS_FEATURE = new BasicOption("definition.constraints.feature", false); //$NON-NLS-1$ /** *

* Parsing option indicating whether to interpolate {@literal <}, * {@literal <=}, {@literal >}, and {@literal >=} operations when a model * type defines a Java-style compareTo(...) operation. *

* The default value of this option is false. For compatibility * with the 1.1 release behaviour, set this option true. *

*/ public static final Option USE_COMPARE_TO_OPERATION = new BasicOption("use.compare.to.operation", false); //$NON-NLS-1$ /** *

* Parsing option indicating whether to generate a warning when the * OCL 2.1 parsing of distinct xor, or, and precedences leads to a different * parse to the OCL 2.0 specification of all levels equal. * The default value of this option is false. To diagnose * compatibility with the OCL 2.0 behaviour in the MDT-OCL 1.x release, * set this option true. *

* @since 3.0 */ public static final Option WARN_OF_XOR_OR_AND_PRECEDENCE_CHANGE = new BasicOption("warn.of.xor.or.and.precedence.change", false); //$NON-NLS-1$ /** *

* Static instance for the implicit-root-class option token. It is returned * via an unchecked cast by the {@link #implicitRootClass()} method. *

*/ public static final Option IMPLICIT_ROOT_CLASS = new BasicOption("implict.root.class", null); //$NON-NLS-1$ /** * The alternative strategies for resolving the package name at the start of * a path name. The default LOOKUP_PACKAGE_BY_NAME strategy supports the * OMG 2.2 specification. The alternate strategies support a potential extension * for 'import' statements. * * @since 3.1 */ public static enum PACKAGE_LOOKUP_STRATEGIES { /** * LOOKUP_PACKAGE_BY_NAME is the default and traditional * behavior whereby the first package name is resolved by recursive * search from names in the current environment to parent environments. * Once all these search possibilities have been exhausted, the package * registry for the root environment is searched for an already resolved * package whose name matches the first package name. Unresolved package * descriptors are not resolved during this process which also means * that packages contained by yet unresolved in the registry will not be * found. *

* The outward direction of this search allows inner environments to * occlude outer definitions and in some cases may make outer * definitions inaccessible. */ LOOKUP_PACKAGE_BY_NAME, /** * LOOKUP_PACKAGE_BY_ALIAS ignores hierarchical context and just * looks up the first package name as the 'nsURI' key in the package registry * of the root environment. For this to give useful results, the package * registry should be populated with a mapping from package name aliases to packages. *

* This strategy therefore supports a possible import syntax such as: *

  import OclEcore 'http://www.eclipse.org/ocl/1.1.0/Ecore'
* in which OclEcore is defined as an alias for the OCL Ecore package. *

* More than one 'alias' may map to the same package. *

* This strategy is only supported for the Ecore binding. */ LOOKUP_PACKAGE_BY_ALIAS, /** * LOOKUP_PACKAGE_BY_ALIAS_THEN_NAME combines the alias and * traditional strategies. If the first package name can be located as * an alias, then the alias resolution is used, otherwise the recursive * environment search proceeds. *

* This strategy ensures that package name aliases cannot be occluded. *

* In order to use this strategy and avoid cluttering a registry of * packages that may serve other purposes, it is recommended that the * root environment is created with a fresh * {@link EPackageRegistryImpl#EPackageRegistryImpl() registry} that is * populated with the packages required, e.g., by copying all contents * of the {@link EPackage.Registry#INSTANCE default package registry} * using {@link java.util.Map#putAll(java.util.Map)}. Note, that this * will copy unresolved package descriptors to the new registry without * resolving them. *

* This strategy is only supported for the Ecore binding. */ LOOKUP_PACKAGE_BY_ALIAS_THEN_NAME }; /** *

* Static instance for the lookup-package-by-aliase option token. It is returned * via an unchecked cast by the {@link #implicitRootClass()} method. *

* @since 3.1 */ public static final Option PACKAGE_LOOKUP_STRATEGY = new BasicOption("lookup.package.by.alias", PACKAGE_LOOKUP_STRATEGIES.LOOKUP_PACKAGE_BY_NAME); //$NON-NLS-1$ /** *

* Parsing option indicating whether to process backslash escape sequences ( * \n, \r, etc.) as specified by OMG Issue 14357 for OCL 2.3. *

*

* The default value of this option is true. To disable * backslash escaping support, set this option false. *

* * @since 1.3 */ public static final Option USE_BACKSLASH_ESCAPE_PROCESSING = new BasicOption("use.backslash.escape.processing", true); //$NON-NLS-1$ /** *

* A parsing option specifying a class that's assumed to be the implicit * root of the subject model's class hierarchy. Note that this excludes * datatypes defined by OCL such as the collections and tuples, and also those * defined by the subject model. This option is only used in accessing operations * and attributes; for other characteristics of a classifier, a specialized * environment implementation is required. *

* This option is commonly used to provide access to operations and attributes * defined by an implicit root extends class in Ecore-based models, for example, * such as EObject, that is not explicitly referenced in the subject model. *

* The default value of this option is null. *

* * @param the type representing classes in the target metamodel, consistent with * the current {@link Environment} implementation * * @param env the environment to which this option is to be applied * * @return the option token */ @SuppressWarnings("unchecked") public static Option implicitRootClass( Environment env) { return (Option) IMPLICIT_ROOT_CLASS; } /** *

* Parsing option indicating whether to accept static as part of a * definition constraint. static are a proposed cpability of OCL 2.1, * however they are only available for meta-models that implement the * {@link UMLReflection#setIsStatic(Object, boolean)} method. Therefore use of static constraints * will generate an error message on the Ecore binding regardless of this setting. *

* The default value of this option is true. For stricter compatibility * with OCL 2.0, set this option false. *

* @since 3.0 * * @see UMLReflection#setIsStatic(Object, boolean) */ public static final Option SUPPORT_STATIC_FEATURES = new BasicOption("support.static.features", true); //$NON-NLS-1$ /** * Not instantiable by clients. */ private ParsingOptions() { super(); } /** * 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 void setOption(Environment env, Option 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); } /** * 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 getValue(Environment env, Option 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); } }