<commit_before>/**
 * Copyright 2013-2018 the original author or authors from the JHipster project.
 * 
 * This file is part of the JHipster project, see http://www.jhipster.tech/
 * for more information.
 * 
 * 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 io.github.jhipster.jdl.validation

import com.google.inject.Inject
import io.github.jhipster.jdl.jdl.JdlApplicationConfig
import io.github.jhipster.jdl.jdl.JdlDeployment
import io.github.jhipster.jdl.jdl.JdlDomainModel
import io.github.jhipster.jdl.jdl.JdlEntity
import io.github.jhipster.jdl.jdl.JdlEnum
import io.github.jhipster.jdl.jdl.JdlRelationships
import io.github.jhipster.jdl.services.JDLGrammarAccess
import java.util.Collections
import java.util.concurrent.atomic.AtomicBoolean
import java.util.stream.Collectors
import java.util.stream.IntStream
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.EValidatorRegistrar

import static io.github.jhipster.jdl.jdl.JdlPackage.Literals.*
import static io.github.jhipster.jdl.validation.IssueCodes.*
import static org.apache.commons.lang3.StringUtils.*
import static org.eclipse.xtext.EcoreUtil2.*
import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.*

/**
 * @author <NAME> - Initial contribution and API
 */
class JdlLint extends AbstractDeclarativeValidator {
	
	@Inject JDLGrammarAccess ga

	override register(EValidatorRegistrar registrar) {
	}

	@Check
	def void checkApplicationParametersUniqueness(JdlApplicationConfig config) {
		val set = newHashSet
		config.paramters.map[
			it.paramName.literal
		].forEach[ p, i |
			if (!set.add(p)) error(
				String.format(INVALID_PARAM_NOTUNIQUE_MSG, p), JDL_APPLICATION_CONFIG__PARAMTERS, i
			)
		]
	}

	@Check
	def void checkDeploymentParametersUniqueness(JdlDeployment deployment) {
		val set = newHashSet
		deployment.paramters.map[
			it.paramName.literal
		].forEach[ p, i |
			if (!set.add(p)) error(
				String.format(INVALID_PARAM_NOTUNIQUE_MSG, p), JDL_DEPLOYMENT__PARAMTERS, i
			)
		]
	}

	@Check
	def void checkForGroupableRelationships(JdlRelationships relations) {
		val set = newHashSet
		set.add(relations.cardinality)
		val model = getContainerOfType(relations, JdlDomainModel)
		model.features.filter(JdlRelationships).forEach[ r, i |
			if (!set.add(r.cardinality)) info(
				String.format(FOUND_GROUPABLE_RELATIONSHIP_MSG, r.cardinality), JDL_RELATIONSHIPS__RELATIONSHIPS, i
			)
		]
	}
	
	@Check
	def void checkRelationshipUniqueness(JdlRelationships relations) {
		val set = newHashSet
		relations.relationships.filter[<commit_msg>changed groupable validation to warning according to MAA<commit_after>/**
 * Copyright 2013-2018 the original author or authors from the JHipster project.
 * 
 * This file is part of the JHipster project, see http://www.jhipster.tech/
 * for more information.
 * 
 * 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 io.github.jhipster.jdl.validation

import com.google.inject.Inject
import io.github.jhipster.jdl.jdl.JdlApplicationConfig
import io.github.jhipster.jdl.jdl.JdlDeployment
import io.github.jhipster.jdl.jdl.JdlDomainModel
import io.github.jhipster.jdl.jdl.JdlEntity
import io.github.jhipster.jdl.jdl.JdlEnum
import io.github.jhipster.jdl.jdl.JdlRelationships
import io.github.jhipster.jdl.services.JDLGrammarAccess
import java.util.Collections
import java.util.concurrent.atomic.AtomicBoolean
import java.util.stream.Collectors
import java.util.stream.IntStream
import org.eclipse.emf.ecore.EObject
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.EValidatorRegistrar

import static io.github.jhipster.jdl.jdl.JdlPackage.Literals.*
import static io.github.jhipster.jdl.validation.IssueCodes.*
import static org.apache.commons.lang3.StringUtils.*
import static org.eclipse.xtext.EcoreUtil2.*
import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.*

/**
 * @author <NAME> - Initial contribution and API
 */
class JdlLint extends AbstractDeclarativeValidator {
	
	@Inject JDLGrammarAccess ga

	override register(EValidatorRegistrar registrar) {
	}

	@Check
	def void checkApplicationParametersUniqueness(JdlApplicationConfig config) {
		val set = newHashSet
		config.paramters.map[
			it.paramName.literal
		].forEach[ p, i |
			if (!set.add(p)) error(
				String.format(INVALID_PARAM_NOTUNIQUE_MSG, p), JDL_APPLICATION_CONFIG__PARAMTERS, i
			)
		]
	}

	@Check
	def void checkDeploymentParametersUniqueness(JdlDeployment deployment) {
		val set = newHashSet
		deployment.paramters.map[
			it.paramName.literal
		].forEach[ p, i |
			if (!set.add(p)) error(
				String.format(INVALID_PARAM_NOTUNIQUE_MSG, p), JDL_DEPLOYMENT__PARAMTERS, i
			)
		]
	}

	@Check
	def void checkForGroupableRelationships(JdlRelationships relations) {
		val set = newHashSet
		set.add(relations.cardinality)
		val model = getContainerOfType(relations, JdlDomainModel)
		model.features.filter(JdlRelationships).forEach[ r, i |
			if (!set.add(r.cardinality)) warning(
				String.format(FOUND_GROUPABLE_RELATIONSHIP_MSG, r.cardinality), JDL_RELATIONSHIPS__RELATIONSHIPS, i
			)
		]
	}
	
	@Check
	def void checkRelationshipUniqueness(JdlRelationships relations) {
		val set = newHashSet
		relations.relationships.filter[
{'fraction_non_alphanumeric': 0.08931917551530294, 'fraction_numerical': 0.004372267332916927, 'mean_word_length': 4.77027027027027, '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': '1376312', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2031, 'n_words': 486}