<commit_before>package mobi.hsz.idea.gitignore.file;

import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor;
import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptorFactory;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.util.IncorrectOperationException;
import mobi.hsz.idea.gitignore.GitignoreBundle;
import mobi.hsz.idea.gitignore.GitignoreLanguage;
import mobi.hsz.idea.gitignore.util.Icons;

public class GitignoreTemplatesFactory implements FileTemplateGroupDescriptorFactory {
    private static final String TEXT = GitignoreBundle.message("file.templateNote");
    private final FileTemplateGroupDescriptor templateGroup;

    public GitignoreTemplatesFactory() {
        templateGroup = new FileTemplateGroupDescriptor(GitignoreLanguage.NAME, Icons.FILE);
        templateGroup.addTemplate(GitignoreLanguage.FILENAME);
    }

    @Override
    public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
        return templateGroup;
    }

    public static PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
        final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
        final PsiFile file = factory.createFileFromText(GitignoreLanguage.FILENAME, GitignoreFileType.INSTANCE, TEXT);
        return (PsiFile) directory.add(file);
    }
}<commit_msg>Fixed #55 - Cannot create .gitignore, file already exists.<commit_after>package mobi.hsz.idea.gitignore.file;

import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor;
import com.intellij.ide.fileTemplates.FileTemplateGroupDescriptorFactory;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.util.IncorrectOperationException;
import mobi.hsz.idea.gitignore.GitignoreBundle;
import mobi.hsz.idea.gitignore.GitignoreLanguage;
import mobi.hsz.idea.gitignore.util.Icons;

public class GitignoreTemplatesFactory implements FileTemplateGroupDescriptorFactory {
    private static final String TEXT = GitignoreBundle.message("file.templateNote");
    private final FileTemplateGroupDescriptor templateGroup;

    public GitignoreTemplatesFactory() {
        templateGroup = new FileTemplateGroupDescriptor(GitignoreLanguage.NAME, Icons.FILE);
        templateGroup.addTemplate(GitignoreLanguage.FILENAME);
    }

    @Override
    public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
        return templateGroup;
    }

    public static PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
        final PsiFile currentFile = directory.findFile(GitignoreLanguage.FILENAME);
        if (currentFile != null) {
            return currentFile;
        }
        final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
        final PsiFile file = factory.createFileFromText(GitignoreLanguage.FILENAME, GitignoreFileType.INSTANCE, TEXT);
        return (PsiFile) directory.add(file);
    }
}
{'fraction_non_alphanumeric': 0.07672469374597034, 'fraction_numerical': 0.0006447453255963894, 'mean_word_length': 5.218436873747495, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2369152', 'n_tokens_mistral': 847, 'n_tokens_neox': 823, 'n_words': 155}