<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2006 Subclipse project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Subclipse project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.subclipse.core.util;

import java.io.File;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

/**
 * Utility class to get the IResource corresponding to given File
 * 
 * @author <NAME> (cchab at tigris.org)
 */
public class File2Resource {

    /**
     * get the IResource corresponding to the given file. Given file should
     * exist because it is used to determine whether we need to create a
     * IContainer or a IFile
     * 
     * @param file
     * @return
     */
    public static IResource getResource(File file) {
        return getResource(file, file.isDirectory());
    }

    /**
     * get the IResource corresponding to the given file. Given file does not
     * need to exist.
     * 
     * @param file
     * @param isDirectory
     *            if true, an IContainer will be returned, otherwise an IFile
     *            will be returned
     * @return
     */
    public static IResource getResource(File file, boolean isDirectory) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot workspaceRoot = workspace.getRoot();

        IPath pathEclipse = new Path(file.getAbsolutePath());

        IResource resource = null;

        if (isDirectory) {
            resource = workspaceRoot.getContainerForLocation(pathEclipse);
        } else {
            resource = workspaceRoot.getFileForLocation(pathEclipse);
        }
        return resource;
    }

}<commit_msg>Fixed NPE in Revert when text is conflicted by there is no conflict working file.<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2006 Subclipse project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Subclipse project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.subclipse.core.util;

import java.io.File;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

/**
 * Utility class to get the IResource corresponding to given File
 * 
 * @author <NAME> (cchab at tigris.org)
 */
public class File2Resource {

    /**
     * get the IResource corresponding to the given file. Given file should
     * exist because it is used to determine whether we need to create a
     * IContainer or a IFile
     * 
     * @param file
     * @return
     */
    public static IResource getResource(File file) {
    	if (file == null) return null;
        return getResource(file, file.isDirectory());
    }

    /**
     * get the IResource corresponding to the given file. Given file does not
     * need to exist.
     * 
     * @param file
     * @param isDirectory
     *            if true, an IContainer will be returned, otherwise an IFile
     *            will be returned
     * @return
     */
    public static IResource getResource(File file, boolean isDirectory) {
    	if (file == null) return null;
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot workspaceRoot = workspace.getRoot();

        IPath pathEclipse = new Path(file.getAbsolutePath());

        IResource resource = null;

        if (isDirectory) {
            resource = workspaceRoot.getContainerForLocation(pathEclipse);
        } else {
            resource = workspaceRoot.getFileForLocation(pathEclipse);
        }
        return resource;
    }

}
{'fraction_non_alphanumeric': 0.14418103448275862, 'fraction_numerical': 0.005603448275862069, 'mean_word_length': 3.1363636363636362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1793562', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1153, 'n_words': 388}