<commit_before>/*******************************************************************************
 * Copyright (c) 2009, 2012 <NAME> 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:
 *     <NAME> (XMLmodeling.com) - initial API and implementation
 *     <NAME> (IBM Corporation) - added template parameter
 *     <NAME> - generate multiple OCL constraints from one property (artf3121)
 *                        - discriminate multiple property constraints (artf3185)
 *                        - implement terminology constraint dependencies (artf3030)
 *                        - support nested datatype subclasses (artf3350)
 *     
 * $Id$
 *******************************************************************************/
package org.openhealthtools.mdht.uml.transform;

import java.util.Collection;
import java.util.Map;

import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.util.UMLSwitch;
import org.openhealthtools.mdht.uml.common.util.UMLUtil;

/**
 * Abstract base class for model transformations.
 */
public abstract class AbstractTransform extends UMLSwitch<Object> {
	protected TransformerOptions transformerOptions;

	private final IBaseModelReflection baseModelReflection;

	public AbstractTransform(TransformerOptions options, IBaseModelReflection baseModelReflection) {
		transformerOptions = options;
		this.baseModelReflection = baseModelReflection;
	}

	public void removeModelElement(Element element) {
		if (element != null && !isRemoved(element)) {
			transformerOptions.getDeletedElementList().add(element);
		}
	}

	public boolean isRemoved(Element element) {
		return transformerOptions.getDeletedElementList().contains(element);
	}

	protected <C extends Classifier> C getBaseClass(C userClass) {
		return baseModelReflection.getBaseClass(userClass);
	}

	protected Package getBaseModel(Classifier userClass) {
		Package result = baseModelReflection.getBaseModel(userClass);

		if (result == null) {
			// maybe it's not explicitly imported
			Classifier baseClass = getBaseClass(userClass);
			if (baseClass != null) {
				result = UMLUtil.getTopPackage(baseClass);
			}
		}

		return result;
	}

	protected boolean isBaseModel(Element userElement, Element baseElement) {
		return baseModelReflection.isBaseModelElement(userElement, baseElement);
	}

	protected Property getBaseProperty(Property templateProperty) {
		return baseModelReflection.getBaseProperty((Classifier) templateProperty.getOwner(), templateProperty);
	}

	/**
	 * Gets the datatype from the base datatypes model that the specified {@code umlDatatype} specializes, if any, and only if the {@code umlDatatype}
	 * is defined
	 * locally to the given {@code context} element (in the same model as it).
	 * 
	 * @param umlDatatype
	 *            a class that may or may not be a specialization of a base datatype
	 * @param context
	 *            the context in which the datatype is used, or {code null} if the locality check is not required. This is often a {@link Property}
	 *            that is typed by the {@code umlDatatype}
	 * 
	 * @return the base datatype of which the {@code umlDatatype} is a local subclass, or {@code null} if the {@code umlDatatype} is not a local
	 *         subclass of a base datatype
	 */
	protected <C extends Classifier> C getBaseDatatype(C umlDatatype, Element context) {
		C result = baseModelReflection.getBaseDatatype(umlDatatype);<commit_msg>expsosed isbasedatatypemodel to transforms<commit_after>/*******************************************************************************
 * Copyright (c) 2009, 2012 <NAME> 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:
 *     <NAME> (XMLmodeling.com) - initial API and implementation
 *     <NAME> (IBM Corporation) - added template parameter
 *     <NAME> - generate multiple OCL constraints from one property (artf3121)
 *                        - discriminate multiple property constraints (artf3185)
 *                        - implement terminology constraint dependencies (artf3030)
 *                        - support nested datatype subclasses (artf3350)
 *     
 * $Id$
 *******************************************************************************/
package org.openhealthtools.mdht.uml.transform;

import java.util.Collection;
import java.util.Map;

import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.util.UMLSwitch;
import org.openhealthtools.mdht.uml.common.util.UMLUtil;

/**
 * Abstract base class for model transformations.
 */
public abstract class AbstractTransform extends UMLSwitch<Object> {
	protected TransformerOptions transformerOptions;

	protected final IBaseModelReflection baseModelReflection;

	public AbstractTransform(TransformerOptions options, IBaseModelReflection baseModelReflection) {
		transformerOptions = options;
		this.baseModelReflection = baseModelReflection;
	}

	public void removeModelElement(Element element) {
		if (element != null && !isRemoved(element)) {
			transformerOptions.getDeletedElementList().add(element);
		}
	}

	public boolean isRemoved(Element element) {
		return transformerOptions.getDeletedElementList().contains(element);
	}

	protected <C extends Classifier> C getBaseClass(C userClass) {
		return baseModelReflection.getBaseClass(userClass);
	}

	protected Package getBaseModel(Classifier userClass) {
		Package result = baseModelReflection.getBaseModel(userClass);

		if (result == null) {
			// maybe it's not explicitly imported
			Classifier baseClass = getBaseClass(userClass);
			if (baseClass != null) {
				result = UMLUtil.getTopPackage(baseClass);
			}
		}

		return result;
	}

	protected boolean isBaseModel(Element userElement, Element baseElement) {
		return baseModelReflection.isBaseModelElement(userElement, baseElement);
	}

	protected boolean isDatatypesModelElement(Element context, Element base) {
		return baseModelReflection.isDatatypesModelElement(context, base);
	}

	protected Property getBaseProperty(Property templateProperty) {
		return baseModelReflection.getBaseProperty((Classifier) templateProperty.getOwner(), templateProperty);
	}

	/**
	 * Gets the datatype from the base datatypes model that the specified {@code umlDatatype} specializes, if any, and only if the {@code umlDatatype}
	 * is defined
	 * locally to the given {@code context} element (in the same model as it).
	 * 
	 * @param umlDatatype
	 *            a class that may or may not be a specialization of a base datatype
	 * @param context
	 *            the context in which the datatype is used, or {code null} if the locality check is not required. This is often a {@link Property}
	 *            that is typed by the {@code umlDatatype}
	 * 
	 * @return the base datatype of which the {@code umlDatatype} is a local subclass, or {@code null} if the {@code umlDatatype} is not a local
	 *         subclass of a base datatype
	 */
	protected <C extends Classifier> C getBaseDatatype(C umlDatatype, Element context) {
		C result = baseModelReflection.getBaseDatatype(umlDatatype);
{'fraction_non_alphanumeric': 0.12070302403721891, 'fraction_numerical': 0.009046265184802274, 'mean_word_length': 4.297056810403833, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1470540', 'n_tokens_mistral': 2215, 'n_tokens_neox': 2040, 'n_words': 645}