<commit_before>/******************************************************************************
 * Copyright (c) 2000-2015 Ericsson Telecom AB
 * 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.titan.designer.AST.brokenpartsanalyzers;

import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;

/**
 * Helper class to check broken parts.
 *
 * @author <NAME>
 */
public final class BrokenPartsChecker {

	private final SubProgressMonitor semanticMonitor;

	private final IProgressMonitor monitor;

	private final CompilationTimeStamp compilationCounter;

	private final SelectionMethodBase selectionMethod;

	public BrokenPartsChecker(final IProgressMonitor monitor, final CompilationTimeStamp compilationCounter, final SelectionMethodBase selectionMethod) {
		this.compilationCounter = compilationCounter;
		this.selectionMethod = selectionMethod;
		this.monitor = monitor;
		semanticMonitor = new SubProgressMonitor(this.monitor, 1);
	}

	public void doChecking() {
		monitor.subTask("Semantic checking");
		
		switch (selectionMethod.getSelectionAlgorithm()) {
			case MODULESELECTIONORIGINAL:
				generalChecker();
				break;
			case BROKENREFERENCESINVERTED:
				BrokenPartsViaReferences brokenParts = (BrokenPartsViaReferences)selectionMethod;
				if (brokenParts.getAnalyzeOnlyDefinitions()) {
					Map<Module, List<Assignment>> moduleAndBrokenDefinitions = brokenParts.getModuleAndBrokenDefs();
					definitionsChecker(moduleAndBrokenDefinitions);
				} else {
					generalChecker();
				}
				break;
			default:
				generalChecker();
				break;
		}
		
		
		
		monitor.subTask("Doing post semantic checks");

		for (Module module : selectionMethod.getModulesToCheck()) {
			module.postCheck();
		}
		
		semanticMonitor.done();
	}
	//TODO check if this can be merged with the following one
	private void generalChecker() {
		semanticMonitor.beginTask("Semantic check", selectionMethod.getModulesToCheck().size());
		// process the modules one-by-one
		for (final Module module : selectionMethod.getModulesToCheck()) {
			semanticMonitor.subTask("Semantically checking module: " + module.getName());
			module.check(compilationCounter);
			semanticMonitor.worked(1);
		}
	}

	private void definitionsChecker(final Map<Module, List<Assignment>> moduleAndBrokenDefs) {
		semanticMonitor.beginTask("Semantic check", moduleAndBrokenDefs.size());

		for (Map.Entry<Module, List<Assignment>> entry : moduleAndBrokenDefs.entrySet()) {
			Module module = entry.getKey();

			semanticMonitor.subTask("Semantically checking broken parts in module: " + module.getName());

			if (module instanceof TTCN3Module) {
				((TTCN3Module) module).checkWithDefinitions(compilationCounter, entry.getValue());
			} else {
				module.check(compilationCounter);
			}
			semanticMonitor.worked(1);<commit_msg>the module skipping functionality is only used by one of the selection methods, so move it there.<commit_after>/******************************************************************************
 * Copyright (c) 2000-2015 Ericsson Telecom AB
 * 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.titan.designer.AST.brokenpartsanalyzers;

import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.titan.designer.AST.Assignment;
import org.eclipse.titan.designer.AST.Module;
import org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;

/**
 * Helper class to check broken parts.
 *
 * @author <NAME>
 */
public final class BrokenPartsChecker {

	private final SubProgressMonitor semanticMonitor;

	private final IProgressMonitor monitor;

	private final CompilationTimeStamp compilationCounter;

	private final SelectionMethodBase selectionMethod;

	public BrokenPartsChecker(final IProgressMonitor monitor, final CompilationTimeStamp compilationCounter, final SelectionMethodBase selectionMethod) {
		this.compilationCounter = compilationCounter;
		this.selectionMethod = selectionMethod;
		this.monitor = monitor;
		semanticMonitor = new SubProgressMonitor(this.monitor, 1);
	}

	public void doChecking() {
		monitor.subTask("Semantic checking");
		
		switch (selectionMethod.getSelectionAlgorithm()) {
			case MODULESELECTIONORIGINAL:
				generalChecker();
				break;
			case BROKENREFERENCESINVERTED:
				BrokenPartsViaReferences brokenParts = (BrokenPartsViaReferences)selectionMethod;
				if (brokenParts.getAnalyzeOnlyDefinitions()) {
					Map<Module, List<Assignment>> moduleAndBrokenDefinitions = brokenParts.getModuleAndBrokenDefs();
					definitionsChecker(moduleAndBrokenDefinitions);
				} else {
					generalChecker();
				}
				break;
			default:
				generalChecker();
				break;
		}
		
		
		
		monitor.subTask("Doing post semantic checks");

		for (Module module : selectionMethod.getModulesToCheck()) {
			module.postCheck();
		}
		
		semanticMonitor.done();
	}
	//TODO check if this can be merged with the following one
	private void generalChecker() {
		semanticMonitor.beginTask("Semantic check", selectionMethod.getModulesToCheck().size());
		
		for (Module module : selectionMethod.getModulesToSkip()) {
			module.setSkippedFromSemanticChecking(true);
		}
		for (Module module : selectionMethod.getModulesToCheck()) {
			module.setSkippedFromSemanticChecking(false);
		}

		// process the modules one-by-one
		for (final Module module : selectionMethod.getModulesToCheck()) {
			semanticMonitor.subTask("Semantically checking module: " + module.getName());
			module.check(compilationCounter);
			semanticMonitor.worked(1);
		}

		for (final Module module : selectionMethod.getModulesToSkip()) {
			module.setSkippedFromSemanticChecking(false);
		}
	}

	private void definitionsChecker(final Map<Module, List<Assignment>> moduleAndBrokenDefs) {
		semanticMonitor.beginTask("Semantic check", moduleAndBrokenDefs.size());

		for (Map.Entry<Module, List<Assignment>> entry : moduleAndBrokenDefs.entrySet()) {
			Module module = entry.getKey();

			semanticMonitor.subTask("Semantically checking broken parts in module: " + module.getName());

			if (module instanceof TTCN3Module) {
				((TTCN3Module) module).checkWithDefinitions(compilationCounter, entry.getValue());
			} else {
				module.check(compilationCounter);
			}
			semanticMonitor.worked(1);
{'fraction_non_alphanumeric': 0.13495239409410792, 'fraction_numerical': 0.005243549054781289, 'mean_word_length': 5.37467018469657, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3234427', 'n_tokens_mistral': 2235, 'n_tokens_neox': 1966, 'n_words': 447}