<commit_before>package hu.elte.txtuml.export.papyrus.elementsmanagers;

import hu.elte.txtuml.export.papyrus.ModelManager;
import hu.elte.txtuml.export.papyrus.preferences.PreferencesManager;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPart;
import org.eclipse.uml2.uml.*;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;

/**
 * An abstract class for adding/removing elements to ClassDiagrams.
 *
 * @author <NAME>
 */
public class ClassDiagramElementsManager extends AbstractDiagramElementsManager{
	
	private PreferencesManager preferencesManager;
	
	private List<java.lang.Class<?>> elementsToBeAdded;
	private List<java.lang.Class<?>> connectorsToBeAdded;
	private List<java.lang.Class<?>> propertyFieldElementsToBeAdded;
	private List<java.lang.Class<?>> methodFieldElementsToBeAdded;
	
	/**
	 * The Constructor
	 * @param modelManager - The ModelManager which serves the model elements
	 * @param diagramEditPart - The DiagramEditPart of the diagram which is to be handled
	 */
	public ClassDiagramElementsManager(ModelManager modelManager,DiagramEditPart diagramEditPart) {
		super(modelManager, diagramEditPart);
		preferencesManager = new PreferencesManager();
		elementsToBeAdded = generateElementsToBeAdded();
		connectorsToBeAdded = generateConnectorsToBeAdded();
		propertyFieldElementsToBeAdded = generatePropertyFieldElementsToBeAdded();
		methodFieldElementsToBeAdded = generateMethodFieldElementsToBeAdded();
	}

	/**
	 * Returns the types of elements that are to be added
	 * @return Returns the types of elements that are to be added
	 */
	private List<java.lang.Class<?>> generateElementsToBeAdded() {
		List<java.lang.Class<?>> nodes = new LinkedList<java.lang.Class<?>>(
				Arrays.asList(
						Class.class,
						Component.class,
						DataType.class,
						Enumeration.class,
						InformationItem.class,
						InstanceSpecification.class,
						Interface.class,
						Model.class,
						Package.class,
						PrimitiveType.class
				));
		
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_CONSTRAINT_PREF))
			nodes.add(Constraint.class);
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_COMMENT_PREF))
			nodes.add(Comment.class);
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_SIGNAL_PREF))
			nodes.add(Signal.class);
		
		return nodes;
	}
	
	/**
	 * Returns the types of connectors that are to be added
	 * @return Returns the types of connectors that are to be added 
	 */
	private List<java.lang.Class<?>> generateConnectorsToBeAdded() {
		List<java.lang.Class<?>> connectors = Arrays.asList(Association.class, Generalization.class, InterfaceRealization.class);
		return connectors;
	}
	
	/**
	 * Returns the types of elements that are to be added to the 
	 * properties compartment of a class
	 * @return Returns the types of elements that are to be added 
	 * to the properties compartment of a class 
	 */
	private List<java.lang.Class<?>> generatePropertyFieldElementsToBeAdded() {
		List<java.lang.Class<?>> properties= Arrays.asList(Property.class, Port.class);
		return properties;
	}
	
	/**
	 * Returns the types of elements that are to be added to the 
	 * methods compartment of a class
	 * @return Returns the types of elements that are to be added to the 
	 * methods compartment of a class 
	 */
	private List<java.lang.Class<?>> generateMethodFieldElementsToBeAdded() {
		List<java.lang.Class<?>> methods = Arrays.asList(Operation.class, Reception.class);
		return methods;
	}
	
	/*
	 * (non-Javadoc)
	 * @see hu.elte.txtuml.export.papyrus.elementsmanagers.AbstractDiagramElementsManager#addElementsToDiagram(java.util.List)
	 */
	@Override
	public void addElementsToDiagram(List<Element> elements) throws ServiceException {
		List<java.lang.Class<?>> types = new LinkedList<java.lang.Class<?>>();
		types.addAll(elementsToBeAdded);
		types.addAll(connectorsToBeAdded);
		
		for(java.lang.Class<?> type : types){
			List<Element> listofTypes = modelManager.getElementsOfTypeFromList(elements, type);
			if(!listofTypes.isEmpty()){
				super.addElementsToEditpart(diagramEditPart, listofTypes);
			}
		}
		
		@SuppressWarnings("unchecked")
		List<EditPart> editParts = diagramEditPart.getChildren();
		
		for(EditPart editPart : editParts){
			if(editPart instanceof ClassEditPart || editPart instanceof InterfaceEditPart){
				addSubElements(editPart);
			}
		}
	}
	
	/**
	 * Fills up the compartments of classes and interfaces
	 * @param ep - The EditPart of the class or interface
	 * @throws ServiceException
	 */
	private void addSubElements(EditPart ep) throws ServiceException{
		EObject parent = ((View) ep.getModel()).getElement();
		@SuppressWarnings("unchecked")
		List<EditPart> parentEditParts = ep.getChildren();
		List<Element> list = ((Element) parent).getOwnedElements();
		
		List<Element> properties = modelManager.getElementsOfTypesFromList(list, propertyFieldElementsToBeAdded);
		List<Element> methods = modelManager.getElementsOfTypesFromList(list, methodFieldElementsToBeAdded);
	
		EditPart parametersEp = parentEditParts.get(1);
		addElementsToEditpart(parametersEp, properties);
	
		EditPart methodsEp = parentEditParts.get(2);
		addElementsToEditpart(methodsEp, methods);
	}
}
<commit_msg>Association attributes does not come on the attributes compartment of classes.<commit_after>package hu.elte.txtuml.export.papyrus.elementsmanagers;

import hu.elte.txtuml.export.papyrus.ModelManager;
import hu.elte.txtuml.export.papyrus.preferences.PreferencesManager;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPart;
import org.eclipse.uml2.uml.*;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Package;

/**
 * An abstract class for adding/removing elements to ClassDiagrams.
 *
 * @author <NAME>
 */
public class ClassDiagramElementsManager extends AbstractDiagramElementsManager{
	
	private PreferencesManager preferencesManager;
	
	private List<java.lang.Class<?>> elementsToBeAdded;
	private List<java.lang.Class<?>> connectorsToBeAdded;
	private List<java.lang.Class<?>> propertyFieldElementsToBeAdded;
	private List<java.lang.Class<?>> methodFieldElementsToBeAdded;
	
	/**
	 * The Constructor
	 * @param modelManager - The ModelManager which serves the model elements
	 * @param diagramEditPart - The DiagramEditPart of the diagram which is to be handled
	 */
	public ClassDiagramElementsManager(ModelManager modelManager,DiagramEditPart diagramEditPart) {
		super(modelManager, diagramEditPart);
		preferencesManager = new PreferencesManager();
		elementsToBeAdded = generateElementsToBeAdded();
		connectorsToBeAdded = generateConnectorsToBeAdded();
		propertyFieldElementsToBeAdded = generatePropertyFieldElementsToBeAdded();
		methodFieldElementsToBeAdded = generateMethodFieldElementsToBeAdded();
	}

	/**
	 * Returns the types of elements that are to be added
	 * @return Returns the types of elements that are to be added
	 */
	private List<java.lang.Class<?>> generateElementsToBeAdded() {
		List<java.lang.Class<?>> nodes = new LinkedList<java.lang.Class<?>>(
				Arrays.asList(
						Class.class,
						Component.class,
						DataType.class,
						Enumeration.class,
						InformationItem.class,
						InstanceSpecification.class,
						Interface.class,
						Model.class,
						Package.class,
						PrimitiveType.class
				));
		
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_CONSTRAINT_PREF))
			nodes.add(Constraint.class);
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_COMMENT_PREF))
			nodes.add(Comment.class);
		if(preferencesManager.getBoolean(PreferencesManager.CLASS_DIAGRAM_SIGNAL_PREF))
			nodes.add(Signal.class);
		
		return nodes;
	}
	
	/**
	 * Returns the types of connectors that are to be added
	 * @return Returns the types of connectors that are to be added 
	 */
	private List<java.lang.Class<?>> generateConnectorsToBeAdded() {
		List<java.lang.Class<?>> connectors = Arrays.asList(Association.class, Generalization.class, InterfaceRealization.class);
		return connectors;
	}
	
	/**
	 * Returns the types of elements that are to be added to the 
	 * properties compartment of a class
	 * @return Returns the types of elements that are to be added 
	 * to the properties compartment of a class 
	 */
	private List<java.lang.Class<?>> generatePropertyFieldElementsToBeAdded() {
		List<java.lang.Class<?>> properties= Arrays.asList(Property.class, Port.class);
		return properties;
	}
	
	/**
	 * Returns the types of elements that are to be added to the 
	 * methods compartment of a class
	 * @return Returns the types of elements that are to be added to the 
	 * methods compartment of a class 
	 */
	private List<java.lang.Class<?>> generateMethodFieldElementsToBeAdded() {
		List<java.lang.Class<?>> methods = Arrays.asList(Operation.class, Reception.class);
		return methods;
	}
	
	/*
	 * (non-Javadoc)
	 * @see hu.elte.txtuml.export.papyrus.elementsmanagers.AbstractDiagramElementsManager#addElementsToDiagram(java.util.List)
	 */
	@Override
	public void addElementsToDiagram(List<Element> elements) throws ServiceException {
		List<java.lang.Class<?>> types = new LinkedList<java.lang.Class<?>>();
		
		types.addAll(elementsToBeAdded);
		types.addAll(connectorsToBeAdded);
		
		for(java.lang.Class<?> type : types){
			List<Element> listofTypes = modelManager.getElementsOfTypeFromList(elements, type);
			if(!listofTypes.isEmpty()){
				super.addElementsToEditpart(diagramEditPart, listofTypes);
			}
		}
		
		
		@SuppressWarnings("unchecked")
		List<EditPart> editParts = diagramEditPart.getChildren();
		
		for(EditPart editPart : editParts){
			if(editPart instanceof ClassEditPart || editPart instanceof InterfaceEditPart){
				addSubElements(editPart);
			}
		}
	}
	
	/**
	 * Fills up the compartments of classes and interfaces
	 * @param ep - The EditPart of the class or interface
	 * @throws ServiceException
	 */
	private void addSubElements(EditPart ep) throws ServiceException{
		EObject parent = ((View) ep.getModel()).getElement();
		@SuppressWarnings("unchecked")
		List<EditPart> parentEditParts = ep.getChildren();
		List<Element> list = ((Element) parent).getOwnedElements();
		
		List<Element> properties = modelManager.getElementsOfTypesFromList(list, propertyFieldElementsToBeAdded);
		List<Element> methods = modelManager.getElementsOfTypesFromList(list, methodFieldElementsToBeAdded);
		
		removeAssociationProperties(properties);
		
		EditPart parametersEp = parentEditParts.get(1);
		addElementsToEditpart(parametersEp, properties);
	
		EditPart methodsEp = parentEditParts.get(2);
		addElementsToEditpart(methodsEp, methods);
	}
	
	private void removeAssociationProperties(List<Element> properties){
		List<Element> propertiesToRemove = new LinkedList<Element>();
		for(Element property : properties){
			Property prop = (Property) property;
			if(prop.getAssociation() != null){
				propertiesToRemove.add(property);
			}
		}
		properties.removeAll(propertiesToRemove);
	}
}



{'fraction_non_alphanumeric': 0.09974613053803948, 'fraction_numerical': 0.0008189337482597658, 'mean_word_length': 4.328097731239093, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 84, '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': '5331422', 'n_tokens_mistral': 3962, 'n_tokens_neox': 3508, 'n_words': 758}