<commit_before>/**
 *  Copyright (c) 2012, 2016 Sme.UP 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> 			 - Initial API and implementation
 *   <NAME> - Implementation
 */
package org.smeup.sys.dk.compiler.rpj;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.smeup.sys.dk.compiler.DevelopmentKitCompilerRuntimeException;
import org.smeup.sys.dk.compiler.QCompilationUnit;
import org.smeup.sys.dk.compiler.QDerived;
import org.smeup.sys.dk.compiler.QDevelopmentKitCompilerFactory;
import org.smeup.sys.il.data.QDataContext;
import org.smeup.sys.il.data.QDataStruct;
import org.smeup.sys.il.data.def.QBinaryDef;
import org.smeup.sys.il.data.def.QCharacterDef;
import org.smeup.sys.il.data.def.QCompoundDataDef;
import org.smeup.sys.il.data.def.QDataAreaDef;
import org.smeup.sys.il.data.def.QDataDef;
import org.smeup.sys.il.data.def.QDataStructDef;
import org.smeup.sys.il.data.def.QDecimalDef;
import org.smeup.sys.il.data.def.QIndicatorDef;
import org.smeup.sys.il.data.def.QMultipleAtomicBufferedDataDef;
import org.smeup.sys.il.data.def.QMultipleAtomicDataDef;
import org.smeup.sys.il.data.def.QStrollerDef;
import org.smeup.sys.il.data.term.QDataTerm;
import org.smeup.sys.il.data.term.impl.DataTermVisitorImpl;

public abstract class RPJAbstractDataRefactor extends DataTermVisitorImpl {

	private QCompilationUnit compilationUnit;

	@Inject
	public RPJAbstractDataRefactor(QCompilationUnit compilationUnit) {
		this.compilationUnit = compilationUnit;
	}

	protected QCompilationUnit getCompilationUnit() {
		return this.compilationUnit;
	}

	public abstract RPJAbstractDataRefactor copy();

	@SuppressWarnings("unchecked")
	@Override
	public boolean visit(QDataTerm<?> dataTerm) {


		if (dataTerm.getDataTermType() != null && dataTerm.getDataTermType().isCompound()) {
			QCompoundDataDef<?, QDataTerm<?>> compoundDataDef = null;
			
			if (dataTerm.getDefinition() instanceof QDataAreaDef) {
				QDataAreaDef<?> dataAreaDef = (QDataAreaDef<?>) dataTerm.getDefinition();
				compoundDataDef = (QCompoundDataDef<?, QDataTerm<?>>) dataAreaDef.getArgument();
			} else
				compoundDataDef = (QCompoundDataDef<?, QDataTerm<?>>) dataTerm.getDefinition();
			

			RPJAbstractDataRefactor visitor = this.copy();
			for (QDataTerm<?> elementTerm : compoundDataDef.getElements())
				elementTerm.accept(visitor);
		}

		return false;
	}

	protected void appendDefinitionToMultiple(QDataDef<?> source, QDataTerm<QMultipleAtomicDataDef<?>> termTarget) {

		QMultipleAtomicBufferedDataDef<?> target = (QMultipleAtomicBufferedDataDef<?>) termTarget.getDefinition();

		if (!source.getClass().equals(target.getArgument().getClass())) {
			if (target.getArgument() instanceof QCharacterDef && source instanceof QDecimalDef) {
				target.setArgument((QDecimalDef) EcoreUtil.copy((EObject) source));
				appendDefinition(source, target.getArgument());
			} else
				throw new DevelopmentKitCompilerRuntimeException("Unexpected condition: sb9r89tnbr9tbnt9s");
		} else
			appendDefinition(source, target.getArgument());
	}

	@SuppressWarnings("unchecked")
	protected void appendDefinition(QDataDef<?> source, QDataTerm<?> termTarget) {

		QDataDef<?> target = termTarget.getDefinition();

		if (!source.getClass().equals(target.getClass())) {
			if (target instanceof QCharacterDef && source instanceof QDecimalDef) {
				((QDataTerm<QDecimalDef>) termTarget).setDefinition((QDecimalDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else if (target instanceof QCharacterDef && source instanceof QBinaryDef) {
				((QDataTerm<QBinaryDef>) termTarget).setDefinition((QBinaryDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else if (target instanceof QCharacterDef && source instanceof QIndicatorDef) {
				((QDataTerm<QIndicatorDef>) termTarget).setDefinition((QIndicatorDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else
				throw new DevelopmentKitCompilerRuntimeException("Unexpected condition: sb8te8rtwbr9tbnt9s");
		}

		appendDefinition(source, target);
	}<commit_msg>Patch compilatore<commit_after>/**
 *  Copyright (c) 2012, 2016 Sme.UP 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> 			 - Initial API and implementation
 *   <NAME> - Implementation
 */
package org.smeup.sys.dk.compiler.rpj;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.smeup.sys.dk.compiler.DevelopmentKitCompilerRuntimeException;
import org.smeup.sys.dk.compiler.QCompilationUnit;
import org.smeup.sys.dk.compiler.QDerived;
import org.smeup.sys.dk.compiler.QDevelopmentKitCompilerFactory;
import org.smeup.sys.il.data.QDataContext;
import org.smeup.sys.il.data.QDataStruct;
import org.smeup.sys.il.data.def.QBinaryDef;
import org.smeup.sys.il.data.def.QCharacterDef;
import org.smeup.sys.il.data.def.QCompoundDataDef;
import org.smeup.sys.il.data.def.QDataAreaDef;
import org.smeup.sys.il.data.def.QDataDef;
import org.smeup.sys.il.data.def.QDataStructDef;
import org.smeup.sys.il.data.def.QDecimalDef;
import org.smeup.sys.il.data.def.QIndicatorDef;
import org.smeup.sys.il.data.def.QMultipleAtomicBufferedDataDef;
import org.smeup.sys.il.data.def.QMultipleAtomicDataDef;
import org.smeup.sys.il.data.def.QStrollerDef;
import org.smeup.sys.il.data.term.QDataTerm;
import org.smeup.sys.il.data.term.impl.DataTermVisitorImpl;

public abstract class RPJAbstractDataRefactor extends DataTermVisitorImpl {

	private QCompilationUnit compilationUnit;

	@Inject
	public RPJAbstractDataRefactor(QCompilationUnit compilationUnit) {
		this.compilationUnit = compilationUnit;
	}

	protected QCompilationUnit getCompilationUnit() {
		return this.compilationUnit;
	}

	public abstract RPJAbstractDataRefactor copy();

	@SuppressWarnings("unchecked")
	@Override
	public boolean visit(QDataTerm<?> dataTerm) {


		if (dataTerm.getDataTermType() != null && dataTerm.getDataTermType().isCompound()) {
			QCompoundDataDef<?, QDataTerm<?>> compoundDataDef = null;
			
			if (dataTerm.getDefinition() instanceof QDataAreaDef) {
				QDataAreaDef<?> dataAreaDef = (QDataAreaDef<?>) dataTerm.getDefinition();
				compoundDataDef = (QCompoundDataDef<?, QDataTerm<?>>) dataAreaDef.getArgument();
			} else
				compoundDataDef = (QCompoundDataDef<?, QDataTerm<?>>) dataTerm.getDefinition();
			

			RPJAbstractDataRefactor visitor = this.copy();
			for (QDataTerm<?> elementTerm : compoundDataDef.getElements())
				elementTerm.accept(visitor);
		}

		return false;
	}

	protected void appendDefinitionToMultiple(QDataDef<?> source, QDataTerm<QMultipleAtomicDataDef<?>> termTarget) {

		QMultipleAtomicBufferedDataDef<?> target = (QMultipleAtomicBufferedDataDef<?>) termTarget.getDefinition();

		if (!source.getClass().equals(target.getArgument().getClass())) {
			if (target.getArgument() instanceof QCharacterDef && source instanceof QDecimalDef) {
				target.setArgument((QDecimalDef) EcoreUtil.copy((EObject) source));
				appendDefinition(source, target.getArgument());
			}
			else if (target.getArgument() instanceof QCharacterDef && source instanceof QIndicatorDef) {
				target.setArgument((QIndicatorDef) EcoreUtil.copy((EObject) source));
				appendDefinition(source, target.getArgument());
			}
			else
				throw new DevelopmentKitCompilerRuntimeException("Unexpected condition: sb9r89tnbr9tbnt9s");
		} else
			appendDefinition(source, target.getArgument());
	}

	@SuppressWarnings("unchecked")
	protected void appendDefinition(QDataDef<?> source, QDataTerm<?> termTarget) {

		QDataDef<?> target = termTarget.getDefinition();

		if (!source.getClass().equals(target.getClass())) {
			if (target instanceof QCharacterDef && source instanceof QDecimalDef) {
				((QDataTerm<QDecimalDef>) termTarget).setDefinition((QDecimalDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else if (target instanceof QCharacterDef && source instanceof QBinaryDef) {
				((QDataTerm<QBinaryDef>) termTarget).setDefinition((QBinaryDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else if (target instanceof QCharacterDef && source instanceof QIndicatorDef) {
				((QDataTerm<QIndicatorDef>) termTarget).setDefinition((QIndicatorDef) EcoreUtil.copy((EObject) source));
				target = termTarget.getDefinition();
			} else
				throw new DevelopmentKitCompilerRuntimeException("Unexpected condition: sb8te8rtwbr9tbnt9s");
		}

		appendDefinition(source, target);
	}
{'fraction_non_alphanumeric': 0.12016752577319588, 'fraction_numerical': 0.004510309278350515, 'mean_word_length': 5.581625441696113, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987844', 'n_tokens_mistral': 3155, 'n_tokens_neox': 2941, 'n_words': 532}