<commit_before>package eu.scasefp7.eclipse.core.handlers;

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.services.IServiceLocator;

import eu.scasefp7.eclipse.core.Activator;

/**
 * Abstract handler with a convenience method to execute other commands.
 * 
 * @author themis
 */
public abstract class CommandExecutorHandler extends ProjectAwareHandler {

	/**
	 * Executes an existing command.
	 * 
	 * @param commandId the id of the command to be executed, which can reside in other plugins.
	 */
	protected void executeCommand(String commandId) {
		IServiceLocator serviceLocator = PlatformUI.getWorkbench();
		ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
		try {
			Command command = commandService.getCommand(commandId);
			command.executeWithChecks(new ExecutionEvent());
		} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
		    Activator.log("Unable to execute command " + commandId, e);
		}
	}

}<commit_msg>Check whether the commands to be executed exist<commit_after>package eu.scasefp7.eclipse.core.handlers;

import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.services.IServiceLocator;

import eu.scasefp7.eclipse.core.Activator;

/**
 * Abstract handler with a convenience method to execute other commands.
 * 
 * @author themis
 */
public abstract class CommandExecutorHandler extends ProjectAwareHandler {

	/**
	 * Executes a command if it exists. Returns {@code true} if the command exists or {@code false} otherwise. Note that
	 * if the command exists but is not executed correctly (e.g. it is not enabled), this function still returns
	 * {@code true}.
	 * 
	 * @param commandId the id of the command to be executed, which can reside in other plugins.
	 * @return {@code true} if the command exists or {@code false} otherwise.
	 */
	protected boolean executeCommand(String commandId) {
		IServiceLocator serviceLocator = PlatformUI.getWorkbench();
		ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class);
		if (commandService.getDefinedCommandIds().contains(commandId)) {
			try {
				Command command = commandService.getCommand(commandId);
				command.executeWithChecks(new ExecutionEvent());
			} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
				Activator.log("Unable to execute command " + commandId, e);
			}
			return true;
		} else
			return false;
	}

}
{'fraction_non_alphanumeric': 0.09099378881987577, 'fraction_numerical': 0.0012422360248447205, 'mean_word_length': 5.170498084291188, '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': '4631931', 'n_tokens_mistral': 922, 'n_tokens_neox': 875, 'n_words': 238}