<commit_before>/*
 * Copyright 2007 <NAME>
 *
 * 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.stevechaloner.intellijad.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import net.stevechaloner.intellijad.IntelliJadConstants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Closes all files marked as being decompiled by IntelliJad.
 */
public class CloseAllDecompiledFilesAction extends AnAction
{
    /** {@inheritDoc} */
    public void update(AnActionEvent e) {
        Project project = DataKeys.PROJECT.getData(e.getDataContext());
        List<VirtualFile> files = new ArrayList<VirtualFile>(Arrays.asList(FileEditorManager.getInstance(project).getOpenFiles()));
        boolean hasDecompiledFiles = false;

        for (int i = 0; !hasDecompiledFiles && i < files.size(); i++) {
            if (files.get(i).getUserData(IntelliJadConstants.DECOMPILED_BY_INTELLIJAD) != null)
            {
                hasDecompiledFiles = true;
            }
        }
        e.getPresentation().setEnabled(hasDecompiledFiles);
    }

    /** {@inheritDoc} */
    public void actionPerformed(AnActionEvent e)
    {
        Project project = DataKeys.PROJECT.getData(e.getDataContext());
        List<VirtualFile> files = new ArrayList<VirtualFile>(Arrays.asList(FileEditorManager.getInstance(project).getOpenFiles()));

        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        for (VirtualFile file : files)
        {
            if (file.getUserData(IntelliJadConstants.DECOMPILED_BY_INTELLIJAD) != null)
            {
                fileEditorManager.closeFile(file);
            }
        }
    }
}<commit_msg>check if project == null before using it<commit_after>/*
 * Copyright 2007 <NAME>
 *
 * 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.stevechaloner.intellijad.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import net.stevechaloner.intellijad.IntelliJadConstants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Closes all files marked as being decompiled by IntelliJad.
 */
public class CloseAllDecompiledFilesAction extends AnAction
{
    /** {@inheritDoc} */
    public void update(AnActionEvent e) {
        Project project = DataKeys.PROJECT.getData(e.getDataContext());
        boolean enabled = false;
	if (project != null)
            List<VirtualFile> files = new ArrayList<VirtualFile>(Arrays.asList(FileEditorManager.getInstance(project).getOpenFiles()));

            for (int i = 0; !hasDecompiledFiles && i < files.size(); i++) {
                if (files.get(i).getUserData(IntelliJadConstants.DECOMPILED_BY_INTELLIJAD) != null)
                {
                    enabled = true;
                }
            }
        }
        e.getPresentation().setEnabled(enabled);
    }

    /** {@inheritDoc} */
    public void actionPerformed(AnActionEvent e)
    {
        Project project = DataKeys.PROJECT.getData(e.getDataContext());
        List<VirtualFile> files = new ArrayList<VirtualFile>(Arrays.asList(FileEditorManager.getInstance(project).getOpenFiles()));

        FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
        for (VirtualFile file : files)
        {
            if (file.getUserData(IntelliJadConstants.DECOMPILED_BY_INTELLIJAD) != null)
            {
                fileEditorManager.closeFile(file);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09803528468323977, 'fraction_numerical': 0.0036086607858861267, 'mean_word_length': 3.376315789473684, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '5714411', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1392, 'n_words': 349}