<commit_before>/*
 * Copyright 2013 <NAME>, Inc.
 *
 * 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 com.palantir.typescript;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.texteditor.MarkerUtilities;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.palantir.typescript.services.language.CompilationSettings;
import com.palantir.typescript.services.language.Diagnostic;
import com.palantir.typescript.services.language.FileDelta;
import com.palantir.typescript.services.language.LanguageService;
import com.palantir.typescript.services.language.LanguageVersion;
import com.palantir.typescript.services.language.ModuleGenTarget;

/**
 * The TypeScript builder transpiles TypeScript files into JavaScript.
 *
 * @author dcicerone
 */
public final class TypeScriptBuilder extends IncrementalProjectBuilder {

    public static final String ID = "com.palantir.typescript.typeScriptBuilder";

    private static final String MARKER_TYPE = "com.palantir.typescript.typeScriptProblem";

    private LanguageService languageService;

    @Override
    protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
        checkNotNull(monitor);

        if (this.languageService == null) {
            this.languageService = new LanguageService(this.getProject());
        }

        IPreferenceStore store = TypeScriptPlugin.getDefault().getPreferenceStore();

        if (store.getBoolean(IPreferenceConstants.COMPILER_COMPILE_ON_SAVE)) {
            this.languageService.setCompilationSettings(this.getWorkspaceCompilationSettings(store));

            switch (kind) {
                case IncrementalProjectBuilder.AUTO_BUILD:
                case IncrementalProjectBuilder.INCREMENTAL_BUILD:
                    this.incrementalBuild(monitor);
                    break;
                case IncrementalProjectBuilder.FULL_BUILD:
                    this.fullBuild(monitor);
                    break;
            }
        } else {
            this.updateMarkers();
        }
        return null;
    }

    private CompilationSettings getWorkspaceCompilationSettings(IPreferenceStore store) {
        return new CompilationSettings(
            store.getBoolean(IPreferenceConstants.COMPILER_NO_LIB),
            LanguageVersion.valueOf(store.getString(IPreferenceConstants.COMPILER_CODE_GEN_TARGET)),
            ModuleGenTarget.valueOf(store.getString(IPreferenceConstants.COMPILER_MODULE_GEN_TARGET)),
            store.getBoolean(IPreferenceConstants.COMPILER_MAP_SOURCE_FILES),
            store.getBoolean(IPreferenceConstants.COMPILER_REMOVE_COMMENTS));
    }<commit_msg>Small tweak to build startup<commit_after>/*
 * Copyright 2013 Palantir Technologies, Inc.
 *
 * 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 com.palantir.typescript;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.texteditor.MarkerUtilities;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.palantir.typescript.services.language.CompilationSettings;
import com.palantir.typescript.services.language.Diagnostic;
import com.palantir.typescript.services.language.FileDelta;
import com.palantir.typescript.services.language.LanguageService;
import com.palantir.typescript.services.language.LanguageVersion;
import com.palantir.typescript.services.language.ModuleGenTarget;

/**
 * The TypeScript builder transpiles TypeScript files into JavaScript.
 *
 * @author dcicerone
 */
public final class TypeScriptBuilder extends IncrementalProjectBuilder {

    public static final String ID = "com.palantir.typescript.typeScriptBuilder";

    private static final String MARKER_TYPE = "com.palantir.typescript.typeScriptProblem";

    private LanguageService languageService;

    @Override
    protected void startupOnInitialize() {
        super.startupOnInitialize();

        this.languageService = new LanguageService(this.getProject());
    }

    @Override
    protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
        checkNotNull(monitor);

        IPreferenceStore store = TypeScriptPlugin.getDefault().getPreferenceStore();

        if (store.getBoolean(IPreferenceConstants.COMPILER_COMPILE_ON_SAVE)) {
            this.languageService.setCompilationSettings(this.getWorkspaceCompilationSettings(store));

            switch (kind) {
                case IncrementalProjectBuilder.AUTO_BUILD:
                case IncrementalProjectBuilder.INCREMENTAL_BUILD:
                    this.incrementalBuild(monitor);
                    break;
                case IncrementalProjectBuilder.FULL_BUILD:
                    this.fullBuild(monitor);
                    break;
            }
        } else {
            this.updateMarkers();
        }

        return null;
    }

    private CompilationSettings getWorkspaceCompilationSettings(IPreferenceStore store) {
        return new CompilationSettings(
            store.getBoolean(IPreferenceConstants.COMPILER_NO_LIB),
            LanguageVersion.valueOf(store.getString(IPreferenceConstants.COMPILER_CODE_GEN_TARGET)),
            ModuleGenTarget.valueOf(store.getString(IPreferenceConstants.COMPILER_MODULE_GEN_TARGET)),
            store.getBoolean(IPreferenceConstants.COMPILER_MAP_SOURCE_FILES),
            store.getBoolean(IPreferenceConstants.COMPILER_REMOVE_COMMENTS));
    }
{'fraction_non_alphanumeric': 0.08202927814235235, 'fraction_numerical': 0.0020191822311963654, 'mean_word_length': 3.8829328404189773, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '535421', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2045, 'n_words': 449}