<commit_before>/*******************************************************************************
 * Copyright (c) 2015 itemis AG (http://www.itemis.eu) 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
 *******************************************************************************/
package org.eclipse.xtext.generator

import org.eclipse.emf.ecore.resource.Resource
import com.google.inject.ImplementedBy
import com.google.inject.Inject
import org.eclipse.xtext.validation.IResourceValidator
import org.eclipse.xtext.validation.CheckMode
import org.eclipse.xtext.util.CancelIndicator
import com.google.common.annotations.Beta

/**
 * @author <NAME> - Initial contribution and API
 * 
 * @since 2.9
 */
@Beta
@ImplementedBy(OnlyWithoutErrors)
interface IShouldGenerate {
	
	/**
	 * whether code should be generated for this resource.
	 */
	def boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator);
	
	@Beta
	static class OnlyWithoutErrors implements IShouldGenerate {
		
		@Inject IResourceValidator resourceValidator
		
		override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
			return resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator).empty
		}
		
	}
	@Beta
	static class Always implements IShouldGenerate {
		
		override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
			return true
		}
		
	}
}<commit_msg>fixed IShouldGenerate.OnlyOnError<commit_after>/*******************************************************************************
 * Copyright (c) 2015 itemis AG (http://www.itemis.eu) 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
 *******************************************************************************/
package org.eclipse.xtext.generator

import com.google.common.annotations.Beta
import com.google.inject.ImplementedBy
import com.google.inject.Inject
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.diagnostics.Severity
import org.eclipse.xtext.util.CancelIndicator
import org.eclipse.xtext.validation.CheckMode
import org.eclipse.xtext.validation.IResourceValidator

/**
 * @author <NAME> - Initial contribution and API
 * 
 * @since 2.9
 */
@Beta
@ImplementedBy(OnlyWithoutErrors)
interface IShouldGenerate {
	
	/**
	 * whether code should be generated for this resource.
	 */
	def boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator);
	
	@Beta
	static class OnlyWithoutErrors implements IShouldGenerate {
		
		@Inject IResourceValidator resourceValidator
		
		override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
			if (!resource.errors.isEmpty)
				return false
			val issues = resourceValidator.validate(resource, CheckMode.NORMAL_AND_FAST, cancelIndicator)
			return !issues.exists[severity == Severity.ERROR]
		}
		
	}
	@Beta
	static class Always implements IShouldGenerate {
		
		override shouldGenerate(Resource resource, CancelIndicator cancelIndicator) {
			return true
		}
		
	}
}
{'fraction_non_alphanumeric': 0.1667156718612173, 'fraction_numerical': 0.005880623346074684, 'mean_word_length': 5.323420074349443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2407954', 'n_tokens_mistral': 930, 'n_tokens_neox': 854, 'n_words': 235}