<commit_before>package jce.codemanipulation.origin;

import static jce.properties.TextProperty.WRAPPER_PACKAGE;
import static jce.properties.TextProperty.WRAPPER_PREFIX;
import static jce.properties.TextProperty.WRAPPER_SUFFIX;

import org.apache.log4j.LogManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;

import jce.properties.EcorificationProperties;
import jce.util.logging.MonitorFactory;

/**
 * {@link ASTVisitor} class that manipulates the inheritance relations of the origin code.
 * @author <NAME>
 */
public class InheritanceManipulationVisitor extends ASTVisitor {
    private final String currentPackage;
    private final EcorificationProperties properties;
    private final IProgressMonitor monitor;

    /**
     * Basic constructor.
     * @param currentPackage is the current package.
     * @param properties are the Ecorification properties.
     */
    public InheritanceManipulationVisitor(String currentPackage, EcorificationProperties properties) {
        this.currentPackage = currentPackage;
        this.properties = properties;
        monitor = MonitorFactory.createProgressMonitor(LogManager.getLogger(getClass().getName()), properties);
    }

    @Override
    public boolean visit(TypeDeclaration node) {
        if (!node.isInterface()) { // if is class, manipulate inheritance:
            setSuperClass(node, getPackage() + "." + getName(node));
            monitor.beginTask("Changed super type of " + node.getName().getIdentifier(), 0);
        }
        return false;
    }

    /**
     * Returns the name of the super class.
     */
    private String getName(TypeDeclaration node) {
        return properties.get(WRAPPER_PREFIX) + node.getName().toString() + properties.get(WRAPPER_SUFFIX);
    }

    /**
     * Returns the package path of the super class.
     */
    private String getPackage() {
        return properties.get(WRAPPER_PACKAGE) + "." + currentPackage;
    }

    /**
     * Sets a qualified name as super class of a type declaration.
     * @param declaration is the type declaration.
     * @param qualifiedName is the qualified name.
     */
    private void setSuperClass(TypeDeclaration declaration, String qualifiedName) {
        AST ast = declaration.getAST();
        Name name = ast.newName(qualifiedName);
        Type type = ast.newSimpleType(name);
        declaration.setSuperclassType(type);
    }

}<commit_msg>EDIT: Implemented the addition of superinterface relations from origin code interfaces to their correlating Ecore interface.<commit_after>package jce.codemanipulation.origin;

import static jce.properties.TextProperty.ECORE_PACKAGE;
import static jce.properties.TextProperty.WRAPPER_PACKAGE;
import static jce.properties.TextProperty.WRAPPER_PREFIX;
import static jce.properties.TextProperty.WRAPPER_SUFFIX;

import org.apache.log4j.LogManager;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;

import jce.properties.EcorificationProperties;
import jce.util.PathHelper;
import jce.util.logging.MonitorFactory;

/**
 * {@link ASTVisitor} class that manipulates the inheritance relations of the origin code.
 * @author <NAME>
 */
public class InheritanceManipulationVisitor extends ASTVisitor {
    private final String currentPackage;
    private final IProgressMonitor monitor;
    private final PathHelper nameUtil;
    private final EcorificationProperties properties;

    /**
     * Basic constructor.
     * @param currentPackage is the current package.
     * @param properties are the Ecorification properties.
     */
    public InheritanceManipulationVisitor(String currentPackage, EcorificationProperties properties) {
        this.currentPackage = currentPackage;
        this.properties = properties;
        monitor = MonitorFactory.createProgressMonitor(LogManager.getLogger(getClass().getName()), properties);
        nameUtil = new PathHelper('.');
    }

    @Override
    public boolean visit(TypeDeclaration node) {
        if (node.isInterface()) {
            addEcoreInterface(node); // add correlating Ecore interface as super interface
        } else {
            overrideSuperclass(node); // set correlating wrapper as super class
        }
        return false;
    }

    /**
     * Adds the correlating Ecore interface of an {@link TypeDeclaration} as super interface. Other superinterfaces are
     * being retained.
     */
    @SuppressWarnings("unchecked")
    private void addEcoreInterface(TypeDeclaration node) {
        String name = nameUtil.append(properties.get(ECORE_PACKAGE), currentPackage, node.getName().getIdentifier());
        node.superInterfaceTypes().add(nameToType(node, name));
        monitor.beginTask("Added Ecore super interface to " + node.getName().getIdentifier(), 0);
    }

    /**
     * Returns the name of the super class.
     */
    private String getWrapperName(TypeDeclaration node) {
        return properties.get(WRAPPER_PREFIX) + node.getName().getIdentifier() + properties.get(WRAPPER_SUFFIX);
    }

    /**
     * Builds an {@link SimpleType} out of an fully qualified name and a {@link TypeDeclaration}.
     */
    private Type nameToType(TypeDeclaration declaration, String qualifiedName) {
        AST ast = declaration.getAST();
        Name name = ast.newName(qualifiedName);
        return ast.newSimpleType(name);
    }

    /**
     * Sets the correlating wrapper class of an {@link TypeDeclaration} as the super class. This overrides the old super
     * class.
     */
    private void overrideSuperclass(TypeDeclaration node) {
        String name = nameUtil.append(properties.get(WRAPPER_PACKAGE), currentPackage, getWrapperName(node));
        node.setSuperclassType(nameToType(node, name));
        monitor.beginTask("Changed super type of " + node.getName().getIdentifier(), 0);
    }

}
{'fraction_non_alphanumeric': 0.0940157227659233, 'fraction_numerical': 0.0008021819348628269, 'mean_word_length': 3.614359733530718, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1795934', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1648, 'n_words': 432}