<commit_before>package de.cooperateproject.modeling.textual.cls.derivedstate.remover;

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.TypedElement;

import de.cooperateproject.modeling.textual.cls.cls.AssociationMemberEnd;
import de.cooperateproject.modeling.textual.cls.cls.XtextAssociation;
import de.cooperateproject.modeling.textual.common.metamodel.textualCommons.Cardinality;
import de.cooperateproject.modeling.textual.common.metamodel.textualCommons.UMLReferencingElement;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.Applicability;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.AtomicDerivedStateProcessorBase;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.DerivedStateProcessorApplicability;

/**
 * State remover for Xtext associations.
 */
@Applicability(applicabilities = DerivedStateProcessorApplicability.CLEANING)
public class XtextAssociationRemover extends AtomicDerivedStateProcessorBase<XtextAssociation> {

    /**
     * Constructs the state remover.
     */
    public XtextAssociationRemover() {
        super(XtextAssociation.class);
    }

    @Override
    protected void applyTyped(XtextAssociation object) {
        object.getMemberEndCardinalities().clear();
        object.getMemberEndNames().clear();
        object.getMemberEndNavigabilities().clear();
        object.getMemberEndTypes().clear();
        object.getMemberEnds().forEach(XtextAssociationRemover::process);
    }

    private static void process(AssociationMemberEnd memberEnd) {
        if (memberEnd.getReferencedElement() != null) {
            if (Objects.equals(memberEnd.getName(), memberEnd.getReferencedElement().getName())) {
                memberEnd.unsetName();
            }
            if (Optional.ofNullable(memberEnd.getType()).map(UMLReferencingElement::getReferencedElement)
                    .equals(Optional.ofNullable(memberEnd.getReferencedElement()).map(TypedElement::getType))) {
                memberEnd.unsetAggregationKind();
            }
            if (memberEnd.isNavigable() == memberEnd.getReferencedElement().isNavigable()) {
                memberEnd.unsetNavigable();
            }
            Optional.ofNullable(memberEnd.getCardinality()).ifPresent(XtextAssociationRemover::process);
        }
    }

    private static void process(Cardinality cardinality) {
        if (cardinality.getReferencedElement() != null) {
            if (cardinality.getLowerBound() == cardinality.getReferencedElement().getLower()) {
                cardinality.unsetLowerBound();
            }
            if (cardinality.getUpperBound() == cardinality.getReferencedElement().getUpper()) {
                cardinality.unsetUpperBound();
            }
        }
    }

    @Override
    public Collection<Class<? extends EObject>> getRequirements() {
        return Arrays.asList(UMLReferencingElement.class);
    }

}
<commit_msg>#89 Fixed bug in handling types of association member ends<commit_after>package de.cooperateproject.modeling.textual.cls.derivedstate.remover;

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.TypedElement;

import de.cooperateproject.modeling.textual.cls.cls.AssociationMemberEnd;
import de.cooperateproject.modeling.textual.cls.cls.ClsPackage;
import de.cooperateproject.modeling.textual.cls.cls.XtextAssociation;
import de.cooperateproject.modeling.textual.cls.utils.ClsConversionUtilities;
import de.cooperateproject.modeling.textual.common.metamodel.textualCommons.Cardinality;
import de.cooperateproject.modeling.textual.common.metamodel.textualCommons.UMLReferencingElement;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.Applicability;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.AtomicDerivedStateProcessorBase;
import de.cooperateproject.modeling.textual.xtext.runtime.derivedstate.initializer.DerivedStateProcessorApplicability;

/**
 * State remover for Xtext associations.
 */
@Applicability(applicabilities = DerivedStateProcessorApplicability.CLEANING)
public class XtextAssociationRemover extends AtomicDerivedStateProcessorBase<XtextAssociation> {

    /**
     * Constructs the state remover.
     */
    public XtextAssociationRemover() {
        super(XtextAssociation.class);
    }

    @Override
    protected void applyTyped(XtextAssociation object) {
        object.getMemberEndCardinalities().clear();
        object.getMemberEndNames().clear();
        object.getMemberEndNavigabilities().clear();
        object.getMemberEndTypes().clear();
        object.getMemberEnds().forEach(XtextAssociationRemover::process);
    }

    private static void process(AssociationMemberEnd memberEnd) {
        if (memberEnd.getReferencedElement() != null) {
            if (Objects.equals(memberEnd.getName(), memberEnd.getReferencedElement().getName())) {
                memberEnd.unsetName();
            }
            if (Optional.ofNullable(memberEnd.getType()).map(UMLReferencingElement::getReferencedElement)
                    .equals(Optional.ofNullable(memberEnd.getReferencedElement()).map(TypedElement::getType))) {
                memberEnd.eUnset(ClsPackage.Literals.ASSOCIATION_MEMBER_END__TYPE);
            }
            if (memberEnd.isNavigable() == memberEnd.getReferencedElement().isNavigable()) {
                memberEnd.unsetNavigable();
            }
            if (memberEnd.getReferencedElement().getAggregation() == ClsConversionUtilities
                    .convert(memberEnd.getAggregationKind())) {
                memberEnd.unsetAggregationKind();
            }
            Optional.ofNullable(memberEnd.getCardinality()).ifPresent(XtextAssociationRemover::process);
        }
    }

    private static void process(Cardinality cardinality) {
        if (cardinality.getReferencedElement() != null) {
            if (cardinality.getLowerBound() == cardinality.getReferencedElement().getLower()) {
                cardinality.unsetLowerBound();
            }
            if (cardinality.getUpperBound() == cardinality.getReferencedElement().getUpper()) {
                cardinality.unsetUpperBound();
            }
        }
    }

    @Override
    public Collection<Class<? extends EObject>> getRequirements() {
        return Arrays.asList(UMLReferencingElement.class);
    }

}

{'fraction_non_alphanumeric': 0.1043648995619997, 'fraction_numerical': 0.0006041383476816191, 'mean_word_length': 3.686482661004954, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5838042', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1827, 'n_words': 222}