<commit_before>/*
 * 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.services.language;

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

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.palantir.typescript.EclipseResources;
import com.palantir.typescript.services.Bridge;
import com.palantir.typescript.services.Request;

/**
 * The workspace language enpoint.
 *
 * @author dcicerone
 */
public final class LanguageEndpoint {

    private static final String LIB_FILE_NAME = "lib.d.ts";
    private static final String SERVICE = "language";

    private final Bridge bridge;

    public LanguageEndpoint(String endpointName) {
        this.bridge = new Bridge(endpointName);

        this.setLibContents();
    }

    public void cleanProject(IProject project) {
        checkNotNull(project);

        String projectName = project.getName();
        Request request = new Request(SERVICE, "cleanProject", projectName);
        this.bridge.call(request, Void.class);
    }

    public void initializeProject(IProject project) {
        checkNotNull(project);

        // ensure referenced projects are initialized first
        try {
            for (IProject referencedProject : project.getReferencedProjects()) {
                if (!isProjectInitialized(referencedProject)) {
                    this.initializeProject(referencedProject);
                }
            }
        } catch (CoreException e) {
            throw new RuntimeException(e);
        }

        String projectName = project.getName();
        CompilationSettings compilationSettings = CompilationSettings.fromProject(project);
        List<String> referencedProjectNames = getReferencedProjectNames(project);<commit_msg>block loops<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.services.language;

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

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.palantir.typescript.EclipseResources;
import com.palantir.typescript.services.Bridge;
import com.palantir.typescript.services.Request;

/**
 * The workspace language enpoint.
 *
 * @author dcicerone
 */
public final class LanguageEndpoint {

    private static final String LIB_FILE_NAME = "lib.d.ts";
    private static final String SERVICE = "language";

    private final Bridge bridge;

    public LanguageEndpoint(String endpointName) {
        this.bridge = new Bridge(endpointName);

        this.setLibContents();
    }

    public void cleanProject(IProject project) {
        checkNotNull(project);

        String projectName = project.getName();
        Request request = new Request(SERVICE, "cleanProject", projectName);
        this.bridge.call(request, Void.class);
    }

    public void initializeProject(IProject project) {
        checkNotNull(project);

        // ensure referenced projects are initialized first
        try {
            for (IProject referencedProject : project.getReferencedProjects()) {
                if (!isProjectInitialized(referencedProject) && !project.getName().equals(referencedProject.getName())) {
                    this.initializeProject(referencedProject);
                }
            }
        } catch (CoreException e) {
            throw new RuntimeException(e);
        }

        String projectName = project.getName();
        CompilationSettings compilationSettings = CompilationSettings.fromProject(project);
        List<String> referencedProjectNames = getReferencedProjectNames(project);
{'fraction_non_alphanumeric': 0.09025270758122744, 'fraction_numerical': 0.002625533311453889, 'mean_word_length': 3.7065637065637067, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, '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': '5221913', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1553, 'n_words': 431}