<commit_before>/*
 * External Code Formatter
 * Copyright (c) 2007 <NAME>, www.orfjackal.net
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.orfjackal.extformatter;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;

/**
 * @author <NAME>
 * @since 1.12.2007
 */
public class EclipseCodeFormatter implements CodeFormatter {

    @NotNull private File eclipseInstallDir;
    @NotNull private File eclipsePrefsFile;
    @NotNull private Executer executer;

    public EclipseCodeFormatter(@NotNull File eclipseInstallDir, @NotNull File eclipsePrefsFile) {
        this.eclipseInstallDir = eclipseInstallDir;
        this.eclipsePrefsFile = eclipsePrefsFile;
        this.executer = new ExecuterImpl();
    }

    public void reformatFile(@NotNull File file) {
        try {
            executer.execute(commandFor(quoted(file.getCanonicalPath())));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void reformatFiles(@NotNull File... files) {
        try {
            executer.execute(commandFor(listOf(files)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void reformatFilesInDirectory(@NotNull File directory) {
        // TODO
    }

    public void reformatFilesInDirectoryRecursively(@NotNull File directory) {
        // TODO
    }

    private String commandFor(String path) {
        /*
         *  Usage: eclipse -application org.eclipse.jdt.core.JavaCodeFormatter [ OPTIONS ] -config <configFile> <files>
         *
         *     <files>   Java source files and/or directories to format.
         *               Only files ending with .java will be formatted in the given directory.
         *     -config <configFile> Use the formatting style from the specified properties file.
         *                          Refer to the help documentation to find out how to generate this file.
         *
         *   OPTIONS:
         *<commit_msg>Reformat directory recursively<commit_after>/*
 * External Code Formatter
 * Copyright (c) 2007 <NAME>, www.orfjackal.net
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.orfjackal.extformatter;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;

/**
 * @author <NAME>
 * @since 1.12.2007
 */
public class EclipseCodeFormatter implements CodeFormatter {

    @NotNull private File eclipseInstallDir;
    @NotNull private File eclipsePrefsFile;
    @NotNull private Executer executer;

    public EclipseCodeFormatter(@NotNull File eclipseInstallDir, @NotNull File eclipsePrefsFile) {
        this.eclipseInstallDir = eclipseInstallDir;
        this.eclipsePrefsFile = eclipsePrefsFile;
        this.executer = new ExecuterImpl();
    }

    public void reformatFile(@NotNull File file) {
        try {
            executer.execute(commandFor(quoted(file.getCanonicalPath())));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void reformatFiles(@NotNull File... files) {
        try {
            executer.execute(commandFor(listOf(files)));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void reformatFilesInDirectory(@NotNull File directory) {
    }

    public void reformatFilesInDirectoryRecursively(@NotNull File directory) {
        try {
            executer.execute(commandFor(quoted(directory.getCanonicalPath())));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private String commandFor(String path) {
        /*
         *  Usage: eclipse -application org.eclipse.jdt.core.JavaCodeFormatter [ OPTIONS ] -config <configFile> <files>
         *
         *     <files>   Java source files and/or directories to format.
         *               Only files ending with .java will be formatted in the given directory.
         *     -config <configFile> Use the formatting style from the specified properties file.
         *                          Refer to the help documentation to find out how to generate this file.
         *
         *   OPTIONS:
         *
{'fraction_non_alphanumeric': 0.08161708619374523, 'fraction_numerical': 0.005720823798627002, 'mean_word_length': 2.629757785467128, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2280944', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1316, 'n_words': 458}