<commit_before>package hu.elte.txtuml.utils.eclipse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ListSelectionDialog;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

public final class SaveUtils {
	public static HashSet<String> getPackageElements(String projectName, String modelName,
			Iterable<String> descriptions) {
		HashSet<String> packageElements = new HashSet<String>();

		for (String description : descriptions) {
			packageElements.add(description + ".java");
		}

		try {
			IPackageFragment[] packages = PackageUtils.findPackageFragments(projectName, modelName);

			for (IPackageFragment pack : packages) {
				String packageName = pack.getElementName();

				for (IJavaElement elem : pack.getChildren()) {
					String fileName = elem.getElementName();
					String fullName = packageName + "." + fileName;

					packageElements.add(fullName);
				}
			}
		} catch (JavaModelException | NotFoundException ex) {
		}

		return packageElements;
	}

	public static ArrayList<IEditorPart> getAffectedDirtyEditors(String projectName, String modelName,
			Iterable<String> descriptions) {
		HashSet<String> packageElements = getPackageElements(projectName, modelName, descriptions);
		IEditorPart[] dirtyEditors = getDitryEditors();
		ArrayList<IEditorPart> affectedEditors = new ArrayList<IEditorPart>(dirtyEditors.length);

		for (IEditorPart part : dirtyEditors) {
			IEditorInput input = part.getEditorInput();

			if (input instanceof IFileEditorInput) {
				String packageName = JavaCore.create(((IFileEditorInput) input).getFile().getParent()).getElementName();
				String fileName = input.getName();
				String fullName = packageName + "." + fileName;

				if (packageElements.contains(fullName)) {
					affectedEditors.add(part);
				}<commit_msg>Fix SaveUtils #501<commit_after>package hu.elte.txtuml.utils.eclipse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ListSelectionDialog;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

public final class SaveUtils {
	public static HashSet<String> getPackageElements(String projectName, String modelName,
			Iterable<String> descriptions) {
		HashSet<String> packageElements = new HashSet<String>();

		for (String description : descriptions) {
			packageElements.add(description + ".java");
		}

		try {
			IPackageFragment[] packages = PackageUtils.findPackageFragments(projectName, modelName);

			for (IPackageFragment pack : packages) {
				String packageName = pack.getElementName();

				for (IJavaElement elem : pack.getChildren()) {
					String fileName = elem.getElementName();
					String fullName = packageName + "." + fileName;

					packageElements.add(fullName);
				}
			}
		} catch (JavaModelException | NotFoundException ex) {
		}

		return packageElements;
	}

	public static ArrayList<IEditorPart> getAffectedDirtyEditors(String projectName, String modelName,
			Iterable<String> descriptions) {
		HashSet<String> packageElements = getPackageElements(projectName, modelName, descriptions);
		IEditorPart[] dirtyEditors = getDitryEditors();
		ArrayList<IEditorPart> affectedEditors = new ArrayList<IEditorPart>(dirtyEditors.length);

		for (IEditorPart part : dirtyEditors) {
			IEditorInput input = part.getEditorInput();

			if (input instanceof IFileEditorInput) {
				IJavaElement javaPackage = JavaCore.create(((IFileEditorInput) input).getFile().getParent());
				if (javaPackage == null) {
					continue;
				}

				String packageName = javaPackage.getElementName();
				String fileName = input.getName();
				String fullName = packageName + "." + fileName;

				if (packageElements.contains(fullName)) {
					affectedEditors.add(part);
				}
{'fraction_non_alphanumeric': 0.10556186152099886, 'fraction_numerical': 0.0005675368898978433, 'mean_word_length': 5.369879518072289, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6965406', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1525, 'n_words': 299}